Coder Social home page Coder Social logo

Default content about punch HOT 26 CLOSED

laktek avatar laktek commented on June 16, 2024
Default content

from punch.

Comments (26)

laktek avatar laktek commented on June 16, 2024

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.

thelucid avatar thelucid commented on June 16, 2024

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.

laktek avatar laktek commented on June 16, 2024

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.

thelucid avatar thelucid commented on June 16, 2024

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.

thelucid avatar thelucid commented on June 16, 2024

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

from punch.

laktek avatar laktek commented on June 16, 2024

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.

laktek avatar laktek commented on June 16, 2024

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.

thelucid avatar thelucid commented on June 16, 2024

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.

laktek avatar laktek commented on June 16, 2024

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.

thelucid avatar thelucid commented on June 16, 2024

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.

thelucid avatar thelucid commented on June 16, 2024

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.

laktek avatar laktek commented on June 16, 2024

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.

thelucid avatar thelucid commented on June 16, 2024

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.

laktek avatar laktek commented on June 16, 2024

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.

thelucid avatar thelucid commented on June 16, 2024

Great, thanks.

from punch.

thelucid avatar thelucid commented on June 16, 2024

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

from punch.

laktek avatar laktek commented on June 16, 2024

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.

thelucid avatar thelucid commented on June 16, 2024

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

from punch.

laktek avatar laktek commented on June 16, 2024

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.

thelucid avatar thelucid commented on June 16, 2024

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

from punch.

jtrain avatar jtrain commented on June 16, 2024

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

thelucid avatar thelucid commented on June 16, 2024

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

laktek avatar laktek commented on June 16, 2024

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

thelucid avatar thelucid commented on June 16, 2024

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.

laktek avatar laktek commented on June 16, 2024

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.

laktek avatar laktek commented on June 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.