Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Partials on sub-view folders working. #2

  • Loading branch information...
commit f186fed520f3ded34c80fe0a8acbe482bd98a8d3 1 parent 211ea4e
@quangv authored
Showing with 8 additions and 5 deletions.
  1. +3 −3 cakes/view_partials.coffee
  2. +5 −2 hulk.coffee
View
6 cakes/view_partials.coffee
@@ -11,7 +11,7 @@ Feature 'View Partials',
Given 'an Express server', ->
express = require 'express'
app = express.createServer()
- app.set 'views', process.cwd()
+ app.set 'views', process.cwd()+'/views'
app.listen 3000
And "it's registered to use Hulk-Hogan", ->
@@ -22,14 +22,14 @@ Feature 'View Partials',
fs = require 'fs'
And 'I have a partial template file', ->
- file = 'salute.hulk'
+ file = 'views/salute.hulk'
template = fs.readFileSync file
template.toString().replace('\n','').should.eql 'How are you, {{what}}?'
file_template = 'view_partials.hulk'
And 'I have a template file that includes that partial', ->
- template = fs.readFileSync file_template
+ template = fs.readFileSync 'views/'+file_template
template.toString().replace('\n','').should.eql 'Hello {{what}}! {{> salute}}'
When 'I render that template', ->
View
7 hulk.coffee
@@ -1,3 +1,5 @@
+{join} = require 'path'
+
exports.compile = (source='', options)->
hogan = require 'hogan.js'
compiled = hogan.compile source
@@ -15,11 +17,12 @@ exports.compile = (source='', options)->
if partial_files.length
fs = require 'fs'
for file in partial_files
+ filepath = join options.root, file
try
- partials[file] = fs.readFileSync(file).toString() # TODO better way to read file, especially large ones.
+ partials[file] = fs.readFileSync(filepath).toString() # TODO better way to read file, especially large ones.
catch e
if options.defaultEngine
- partials[file] = fs.readFileSync(file+'.'+options.defaultEngine).toString() # TODO better way to read file, especially large ones.
+ partials[file] = fs.readFileSync(filepath+'.'+options.defaultEngine).toString() # TODO better way to read file, especially large ones.
return ->
return compiled.render options, partials
Please sign in to comment.
Something went wrong with that request. Please try again.