tadpole 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +1 -1
- data/lib/tadpole/filters.rb +5 -3
- data/lib/tadpole/main.rb +5 -2
- data/lib/tadpole/template.rb +9 -1
- data/lib/tadpole.rb +1 -1
- data/spec/array_spec.rb +33 -0
- data/spec/basic_spec.rb +37 -37
- data/spec/examples/filters/setup.rb +3 -0
- data/spec/filters_spec.rb +40 -18
- metadata +7 -29
data/README.markdown
CHANGED
@@ -68,7 +68,7 @@ And to run this file all we need to do is:
|
|
68
68
|
# Running our template will now add our 'header' file to the output
|
69
69
|
Tadpole('mytemplate').run
|
70
70
|
|
71
|
-
###
|
71
|
+
### Hierarchical Sections
|
72
72
|
|
73
73
|
Sometimes you may need to encapsulate the output of some sections inside another one. An HTML
|
74
74
|
template, for example, will usually contain the page body inside the body tag of a more general
|
data/lib/tadpole/filters.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module Tadpole
|
2
2
|
module Filters
|
3
3
|
module ClassMethods
|
4
|
-
def before_section(*args)
|
4
|
+
def before_section(*args, &block)
|
5
|
+
args.push(block) if block
|
5
6
|
if args.size == 1
|
6
7
|
before_section_filters.push [nil, args.first]
|
7
8
|
elsif args.size == 2
|
@@ -10,13 +11,14 @@ module Tadpole
|
|
10
11
|
raise ArgumentError, "before_section takes a section followed by a Proc/lambda or Symbol referencing the method name"
|
11
12
|
end
|
12
13
|
end
|
14
|
+
alias before before_section
|
13
15
|
|
14
16
|
def before_section_filters
|
15
17
|
@before_section_filters ||= []
|
16
18
|
end
|
17
19
|
|
18
|
-
def before_run(meth)
|
19
|
-
before_run_filters.push(meth)
|
20
|
+
def before_run(meth = nil, &block)
|
21
|
+
before_run_filters.push(meth ? meth : block)
|
20
22
|
end
|
21
23
|
|
22
24
|
def before_run_filters
|
data/lib/tadpole/main.rb
CHANGED
@@ -5,10 +5,13 @@ end
|
|
5
5
|
class Insertion
|
6
6
|
def initialize(list, value) @list, @value = list, value end
|
7
7
|
def before(val) insertion(val, 0) end
|
8
|
-
def after(val) insertion(val, 1) end
|
8
|
+
def after(val, ignore_subsections = true) insertion(val, 1, ignore_subsections) end
|
9
9
|
private
|
10
|
-
def insertion(val, rel)
|
10
|
+
def insertion(val, rel, ignore_subsections = true)
|
11
11
|
if index = @list.index(val)
|
12
|
+
if ignore_subsections && rel == 1 && @list[index + 1].is_a?(Array)
|
13
|
+
rel += 1
|
14
|
+
end
|
12
15
|
@list[index+rel,0] = @value
|
13
16
|
end
|
14
17
|
@list
|
data/lib/tadpole/template.rb
CHANGED
@@ -7,6 +7,14 @@ class OpenHashStruct < OpenStruct
|
|
7
7
|
alias has_key? respond_to?
|
8
8
|
end
|
9
9
|
|
10
|
+
if RUBY_VERSION < "1.9"
|
11
|
+
class Hash
|
12
|
+
def key(value)
|
13
|
+
each {|k, v| return k if v == value }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
10
18
|
module Tadpole
|
11
19
|
module Template
|
12
20
|
class MissingSectionError < Exception; end
|
@@ -204,7 +212,7 @@ module Tadpole
|
|
204
212
|
def section_name(section)
|
205
213
|
case section
|
206
214
|
when SectionProviders::SectionProvider
|
207
|
-
@providers.
|
215
|
+
@providers.key(section) || section
|
208
216
|
else
|
209
217
|
section.respond_to?(:path) ? section.path : section
|
210
218
|
end.to_s
|
data/lib/tadpole.rb
CHANGED
data/spec/array_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'tadpole')
|
2
|
+
|
3
|
+
describe Array do
|
4
|
+
describe '#place' do
|
5
|
+
it "should create an Insertion object" do
|
6
|
+
[].place('x').should be_kind_of(Insertion)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Insertion do
|
12
|
+
describe '#before' do
|
13
|
+
it "should place an object before another" do
|
14
|
+
[1, 2].place(3).before(2).should == [1, 3, 2]
|
15
|
+
[1, 2].place(3).before(1).should == [3, 1, 2]
|
16
|
+
[1, [4], 2].place(3).before(2).should == [1, [4], 3, 2]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#after' do
|
21
|
+
it "should place an object after another" do
|
22
|
+
[1, 2].place(3).after(2).should == [1, 2, 3]
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should place an object after another and its subsections" do
|
26
|
+
[1, [2]].place(3).after(1).should == [1, [2], 3]
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not not ignore subsections if ignore_subections=false" do
|
30
|
+
[1, [2]].place(3).after(1, false).should == [1, 3, [2]]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/basic_spec.rb
CHANGED
@@ -2,59 +2,59 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'tadpole')
|
|
2
2
|
|
3
3
|
Tadpole.caching = false
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe Tadpole do
|
6
6
|
before { Tadpole.template_paths.clear }
|
7
7
|
|
8
8
|
it "should be an alias to Tadpole.template" do
|
9
9
|
Tadpole.should_receive(:template).with(:x, :y, :z)
|
10
10
|
Tadpole(:x, :y, :z)
|
11
11
|
end
|
12
|
-
end
|
13
12
|
|
14
|
-
describe
|
15
|
-
|
13
|
+
describe '.template' do
|
14
|
+
it "should raise ArgumentError if path does not exist in template_paths" do
|
15
|
+
lambda { Tadpole(:x, :y, :z) }.should raise_error(ArgumentError)
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
Tadpole.constants.should include("LocalTemplate_default_html")
|
27
|
-
Tadpole.constants.should include("LocalTemplate_default")
|
28
|
-
end
|
18
|
+
it "should create the module with the path name" do
|
19
|
+
Tadpole.register_template_path ''
|
20
|
+
File.should_receive(:directory?).exactly(3).times.and_return(true)
|
21
|
+
Tadpole('default/html')
|
22
|
+
symbolized_consts = Tadpole.constants.map {|c| c.to_sym }
|
23
|
+
symbolized_consts.should include(:Template_default_html)
|
24
|
+
symbolized_consts.should include(:LocalTemplate_default_html)
|
25
|
+
symbolized_consts.should include(:LocalTemplate_default)
|
26
|
+
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
Tadpole::
|
42
|
-
|
43
|
-
|
28
|
+
it "should override templates from other template paths" do
|
29
|
+
Tadpole.register_template_path 'a'
|
30
|
+
Tadpole.register_template_path 'b'
|
31
|
+
File.should_receive(:directory?).exactly(6).times.and_return(true)
|
32
|
+
Tadpole(:new, :template)
|
33
|
+
symbolized_consts = Tadpole.constants.map {|c| c.to_sym }
|
34
|
+
symbolized_consts.should include(:Template_new_template)
|
35
|
+
symbolized_consts.should include(:LocalTemplate_a_new_template)
|
36
|
+
symbolized_consts.should include(:LocalTemplate_a_new)
|
37
|
+
symbolized_consts.should include(:LocalTemplate_b_new_template)
|
38
|
+
symbolized_consts.should include(:LocalTemplate_b_new)
|
39
|
+
Tadpole::Template_new_template.ancestors.should == [Tadpole::Template_new_template,
|
40
|
+
Tadpole::LocalTemplate_b_new_template, Tadpole::LocalTemplate_a_new_template,
|
41
|
+
Tadpole::LocalTemplate_b_new, Tadpole::LocalTemplate_a_new, Tadpole::LocalTemplate,
|
42
|
+
Tadpole::Template]
|
43
|
+
end
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
describe Tadpole
|
48
|
-
before
|
47
|
+
describe Tadpole::Template do
|
48
|
+
before do
|
49
|
+
Tadpole.template_paths.clear
|
50
|
+
Tadpole.register_template_path '.'
|
51
|
+
end
|
49
52
|
|
50
53
|
it "should act as a class (have a .new, #inspect, etc.)" do
|
51
|
-
#File.should_receive(:directory?).and_return(true)
|
52
|
-
#Tadpole.caching = false
|
53
54
|
Tadpole(:default, :html).should respond_to(:new)
|
54
55
|
Tadpole::Template.should === Tadpole(:default, :html).new
|
55
|
-
#Tadpole.caching = false
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
it "should #run with Symbol sections as methods" do
|
59
59
|
File.should_receive(:directory?).at_least(1).times.and_return(true)
|
60
60
|
obj = Tadpole(:x, :q).new
|
@@ -77,7 +77,7 @@ describe Tadpole, "::Template" do
|
|
77
77
|
qs.should_receive(:run).and_return('Z')
|
78
78
|
obj.run.should == 'XYZ'
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
it "should alias .run as new.run" do
|
82
82
|
File.should_receive(:directory?).at_least(1).times.and_return(true)
|
83
83
|
obj = mock(:obj)
|
data/spec/filters_spec.rb
CHANGED
@@ -6,24 +6,6 @@ describe Tadpole::Filters do
|
|
6
6
|
Tadpole.register_template_path File.dirname(__FILE__) + '/examples'
|
7
7
|
end
|
8
8
|
|
9
|
-
it "should call before_run filter" do
|
10
|
-
obj = Template(:filters).new
|
11
|
-
obj.should_receive(:test)
|
12
|
-
obj.run
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should call before_section filter for specific section" do
|
16
|
-
obj = Template(:filters).new
|
17
|
-
obj.should_receive(:run_a).with('a')
|
18
|
-
obj.run
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should call before_section filter for all sections" do
|
22
|
-
obj = Template(:filters).new
|
23
|
-
obj.should_receive(:all).exactly(2).times
|
24
|
-
obj.run
|
25
|
-
end
|
26
|
-
|
27
9
|
it "should allow filters specified directly in LocalTemplate" do
|
28
10
|
eval "module Tadpole::LocalTemplate; before_run :xyz end"
|
29
11
|
|
@@ -34,4 +16,44 @@ describe Tadpole::Filters do
|
|
34
16
|
obj.run
|
35
17
|
Tadpole::LocalTemplate.before_run_filters.clear
|
36
18
|
end
|
19
|
+
|
20
|
+
describe '#before_run' do
|
21
|
+
it "should call filter" do
|
22
|
+
Template(:filters).before_run_filters.size.should == 2
|
23
|
+
obj = Template(:filters).new
|
24
|
+
obj.should_receive(:test)
|
25
|
+
obj.run
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should take a block" do
|
29
|
+
Template(:filters).before_run_filters.last.should be_kind_of(Proc)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#before_section' do
|
34
|
+
it "should call filter for specific section" do
|
35
|
+
obj = Template(:filters).new
|
36
|
+
obj.should_receive(:run_a).with('a')
|
37
|
+
obj.run
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should call filter for all sections" do
|
41
|
+
obj = Template(:filters).new
|
42
|
+
obj.should_receive(:all).exactly(2).times
|
43
|
+
obj.run
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should take a block for a specific section" do
|
47
|
+
filter = Template(:filters).before_section_filters[3]
|
48
|
+
filter[0].should == :b
|
49
|
+
filter[1].should be_kind_of(Proc)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should take a block for a all sections" do
|
53
|
+
filter = Template(:filters).before_section_filters[2]
|
54
|
+
filter[0].should == nil
|
55
|
+
filter[1].should be_kind_of(Proc)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
37
59
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tadpole
|
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
|
- Loren Segal
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-07-09 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,11 +22,9 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
|
24
24
|
files:
|
25
|
-
- lib/tadpole
|
26
25
|
- lib/tadpole/filters.rb
|
27
26
|
- lib/tadpole/local_template.rb
|
28
27
|
- lib/tadpole/main.rb
|
29
|
-
- lib/tadpole/providers
|
30
28
|
- lib/tadpole/providers/erb.rb
|
31
29
|
- lib/tadpole/providers/file.rb
|
32
30
|
- lib/tadpole/providers/haml.rb
|
@@ -35,68 +33,46 @@ files:
|
|
35
33
|
- lib/tadpole/providers/template.rb
|
36
34
|
- lib/tadpole/template.rb
|
37
35
|
- lib/tadpole.rb
|
36
|
+
- spec/array_spec.rb
|
38
37
|
- spec/basic_spec.rb
|
39
|
-
- spec/examples
|
40
|
-
- spec/examples/filters
|
41
38
|
- spec/examples/filters/a.txt
|
42
39
|
- spec/examples/filters/b.txt
|
43
40
|
- spec/examples/filters/setup.rb
|
44
|
-
- spec/examples/render
|
45
|
-
- spec/examples/render/1
|
46
41
|
- spec/examples/render/1/a.txt
|
47
42
|
- spec/examples/render/1/b.txt
|
48
43
|
- spec/examples/render/1/d.erb
|
49
44
|
- spec/examples/render/1/setup.rb
|
50
|
-
- spec/examples/render/2
|
51
45
|
- spec/examples/render/2/setup.rb
|
52
|
-
- spec/examples/render/3
|
53
46
|
- spec/examples/render/3/setup.rb
|
54
|
-
- spec/examples/render/4
|
55
47
|
- spec/examples/render/4/a.erb
|
56
48
|
- spec/examples/render/4/setup.rb
|
57
|
-
- spec/examples/render/5
|
58
49
|
- spec/examples/render/5/setup.rb
|
59
|
-
- spec/examples/render/6
|
60
50
|
- spec/examples/render/6/setup.rb
|
61
51
|
- spec/filters_spec.rb
|
62
52
|
- spec/render_spec.rb
|
63
53
|
- benchmarks/eval-vs-non-eval.rb
|
64
54
|
- benchmarks/require-vs-none.rb
|
65
55
|
- benchmarks/run-caching.rb
|
66
|
-
- examples/example1
|
67
|
-
- examples/example1/custom
|
68
|
-
- examples/example1/custom/html
|
69
|
-
- examples/example1/custom/html/body
|
70
56
|
- examples/example1/custom/html/body/important.html
|
71
57
|
- examples/example1/custom/html/body/setup.rb
|
72
58
|
- examples/example1/custom/html/setup.rb
|
73
|
-
- examples/example1/default
|
74
|
-
- examples/example1/default/html
|
75
|
-
- examples/example1/default/html/body
|
76
59
|
- examples/example1/default/html/body/info.erb
|
77
60
|
- examples/example1/default/html/body/setup.rb
|
78
61
|
- examples/example1/default/html/main.haml
|
79
62
|
- examples/example1/default/html/setup.rb
|
80
63
|
- examples/example1/run.rb
|
81
|
-
- examples/example2
|
82
64
|
- examples/example2/run.rb
|
83
|
-
- examples/example2/tadpole
|
84
|
-
- examples/example2/tadpole/html
|
85
65
|
- examples/example2/tadpole/html/content.haml
|
86
66
|
- examples/example2/tadpole/html/main.haml
|
87
|
-
- examples/example2/tadpole/html/readme
|
88
67
|
- examples/example2/tadpole/html/readme/setup.rb
|
89
68
|
- examples/example2/tadpole/html/setup.rb
|
90
|
-
- examples/example2/tadpole/markdown
|
91
69
|
- examples/example2/tadpole/markdown/copyright.md
|
92
70
|
- examples/example2/tadpole/markdown/examples.md
|
93
|
-
- examples/example2/tadpole/markdown/quick
|
94
71
|
- examples/example2/tadpole/markdown/quick/create.md
|
95
72
|
- examples/example2/tadpole/markdown/quick/heirarchical.md
|
96
73
|
- examples/example2/tadpole/markdown/quick/override.md
|
97
74
|
- examples/example2/tadpole/markdown/quick/quick.erb
|
98
75
|
- examples/example2/tadpole/markdown/quick/setup.rb
|
99
|
-
- examples/example2/tadpole/markdown/readme
|
100
76
|
- examples/example2/tadpole/markdown/readme/readme_notice.txt
|
101
77
|
- examples/example2/tadpole/markdown/readme/setup.rb
|
102
78
|
- examples/example2/tadpole/markdown/setup.rb
|
@@ -108,6 +84,8 @@ files:
|
|
108
84
|
- README.markdown
|
109
85
|
has_rdoc: false
|
110
86
|
homepage: http://www.soen.ca
|
87
|
+
licenses: []
|
88
|
+
|
111
89
|
post_install_message:
|
112
90
|
rdoc_options: []
|
113
91
|
|
@@ -128,9 +106,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
106
|
requirements: []
|
129
107
|
|
130
108
|
rubyforge_project: tadpole
|
131
|
-
rubygems_version: 1.
|
109
|
+
rubygems_version: 1.3.4
|
132
110
|
signing_key:
|
133
|
-
specification_version:
|
111
|
+
specification_version: 3
|
134
112
|
summary: A Small but Extensible Templating Engine for Ruby
|
135
113
|
test_files: []
|
136
114
|
|