Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nap is attached to global scope. #2

Open
monokrome opened this issue Jan 6, 2014 · 9 comments
Open

Nap is attached to global scope. #2

monokrome opened this issue Jan 6, 2014 · 9 comments
Assignees

Comments

@monokrome
Copy link
Contributor

As avoiding globals is a generally good practice, it'd make more sense to attach the nap object to env.helpers such as done in wintersmith-livereload.

@aularon
Copy link
Contributor

aularon commented Jan 6, 2014

I will look into this today. Thanks!

@ghost ghost assigned aularon Jan 6, 2014
@monokrome
Copy link
Contributor Author

Thank you!

@aularon
Copy link
Contributor

aularon commented Jan 9, 2014

Apparently env.helpers is not exposed inside templates, so for now I am sticking with the ugly global. solution 😞

@aularon
Copy link
Contributor

aularon commented Jan 9, 2014

And the latest jade totally hides global objects inside template, which is good, but now one has to call global.nap, I am looking into wintersmith on how to add a function/object to be accessible from within views.

@aularon
Copy link
Contributor

aularon commented Jan 9, 2014

Found a method utilizing wintersmith's env.locals, works like a charm! 😎

@aularon aularon closed this as completed Jan 9, 2014
@monokrome
Copy link
Contributor Author

env.helpers is exposed in templates. If it wasn't, that livereload plugin wouldn't work. It creates a function that injects a script into the HTML.

@aularon
Copy link
Contributor

aularon commented Jan 10, 2014

mmm I see, but you have to call it as !{ env.helpers.livereload() }, instead of directly as in != nap.css('main').
The env.locals is exposed in templates so one can directly call != nap.css('main'), I believe this is better.

I am going to open an issue on wintersmith asking whether using env.locals this way is good, and won't break in the future.

@monokrome
Copy link
Contributor Author

The env.locals is not as good, because there is potential that a specific template can override them. The env.locals variable (if I understand correctly) will potentially be overridden with context data from the template being rendered. However, env.helpers doesn't have this issue.

For instance, if I had a template:

jade.compileClient('something, { locals: { nap: true } });

The nap variable would now be set to true at the template level, but this wouldn't be the case with env.helpers. I specifically referenced the LiveReload plugin, because it is written by the same person who wrote WinterSmith itself. I expect that is the expected use case for WinterSmith due to this, but may be assuming too much?

The issue here is that locals is intended for transient template variables, while it makes more sense from a development standpoint for things like nap to be accessible in the env via something like env.helpers.

@aularon aularon reopened this Jan 19, 2014
@aularon
Copy link
Contributor

aularon commented Jan 19, 2014

Sorry for the late reply, I am having electricity blackouts where I live that I am barely keeping up with my TODOs.

I will make it as an option in the config object, if set to true, it will make it to env.locals. It will be false be default (So it will be only present in env.helpers by default).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants