Comments (26)
Hi Jamie,
Any property you define in contents/shared.json
is made available to all pages. By default a shared.json
file is created when you run punch setup
, which sets site-wide properties like the site title.
Is this what you're looking for?
from punch.
That's exactly what I'm after, thanks. Just for the record, when I run punch setup
the shared.json
file doesn't get generated, no biggie.
On a similar subject, how would I go about creating functions on the view for example a {{#nav}}{{/nav}}
block that had a {{current}}
property that was true or false depending if you were on the current page. Are there any hooks for this kind of thing?
from punch.
What's the version of Punch you are using? (run punch v
). From 0.4, the
default site generated from punch setup
will also include shared.json
file.
On a similar subject, how would I go about creating functions on the view
for example a {{#nav}}{{/nav}} block that had a {{current}} property that
was true or false depending if you were on the current page. Are there any
hooks for this kind of thing?
You can implement a custom helper to generate the link tags. There you can
check for the links that matches the current path and add a special class,
like "current". Take a look at asset_bundle_helper.js
for a similar implementation.
from punch.
Apologies, I wasn't on the latest release, that's great.
Thanks, helpers look like the solution to custom blocks. Where would I put these for them to get picked up? ...sorry for the dumb questions but the helpers page in the Wiki is currently blank.
from punch.
One last question, after upgrading my public files are not getting served e.g. /css/screen.css
?
from punch.
Keep those questions coming. That'll help me to figure out what needs
attention in the documentation (I'll be committing this weekend to finish
the guide).
You can place the custom helpers in anywhere in the project (I would
suggest to create a directory named helpers
to keep them together). Then,
you need to define the path in the config.json
. Check the helpers section
in this example.
On Fri, Sep 7, 2012 at 5:57 PM, Jamie Hill [email protected] wrote:
Apologies, I wasn't on the latest release, that's great.
Thanks, helpers look like the solution to custom blocks. Where would I put
these for them to get picked up? ...sorry for the dumb questions but the
helpers page in the Wiki is currently blank.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/24#issuecomment-8363795.
from punch.
Are they placed in templates
directory? You should keep all static assets
in the templates
directory (in this case there should be a css
directory inside templates
).
On Fri, Sep 7, 2012 at 6:12 PM, Jamie Hill [email protected] wrote:
One last question, after upgrading my public files are not getting served
e.g. /css/screen.css?—
Reply to this email directly or view it on GitHubhttps://github.com//issues/24#issuecomment-8364096.
from punch.
Excellent, that clears that up. I was previously just putting my assets, images etc. in the public directory (like in Rails) and they were getting found, I've moved them to the templates dir and all is fine.
One thing I would say is that having to have all the images etc. in the template directory means that you are effectively doubling the size of your project on disk as they all just get copied to the public directory anyway.
from punch.
Public directory (or the output directory) is used only to preview the site during the development or to upload the generated site to a remote server. So if you are not actively working on a site, you can simply delete its public
directory.
Also, having static assets in templates would make it easy to switch the design of a site, by just replacing the templates directory.
from punch.
I see the reasoning now, so you could basically ignore the public directory entirely in a git project and just run punch generate
on the server. Great, thanks for your help on these bits and pieces.
from punch.
Sorry to be a pain... on the subject of setting a current
class on a nav item using a helper, this becomes very messy, very fast, with a block tag requiring some custom syntax e.g. {{#nav_item}}About:/about{{/nav_item}}
. That becomes worse when you want to include things like class
attributes etc. on the tag.
What would be nicer is being able to just insert a current
boolean into the view object dynamically i.e:
View
{
"nav": [
{ "label": "Home", "class": "home", "href": "/" },
{ "label": "About Us", "class": "about-us", "href": "/about", "current": true } // 'current' inserted dynamically
]
}
Template
<nav>
<ul>
{{#nav}}
<li class="n-{{class}}{{#current}}current{{/current}}"><a href="#">{{label}}</a>
{{/nav}}
</ul>
</nav>
I can't see a way of doing this with the current setup, am I missing something?
from punch.
Did you check the Current Page Helper plugin? https://github.com/laktek/punch-current-page-helper
Follows a very similar syntax to what you suggest, only you have to pass the URL between the section tags {{#current}}..{{/current}}.
from punch.
Ah, I didn't see that one, thanks. What's the best way to install plugins other than just copying the code into a helper?
from punch.
Every Plugin's README provides the necessary steps to install. Basically,
you need install the plugin (using npm) inside your project directory and
then define it in the config.json.
On Sun, Nov 18, 2012 at 11:53 PM, Jamie Hill [email protected]:
Ah, I didn't see that one, thanks. What's the best way to install plugins
other than just copying the code into a helper?—
Reply to this email directly or view it on GitHubhttps://github.com//issues/24#issuecomment-10489296.
from punch.
Great, thanks.
from punch.
Slight problem with that approach, what if you already have classes on your tag and therefore need a space before it?
from punch.
Yep..you will need to keep a space in between.
On Mon, Nov 19, 2012 at 12:05 AM, Jamie Hill [email protected]:
Slight problem with that approach, what if you already have classes on
your tag and therefore need a space before it?—
Reply to this email directly or view it on GitHubhttps://github.com//issues/24#issuecomment-10489460.
from punch.
But then, you will end up with a space even when not using the current
class e.g. class="other-class "
.
from punch.
Hmm..true. I'll see if I could improve it in a way so there won't be a need
to keep spaces.
On Mon, Nov 19, 2012 at 12:09 AM, Jamie Hill [email protected]:
But then, you will end up with a space even when not using the currentclass e.g. class="other-class
".—
Reply to this email directly or view it on GitHubhttps://github.com//issues/24#issuecomment-10489508.
from punch.
I still think the best option is to allow hooking into the content object.
from punch.
@thelucid and @laktek I'm not much of a HTML + CSS person, but sometimes I leave spaces in my class definitions for this reason (either with punch or other frameworks like Django)
What is the downside of leaving spaces? Is it aesthetic or can it cause parse problems?
from punch.
@jtrain Both, I like to keep markup as clean as possible and have experienced validation issues in the past.
@laktek How do you feel about some kind of system whereby you could hook into the content for a request e.g.
module.exports = {
after: function(request, content) {
content['some_key'] = 'some value';
}
};
Not sure about the method name after
but hopefully you get the idea. How easy would this be to implement?
from punch.
@thelucid This is part of what helpers do. It extends the content (for more straightforward example check, Third Party Snippets Helper ).
However, in this case of adding something like a current flag to a link within a list, Punch has to be aware of the structure of the content and modify it. That's not practical because different users will choose different structures for their content.
from punch.
I'm not saying that Punch should implement the 'current' functionality itself, just a generic hook that allows users like myself to manipulate the content before it gets handed to the template. The callback that manipulated the content could be given access to the request as per my example. I see uses other than the 'current' flag.
from punch.
Helpers do have access to the request. However, it's not aware of the rest of the content model. Have to see whether it can be accommodated with helpers itself, or should we need a new type of a hook.
If you're interested to dig deeper on this idea, please go ahead.
from punch.
I'm closing this thread. It's better to move any further discussions about exposing content to helpers in to a separate issue.
from punch.
Related Issues (20)
- TypeError: Cannot call method 'getTime' of null HOT 5
- Ability to add self-contained widgets (css, js, template) HOT 2
- Issues displaying {{date}} HOT 2
- style failed to compile HOT 2
- Cannot start server Connect has no method 'logger' HOT 1
- Can't get this working in a docker container
- Pulling bundle assets from outside local directory
- Punch Plugin: How to find the file path to the "templates" directory? HOT 2
- S3 gzip support
- Failed to read the configurations. HOT 1
- Copy command fails with paths that contain spaces HOT 1
- Failing basic setup HOT 2
- Trouble Implementing Autoprefixer compiler/minifier
- is this still happening? HOT 1
- Themes?
- What is the best practice for i18n?
- Creating intro.markdown in contents/_index during tutorial doesn't render the HTML HOT 1
- Custom compiler works only on generate HOT 4
- Javascript does not bundle HOT 1
- Mime.extension and Mime.lookup is not a function HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from punch.