templater 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/templater.rb CHANGED
@@ -11,6 +11,7 @@ require path + 'capture_helpers'
11
11
  require path + 'actions/action'
12
12
  require path + 'actions/template'
13
13
  require path + 'actions/file'
14
+ require path + 'actions/directory'
14
15
  require path + 'actions/empty_directory'
15
16
  require path + 'description'
16
17
  require path + 'generator'
@@ -42,6 +43,6 @@ module Templater
42
43
  class MalformattedArgumentError < ArgumentError #:nodoc:
43
44
  end
44
45
 
45
- VERSION = '0.2.2'
46
+ VERSION = '0.3.0'
46
47
 
47
48
  end
@@ -0,0 +1,14 @@
1
+ module Templater
2
+ module Actions
3
+ class Directory < File
4
+
5
+ # Returns empty string
6
+ #
7
+ # === Returns
8
+ # String:: Empty string.
9
+ def render
10
+ ""
11
+ end
12
+ end
13
+ end
14
+ end
@@ -52,7 +52,7 @@ module Templater
52
52
 
53
53
  # removes the destination file
54
54
  def revoke!
55
- ::FileUtils.rm(destination, :force => true)
55
+ ::FileUtils.rm_r(destination, :force => true)
56
56
  end
57
57
 
58
58
  end
@@ -60,6 +60,12 @@ module Templater
60
60
  # === Returns
61
61
  # Array[Templater::ActionDescription]:: A list of file descriptions.
62
62
  def files; actions[:files] ||= []; end
63
+
64
+ # Returns an array of ActionDescriptions, where each describes a single directory.
65
+ #
66
+ # === Returns
67
+ # Array[Templater::ActionDescription]:: A list of file descriptions.
68
+ def directories; actions[:directories] ||= []; end
63
69
 
64
70
  # Returns an array of ActionDescriptions, where each describes a single empty directory created by generator.
65
71
  #
@@ -254,7 +260,31 @@ module Templater
254
260
  end
255
261
  end
256
262
 
257
- alias_method :directory, :file
263
+ # Adds a directory that is copied directly. This method is usedful
264
+ # when globbing is not exactly what you want, or you need to access
265
+ # options to decide what source or destination should be.
266
+ #
267
+ # === Parameters
268
+ # name<Symbol>:: The name of this template
269
+ # source<String>:: The source template, can be omitted
270
+ # destination<String>:: The destination where the result will be put.
271
+ # options<Hash>:: Options for this template
272
+ # &block<Proc>:: A block to execute when the generator is instantiated
273
+ #
274
+ # === Options
275
+ # :before<Symbol>:: Name of a method to execute before this template is invoked
276
+ # :after<Symbol>:: Name of a method to execute after this template is invoked
277
+ def directory(name, *args, &block)
278
+ options = args.last.is_a?(Hash) ? args.pop : {}
279
+ source, destination = args
280
+ source, destination = source, source if args.size == 1
281
+
282
+ directories << ActionDescription.new(name, options) do |generator|
283
+ directory = Actions::Directory.new(generator, name, source, destination, options)
284
+ generator.instance_exec(directory, &block) if block
285
+ directory
286
+ end
287
+ end
258
288
 
259
289
  # Adds an empty directory that will be created when the generator is run.
260
290
  #
@@ -323,7 +353,28 @@ module Templater
323
353
  end
324
354
  end
325
355
 
326
- alias_method :directory_list, :file_list
356
+ # An easy way to add many non-rendering templates to a generator. The provided list can be either an
357
+ # array of Strings or a Here-Doc with templates on individual lines.
358
+ #
359
+ # === Parameters
360
+ # list<String|Array>:: A list of non-rendering templates to be added to this generator
361
+ #
362
+ # === Examples
363
+ #
364
+ # class MyGenerator < Templater::Generator
365
+ # directory_list <<-LIST
366
+ # path/to/directory
367
+ # another/directory
368
+ # LIST
369
+ # directory_list ['a/third/directory', 'and/a/fourth']
370
+ # end
371
+ def directory_list(list)
372
+ list.to_a.each do |item|
373
+ item = item.to_s.chomp.strip
374
+ self.directory(item.gsub(/[\.\/]/, '_').to_sym, item)
375
+ end
376
+ end
377
+
327
378
 
328
379
  # Search a directory for templates and files and add them to this generator. Any file
329
380
  # whose extension matches one of those provided in the template_extensions parameter
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Templater::Actions::Directory do
4
+ before(:each) do
5
+
6
+ end
7
+
8
+ before do
9
+ @generator = mock('a generator')
10
+ @generator.stub!(:source_root).and_return('/tmp/source')
11
+ @generator.stub!(:destination_root).and_return('/tmp/destination')
12
+ end
13
+
14
+ describe '#render' do
15
+ it "returns empty string" do
16
+ file = Templater::Actions::Directory.new(@generator, :monkey, template_path('simple_erb.rbt'), '/path/to/destination')
17
+ file.render.should == ""
18
+ end
19
+ end
20
+
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: templater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
@@ -74,6 +74,7 @@ files:
74
74
  - lib/templater/cli/parser.rb
75
75
  - lib/templater/discovery.rb
76
76
  - lib/templater/actions
77
+ - lib/templater/actions/directory.rb
77
78
  - lib/templater/actions/empty_directory.rb
78
79
  - lib/templater/actions/template.rb
79
80
  - lib/templater/actions/action.rb
@@ -121,6 +122,7 @@ files:
121
122
  - spec/actions
122
123
  - spec/actions/file_spec.rb
123
124
  - spec/actions/empty_directory_spec.rb
125
+ - spec/actions/directory_spec.rb
124
126
  - spec/actions/template_spec.rb
125
127
  has_rdoc: true
126
128
  homepage: http://templater.rubyforge.org/