Sha256: d6d9b126e141a27bf45ea357be3b5b252f5e46cfeec57801e19c76de91eb9ec4

Contents?: true

Size: 962 Bytes

Versions: 11

Compression:

Stored size: 962 Bytes

Contents

# frozen_string_literal: true

require 'rake_factory'

require_relative '../template'

module RakeTemplate
  module Tasks
    class Render < RakeFactory::Task
      default_name :render
      default_description(RakeFactory::DynamicValue.new do |t|
        "Render #{t.template_name ? "the #{t.template_name}" : 'a'} template"
      end)

      parameter :template_name
      parameter :template_file_path, required: true
      parameter :output_file_path, required: true
      parameter :vars, default: {}

      action do |t|
        $stdout.puts(
          "Rendering template at #{t.template_file_path} " \
          "to #{t.output_file_path}..."
        )
        template = Template.from_file(t.template_file_path)
        rendered = template.render(t.vars)
        mkdir_p(File.dirname(t.output_file_path))
        File.open(t.output_file_path, 'w') do |f|
          f.write(rendered)
        end
        $stdout.puts('Done.')
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rake_template-0.9.0.pre.2 lib/rake_template/tasks/render.rb
rake_template-0.9.0.pre.1 lib/rake_template/tasks/render.rb
rake_template-0.8.0 lib/rake_template/tasks/render.rb
rake_template-0.7.0.pre.5 lib/rake_template/tasks/render.rb
rake_template-0.7.0.pre.4 lib/rake_template/tasks/render.rb
rake_template-0.7.0.pre.3 lib/rake_template/tasks/render.rb
rake_template-0.7.0.pre.2 lib/rake_template/tasks/render.rb
rake_template-0.7.0.pre.1 lib/rake_template/tasks/render.rb
rake_template-0.6.0 lib/rake_template/tasks/render.rb
rake_template-0.5.0.pre.8 lib/rake_template/tasks/render.rb
rake_template-0.5.0.pre.7 lib/rake_template/tasks/render.rb