Class: Deface::Precompiler

Inherits:
Object
  • Object
show all
Extended by:
TemplateHelper
Defined in:
lib/deface/precompiler.rb

Class Method Summary collapse

Methods included from TemplateHelper

element_source, load_template_source, lookup_context

Class Method Details

.precompileObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/deface/precompiler.rb', line 6

def self.precompile
  base_path = Rails.root.join("app/compiled_views")
  # temporarily configures deface env and loads
  # all overrides so we can precompile
  unless Rails.application.config.deface.enabled
    Rails.application.config.deface = Deface::Environment.new
    Rails.application.config.deface.overrides.early_check
    Rails.application.config.deface.overrides.load_all Rails.application
  end

  Rails.application.config.deface.overrides.all.each do |virtual_path,overrides|
    template_path = base_path.join( "#{virtual_path}.html.erb")

    FileUtils.mkdir_p template_path.dirname
    begin
      source = load_template_source(virtual_path.to_s, false, true)
      if source.blank?
        raise "Compiled source was blank for '#{virtual_path}'"
      end
      File.open(template_path, 'w') {|f| f.write source } 
    rescue Exception => e
      puts "Unable to precompile '#{virtual_path}' due to: "
      puts e.message
    end
  end
end