Module: LogMagic::TemplatingUtils
- Included in:
- BaseExplainer, HoverRenderer, MySqlExplainer::IsNullExplainerSection, MySqlExplainer::OrderByExplainerSection, MySqlExplainer::QueryExplainerSection, MySqlExplainer::SelectExplainerSection, MySqlExplainer::WhereExplainerSection, SearchkickExplainer::AnalyzerExplainerSection, SearchkickExplainer::BoostExplainerSection, SearchkickExplainer::DisMaxExplainerSection, SearchkickExplainer::FuzzyTranspositionsSection, SearchkickExplainer::MatchExplainerSection, SearchkickExplainer::MaxExpansionsSection, SearchkickExplainer::QueryExplainerSection, SearchkickExplainer::SettingsExplainerSection, SearchkickExplainer::UnderscoreAllExplainerSection
- Defined in:
- lib/log_magic/utils/templating_utils.rb
Instance Method Summary collapse
- #enriche ⇒ Object
- #initialize(object_to_enriche) ⇒ Object
- #match_regex ⇒ Object
- #rendered_template ⇒ Object
- #template_dir ⇒ Object
- #template_name ⇒ Object
- #template_path ⇒ Object
Instance Method Details
#enriche ⇒ Object
19 20 21 |
# File 'lib/log_magic/utils/templating_utils.rb', line 19 def enriche @object_to_enriche.gsub!(match_regex, rendered_template) end |
#initialize(object_to_enriche) ⇒ Object
2 3 4 |
# File 'lib/log_magic/utils/templating_utils.rb', line 2 def initialize(object_to_enriche) @object_to_enriche = object_to_enriche end |
#match_regex ⇒ Object
23 24 25 |
# File 'lib/log_magic/utils/templating_utils.rb', line 23 def match_regex /(?:[^\w]|\A)#{term_name}[^\w]/ end |
#rendered_template ⇒ Object
6 7 8 9 |
# 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 ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# 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 ⇒ Object
27 28 29 |
# File 'lib/log_magic/utils/templating_utils.rb', line 27 def template_name "#{term_name}.haml" end |
#template_path ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/log_magic/utils/templating_utils.rb', line 11 def template_path file_name = File.( 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 |