Class: CodeTemplater
- Inherits:
-
Object
- Object
- CodeTemplater
- Defined in:
- lib/ccios/code_templater.rb
Instance Method Summary collapse
- #get_unknown_context_keys_for_string(template) ⇒ Object
- #get_unknown_context_keys_for_template(template_path) ⇒ Object
- #render_file_content_from_template(template_path, filename, context) ⇒ Object
- #render_string(template, context) ⇒ Object
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 = stringView.template. || [] = .map { |t| t.split(".")[-1] }.to_set 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 = (templateView.template. || []) = .map { |t| t.split(".")[-1] }.to_set .subtract(Set["filename", "lowercased_filename"]) 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 |