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 +2 -2
- data/Rakefile +4 -3
- data/TODO +2 -4
- data/lib/templater.rb +1 -1
- data/lib/templater/cli/generator.rb +20 -15
- data/lib/templater/cli/manifold.rb +1 -1
- data/lib/templater/cli/parser.rb +5 -4
- data/lib/templater/file.rb +5 -0
- data/lib/templater/generator.rb +2 -2
- data/lib/templater/manifold.rb +41 -15
- data/lib/templater/proxy.rb +16 -27
- data/lib/templater/template.rb +8 -8
- data/spec/file_spec.rb +17 -0
- data/spec/generator_spec.rb +87 -9
- data/spec/manifold_spec.rb +79 -10
- data/spec/template_spec.rb +14 -7
- metadata +8 -12
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
|
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
|
-
|
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 =
|
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
data/lib/templater.rb
CHANGED
@@ -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
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
action
|
80
|
-
elsif
|
81
|
-
|
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
|
-
|
84
|
-
|
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.
|
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
|
data/lib/templater/cli/parser.rb
CHANGED
@@ -42,12 +42,13 @@ module Templater
|
|
42
42
|
options[:skip] = s
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
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[:
|
51
|
+
options[:delete] = s
|
51
52
|
end
|
52
53
|
|
53
54
|
opts.on("--no-color", "Don't colorize the output") do
|
data/lib/templater/file.rb
CHANGED
data/lib/templater/generator.rb
CHANGED
@@ -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::
|
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::
|
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
|
data/lib/templater/manifold.rb
CHANGED
@@ -2,22 +2,51 @@ module Templater
|
|
2
2
|
|
3
3
|
module Manifold
|
4
4
|
|
5
|
-
|
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
|
13
|
-
|
14
|
-
|
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
|
-
|
29
|
-
(
|
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
|
-
|
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.
|
data/lib/templater/proxy.rb
CHANGED
@@ -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
|
data/lib/templater/template.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
data/spec/generator_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
-
describe Templater::Generator, '
|
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(:
|
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(:
|
317
|
-
@instance.file(:
|
318
|
-
@instance.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(:
|
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(:
|
328
|
-
@instance.file(:
|
329
|
-
@instance.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
|
data/spec/manifold_spec.rb
CHANGED
@@ -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
|
13
|
-
@manifold.
|
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
|
-
|
19
|
-
|
20
|
-
|
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.
|
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
|
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
|
47
|
-
@manifold.
|
113
|
+
it "should remove a private generator" do
|
114
|
+
@manifold.add_private(:monkey, @generator)
|
48
115
|
@manifold.remove(:monkey)
|
49
|
-
@manifold.
|
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
|
data/spec/template_spec.rb
CHANGED
@@ -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
|
114
|
-
template = Templater::Template.new(@context, :monkey, template_path('simple_erb.rbt'), result_path('
|
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('
|
119
|
-
|
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
|
-
|
122
|
-
FileUtils.rm_rf(result_path('path'))
|
128
|
+
File.exists?(result_path('test.rbs')).should be_false
|
123
129
|
end
|
124
|
-
|
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:
|
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-
|
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.
|
114
|
+
rubygems_version: 1.2.0
|
119
115
|
signing_key:
|
120
116
|
specification_version: 2
|
121
117
|
summary: File generation system
|