npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reshape-define-locals

v0.2.1

Published

Define locals for your reshape files inline

Downloads

3

Readme

Reshape Define Locals

NPM Version Build Status

Define and append locals inside your reshape/sugarml files. Supports YAML and scoping. Be sure to read Gotchas

<div class='just-some-div'>
  <define-locals>
    options:
    - one
    - two
    - three
  </define-locals>

  <p>{{ options.join(', ') }}</p>
</div>

Installation

$ npm i -S reshape-define-locals

Usage

const reshape = require('reshape')
const expressions = require('reshape-expressions')
const defineLocals = require('reshape-define-locals')

const source = `<define-locals>
  paraContent: 'This is my paragraph.'
</define-locals>
<p class="{{ paraClass }}">{{ file.paraContent }}</p>`
  const config = {locals: {paraClass: 'center'}}

const actual = await reshape({
  plugins: [defineLocals(config), expressions(config)]
}).process(source)

Configuration

{
  tag: 'define-locals',
  scope: 'file',
  locals
}

tag

string, default: 'define-locals'

This is the tag that is parsed as locals.

scope

string or false, default: 'file'

All locals blocks are parsed and available as locals.file, or simply file in your templates. Using usage example, you can set scope to false and the you'll be able to use {{ paraContent }} only. This will keep data between files until they are overwritten, so be sure to read gotchas.

locals

object, default: {}

Locals coming from your application.

Gotchas

My locals defined as a direct descendand of "extends" aren't loaded

As far as I can tell, only named blocks are processed in extends, so either define your locals before extends, or in the named block.

<!-- this won't work -->
<extends src='layout.html'>
  <define-locals>
    key: value
  </define-locals>
  <block name='content'>
    <p>{{ file.key }}</p>
  </block>
</extends>

<!-- this will -->
<define-locals>
  key: value
</define-locals>
<extends src='layout.html'>
  <block name='content'>
    <p>{{ file.key }}</p>
  </block>
</extends>

<!-- this will as well -->
<extends src='layout.html'>
  <block name='content'>
    <define-locals>
      key: value
    </define-locals>
    <p>{{ file.key }}</p>
  </block>
</extends>

Old locals are available until changed when using unscoped locals

The simplest way to actually bring the data from your define-locals block to reshape is to modify original locals object. What this means though, is that keys unchanged between files stay the same, meaning that, if file-1.html defines local property key to value and file-2.html doesn't, if you call {{ key }} in file-2.html, you will probably not get undefined. Since there isn't particular order in which are files processed, at least with Spike, the data may bleed over, or it may not, depending on the file order.

What this means in practice: you need to reset data between different files yourself, or not be dependent on non-existence of some data.

License

MIT, © 2018 Adam Kiss