module LogMagic::TemplatingUtils
Public Class Methods
new(object_to_enriche)
click to toggle source
# File lib/log_magic/utils/templating_utils.rb, line 2 def initialize(object_to_enriche) @object_to_enriche = object_to_enriche end
Public Instance Methods
enriche()
click to toggle source
# File lib/log_magic/utils/templating_utils.rb, line 19 def enriche @object_to_enriche.gsub!(match_regex, rendered_template) end
match_regex()
click to toggle source
# File lib/log_magic/utils/templating_utils.rb, line 23 def match_regex /(?:[^\w]|\A)#{term_name}[^\w]/ end
rendered_template()
click to toggle source
# File lib/log_magic/utils/templating_utils.rb, line 6 def rendered_template engine = Haml::Engine.new(File.read(template_path)) engine.render(self) end
template_dir()
click to toggle source
# File lib/log_magic/utils/templating_utils.rb, line 31 def template_dir if self.class.name =~ /\w*::\w*::\w*/ if self.class.name =~ /LogMagic::SearchkickExplainer/ 'explainer_templates/searchkick' elsif self.class.name =~ /LogMagic::MySqlExplainer/ 'explainer_templates/mysql' end else 'explainer_templates' end end
template_name()
click to toggle source
# File lib/log_magic/utils/templating_utils.rb, line 27 def template_name "#{term_name}.haml" end
template_path()
click to toggle source
# File lib/log_magic/utils/templating_utils.rb, line 11 def template_path file_name = File.expand_path( file_name = File.join(__FILE__, '..', '..', template_dir, template_name) ) fail("No template found for #{self.class.name}") unless File.exist?(file_name) return file_name end