Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Default content #24

Closed
ghost opened this issue Sep 7, 2012 · 26 comments
Closed

Default content #24

ghost opened this issue Sep 7, 2012 · 26 comments

Comments

@ghost
Copy link

ghost commented Sep 7, 2012

Hi,

Is there currently any way of implementing default/site-wide content? I'm thinking a defaults.json or site.json file where the contents for each page get deep merged into it to accommodate common site content.

On second thoughts, it wouldn't necessarily even need to be merged, it could just add a site key to the json that is made available to the template.

Is there currently a way to achieve this before I go ahead and look adding it?

@laktek
Copy link
Owner

laktek commented Sep 7, 2012

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?

@ghost
Copy link
Author

ghost commented Sep 7, 2012

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?

@laktek
Copy link
Owner

laktek commented Sep 7, 2012

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.

@ghost
Copy link
Author

ghost commented Sep 7, 2012

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.

@ghost
Copy link
Author

ghost commented Sep 7, 2012

One last question, after upgrading my public files are not getting served e.g. /css/screen.css?

@laktek
Copy link
Owner

laktek commented Sep 7, 2012

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 notifications@github.com 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.

@laktek
Copy link
Owner

laktek commented Sep 7, 2012

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 notifications@github.com 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.

@ghost
Copy link
Author

ghost commented Sep 7, 2012

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.

@laktek
Copy link
Owner

laktek commented Sep 7, 2012

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.

@ghost
Copy link
Author

ghost commented Sep 7, 2012

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.

@ghost ghost closed this as completed Sep 7, 2012
@ghost
Copy link
Author

ghost commented Nov 18, 2012

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?

@ghost ghost reopened this Nov 18, 2012
@laktek
Copy link
Owner

laktek commented Nov 18, 2012

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}}.

@ghost
Copy link
Author

ghost commented Nov 18, 2012

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?

@laktek
Copy link
Owner

laktek commented Nov 18, 2012

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 notifications@github.comwrote:

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.

@ghost
Copy link
Author

ghost commented Nov 18, 2012

Great, thanks.

@ghost
Copy link
Author

ghost commented Nov 18, 2012

Slight problem with that approach, what if you already have classes on your tag and therefore need a space before it?

@laktek
Copy link
Owner

laktek commented Nov 18, 2012

Yep..you will need to keep a space in between.

On Mon, Nov 19, 2012 at 12:05 AM, Jamie Hill notifications@github.comwrote:

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.

@ghost
Copy link
Author

ghost commented Nov 18, 2012

But then, you will end up with a space even when not using the current class e.g. class="other-class ".

@laktek
Copy link
Owner

laktek commented Nov 18, 2012

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 notifications@github.comwrote:

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.

@ghost
Copy link
Author

ghost commented Nov 18, 2012

I still think the best option is to allow hooking into the content object.

@jtrain
Copy link

jtrain commented Nov 23, 2012

@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?

@ghost
Copy link
Author

ghost commented Nov 25, 2012

@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?

@laktek
Copy link
Owner

laktek commented Nov 25, 2012

@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.

@ghost
Copy link
Author

ghost commented Nov 25, 2012

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.

@laktek
Copy link
Owner

laktek commented Nov 25, 2012

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.

@laktek
Copy link
Owner

laktek commented Nov 28, 2012

I'm closing this thread. It's better to move any further discussions about exposing content to helpers in to a separate issue.

@laktek laktek closed this as completed Nov 28, 2012
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants