Class: Gluey::Dependencies::Handlebars_bundle
- Inherits:
-
SingleFile
- Object
- SingleFile
- Gluey::Dependencies::Handlebars_bundle
- Defined in:
- lib/gluey/workshop/dependencies/handlebars_bundle.rb
Instance Attribute Summary
Attributes inherited from SingleFile
Instance Method Summary collapse
- #actualize ⇒ Object
- #changed? ⇒ Boolean
-
#initialize(dir, logical_path, context) ⇒ Handlebars_bundle
constructor
A new instance of Handlebars_bundle.
- #mark ⇒ Object
Methods inherited from SingleFile
Constructor Details
#initialize(dir, logical_path, context) ⇒ Handlebars_bundle
Returns a new instance of Handlebars_bundle.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/gluey/workshop/dependencies/handlebars_bundle.rb', line 7 def initialize(dir, logical_path, context) tmp_dir = "#{context.cache_path}/.texts_bundle" Dir.mkdir tmp_dir unless Dir.exists? tmp_dir @cache_path = "#{tmp_dir}/#{logical_path.gsub '/', '-'}" Dir.mkdir @cache_path unless Dir.exists? @cache_path @dir_dep = ::Gluey::Dependencies::Directory.new(dir, '**/*.hb') @dependencies = [] super "#{@cache_path}.hb_bundle" end |
Instance Method Details
#actualize ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/gluey/workshop/dependencies/handlebars_bundle.rb', line 26 def actualize # remove deleted files @dependencies.delete_if{|dep| !dep.exists? } # add new files new_files = (@dir_dep.files_list - @dependencies.map(&:file)).map do |f| template = f[/#{@dir_dep.file}\/(.+)\.hb$/, 1] ::Gluey::Dependencies::SingleFile.new f, template: template, hb_precompiled: "#{@cache_path}/#{template.gsub '/', '-'}" end @dependencies.concat new_files @dir_dep.actualize # re-precompile changed = ::Handlebars::Context.new @dependencies.each do |dep| next if !dep.changed? && File.exists?(dep.data[:hb_precompiled]) dep.actualize precompile_output = .precompile File.read(dep.file) File.write dep.data[:hb_precompiled], precompile_output end write_bundle @mtime = File.mtime(@file).to_i self end |
#changed? ⇒ Boolean
18 19 20 |
# File 'lib/gluey/workshop/dependencies/handlebars_bundle.rb', line 18 def changed? @dependencies.any?{|d| d.changed?} || @dir_dep.changed? || (File.mtime(@file).to_i != @mtime rescue true) end |
#mark ⇒ Object
22 23 24 |
# File 'lib/gluey/workshop/dependencies/handlebars_bundle.rb', line 22 def mark @dependencies.map(&:mark).join end |