templater 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -71,7 +71,7 @@ Generators can invoke other generators, a WikiBlog generator that creates both a
71
71
 
72
72
  end
73
73
 
74
- It needs to source_root, since it has no actions. Not here that the generators are invoked by their name in the manifold, *not* by their class name. This gives the system a great deal of flexibility.
74
+ It needs no source_root, since it has no actions. The generators are invoked by their name in the manifold, not by their class name; this gives the system a great deal of flexibility.
75
75
 
76
76
  == Automatically adding actions
77
77
 
@@ -114,7 +114,7 @@ Inside the templates normal ERB can be used. The templates are rendered in the s
114
114
  puts "I have no name"
115
115
  <% end %>
116
116
 
117
- IF you need to render templates where the result should contain actual erb, simply use a double percentage sign, this will prevent the statement from being executed.
117
+ If you need to render templates where the result should contain actual erb, simply use a double percentage sign, this will prevent the statement from being executed.
118
118
 
119
119
  <%= 2 + 2 %>
120
120
  <%%= 2 + 2 %>
data/Rakefile CHANGED
@@ -3,10 +3,10 @@ require 'rake/gempackagetask'
3
3
  require 'rubygems/specification'
4
4
  require 'rake/rdoctask'
5
5
  require 'date'
6
+ require File.join(File.dirname(__FILE__), 'lib', 'templater')
6
7
 
7
8
  PLUGIN = "templater"
8
9
  NAME = "templater"
9
- GEM_VERSION = "0.1"
10
10
  AUTHOR = "Jonas Nicklas"
11
11
  EMAIL = "jonas.nicklas@gmail.com"
12
12
  HOMEPAGE = "http://templater.rubyforge.org/"
@@ -14,7 +14,7 @@ SUMMARY = "File generation system"
14
14
 
15
15
  spec = Gem::Specification.new do |s|
16
16
  s.name = NAME
17
- s.version = GEM_VERSION
17
+ s.version = Templater::VERSION
18
18
  s.platform = Gem::Platform::RUBY
19
19
  s.has_rdoc = true
20
20
  s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
@@ -30,7 +30,8 @@ spec = Gem::Specification.new do |s|
30
30
  s.add_dependency "highline", ">= 1.4.0"
31
31
  s.add_dependency "diff-lcs", ">= 1.1.2"
32
32
  # Templater uses facets only for a single instance_exec. This dependency might be a bit stupid.
33
- s.add_dependency "facets"
33
+ # s.add_dependency "facets", ">= 2.2.0"
34
+ # FIXME: I've commented this out since it keeps installing Facets 2.4.1 which seems to be broken in some ways.
34
35
  end
35
36
 
36
37
  Rake::GemPackageTask.new(spec) do |pkg|
data/TODO CHANGED
@@ -1,5 +1,3 @@
1
1
  TODO:
2
- Fix LICENSE with your name
3
- Fix Rakefile with your name and contact info
4
- Add your code to lib/templater.rb
5
- Add your Merb rake tasks to lib/templater/merbtasks.rb
2
+
3
+ * Add magic template names for files as well
data/lib/templater.rb CHANGED
@@ -39,6 +39,6 @@ module Templater
39
39
  class MalformattedArgumentError < ArgumentError #:nodoc:
40
40
  end
41
41
 
42
- VERSION = '0.1'
42
+ VERSION = '0.1.1'
43
43
 
44
44
  end
@@ -43,7 +43,7 @@ module Templater
43
43
  end
44
44
  else
45
45
  opts.on("--#{name} OPTION", option[:options][:desc]) do |s|
46
- options[option[:name]] = s.to_sym
46
+ options[option[:name]] = s.gsub('-', '_').to_sym
47
47
  end
48
48
  end
49
49
  end
@@ -71,21 +71,26 @@ module Templater
71
71
 
72
72
  def step_through_templates
73
73
  @generator.actions.each do |action|
