Class: ActionviewPrecompiler::Precompiler
- Inherits:
-
Object
- Object
- ActionviewPrecompiler::Precompiler
- Defined in:
- lib/actionview_precompiler/precompiler.rb
Instance Method Summary collapse
- #add_template(virtual_path, locals = []) ⇒ Object
-
#initialize(verbose: false) ⇒ Precompiler
constructor
A new instance of Precompiler.
- #run ⇒ Object
- #scan_controller_dir(controller_dir) ⇒ Object
- #scan_helper_dir(controller_dir) ⇒ Object
- #scan_view_dir(view_dir) ⇒ Object
- #template_renders ⇒ Object
Constructor Details
#initialize(verbose: false) ⇒ Precompiler
Returns a new instance of Precompiler.
8 9 10 11 12 13 14 |
# File 'lib/actionview_precompiler/precompiler.rb', line 8 def initialize(verbose: false) @scanners = [] @loader = TemplateLoader.new @verbose = verbose @static_templates = [] @template_renders = nil end |
Instance Method Details
#add_template(virtual_path, locals = []) ⇒ Object
28 29 30 31 |
# File 'lib/actionview_precompiler/precompiler.rb', line 28 def add_template(virtual_path, locals = []) locals = locals.map(&:to_s).sort @static_templates << [virtual_path, locals] end |
#run ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/actionview_precompiler/precompiler.rb', line 33 def run count = 0 template_renders.each do |virtual_path, locals| debug "precompiling: #{virtual_path}" templates = @loader.load_template(virtual_path, locals) count += templates.count debug " No templates found at #{virtual_path}" if templates.empty? end debug "Precompiled #{count} Templates" end |
#scan_controller_dir(controller_dir) ⇒ Object
20 21 22 |
# File 'lib/actionview_precompiler/precompiler.rb', line 20 def scan_controller_dir(controller_dir) @scanners << ControllerScanner.new(controller_dir) end |
#scan_helper_dir(controller_dir) ⇒ Object
24 25 26 |
# File 'lib/actionview_precompiler/precompiler.rb', line 24 def scan_helper_dir(controller_dir) @scanners << HelperScanner.new(controller_dir) end |
#scan_view_dir(view_dir) ⇒ Object
16 17 18 |
# File 'lib/actionview_precompiler/precompiler.rb', line 16 def scan_view_dir(view_dir) @scanners << TemplateScanner.new(view_dir) end |
#template_renders ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/actionview_precompiler/precompiler.rb', line 47 def template_renders return @template_renders if @template_renders template_renders = [] @scanners.each do |scanner| template_renders.concat scanner.template_renders end template_renders.concat @static_templates template_renders.uniq! @template_renders = template_renders end |