Skip to content

Commit

Permalink
added multi-directory support
Browse files Browse the repository at this point in the history
Usage:
register Sinatra::Ember
ember {

templates '/templates.js', ['app/templates']

}

will include all templates inside (recursively) app/templates
  • Loading branch information
Conrad VanLandingham committed Aug 25, 2012
1 parent 8a0636d commit 6a15c7d
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions lib/sinatra/ember.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ def ember_init!
mtime, output = @template_cache.fetch(route) do
# find all the template files
paths = globs.map do |glob|
glob = File.expand_path(File.join(settings.root, glob))
Dir[glob].map { |x| x.squeeze('/') }
files = Dir[glob+"/**/*.{handlebars,hbs,hjs}"].map { |x| x.squeeze('/') }
[glob, files.flatten]
end
paths = paths.flatten.uniq

# build up template hash
template_paths = {}
paths.each do |path|
template_paths[File.basename(path, '.hbs')] = path
end
#template_paths = {}
#paths.each do |path|
# template_paths[File.basename(path, '.hbs')] = path
#end

# build up the javascript
templates = template_paths.map do |(name, path)|
content = File.read(path)
"Ember.TEMPLATES[#{name.inspect}] = Ember.Handlebars.compile(#{content.inspect});"
templates = paths.map do |path, files|
files.map do |file|
content = File.read(file)
"Ember.TEMPLATES[#{template_path(path,file)}] = Ember.Handlebars.compile(#{content.inspect});"
end

# wrap it up in a closure
Expand All @@ -63,6 +63,14 @@ def ember_init!
end
end
end
def template_path(path, file)

unless root.blank?
file.gsub!(/^#{Regexp.quote(path)}\/?/, '')
end

file
end
end

class Options
Expand Down

0 comments on commit 6a15c7d

Please sign in to comment.