jsantell / poet

A node.js blog engine
jsantell.github.io/poet
MIT License
605 stars 146 forks source link

compatibility issues with asset-rack #30

Open max-degterev opened 11 years ago

max-degterev commented 11 years ago

It looks like if you instantiate poet before modules that affect express "local" templating scope they fail to initialize properly

An example.

Works:

# Middleware
app.use(assets)
app.use(express.static(__dirname + '/public'))

# Global vars for templates
app.locals.pretty = config.debug
app.locals.helpers = require('./app/helpers') # template helpers etc
app.locals.__env =
  hostname: config.hostname
  debug: config.debug
  ga_id: config.ga_id
  version: require('./package').version

poet = Poet(app,
  postsPerPage: config.blog.per_page
  posts: __dirname + '/posts'
  metaFormat: 'json'
  routes:
    '/blog/read/:post':   'post'
    '/blog/:page':        'page'
    '/blog/tag/:tag':     'tag'
)

# Init routing
poet.init()
app.use(app.router)
server.initialize(app)

Fails:

poet = Poet(app,
  postsPerPage: config.blog.per_page
  posts: __dirname + '/posts'
  metaFormat: 'json'
  routes:
    '/blog/read/:post':   'post'
    '/blog/:page':        'page'
    '/blog/tag/:tag':     'tag'
)

# Middleware
app.use(assets)
app.use(express.static(__dirname + '/public'))

# Global vars for templates
app.locals.pretty = config.debug
app.locals.helpers = require('./app/helpers') # template helpers etc
app.locals.__env =
  hostname: config.hostname
  debug: config.debug
  ga_id: config.ga_id
  version: require('./package').version

# Init routing
poet.init()
app.use(app.router)
server.initialize(app)
jsantell commented 11 years ago

What fails to initialize properly? The locals (__env, pretty, helpers) are not found in the view templates?

max-degterev commented 11 years ago

asset-rack passes asset object that has methods like asset.tag(filename) to create tags etc. if poet doesnt go last its undefined. Of course you can always re-assing it to locals later. I switched to grunt because it allows greater control over assets compilation so its no longer an issue to me. https://github.com/techpines/asset-rack