class Zubot::TemplatePrecompiler
Attributes
app[R]
finder[R]
Public Class Methods
new(app)
click to toggle source
# File lib/zubot.rb, line 8 def initialize(app) @app = app end
Public Instance Methods
compile_templates!()
click to toggle source
# File lib/zubot.rb, line 12 def compile_templates! precompiled_count = 0 view_paths.each do |resolver| resolver_path = resolver.instance_variable_get(:@path) paths = Dir.glob("#{resolver_path}/**/*.*") paths.map do |template_path| name = get_name(template_path) prefix = get_prefix(template_path) partial = name.start_with?("_") format = get_format(template_path) locals = [] name.sub!(/\_/, "") if partial details = make_details(format) key = details_key.get(details) templates = resolver.find_all(name, prefix, partial, details, key, locals) # Basically contains only one template. templates.each do |template| template.send(:compile!, view) precompiled_count += 1 end if templates.present? end end puts "Precompiled count #{precompiled_count}" end
Private Instance Methods
details_key()
click to toggle source
# File lib/zubot.rb, line 51 def details_key ActionView::LookupContext::DetailsKey end
get_format(template_path)
click to toggle source
# File lib/zubot.rb, line 73 def get_format(template_path) template_path.split("/").last.split(".").second.to_sym end
get_name(template_path)
click to toggle source
# File lib/zubot.rb, line 65 def get_name(template_path) template_path.split("/").last.split(".").first end
get_prefix(template_path)
click to toggle source
# File lib/zubot.rb, line 69 def get_prefix(template_path) template_path.split("/")[-2] end
make_details(format)
click to toggle source
# File lib/zubot.rb, line 59 def make_details(format) details = raw_details details[:formats] = [format] details end
raw_details()
click to toggle source
# File lib/zubot.rb, line 55 def raw_details @raw_details ||= view.lookup_context.instance_variable_get(:@details) end
view()
click to toggle source
# File lib/zubot.rb, line 47 def view @view ||= ActionView::Base.new(view_paths, {}) end
view_paths()
click to toggle source
# File lib/zubot.rb, line 43 def view_paths ActionController::Base._view_paths end