Sha256: 2617f02c1292cf547cd5344103eae49dec8a971d2552295c5543dc6121155c61

Contents?: true

Size: 1.05 KB

Versions: 26

Compression:

Stored size: 1.05 KB

Contents

require 'thor/actions/templater'
require 'erb'

class Thor
  module Actions

    # Gets an ERB template at the relative source, executes it and makes a copy
    # at the relative destination. If the destination is not given it's assumed
    # to be equal to the source removing .tt from the filename.
    #
    # ==== Parameters
    # source<String>:: the relative path to the source root
    # destination<String>:: the relative path to the destination root
    # log_status<Boolean>:: if false, does not log the status. True by default.
    #
    # ==== Examples
    #
    #   template "README", "doc/README"
    #
    #   template "doc/README"
    #
    def template(source, destination=nil, log_status=true)
      destination ||= source.gsub(/.tt$/, '')
      action Template.new(self, source, destination, log_status)
    end

    class Template < Templater #:nodoc:

      def render
        @render ||= begin
          context = base.instance_eval('binding')
          ERB.new(::File.read(source), nil, '-').result(context)
        end
      end

    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
josevalim-thor-0.10.10 lib/thor/actions/template.rb
josevalim-thor-0.10.11 lib/thor/actions/template.rb
josevalim-thor-0.10.12 lib/thor/actions/template.rb
josevalim-thor-0.10.13 lib/thor/actions/template.rb
josevalim-thor-0.10.14 lib/thor/actions/template.rb
josevalim-thor-0.10.15 lib/thor/actions/template.rb
josevalim-thor-0.10.16 lib/thor/actions/template.rb
josevalim-thor-0.10.17 lib/thor/actions/template.rb
josevalim-thor-0.10.18 lib/thor/actions/template.rb
josevalim-thor-0.10.19 lib/thor/actions/template.rb
josevalim-thor-0.10.20 lib/thor/actions/template.rb
josevalim-thor-0.10.21 lib/thor/actions/template.rb
josevalim-thor-0.10.22 lib/thor/actions/template.rb
josevalim-thor-0.10.23 lib/thor/actions/template.rb
josevalim-thor-0.10.25 lib/thor/actions/template.rb
josevalim-thor-0.10.26 lib/thor/actions/template.rb
josevalim-thor-0.10.27 lib/thor/actions/template.rb
josevalim-thor-0.10.3 lib/thor/actions/template.rb
josevalim-thor-0.10.4 lib/thor/actions/template.rb
josevalim-thor-0.10.5 lib/thor/actions/template.rb