class TemplateFinder
Attributes
fallback_template[R]
forced_templates[R]
overriden_language_configs[R]
overriden_templates[R]
template_dirs[R]
Public Class Methods
new( template_dirs: nil, overriden_templates: nil, overriden_language_configs: nil, indentation: ' ', forced_templates: nil, fallback_template: nil, **)
click to toggle source
# File lib/hiptest-publisher/options_parser.rb, line 399 def initialize( template_dirs: nil, overriden_templates: nil, overriden_language_configs: nil, indentation: ' ', forced_templates: nil, fallback_template: nil, **) @template_dirs = template_dirs || [] @overriden_templates = overriden_templates @compiled_handlebars = {} @template_path_by_name = {} @forced_templates = forced_templates || {} @fallback_template = fallback_template @context = {indentation: indentation} end
Public Instance Methods
dirs()
click to toggle source
# File lib/hiptest-publisher/options_parser.rb, line 416 def dirs @dirs ||= begin search_dirs = [] # search in overriden template base dir first search_dirs << overriden_templates if overriden_templates template_dirs.each {|template_dir| # search template paths in overriden_templates search_dirs << "#{overriden_templates}/#{template_dir}" if overriden_templates # search template paths in hiptest_publisher search_dirs << "#{hiptest_publisher_path}/lib/templates/#{template_dir}" } search_dirs end end
get_compiled_handlebars(template_name)
click to toggle source
# File lib/hiptest-publisher/options_parser.rb, line 431 def get_compiled_handlebars(template_name) template_path = get_template_path(template_name) @compiled_handlebars[template_path] ||= handlebars.compile(File.read(template_path)) end
get_template_by_name(name)
click to toggle source
# File lib/hiptest-publisher/options_parser.rb, line 436 def get_template_by_name(name) return if name.nil? name = forced_templates.fetch(name, name) dirs.each do |path| template_path = File.join(path, "#{name}.hbs") return template_path if File.file?(template_path) end nil end
get_template_path(template_name)
click to toggle source
# File lib/hiptest-publisher/options_parser.rb, line 446 def get_template_path(template_name) unless @template_path_by_name.has_key?(template_name) @template_path_by_name[template_name] = get_template_by_name(template_name) || get_template_by_name(@fallback_template) end @template_path_by_name[template_name] or raise ArgumentError.new(I18n.t('errors.template_not_found', template_name: template_name, dirs: dirs)) end
register_partials()
click to toggle source
# File lib/hiptest-publisher/options_parser.rb, line 453 def register_partials dirs.reverse_each do |path| next unless File.directory?(path) Dir.entries(path).select do |file_name| file_path = File.join(path, file_name) next unless File.file?(file_path) && file_name.start_with?('_') @handlebars.register_partial(file_name[1..-5], File.read(file_path)) end end end
Private Instance Methods
handlebars()
click to toggle source
# File lib/hiptest-publisher/options_parser.rb, line 466 def handlebars if !@handlebars @handlebars = Handlebars::Handlebars.new @handlebars.set_escaper(Handlebars::Escapers::DummyEscaper) register_partials Hiptest::HandlebarsHelper.register_helpers(@handlebars, @context) end @handlebars end