Class: MKBrut::Ops::RenderTemplate
- Defined in:
- lib/mkbrut/ops/render_template.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(source, destination_root:, erb_binding:) ⇒ RenderTemplate
constructor
A new instance of RenderTemplate.
- #to_s ⇒ Object
Methods inherited from BaseOp
dry_run=, dry_run?, #dry_run?, fileutils_args, #fileutils_args
Constructor Details
#initialize(source, destination_root:, erb_binding:) ⇒ RenderTemplate
Returns a new instance of RenderTemplate.
4 5 6 7 8 |
# File 'lib/mkbrut/ops/render_template.rb', line 4 def initialize(source, destination_root:, erb_binding:) @erb = source @destination_file = destination_root / @erb.basename.sub_ext("") @erb_binding = erb_binding end |
Instance Method Details
#call ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mkbrut/ops/render_template.rb', line 10 def call if dry_run? puts "Render '#{@destination_file}'" return end template = File.read(@erb) File.open(@destination_file, "w") do |file| file.puts ERB.new( template, trim_mode: "-" ).result( @erb_binding.instance_eval { binding } ) end end |
#to_s ⇒ Object
25 |
# File 'lib/mkbrut/ops/render_template.rb', line 25 def to_s = "ERB '#{@erb}' to '#{@destination_file}'" |