lib/roda/plugins/precompile_templates.rb
# Precompile the templates using the given options.  Note that this doesn't
# handle optimized template methods supported in newer versions of Roda, but
# there are still cases where makes sense to use it.
#
# You can call +precompile_templates+ with the pattern of templates you would
# like to precompile:
#
#   precompile_templates "views/**/*.erb"
#
# That will precompile all erb template files in the views directory or
# any subdirectory.
#
# If the templates use local variables, you need to specify which local
# variables to precompile, which should be an array of symbols:
#
#   precompile_templates 'views/users/_*.erb', locals: [:user]
#
# You can specify other render options when calling +precompile_templates+,
# including +:cache_key+, +:template_class+, and +:template_opts+.  If you
# are passing any of those options to render/view for the template, you
# should pass the same options when precompiling the template.
#
# To compile inline templates, just pass a single hash containing an :inline
# to +precompile_templates+:
#
#   precompile_templates inline: some_template_string
Precompile the templates using the given options.  Note that this doesn't
handle optimized template methods supported in newer versions of Roda, but
there are still cases where makes sense to use it.

You can call +precompile_templates+ with the pattern of templates you would
like to precompile.



That will precompile all erb template files in the views directory or
any subdirectory.

If the templates use local variables, you need to specify which local
variables to precompile, which should be an array of symbols.

precompile_templates 'views/users/_*.erb', locals: [:user]



To compile inline templates, just pass a single hash containing an :inline
to +precompile_templates+.


Precompile the templates using the given options . Note that this doesn ' t handle optimized template methods supported in newer versions of Roda but there are still cases where makes sense to use it . You can call + precompile_templates + with the pattern of templates you would like to precompile . That will precompile all erb template files in the views directory or any subdirectory . If the templates use local variables you need to specify which local variables to precompile which should be an array of symbols . precompile_templates ' views / users / _ * . erb ' locals : [ : user ] To compile inline templates just pass a single hash containing an : inline to + precompile_templates + .
def precompile_templates(pattern, opts=OPTS)
          if pattern.is_a?(Hash)
            opts = pattern.merge(opts)
          end
          if locals = opts[:locals]
            locals.sort!
          else
            locals = EMPTY_ARRAY
          end
          compile_opts = if pattern.is_a?(Hash)
            [opts]
          else
            Dir[pattern].map{|file| opts.merge(:path=>File.expand_path(file, nil))}
          end
          instance = allocate
          compile_opts.each do |compile_opt|
            template = instance.send(:retrieve_template, compile_opt)
            begin
              Render.tilt_template_compiled_method(template, locals, self)
            rescue NotImplementedError
              nil
            end
          end
          nil
        end
def precompile_templates ( pattern , opts = OPTS ) if pattern . is_a? ( Hash ) opts = pattern . merge ( opts ) end if locals = opts [ :locals ] locals . sort! else locals = EMPTY_ARRAY end compile_opts = if pattern . is_a? ( Hash ) [ opts ] else Dir [ pattern ] . map { | file | opts . merge ( :path => File . expand_path ( file , nil ) ) } end instance = allocate compile_opts . each do | compile_opt | template = instance . send ( :retrieve_template , compile_opt ) begin Render . tilt_template_compiled_method ( template , locals , self ) rescue NotImplementedError nil end end nil end
Precompile the templates using the given options.
Precompile the templates using the given options .
# When freezing template caches, you may want to precompile a template for a # template type that doesn't support template precompilation, just to populate # the cache.  Tilt rescues NotImplementedError in this case, which we can ignore.
pattern
opts