Module: LogMagic::TemplatingUtils

Instance Method Summary collapse

Instance Method Details

#enricheObject



17
18
19
# File 'lib/log_magic/utils/templating_utils.rb', line 17

def enriche
  @query_json.gsub!(match_regex, rendered_template)
end

#initialize(query_json) ⇒ Object



2
3
4
# File 'lib/log_magic/utils/templating_utils.rb', line 2

def initialize(query_json)
  @query_json = query_json
end

#match_regexObject



21
22
23
# File 'lib/log_magic/utils/templating_utils.rb', line 21

def match_regex
  /[^\w]#{term_name}[^\w]/
end

#rendered_templateObject



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_dirObject



29
30
31
# File 'lib/log_magic/utils/templating_utils.rb', line 29

def template_dir
  'explainer_templates'
end

#template_nameObject



25
26
27
# File 'lib/log_magic/utils/templating_utils.rb', line 25

def template_name
  "#{term_name}.haml"
end

#template_pathObject



11
12
13
14
15
# File 'lib/log_magic/utils/templating_utils.rb', line 11

def template_path
  File.expand_path(
    File.join(__FILE__, '..', '..', template_dir, template_name)
  )
end