templater 0.1
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/LICENSE +20 -0
- data/README +199 -0
- data/Rakefile +69 -0
- data/TODO +5 -0
- data/lib/templater.rb +44 -0
- data/lib/templater/capture_helpers.rb +62 -0
- data/lib/templater/cli/generator.rb +162 -0
- data/lib/templater/cli/manifold.rb +57 -0
- data/lib/templater/cli/parser.rb +88 -0
- data/lib/templater/core_ext/string.rb +8 -0
- data/lib/templater/file.rb +58 -0
- data/lib/templater/generator.rb +560 -0
- data/lib/templater/manifold.rb +72 -0
- data/lib/templater/proxy.rb +66 -0
- data/lib/templater/template.rb +67 -0
- data/spec/core_ext/string_spec.rb +39 -0
- data/spec/file_spec.rb +74 -0
- data/spec/generator_spec.rb +1011 -0
- data/spec/manifold_spec.rb +77 -0
- data/spec/results/erb.rbs +1 -0
- data/spec/results/file.rbs +1 -0
- data/spec/results/random.rbs +1 -0
- data/spec/results/simple_erb.rbs +1 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/template_spec.rb +124 -0
- data/spec/templater_spec.rb +7 -0
- data/spec/templates/erb.rbt +1 -0
- data/spec/templates/glob/README +1 -0
- data/spec/templates/glob/arg.js +3 -0
- data/spec/templates/glob/subfolder/jessica_alba.jpg +1 -0
- data/spec/templates/glob/subfolder/monkey.rb +1 -0
- data/spec/templates/glob/test.rb +1 -0
- data/spec/templates/literals_erb.rbt +1 -0
- data/spec/templates/simple.rbt +1 -0
- data/spec/templates/simple_erb.rbt +1 -0
- metadata +123 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Templater::Manifold, '#add' 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 addition of generators and remember them" do
|
13
|
+
@manifold.add(:monkey, @generator)
|
14
|
+
@manifold.generator(:monkey).should == @generator
|
15
|
+
@manifold.generators[:monkey].should == @generator
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should add a trippy convenience method" do
|
19
|
+
@manifold.add(:monkey, @generator)
|
20
|
+
@manifold.monkey.should == @generator
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should set the manifold for the generator" do
|
24
|
+
@generator.should_receive(:manifold=).with(@manifold)
|
25
|
+
@manifold.add(:monkey, @generator)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe Templater::Manifold, '#remove' do
|
31
|
+
|
32
|
+
before(:each) do
|
33
|
+
@manifold = class << self; self end
|
34
|
+
@manifold.extend Templater::Manifold
|
35
|
+
@generator = mock('a generator')
|
36
|
+
@generator.stub!(:manifold=)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should allow removal of generators" do
|
40
|
+
@manifold.add(:monkey, @generator)
|
41
|
+
@manifold.remove(:monkey)
|
42
|
+
@manifold.generator(:monkey).should be_nil
|
43
|
+
@manifold.generators[:monkey].should be_nil
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should remove the accessor method" do
|
47
|
+
@manifold.add(:monkey, @generator)
|
48
|
+
@manifold.remove(:monkey)
|
49
|
+
@manifold.should_not respond_to(:monkey)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
describe Templater::Manifold, '#run_cli' do
|
55
|
+
|
56
|
+
it "should run the command line interface" do
|
57
|
+
manifold = class << self; self end
|
58
|
+
manifold.extend Templater::Manifold
|
59
|
+
|
60
|
+
Templater::CLI::Manifold.should_receive(:run).with('/path/to/destination', manifold, 'gen', '0.3', ['arg', 'blah'])
|
61
|
+
|
62
|
+
manifold.run_cli('/path/to/destination', 'gen', '0.3', ['arg', 'blah'])
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe Templater::Manifold, '#desc' do
|
68
|
+
|
69
|
+
it "should append text when called with an argument, and return it when called with no argument" do
|
70
|
+
manifold = class << self; self end
|
71
|
+
manifold.extend Templater::Manifold
|
72
|
+
|
73
|
+
manifold.desc "some text"
|
74
|
+
manifold.desc.should == "some text"
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
test_doodle_blah
|
@@ -0,0 +1 @@
|
|
1
|
+
test<%= 1+1 %>test
|
@@ -0,0 +1 @@
|
|
1
|
+
some text
|
@@ -0,0 +1 @@
|
|
1
|
+
test2test
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
$TESTING=true
|
2
|
+
$:.push File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
+
|
4
|
+
def template_path(template)
|
5
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'templates', template))
|
6
|
+
end
|
7
|
+
|
8
|
+
def result_path(result)
|
9
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'results', result))
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'templater.rb'
|
13
|
+
require 'rubygems'
|
14
|
+
require 'spec'
|
15
|
+
require 'fileutils'
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Templater::Template, '.new' do
|
4
|
+
it "should set name, source and destination" do
|
5
|
+
template = Templater::Template.new('some_context', :monkey, '/path/to/source', '/path/to/destination')
|
6
|
+
template.context.should == 'some_context'
|
7
|
+
template.name.should == :monkey
|
8
|
+
template.source.should == '/path/to/source'
|
9
|
+
template.destination.should == '/path/to/destination'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe Templater::Template, '#relative_destination' do
|
14
|
+
it "should get the destination relative to the pwd" do
|
15
|
+
Dir.stub!(:pwd).and_return('/path/to')
|
16
|
+
template = Templater::Template.new('some_context', :monkey, '/path/to/source', '/path/to/destination/with/some/more/subdirs')
|
17
|
+
template.relative_destination.should == 'destination/with/some/more/subdirs'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Templater::Template, '#render' do
|
22
|
+
before do
|
23
|
+
@context = class << self; self end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should render a simple template" do
|
27
|
+
template = Templater::Template.new(@context, :monkey, template_path('simple.rbt'), '/path/to/destination')
|
28
|
+
template.render.should == "Hello World"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should render some basic erb" do
|
32
|
+
template = Templater::Template.new(@context, :monkey, template_path('simple_erb.rbt'), '/path/to/destination')
|
33
|
+
template.render.should == "test2test"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should render some erb and convert erb literals" do
|
37
|
+
template = Templater::Template.new(@context, :monkey, template_path('literals_erb.rbt'), '/path/to/destination')
|
38
|
+
template.render.should == "test2test<%= 1+1 %>blah"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should render some erb fetching stuff from the context" do
|
42
|
+
@context.should_receive(:funkydoodle).and_return('_doodle_')
|
43
|
+
template = Templater::Template.new(@context, :monkey, template_path('erb.rbt'), '/path/to/destination')
|
44
|
+
template.render.should == "test_doodle_blah"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe Templater::Template, '#exists?' do
|
49
|
+
|
50
|
+
it "should exist if the destination file exists" do
|
51
|
+
template = Templater::Template.new(@context, :monkey, template_path('simple.rbt'), result_path('erb.rbs'))
|
52
|
+
template.should be_exists
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should not exist if the destination file does not exist" do
|
56
|
+
template = Templater::Template.new(@context, :monkey, template_path('simple.rbt'), result_path('some_weird_file.rbs'))
|
57
|
+
template.should_not be_exists
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe Templater::Template, '#identical' do
|
63
|
+
before do
|
64
|
+
@context = class << self; self end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should not be identical if the destination file doesn't exist" do
|
68
|
+
template = Templater::Template.new(@context, :monkey, template_path('simple_erb.rbt'), result_path('some_weird_file.rbs'))
|
69
|
+
template.should_not be_identical
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should not be identical if the rendered content does not match the content of the file" do
|
73
|
+
template = Templater::Template.new(@context, :monkey, template_path('simple_erb.rbt'), result_path('random.rbs'))
|
74
|
+
template.should be_exists
|
75
|
+
template.should_not be_identical
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should be identical if the rendered content matches the content of the file" do
|
79
|
+
template = Templater::Template.new(@context, :monkey, template_path('simple_erb.rbt'), result_path('simple_erb.rbs'))
|
80
|
+
template.should be_exists
|
81
|
+
template.should be_identical
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe Templater::Template, '#invoke!' do
|
86
|
+
before do
|
87
|
+
@context = class << self; self end
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should render the template and copy it to the destination" do
|
91
|
+
template = Templater::Template.new(@context, :monkey, template_path('simple_erb.rbt'), result_path('test.rbs'))
|
92
|
+
|
93
|
+
template.invoke!
|
94
|
+
|
95
|
+
File.exists?(result_path('test.rbs')).should be_true
|
96
|
+
File.read(result_path('test.rbs')).should == "test2test"
|
97
|
+
|
98
|
+
FileUtils.rm(result_path('test.rbs'))
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should render the template and copy it to the destination, creating any required subdirectories" do
|
102
|
+
template = Templater::Template.new(@context, :monkey, template_path('simple_erb.rbt'), result_path('path/to/subdir/test.rbs'))
|
103
|
+
|
104
|
+
template.invoke!
|
105
|
+
|
106
|
+
File.exists?(result_path('path/to/subdir/test.rbs')).should be_true
|
107
|
+
File.read(result_path('path/to/subdir/test.rbs')).should == "test2test"
|
108
|
+
|
109
|
+
# cleanup
|
110
|
+
FileUtils.rm_rf(result_path('path'))
|
111
|
+
end
|
112
|
+
|
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)
|
115
|
+
|
116
|
+
template.invoke!
|
117
|
+
|
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
|
120
|
+
|
121
|
+
# cleanup
|
122
|
+
FileUtils.rm_rf(result_path('path'))
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
test<%= funkydoodle %>blah
|
@@ -0,0 +1 @@
|
|
1
|
+
this is stuff is for testing the Templater::Generator.glob! method.
|
@@ -0,0 +1 @@
|
|
1
|
+
a picture of jessica alba.
|
@@ -0,0 +1 @@
|
|
1
|
+
puts "MONKEY".reverse
|
@@ -0,0 +1 @@
|
|
1
|
+
puts 1 + 1
|
@@ -0,0 +1 @@
|
|
1
|
+
test<%= 1+1 %>test<%%= 1+1 %>blah
|
@@ -0,0 +1 @@
|
|
1
|
+
Hello World
|
@@ -0,0 +1 @@
|
|
1
|
+
test<%= 1+1 %>test
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: templater
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonas Nicklas
|
8
|
+
autorequire: templater
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-30 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: highline
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.4.0
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: diff-lcs
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 1.1.2
|
32
|
+
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
|
+
description: File generation system
|
43
|
+
email: jonas.nicklas@gmail.com
|
44
|
+
executables: []
|
45
|
+
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
extra_rdoc_files:
|
49
|
+
- README
|
50
|
+
- LICENSE
|
51
|
+
- TODO
|
52
|
+
files:
|
53
|
+
- LICENSE
|
54
|
+
- README
|
55
|
+
- Rakefile
|
56
|
+
- TODO
|
57
|
+
- lib/templater
|
58
|
+
- lib/templater/capture_helpers.rb
|
59
|
+
- lib/templater/cli
|
60
|
+
- lib/templater/cli/generator.rb
|
61
|
+
- lib/templater/cli/manifold.rb
|
62
|
+
- lib/templater/cli/parser.rb
|
63
|
+
- lib/templater/core_ext
|
64
|
+
- lib/templater/core_ext/string.rb
|
65
|
+
- lib/templater/file.rb
|
66
|
+
- lib/templater/generator.rb
|
67
|
+
- lib/templater/manifold.rb
|
68
|
+
- lib/templater/proxy.rb
|
69
|
+
- lib/templater/template.rb
|
70
|
+
- lib/templater.rb
|
71
|
+
- spec/core_ext
|
72
|
+
- spec/core_ext/string_spec.rb
|
73
|
+
- spec/file_spec.rb
|
74
|
+
- spec/generator_spec.rb
|
75
|
+
- spec/manifold_spec.rb
|
76
|
+
- spec/results
|
77
|
+
- spec/results/erb.rbs
|
78
|
+
- spec/results/file.rbs
|
79
|
+
- spec/results/random.rbs
|
80
|
+
- spec/results/simple_erb.rbs
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
- spec/template_spec.rb
|
83
|
+
- spec/templater_spec.rb
|
84
|
+
- spec/templates
|
85
|
+
- spec/templates/erb.rbt
|
86
|
+
- spec/templates/glob
|
87
|
+
- spec/templates/glob/arg.js
|
88
|
+
- spec/templates/glob/README
|
89
|
+
- spec/templates/glob/subfolder
|
90
|
+
- spec/templates/glob/subfolder/jessica_alba.jpg
|
91
|
+
- spec/templates/glob/subfolder/monkey.rb
|
92
|
+
- spec/templates/glob/test.rb
|
93
|
+
- spec/templates/literals_erb.rbt
|
94
|
+
- spec/templates/simple.rbt
|
95
|
+
- spec/templates/simple_erb.rbt
|
96
|
+
has_rdoc: true
|
97
|
+
homepage: http://templater.rubyforge.org/
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: "0"
|
108
|
+
version:
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: "0"
|
114
|
+
version:
|
115
|
+
requirements: []
|
116
|
+
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.1.1
|
119
|
+
signing_key:
|
120
|
+
specification_version: 2
|
121
|
+
summary: File generation system
|
122
|
+
test_files: []
|
123
|
+
|