module Roda::RodaPlugins::RenderCoverage::ClassMethods

  1. lib/roda/plugins/render_coverage.rb

Methods

Public Instance

  1. create_template

Public Instance methods

create_template(opts, template_opts)

Set a compiled path on the created template, if the path for the template is in one of the allowed_views.

[show source]
   # File lib/roda/plugins/render_coverage.rb
52 def create_template(opts, template_opts)
53   return super if opts[:template_block]
54 
55   path = File.expand_path(opts[:path])
56   compiled_path = nil
57   (self.opts[:render_coverage_strip_paths] || render_opts[:allowed_paths]).each do |dir|
58     dir += "/" unless dir.end_with?("/")
59     if path.start_with?(dir)
60       compiled_path = File.join(self.opts[:render_coverage_dir], path[dir.length, 10000000].tr('/', '-'))
61       break
62     end
63   end
64 
65   # For Tilt 2.6+, when using :scope_class and fixed locals, must provide
66   # compiled path as option, since compilation happens during initalization
67   # in that case. This option should be ignored if the template does not
68   # support it, but some template class may break if the option is not
69   # handled, so for compatibility, only set the method if Tilt::Template
70   # will handle it.
71   if compiled_path && Tilt::Template.method_defined?(:fixed_locals?)
72     template_opts = template_opts.dup
73     template_opts[:compiled_path] = compiled_path
74     compiled_path = nil
75   end
76 
77   template = super
78 
79   # Set compiled path for template when using older tilt versions.
80   # simplecov:disable
81   template.compiled_path = compiled_path if compiled_path
82   # simplecov:enable
83 
84   template
85 end