Skip to content

Instantly share code, notes, and snippets.

@reaktivo
Created July 15, 2012 01:21
Show Gist options
  • Save reaktivo/3114250 to your computer and use it in GitHub Desktop.
Save reaktivo/3114250 to your computer and use it in GitHub Desktop.
Expose jade templares
app = require '../app'
require 'express-expose'
jade = require 'jade'
path = require 'path'
fs = require 'fs'
cache = {}
scriptWrap = (src) ->
"<script>#{src}</script>"
app.helpers
view: (viewName) ->
if process.env.NODE_ENV is not "production" or !cache[viewName]
filepath = path.join app.settings.views, viewName + ".jade"
console.log filepath
source = fs.readFileSync filepath
compiled = jade.compile source,
client: true
compileDebug: false
cache[viewName] = scriptWrap "app.templates['#{viewName}'] = #{compiled.toString()}"
cache[viewName]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment