Module: Roda::RodaPlugins::PrecompileTemplates::ClassMethods

Defined in:
lib/roda/plugins/precompile_templates.rb

Instance Method Summary collapse

Instance Method Details

#precompile_templates(pattern, opts = OPTS) ⇒ Object

Precompile the templates using the given options. See PrecompileTemplates for details.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/roda/plugins/precompile_templates.rb', line 61

def precompile_templates(pattern, opts=OPTS)
  if pattern.is_a?(Hash)
    opts = pattern.merge(opts)
  end

  locals = opts[:locals] || []
  if locals && self.opts[:precompile_templates_sort]
    locals = locals.sort{|x,y| x.to_s <=> y.to_s}
  end

  compile_opts = if pattern.is_a?(Hash)
    [opts]
  else
    Dir[pattern].map{|file| opts.merge(:path=>File.expand_path(file))}
  end

  instance = allocate
  compile_opts.each do |compile_opt|
    template = instance.send(:retrieve_template, compile_opt)
    template.send(:compiled_method, locals)
  end

  nil
end