monokrome / jaded-brunch

Jade for brunch, supporting both dynamic and static loading jade.
MIT License
23 stars 10 forks source link

Allow for passing in options to the template #12

Closed daviesgeek closed 9 years ago

daviesgeek commented 9 years ago

It would be really nice to allow data to be passed from the config into the compiler via the options object for the plugin.

daviesgeek commented 9 years ago

I submitted a pull request adding this feature. You can now pass in locals to the jade compiler via the plugin config like this:

plugins: {
  jade: {
    pretty: true,

    // These will all get passed to the template
    locals: {
      enviroment: 'development',
      magic: true
    }
  }
}

Then in your template you can use the data that was passed in:

if magic == true
  h1 Magic is on
else
  h1 Magic is off
monokrome commented 9 years ago

Hey, @daviesgeek. Thanks for sending over this pull request.

This looks like a duplicate of https://github.com/monokrome/jaded-brunch/pull/11. Would you mind helping me verify whether my comment on that issue solves the problem for you without additional code changes?

daviesgeek commented 9 years ago

Hi @monokrome.

It is a duplicate of #11. I do apologize, as I forgot to check the PRs, I only checked the issues. It does not solve my problem. On line 138, the wrapped template function (from jade) is being called without passing anything in. Thus, no data will ever get to the template because nothing is being passed in.

Either #11 or #12 should address the issue.

daviesgeek commented 9 years ago

Any update on this?

daviesgeek commented 9 years ago

Closed due to https://github.com/monokrome/jaded-brunch/pull/13#issuecomment-71337811

monokrome commented 9 years ago

@daviesgeek I want to make sure that this issue has been resolved and is working as you would expect. Is everything good now, or is there something else that we should be considering here? Please feel free to reopen the issue if something is still outstanding!

daviesgeek commented 9 years ago

Whoops. Thought this needed reopening. But nevermind :)

I was able to pass options to the template like this:

plugins: {
  jaded: {
    pretty: true,
    locals: {
      environment: 'development',
      magic: true
    }
  }
}

Thanks! Works great!

monokrome commented 9 years ago

Cool. I was worried that I merged something bad when I saw that it was reopened. Glad to see it's working as expected! This should work, too - I think:

plugins: {
  jaded: {
    jade: {
      pretty: true,
      locals: {
        environment: 'development',
        magic: true
      }
    }
  }
}