74
- if action.identical?
75
- say_status('identical', action, :blue)
76
- elsif action.exists?
77
- if @options[:force]
78
- say_status('forced', action, :yellow)
79
- action.invoke! unless @options[:pretend]
80
- elsif @options[:skip]
81
- say_status('skipped', action, :yellow)
74
+ if @options[:delete]
75
+ action.revoke! unless @options[:pretend]
76
+ say_status('deleted', action, :red)
77
+ else
78
+ if action.identical?
79
+ say_status('identical', action, :blue)
80
+ elsif action.exists?
81
+ if @options[:force]
82
+ action.invoke! unless @options[:pretend]
83
+ say_status('forced', action, :yellow)
84
+ elsif @options[:skip]
85
+ say_status('skipped', action, :yellow)
86
+ else
87
+ say_status('conflict', action, :red)
88
+ conflict_menu(action)
89
+ end
82
90
  else
83
- say_status('conflict', action, :red)
84
- conflict_menu(action)
91
+ action.invoke! unless @options[:pretend]
92
+ say_status('added', action, :green)
85
93
  end
86
- else
87
- say_status('added', action, :green)
88
- action.invoke! unless @options[:pretend]
89
94
  end
90
95
  end
91
96
  end
@@ -118,7 +123,7 @@ module Templater
118
123
  puts "Showing differences for " + template.relative_destination
119
124
  puts ""
120
125
 
121
- diffs = Diff::LCS.diff(File.read(template.destination).to_s.to_a, template.render.to_a).first
126
+ diffs = Diff::LCS.diff(::File.read(template.destination).to_s.to_a, template.render.to_a).first
122
127
 
123
128
  diffs.each do |diff|
124
129
  output_diff_line(diff)
@@ -39,7 +39,7 @@ module Templater
39
39
  puts @manifold.desc
40
40
  puts ''
41
41
  puts 'Available Generators'
42
- @manifold.generators.each do |name, generator|
42
+ @manifold.public_generators.each do |name, generator|
43
43
  print " "
44
44
  print name.to_s.ljust(33)
45
45
  print generator.desc.to_a.first.chomp if generator.desc
@@ -42,12 +42,13 @@ module Templater
42
42
  options[:skip] = s
43
43
  end
44
44
 
45
- opts.on("-a", "--ask", "Ask about each file before generating it.") do |s|
46
- options[:ask] = s
47
- end
45
+ # TODO: implement this
46
+ #opts.on("-a", "--ask", "Ask about each file before generating it.") do |s|
47
+ # options[:ask] = s
48
+ #end
48
49
 
49
50
  opts.on("-d", "--delete", "Delete files that have previously been generated with this generator.") do |s|
50
- options[:skip] = s
51
+ options[:delete] = s
51
52
  end
52
53
 
53
54
  opts.on("--no-color", "Don't colorize the output") do
@@ -53,6 +53,11 @@ module Templater
53
53
  ::FileUtils.mkdir_p(::File.dirname(destination))
54
54
  ::FileUtils.copy_file(source, destination)
55
55
  end
56
+
57
+ # removes the destination file
58
+ def revoke!
59
+ ::FileUtils.rm(destination)
60
+ end
56
61
 
57
62
  end
58
63
  end
@@ -401,7 +401,7 @@ module Templater
401
401
  # [Templater::Template]:: The found templates.
402
402
  def templates
403
403
  templates = self.class.templates.map do |t|
404
- template = Templater::TemplateProxy.new(t[:name], t[:source], t[:destination], &t[:block]).to_template(self)
404
+ template = Templater::Proxy.new(self, t[:name], t[:source], t[:destination], &t[:block]).to_template
405
405
  match_options?(t[:options]) ? template : nil
406
406
  end
407
407
  templates.compact
@@ -413,7 +413,7 @@ module Templater
413
413
  # [Templater::File]:: The found files.
414
414
  def files
415
415
  files = self.class.files.map do |t|
416
- file = Templater::FileProxy.new(t[:name], t[:source], t[:destination], &t[:block]).to_file(self)
416
+ file = Templater::Proxy.new(self, t[:name], t[:source], t[:destination], &t[:block]).to_file
417
417
  match_options?(t[:options]) ? file : nil
418
418
  end
419
419
  files.compact
@@ -2,22 +2,51 @@ module Templater
2
2
 
3
3
  module Manifold
4
4
 
