Module: Plasmoid::Generator::TemplateHelper
- Included in:
- Plasmoid::Generator
- Defined in:
- lib/plasmoid/generator/template_helper.rb
Class Method Summary collapse
Instance Method Summary collapse
- #mkdir(path) ⇒ Object
- #prefix_dir ⇒ Object
- #render_template(source) ⇒ Object
- #template_dir ⇒ Object
- #write_template(source, destination = source) ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 7 |
# File 'lib/plasmoid/generator/template_helper.rb', line 4 def self.included(base) base.class_eval do end end |
Instance Method Details
#mkdir(path) ⇒ Object
41 42 43 44 45 |
# File 'lib/plasmoid/generator/template_helper.rb', line 41 def mkdir(path) destination = File.join(target_dir, path) FileUtils.mkpath(destination) $stdout.puts ">> mkdir\t#{destination}" end |
#prefix_dir ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/plasmoid/generator/template_helper.rb', line 13 def prefix_dir if self.class == Plasmoid::WebkitGenerator "webkit" elsif self.class == Plasmoid::RubyGenerator "ruby" elsif self.class == Plasmoid::PythonGenerator "python" end end |
#render_template(source) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/plasmoid/generator/template_helper.rb', line 23 def render_template(source) template_contents = File.read(File.join(template_dir, source)) template = ERB.new(template_contents, nil, '<>') template.result(binding).gsub(/\n\n\n+/, "\n\n") end |
#template_dir ⇒ Object
9 10 11 |
# File 'lib/plasmoid/generator/template_helper.rb', line 9 def template_dir @template_dir ||= File.join(File.dirname(__FILE__), 'templates', prefix_dir) end |
#write_template(source, destination = source) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/plasmoid/generator/template_helper.rb', line 30 def write_template(source, destination = source) final_destination = File.join(target_dir, destination) template_result = render_template(source) File.open(final_destination, 'w') do |file| file.write(template_result) end $stdout.puts ">> create\t#{final_destination}" end |