Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added multi-directory support

Usage:
register Sinatra::Ember
ember {

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

}

will include all templates inside (recursively) app/templates
  • Loading branch information...
commit 6a15c7d1697d9b3fc3c8f01582983249194bb247 1 parent 8a0636d
Conrad VanLandingham authored
Showing with 18 additions and 10 deletions.
  1. +18 −10 lib/sinatra/ember.rb
28 lib/sinatra/ember.rb
View
@@ -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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.