5
- attr_accessor :generators
5
+ # Lists all generators in this manifold
6
+ #
7
+ # === Returns
8
+ # Array[Templater::Generator]:: A list of generators
9
+ def generators
10
+ private_generators.merge(public_generators)
11
+ end
12
+
13
+ # Lists all public generators, these are generators that are meant to be invoked directly by the user.
14
+ #
15
+ # === Returns
16
+ # Array[Templater::Generator]:: A list of generators
17
+ def public_generators
18
+ @public_generators ||= {}
19
+ end
20
+
21
+ # Lists all private generators, these are generators that are meant to be used only internally
22
+ # and should not be invoked directly (although the interface may choose to do so)
23
+ #
24
+ # === Returns
25
+ # Array[Templater::Generator]:: A list of generators
26
+ def private_generators
27
+ @private_generators ||= {}
28
+ end
6
29
 
7
30
  # Add a generator to this manifold
8
31
  #
9
32
  # === Parameters
10
33
  # name<Symbol>:: The name given to this generator in the manifold
11
34
  # generator<Templater::Generator>:: The generator class
12
- def add(name, generator)
13
- @generators ||={}
14
- @generators[name.to_sym] = generator
35
+ def add_public(name, generator)
36
+ public_generators[name.to_sym] = generator
37
+ generator.manifold = self
38
+ end
39
+
40
+ alias_method :add, :add_public
41
+
42
+ # Add a generator for internal use to this manifold.
43
+ #
44
+ # === Parameters
45
+ # name<Symbol>:: The name given to this generator in the manifold
46
+ # generator<Templater::Generator>:: The generator class
47
+ def add_private(name, generator)
48
+ private_generators[name.to_sym] = generator
15
49
  generator.manifold = self
