Class: CodeTemplater

Inherits:
Object
  • Object
show all
Defined in:
lib/ccios/code_templater.rb

Instance Method Summary collapse

Instance Method Details

#get_unknown_context_keys_for_string(template) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/ccios/code_templater.rb', line 10

def get_unknown_context_keys_for_string(template)
  stringView = Mustache.new
  stringView.template = template
  tags = stringView.template.tags || []
  tags = tags.map { |t| t.split(".")[-1] }.to_set
  tags
end

#get_unknown_context_keys_for_template(template_path) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/ccios/code_templater.rb', line 24

def get_unknown_context_keys_for_template(template_path)
  templateView = Mustache.new
  templateView.template_file = template_path
  tags = (templateView.template.tags || [])
  tags = tags.map { |t| t.split(".")[-1] }.to_set
  tags.subtract(Set["filename", "lowercased_filename"])
  tags
end

#render_file_content_from_template(template_path, filename, context) ⇒ Object



18
19
20
21
22
# File 'lib/ccios/code_templater.rb', line 18

def render_file_content_from_template(template_path, filename, context)
  filename = File.basename(filename, File.extname(filename))
  context = context.merge({filename: filename, lowercased_filename: filename.camelize(:lower)})
  Mustache.render(File.read(template_path), context)
end

#render_string(template, context) ⇒ Object



6
7
8
# File 'lib/ccios/code_templater.rb', line 6

def render_string(template, context)
  Mustache.render(template, context)
end