cabbagejs / cabbage

A CLI for building conventional web applications with Broccoli
MIT License
5 stars 0 forks source link

A function in the page context #27

Open TravisTheTechie opened 9 years ago

TravisTheTechie commented 9 years ago

So I have a given config/application.js

module.exports = function() {
  //Override application configuration here.
  return {
    // Add properties to pages.context to make them available in app/pages
    //
    pages: {
      context: {
        title: "Some title here",
        bonus: "What's that?",
        bonusFunction: function() { return "Hi there!"; }
      }
    }
  };
};

And the following app/pages/index.us works successfully:

<!DOCTYPE html>
<html>
  <head>
    <title><%= title %></title>

    <link rel="stylesheet" type="text/css" href="<%= css %>" media="all" />
  </head>
  <body>
    <h1> <%= bonus %>! </h1>

    <script type="text/javascript" src="<%= js %>"></script>
  </body>
</html>

But if I add in a reference to bonusFunction() I get an error...

Built with error:
File: cabbage/app/pages/index.us
TypeError: object is not a function
  at eval (<anonymous>:11:9)
  at template (~/src/cabbagejs/cabbage/node_modules/underscore/underscore.js:1336:21)
  at ServerSideTemplateFilter.module.exports.ServerSideTemplateFilter.processString (~/src/cabbagejs/cabbage/lib/plugins/server-side-templates.coffee:14:5)
  at ServerSideTemplateFilter.Filter.processFile (~/src/cabbagejs/cabbage/node_modules/broccoli-filter/index.js:136:31)
  at Promise.resolve.then.catch.err.file (~/src/cabbagejs/cabbage/node_modules/broccoli-filter/index.js:82:21)
  at $$$internal$$tryCatch (~/src/cabbagejs/cabbage/node_modules/broccoli-filter/node_modules/rsvp/dist/rsvp.js:470:16)
  at $$$internal$$invokeCallback (~/src/cabbagejs/cabbage/node_modules/broccoli-filter/node_modules/rsvp/dist/rsvp.js:482:17)
  at /Users/tsmith/src/cabbagejs/cabbage/node_modules/broccoli-filter/node_modules/rsvp/dist/rsvp.js:1066:13
  at $$rsvp$asap$$flush (~/src/cabbagejs/cabbage/node_modules/broccoli-filter/node_modules/rsvp/dist/rsvp.js:1531:9)
  at process._tickCallback (node.js:419:13)

And if I JSON.stringify(bonusFunction()), it's just {}. Which is kinda odd, since

-> JSON.stringify(function () { return "A"; });
<- undefined
searls commented 9 years ago

Huh.