lib/rake/funnel/tasks/quick_template.rb in rake-funnel-0.1.0.pre vs lib/rake/funnel/tasks/quick_template.rb in rake-funnel-0.2.0.pre

- old
+ new

@@ -5,31 +5,33 @@ class QuickTemplate < Rake::TaskLib include Rake::Funnel::Support attr_accessor :name, :search_pattern, :context - def initialize(name = :template) - @name = name + def initialize(*args, &task_block) + setup_ivars(args) + define(args, &task_block) + end + + private + def setup_ivars(args) + @name = args.shift || :template + @search_pattern = %w(**/*.erb) @context = binding - - yield self if block_given? - define end - private - def define - results = templates.all_or_default.map { |t| result_filename(t) } - CLEAN.include(*results) + def define(args, &task_block) + desc 'Generate templates' unless Rake.application.last_description + task(name, *args) do |_, task_args| + task_block.call(*[self, task_args].slice(0, task_block.arity)) if task_block - desc "Generate #{templates.all_or_default.join(', ')}" - task name do templates.all_or_default.each do |template| target = result_filename(template) Rake.rake_output_message "Creating file #{target}" - content = Rake::Funnel::Support::TemplateEngine.render(File.read(template), template, context) + content = TemplateEngine.render(File.read(template), template, context) File.write(target, content) end end self