16
- (class << self; self; end).module_eval <<-MODULE
17
- def #{name}
18
- generator(:#{name})
19
- end
20
- MODULE
21
50
  end
22
51
 
23
52
  # Remove the generator with the given name from the manifold
@@ -25,10 +54,8 @@ module Templater
25
54
  # === Parameters
26
55
  # name<Symbol>:: The name of the generator to be removed.
27
56
  def remove(name)
28
- @generators.delete(name.to_sym)
29
- (class << self; self; end).module_eval <<-MODULE
30
- undef #{name}
31
- MODULE
57
+ public_generators.delete(name.to_sym)
58
+ private_generators.delete(name.to_sym)
32
59
  end
33
60
 
34
61
  # Finds the class of a generator, given its name in the manifold.
@@ -39,8 +66,7 @@ module Templater
39
66
  # === Returns
40
67
  # Templater::Generator:: The found generator class
41
68
  def generator(name)
42
- @generators ||= {}
43
- @generators[name.to_sym]
69
+ generators[name.to_sym]
44
70
  end
45
71
 
46
72
  # A Shortcut method for invoking the command line interface provided with Templater.
@@ -2,17 +2,27 @@ module Templater
2
2
 
3
3
  class Proxy #:nodoc:
4
4
 
5
- def initialize(name, source, destination, &block)
6
- @block, @source, @destination = block, source, destination
5
+ def initialize(generator, name, source, destination, &block)
6
+ @generator, @block, @source, @destination = generator, block, source, destination
7
7
  @name = name.to_sym
8
8
  end
9
9
 
10
- def source(source)
11
- @source = source
10
+ def source(*source)
11
+ @source = ::File.join(*source)
12
12
  end
13
13
 
14
- def destination(dest)
15
- @destination = dest
14
+ def destination(*dest)
15
+ @destination = ::File.join(*dest)
16
+ end
17
+
18
+ def to_template
19
+ instance_eval(&@block) if @block
20
+ Templater::Template.new(@generator, @name, get_source, get_destination)
21
+ end
22
+
23
+ def to_file
24
+ instance_eval(&@block) if @block
25
+ Templater::File.new(@name, get_source, get_destination)
16
26
  end
17
27
 
18
28
  def method_missing(method, *args, &block)
@@ -42,25 +52,4 @@ module Templater
42
52
 
43
53
  end
44
54
 
45
- class TemplateProxy < Proxy #:nodoc:
46
-
47
- def to_template(generator)
48
- @generator = generator
49
- instance_eval(&@block) if @block
50
- Templater::Template.new(generator, @name, get_source, get_destination, true)
51
- end
52
-
53
- end
54
-
55
- class FileProxy < Proxy #:nodoc:
56
-
57
- def to_file(generator)
58
- @generator = generator
59
- instance_eval(&@block) if @block
60
- @generator = nil
61
- Templater::File.new(@name, ::File.join(generator.source_root, @source.to_s), ::File.join(generator.destination_root, @destination.to_s))
62
- end
63
-
64
- end
65
-
66
55
  end
@@ -12,12 +12,11 @@ module Templater
12
12
  # source<String>:: Full path to the source of this template
13
13
  # destination<String>:: Full path to the destination of this template
14
14
  # render<Boolean>:: If set to false, will do a copy instead of rendering.
15
- def initialize(context, name, source, destination, render = true)
15
+ def initialize(context, name, source, destination)
16
16
  @context = context
17
17
  @name = name
18
18
  @source = source
19
19
  @destination = destination
20
- @options = { :render => render }
21
20
  end
22
21
 
23
22
  # Returns the destination path relative to Dir.pwd. This is useful for prettier output in interfaces
@@ -56,12 +55,13 @@ module Templater
56
55
  # Renders the template and copies it to the destination.
57
56
  def invoke!
58
57
  ::FileUtils.mkdir_p(::File.dirname(destination))
59
- if options[:render]
60
- ::File.open(destination, 'w') {|f| f.write render }
61
- else
62
- ::FileUtils.copy_file(source, destination)
63
- end
58
+ ::File.open(destination, 'w') {|f| f.write render }
64
59
  end
65
-
60
+
61
+ # removes the destination file
62
+ def revoke!
63
+ ::FileUtils.rm(destination)
64
+ end
65
+
66
66
  end
67
67
  end
data/spec/file_spec.rb CHANGED
@@ -72,3 +72,20 @@ describe Templater::File, '#invoke!' do
72
72
  FileUtils.rm_rf(result_path('path'))
73
73
  end
74
74
  end
75
+
76
+ describe Templater::File, '#revoke!' do
77
+
78
+ it "should remove the destination file" do
79
+ file = Templater::File.new(:monkey, template_path('simple_erb.rbt'), result_path('path/to/subdir/test2.rbs'))
80
+
81
+ file.invoke!
82
+
83
+ File.exists?(result_path('path/to/subdir/test2.rbs')).should be_true
84
+ FileUtils.identical?(template_path('simple_erb.rbt'), result_path('path/to/subdir/test2.rbs')).should be_true
85
+
86
+ file.revoke!
87
+
88
+ File.exists?(result_path('path/to/subdir/test2.rbs')).should be_false
89
+ end
90
+
91
+ end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
- describe Templater::Generator, '#desc' do
3
+ describe Templater::Generator, '.desc' do
4
4
 
5
5
  it "should append text when called with an argument, and return it when called with no argument" do
6
6
  @generator_class = Class.new(Templater::Generator)
@@ -276,6 +276,20 @@ describe Templater::Generator, '.template' do
276
276
  @instance.template(:my_template).should be_an_instance_of(Templater::Template)
277
277
  end
278
278
 
279
+ it "should add a template with a block, joining multiple arguments" do
280
+ @generator_class.template(:my_template) do
281
+ source 'test', 'something', 'blah.rbt'
282
+ destination 'test', "gurr#{Process.pid.to_s}.rb"
283
+ end
284
+ @instance = @generator_class.new('/tmp/destination')
285
+
286
+ @instance.stub!(:source_root).and_return('/tmp/source')
287
+
288
+ @instance.template(:my_template).source.should == '/tmp/source/test/something/blah.rbt'
289
+ @instance.template(:my_template).destination.should == "/tmp/destination/test/gurr#{Process.pid.to_s}.rb"
290
+ @instance.template(:my_template).should be_an_instance_of(Templater::Template)
291
+ end
292
+
279
293
  it "should add a template and convert an with an instruction encoded in the destination, but not one encoded in the source" do
280
294
  @generator_class.template(:my_template, 'template/%some_method%.rbt', 'template/%another_method%.rb')
281
295
  @instance = @generator_class.new('/tmp/destination')
@@ -308,27 +322,91 @@ describe Templater::Generator, '.file' do
308
322
  end
309
323
 
310
324
  it "should add a file with source and destination" do
311
- @generator_class.file(:my_template, 'path/to/source.rbt', 'path/to/destination.rb')
325
+ @generator_class.file(:my_file, 'path/to/source.rbt', 'path/to/destination.rb')
326
+ @instance = @generator_class.new('/tmp/destination')
327
+
328
+ @instance.stub!(:source_root).and_return('/tmp/source')
329
+
330
+ @instance.file(:my_file).source.should == '/tmp/source/path/to/source.rbt'
331
+ @instance.file(:my_file).destination.should == '/tmp/destination/path/to/destination.rb'
332
+ @instance.file(:my_file).should be_an_instance_of(Templater::File)
333
+ end
334
+
335
+ it "should add a file with absolute source and destination" do
336
+ @generator_class.file(:my_file, '/path/to/source.rbt', '/path/to/destination.rb')
312
337
  @instance = @generator_class.new('/tmp/destination')
313
338
 
314
339
  @instance.stub!(:source_root).and_return('/tmp/source')
315
340
 
316
- @instance.file(:my_template).source.should == '/tmp/source/path/to/source.rbt'
317
- @instance.file(:my_template).destination.should == '/tmp/destination/path/to/destination.rb'
318
- @instance.file(:my_template).should be_an_instance_of(Templater::File)
341
+ @instance.file(:my_file).source.should == '/path/to/source.rbt'
342
+ @instance.file(:my_file).destination.should == '/path/to/destination.rb'
343
+ @instance.file(:my_file).should be_an_instance_of(Templater::File)
319
344
  end
320
345
 
321
346
  it "should add a file with source and infer destination " do
322
- @generator_class.file(:my_template, 'path/to/file.rb')
347
+ @generator_class.file(:my_file, 'path/to/file.rb')
348
+ @instance = @generator_class.new('/tmp/destination')
349
+
350
+ @instance.stub!(:source_root).and_return('/tmp/source')
351
+
352
+ @instance.file(:my_file).source.should == '/tmp/source/path/to/file.rb'
353
+ @instance.file(:my_file).destination.should == '/tmp/destination/path/to/file.rb'
354
+ @instance.file(:my_file).should be_an_instance_of(Templater::File)
355
+ end
356
+
357
+ it "should add a file with a block" do
358
+ @generator_class.file(:my_file) do
359
+ source 'blah.rbt'
360
+ destination "gurr#{Process.pid.to_s}.rb"
361
+ end
323
362
  @instance = @generator_class.new('/tmp/destination')
324
363
 
325
364
  @instance.stub!(:source_root).and_return('/tmp/source')
326
365
 
327
- @instance.file(:my_template).source.should == '/tmp/source/path/to/file.rb'
328
- @instance.file(:my_template).destination.should == '/tmp/destination/path/to/file.rb'
329
- @instance.file(:my_template).should be_an_instance_of(Templater::File)
366
+ @instance.file(:my_file).source.should == '/tmp/source/blah.rbt'
367
+ @instance.file(:my_file).destination.should == "/tmp/destination/gurr#{Process.pid.to_s}.rb"
368
+ @instance.file(:my_file).should be_an_instance_of(Templater::File)
330
369
  end
331
370
 
371
+ it "should add a file with a block, joining multiple arguments" do
372
+ @generator_class.file(:my_file) do
373
+ source 'test', 'something', 'blah.rbt'
374
+ destination 'test', "gurr#{Process.pid.to_s}.rb"
375
+ end
376
+ @instance = @generator_class.new('/tmp/destination')
377
+
378
+ @instance.stub!(:source_root).and_return('/tmp/source')
379
+
380
+ @instance.file(:my_file).source.should == '/tmp/source/test/something/blah.rbt'
381
+ @instance.file(:my_file).destination.should == "/tmp/destination/test/gurr#{Process.pid.to_s}.rb"
382
+ @instance.file(:my_file).should be_an_instance_of(Templater::File)
383
+ end
384
+
385
+
386
+ it "should add a file and convert an instruction encoded in the destination, but not one encoded in the source" do
387
+ @generator_class.file(:my_file, 'template/%some_method%.rbt', 'template/%another_method%.rb')
388
+ @instance = @generator_class.new('/tmp/destination')
389
+
390
+ @instance.stub!(:source_root).and_return('/tmp/source')
391
+ @instance.should_not_receive(:some_method)
392
+ @instance.should_receive(:another_method).at_least(:once).and_return('beast')
393
+
394
+ @instance.file(:my_file).source.should == '/tmp/source/template/%some_method%.rbt'
395
+ @instance.file(:my_file).destination.should == "/tmp/destination/template/beast.rb"
396
+ @instance.file(:my_file).should be_an_instance_of(Templater::File)
397
+ end
398
+
399
+ it "should add a file and leave an encoded instruction be if it doesn't exist as a method" do
400
+ @generator_class.file(:my_file, 'template/blah.rbt', 'template/%some_method%.rb')
401
+ @instance = @generator_class.new('/tmp/destination')
402
+
403
+ @instance.stub!(:source_root).and_return('/tmp/source')
404
+
405
+ @instance.file(:my_file).destination.should == "/tmp/destination/template/%some_method%.rb"
406
+ @instance.file(:my_file).should be_an_instance_of(Templater::File)
407
+ end
408
+
409
+
332
410
  end
333
411
 
334
412
  describe Templater::Generator, '.invoke' do
@@ -1,5 +1,41 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
+ describe Templater::Manifold, '#add_public' do
4
+
5
+ before(:each) do
6
+ @manifold = class << self; self end
7
+ @manifold.extend Templater::Manifold
8
+ @generator = mock('a generator')
9
+ @generator.stub!(:manifold=)
10
+ end
11
+
12
+ it "should allow retrieval with #generate" do
13
+ @manifold.add_public(:monkey, @generator)
14
+ @manifold.generator(:monkey).should == @generator
15
+ end
16
+
17
+ it "should allow retrieval with #generators" do
18
+ @manifold.add_public(:monkey, @generator)
19
+ @manifold.generators[:monkey].should == @generator
20
+ end
21
+
22
+ it "should allow retrieval with #public_generators" do
23
+ @manifold.add_public(:monkey, @generator)
24
+ @manifold.public_generators[:monkey].should == @generator
25
+ end
26
+
27
+ it "should not allow retrieval with #private_generators" do
28
+ @manifold.add_public(:monkey, @generator)
29
+ @manifold.private_generators[:monkey].should be_nil
30
+ end
31
+
32
+ it "should set the manifold for the generator" do
33
+ @generator.should_receive(:manifold=).with(@manifold)
34
+ @manifold.add_public(:monkey, @generator)
35
+ end
36
+
37
+ end
38
+
3
39
  describe Templater::Manifold, '#add' do
4
40
 
5
41
  before(:each) do
@@ -9,24 +45,54 @@ describe Templater::Manifold, '#add' do
9
45
  @generator.stub!(:manifold=)
10
46
  end
11
47
 
12
- it "should allow addition of generators and remember them" do
13
- @manifold.add(:monkey, @generator)
48
+ it "should be an alias for #add_public" do
49
+ @generator.should_receive(:manifold=).with(@manifold)
50
+ @manifold.add_public(:monkey, @generator)
14
51
  @manifold.generator(:monkey).should == @generator
15
52
  @manifold.generators[:monkey].should == @generator
53
+ @manifold.public_generators[:monkey].should == @generator
54
+ @manifold.private_generators[:monkey].should be_nil
16
55
  end
17
56
 
18
- it "should add a trippy convenience method" do
19
- @manifold.add(:monkey, @generator)
20
- @manifold.monkey.should == @generator
57
+ end
58
+
59
+ describe Templater::Manifold, '#add_private' do
60
+
61
+ before(:each) do
62
+ @manifold = class << self; self end
63
+ @manifold.extend Templater::Manifold
64
+ @generator = mock('a generator')
65
+ @generator.stub!(:manifold=)
66
+ end
67
+
68
+ it "should allow retrieval with #generate" do
69
+ @manifold.add_private(:monkey, @generator)
70
+ @manifold.generator(:monkey).should == @generator
71
+ end
72
+
73
+ it "should allow retrieval with #generators" do
74
+ @manifold.add_private(:monkey, @generator)
75
+ @manifold.generators[:monkey].should == @generator
76
+ end
77
+
78
+ it "should not allow retrieval with #public_generators" do
79
+ @manifold.add_private(:monkey, @generator)
80
+ @manifold.public_generators[:monkey].should be_nil
81
+ end
82
+
83
+ it "should allow retrieval with #private_generators" do
84
+ @manifold.add_private(:monkey, @generator)
85
+ @manifold.private_generators[:monkey].should == @generator
21
86
  end
22
87
 
23
88
  it "should set the manifold for the generator" do
24
89
  @generator.should_receive(:manifold=).with(@manifold)
25
- @manifold.add(:monkey, @generator)
90
+ @manifold.add_private(:monkey, @generator)
26
91
  end
27
92
 
28
93
  end
29
94
 
95
+
30
96
  describe Templater::Manifold, '#remove' do
31
97
 
32
98
  before(:each) do
@@ -36,17 +102,20 @@ describe Templater::Manifold, '#remove' do
36
102
  @generator.stub!(:manifold=)
37
103
  end
38
104
 
39
- it "should allow removal of generators" do
105
+ it "should remove a public generator" do
40
106
  @manifold.add(:monkey, @generator)
41
107
  @manifold.remove(:monkey)
42
108
  @manifold.generator(:monkey).should be_nil
43
109
  @manifold.generators[:monkey].should be_nil
110
+ @manifold.public_generators[:monkey].should be_nil
44
111
  end
45
112
 
46
- it "should remove the accessor method" do
47
- @manifold.add(:monkey, @generator)
113
+ it "should remove a private generator" do
114
+ @manifold.add_private(:monkey, @generator)
48
115
  @manifold.remove(:monkey)
49
- @manifold.should_not respond_to(:monkey)
116
+ @manifold.generator(:monkey).should be_nil
117
+ @manifold.generators[:monkey].should be_nil
118
+ @manifold.public_generators[:monkey].should be_nil
50
119
  end
51
120
 
52
121
  end
@@ -109,16 +109,23 @@ describe Templater::Template, '#invoke!' do
109
109
  # cleanup
110
110
  FileUtils.rm_rf(result_path('path'))
111
111
  end
112
+
113
+ end
114
+
115
+
116
+ describe Templater::Template, '#revoke!' do
112
117
 
113
- it "should simply copy the template to the destination if render is false" do
114
- template = Templater::Template.new(@context, :monkey, template_path('simple_erb.rbt'), result_path('path/to/subdir/test2.rbs'), false)
118
+ it "should remove the destination file" do
119
+ template = Templater::Template.new(@context, :monkey, template_path('simple_erb.rbt'), result_path('test.rbs'))
115
120
 
116
121
  template.invoke!
117
122
 
118
- File.exists?(result_path('path/to/subdir/test2.rbs')).should be_true
119
- FileUtils.identical?(template_path('simple_erb.rbt'), result_path('path/to/subdir/test2.rbs')).should be_true
123
+ File.exists?(result_path('test.rbs')).should be_true
124
+ File.read(result_path('test.rbs')).should == "test2test"
125
+
126
+ template.revoke!
120
127
 
121
- # cleanup
122
- FileUtils.rm_rf(result_path('path'))
128
+ File.exists?(result_path('test.rbs')).should be_false
123
129
  end
124
- end
130
+
131
+ 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.1"
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
@@ -9,11 +9,12 @@ autorequire: templater
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-30 00:00:00 +02:00
12
+ date: 2008-07-13 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: highline
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -23,6 +24,7 @@ dependencies:
23
24
  version:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: diff-lcs
27
+ type: :runtime
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
@@ -30,15 +32,6 @@ dependencies:
30
32
  - !ruby/object:Gem::Version
31
33
  version: 1.1.2
32
34
  version:
33
- - !ruby/object:Gem::Dependency
34
- name: facets
35
- version_requirement:
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: "0"
41
- version:
42
35
  description: File generation system
43
36
  email: jonas.nicklas@gmail.com
44
37
  executables: []
@@ -76,6 +69,9 @@ files:
76
69
  - spec/results
77
70
  - spec/results/erb.rbs
78
71
  - spec/results/file.rbs
72
+ - spec/results/path
73
+ - spec/results/path/to
74
+ - spec/results/path/to/subdir
79
75
  - spec/results/random.rbs
80
76
  - spec/results/simple_erb.rbs
81
77
  - spec/spec_helper.rb
@@ -115,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
111
  requirements: []
116
112
 
117
113
  rubyforge_project:
118
- rubygems_version: 1.1.1
114
+ rubygems_version: 1.2.0
119
115
  signing_key:
120
116
  specification_version: 2
121
117
  summary: File generation system