Class: Assette::TemplateSet
- Inherits:
-
Object
- Object
- Assette::TemplateSet
- Defined in:
- lib/assette/template_set.rb
Instance Attribute Summary collapse
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
Instance Method Summary collapse
- #compile(opts = {}) ⇒ Object
-
#initialize(*location) ⇒ TemplateSet
constructor
A new instance of TemplateSet.
- #storage_variable ⇒ Object
Constructor Details
#initialize(*location) ⇒ TemplateSet
Returns a new instance of TemplateSet.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/assette/template_set.rb', line 18 def initialize *location if location.size == 1 location = location.pop end if location.is_a?(Array) location = 'all' if location.include?(:all) || location.include?('all') else location = location.to_s end path = Assette.config.templates_path if location == 'all' dirs = [File.join(path,'*')] elsif location.is_a?(Array) dirs = location.collect do |l| File.join(path,l) end else dirs = [File.join(path,location)] end @paths = [] dirs.each do |dir| @paths += Dir[File.join(dir,'*')] end @templates = @paths.collect do |p| Template.open(p) end end |
Instance Attribute Details
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
16 17 18 |
# File 'lib/assette/template_set.rb', line 16 def templates @templates end |
Instance Method Details
#compile(opts = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/assette/template_set.rb', line 51 def compile(opts={}) coffee = Array.new vars = storage_variable used = [] vars.each do |var| used << var if used.size == 1 str = "window[#{var.to_json}] ||= {}" else str = used.join('.') str << " ||= {}" end coffee << str end templates.each do |template| coffee << template.compile end t = Assette::Reader::Coffee.compile_str(coffee.join("\n")) pre = Assette.preloader_code unless opts[:no_preloader] pre ? [pre,t].join("\n") : t end |