cerubis 0.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/.gitignore +10 -0
- data/.travis.yml +14 -0
- data/Gemfile +15 -0
- data/README.md +111 -0
- data/Rakefile +15 -0
- data/TODO.md +31 -0
- data/cerubis.gemspec +22 -0
- data/examples/blocks.rb +20 -0
- data/examples/full/blocks/script_block.rb +8 -0
- data/examples/full/config.rb +14 -0
- data/examples/full/example.rb +25 -0
- data/examples/full/helpers/html_helpers.rb +13 -0
- data/examples/full/helpers/include_helper.rb +15 -0
- data/examples/full/models/page.rb +17 -0
- data/examples/full/models/site.rb +13 -0
- data/examples/full/templates/_footer.cerubis +1 -0
- data/examples/full/templates/_header.cerubis +1 -0
- data/examples/full/templates/main.cerubis +31 -0
- data/examples/helpers.rb +22 -0
- data/examples/html.rb +18 -0
- data/examples/variables.rb +10 -0
- data/lib/cerubis.rb +55 -0
- data/lib/cerubis/block.rb +27 -0
- data/lib/cerubis/block_node.rb +37 -0
- data/lib/cerubis/blocks/if.rb +8 -0
- data/lib/cerubis/blocks/loop.rb +20 -0
- data/lib/cerubis/blocks/unless.rb +9 -0
- data/lib/cerubis/condition.rb +59 -0
- data/lib/cerubis/context.rb +30 -0
- data/lib/cerubis/helper.rb +12 -0
- data/lib/cerubis/matcher.rb +19 -0
- data/lib/cerubis/method.rb +19 -0
- data/lib/cerubis/node.rb +27 -0
- data/lib/cerubis/objects/array.rb +4 -0
- data/lib/cerubis/objects/fixnum.rb +4 -0
- data/lib/cerubis/objects/float.rb +4 -0
- data/lib/cerubis/objects/hash.rb +4 -0
- data/lib/cerubis/objects/string.rb +4 -0
- data/lib/cerubis/parser.rb +125 -0
- data/lib/cerubis/syntax_error.rb +4 -0
- data/lib/cerubis/template.rb +21 -0
- data/lib/cerubis/text_node.rb +10 -0
- data/lib/cerubis/variable_replacement.rb +34 -0
- data/lib/cerubis/version.rb +3 -0
- data/test/all.rb +3 -0
- data/test/cerubis/block_node_test.rb +36 -0
- data/test/cerubis/blocks/if_test.rb +24 -0
- data/test/cerubis/blocks/loop_test.rb +25 -0
- data/test/cerubis/blocks/unless_test.rb +25 -0
- data/test/cerubis/condition_test.rb +142 -0
- data/test/cerubis/context_test.rb +33 -0
- data/test/cerubis/helper_test.rb +17 -0
- data/test/cerubis/matcher_test.rb +20 -0
- data/test/cerubis/method_test.rb +60 -0
- data/test/cerubis/parser_test.rb +48 -0
- data/test/cerubis/template_test.rb +38 -0
- data/test/cerubis/text_node_test.rb +16 -0
- data/test/cerubis_test.rb +31 -0
- data/test/matchers/test_block_name.rb +25 -0
- data/test/matchers/test_close_block.rb +25 -0
- data/test/matchers/test_conditions.rb +21 -0
- data/test/matchers/test_helpers.rb +21 -0
- data/test/matchers/test_object_method.rb +37 -0
- data/test/matchers/test_open_block.rb +57 -0
- data/test/matchers/test_operators.rb +29 -0
- data/test/matchers/test_variable.rb +37 -0
- data/test/methods/test_array_methods.rb +21 -0
- data/test/methods/test_fixnum_methods.rb +6 -0
- data/test/methods/test_float_methods.rb +6 -0
- data/test/methods/test_hash_methods.rb +11 -0
- data/test/methods/test_string_methods.rb +11 -0
- data/test/nodes/test_node_defaults.rb +30 -0
- data/test/rendered_test.rb +159 -0
- data/test/test_helper.rb +34 -0
- metadata +149 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
module TestNodeDefaults
|
2
|
+
def test_content_returns_unparsed_content
|
3
|
+
node = class_name.new(content, options)
|
4
|
+
assert_equal content, node.content
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_parent_returns_parent_node_or_template
|
8
|
+
parent = StubObject.new
|
9
|
+
node = class_name.new(content, :parent => parent)
|
10
|
+
assert_equal parent, node.parent
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_context_traverses_to_parent
|
14
|
+
parent = StubObject.new(:context => { :foo => :bar })
|
15
|
+
node = class_name.new(content, :parent => parent)
|
16
|
+
assert_equal parent.context, node.context
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def options
|
21
|
+
context = Cerubis::Context.new(:title => 'Foo Title')
|
22
|
+
parent = StubObject.new(:context => context)
|
23
|
+
{ :parent => parent }
|
24
|
+
end
|
25
|
+
|
26
|
+
def content
|
27
|
+
'<h1>{{title}}</h1>'
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RenderedTest < MiniTest::Unit::TestCase
|
4
|
+
def test_render_single_block
|
5
|
+
template = Cerubis.render(content)
|
6
|
+
html = Capybara::Node::Simple.new(template.to_html)
|
7
|
+
|
8
|
+
assert html.has_selector?('body > section', :text => 'Foo Content')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_render_nested_blocks
|
12
|
+
template = Cerubis.render(nested_content)
|
13
|
+
html = Capybara::Node::Simple.new(template.to_html)
|
14
|
+
|
15
|
+
assert html.has_selector?('body > header > h1', :text => 'Header Content')
|
16
|
+
assert html.has_selector?('body > header > section > p', :text => 'Paragraph Content')
|
17
|
+
|
18
|
+
refute html.has_selector?('body > header > #hidden', :text => 'Hidden Content')
|
19
|
+
refute_match /\{\{/, template.to_html
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_render_loop_nested_blocks
|
23
|
+
template = Cerubis.render(loop_nested_content, :collection => [1,2,3])
|
24
|
+
html = Capybara::Node::Simple.new(template.to_html)
|
25
|
+
|
26
|
+
assert html.has_selector?('body > header > ul > li', :text => '1')
|
27
|
+
assert html.has_selector?('body > header > ul > li', :text => '2')
|
28
|
+
assert html.has_selector?('body > header > ul > li', :text => '3')
|
29
|
+
|
30
|
+
refute_match /\{\{/, template.to_html
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_render_unless_block
|
34
|
+
template = Cerubis.render(hidden_content)
|
35
|
+
html = Capybara::Node::Simple.new(template.to_html)
|
36
|
+
|
37
|
+
refute html.has_selector?('body > #hidden', :text => 'Hidden Content')
|
38
|
+
refute_match /\{\{/, template.to_html
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_render_loop_block
|
42
|
+
template = Cerubis.render(loop_content, :collection => [1,2,3])
|
43
|
+
html = Capybara::Node::Simple.new(template.to_html)
|
44
|
+
|
45
|
+
assert html.has_selector?('p', :text => 'Loop Content: 1')
|
46
|
+
assert html.has_selector?('p', :text => 'Loop Content: 2')
|
47
|
+
assert html.has_selector?('p', :text => 'Loop Content: 3')
|
48
|
+
refute_match /\{\{/, template.to_html
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_render_foo_helper
|
52
|
+
Cerubis.register_helper :foo_helper, FooHelper
|
53
|
+
template = Cerubis.render(helper_content, :item => 'Item Value')
|
54
|
+
assert_equal '<p>** Item Value **</p>', template.to_html.strip
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_helper_syntax_error
|
58
|
+
assert_raises Cerubis::SyntaxError do
|
59
|
+
Cerubis.register_helper :foo_helper, FooHelper
|
60
|
+
template = Cerubis.render(helper_content_error)
|
61
|
+
template.to_html
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_render_static_content
|
66
|
+
template = Cerubis.render(static_content)
|
67
|
+
assert_equal '<p>Static Content</p>', template.to_html.strip
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
def content
|
72
|
+
<<-STR
|
73
|
+
<body>
|
74
|
+
{{#if true}}
|
75
|
+
<section>Foo Content</section>
|
76
|
+
{{/if}}
|
77
|
+
</body>
|
78
|
+
STR
|
79
|
+
end
|
80
|
+
|
81
|
+
def nested_content
|
82
|
+
<<-STR
|
83
|
+
<body>
|
84
|
+
<header>
|
85
|
+
{{#if true}}
|
86
|
+
<h1>Header Content</h1>
|
87
|
+
<section>
|
88
|
+
{{#unless false}}
|
89
|
+
<p>{{#if true}} Paragraph Content {{/if}}</p>
|
90
|
+
{{/unless}}
|
91
|
+
</section>
|
92
|
+
{{/if}}
|
93
|
+
</header>
|
94
|
+
</body>
|
95
|
+
STR
|
96
|
+
end
|
97
|
+
|
98
|
+
def loop_nested_content
|
99
|
+
<<-STR
|
100
|
+
<body>
|
101
|
+
{{#if true}}
|
102
|
+
<header>
|
103
|
+
{{#unless false}}
|
104
|
+
<ul>
|
105
|
+
{{#loop item in collection}}
|
106
|
+
<li>{{item}}</li>
|
107
|
+
{{/loop}}
|
108
|
+
</ul>
|
109
|
+
{{/unless}}
|
110
|
+
</header>
|
111
|
+
{{/if}}
|
112
|
+
</body>
|
113
|
+
STR
|
114
|
+
end
|
115
|
+
|
116
|
+
def hidden_content
|
117
|
+
<<-STR
|
118
|
+
<body>
|
119
|
+
{{#unless true}}
|
120
|
+
<section id="hidden">Hidden Content</section>
|
121
|
+
{{/unless}}
|
122
|
+
</body>
|
123
|
+
STR
|
124
|
+
end
|
125
|
+
|
126
|
+
def loop_content
|
127
|
+
<<-STR
|
128
|
+
<body>
|
129
|
+
{{#loop item in collection}}
|
130
|
+
<p>Loop Content: {{ item }}</p>
|
131
|
+
{{/loop}}
|
132
|
+
</body>
|
133
|
+
STR
|
134
|
+
end
|
135
|
+
|
136
|
+
def helper_content
|
137
|
+
<<-STR
|
138
|
+
<p>{{ foo_helper item }}</p>
|
139
|
+
STR
|
140
|
+
end
|
141
|
+
|
142
|
+
def helper_content_error
|
143
|
+
<<-STR
|
144
|
+
{{ foo_helper 'bar', 'baz' }}
|
145
|
+
STR
|
146
|
+
end
|
147
|
+
|
148
|
+
def static_content
|
149
|
+
<<-STR
|
150
|
+
<p>Static Content</p>
|
151
|
+
STR
|
152
|
+
end
|
153
|
+
|
154
|
+
module FooHelper
|
155
|
+
def foo_helper(value)
|
156
|
+
"** #{value} **"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
Bundler.setup(:test)
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'cover_me'
|
8
|
+
rescue LoadError
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'minitest/autorun'
|
12
|
+
require 'cerubis'
|
13
|
+
|
14
|
+
# test tools
|
15
|
+
require 'capybara'
|
16
|
+
|
17
|
+
begin
|
18
|
+
require 'ruby-debug'
|
19
|
+
rescue LoadError
|
20
|
+
end
|
21
|
+
|
22
|
+
class StubObject
|
23
|
+
def initialize(methods={})
|
24
|
+
@methods = methods
|
25
|
+
end
|
26
|
+
|
27
|
+
def method_missing(*args)
|
28
|
+
@methods[args.first] || self.class.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def cerubis_respond_to?(*args)
|
32
|
+
@methods.include?(args.first.to_sym) || super
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cerubis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dane Harrigan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-09-30 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: A simple, secure, non-evaluating template engine
|
15
|
+
email:
|
16
|
+
- dane.harrigan@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .travis.yml
|
23
|
+
- Gemfile
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- TODO.md
|
27
|
+
- cerubis.gemspec
|
28
|
+
- examples/blocks.rb
|
29
|
+
- examples/full/blocks/script_block.rb
|
30
|
+
- examples/full/config.rb
|
31
|
+
- examples/full/example.rb
|
32
|
+
- examples/full/helpers/html_helpers.rb
|
33
|
+
- examples/full/helpers/include_helper.rb
|
34
|
+
- examples/full/models/page.rb
|
35
|
+
- examples/full/models/site.rb
|
36
|
+
- examples/full/templates/_footer.cerubis
|
37
|
+
- examples/full/templates/_header.cerubis
|
38
|
+
- examples/full/templates/main.cerubis
|
39
|
+
- examples/helpers.rb
|
40
|
+
- examples/html.rb
|
41
|
+
- examples/variables.rb
|
42
|
+
- lib/cerubis.rb
|
43
|
+
- lib/cerubis/block.rb
|
44
|
+
- lib/cerubis/block_node.rb
|
45
|
+
- lib/cerubis/blocks/if.rb
|
46
|
+
- lib/cerubis/blocks/loop.rb
|
47
|
+
- lib/cerubis/blocks/unless.rb
|
48
|
+
- lib/cerubis/condition.rb
|
49
|
+
- lib/cerubis/context.rb
|
50
|
+
- lib/cerubis/helper.rb
|
51
|
+
- lib/cerubis/matcher.rb
|
52
|
+
- lib/cerubis/method.rb
|
53
|
+
- lib/cerubis/node.rb
|
54
|
+
- lib/cerubis/objects/array.rb
|
55
|
+
- lib/cerubis/objects/fixnum.rb
|
56
|
+
- lib/cerubis/objects/float.rb
|
57
|
+
- lib/cerubis/objects/hash.rb
|
58
|
+
- lib/cerubis/objects/string.rb
|
59
|
+
- lib/cerubis/parser.rb
|
60
|
+
- lib/cerubis/syntax_error.rb
|
61
|
+
- lib/cerubis/template.rb
|
62
|
+
- lib/cerubis/text_node.rb
|
63
|
+
- lib/cerubis/variable_replacement.rb
|
64
|
+
- lib/cerubis/version.rb
|
65
|
+
- test/all.rb
|
66
|
+
- test/cerubis/block_node_test.rb
|
67
|
+
- test/cerubis/blocks/if_test.rb
|
68
|
+
- test/cerubis/blocks/loop_test.rb
|
69
|
+
- test/cerubis/blocks/unless_test.rb
|
70
|
+
- test/cerubis/condition_test.rb
|
71
|
+
- test/cerubis/context_test.rb
|
72
|
+
- test/cerubis/helper_test.rb
|
73
|
+
- test/cerubis/matcher_test.rb
|
74
|
+
- test/cerubis/method_test.rb
|
75
|
+
- test/cerubis/parser_test.rb
|
76
|
+
- test/cerubis/template_test.rb
|
77
|
+
- test/cerubis/text_node_test.rb
|
78
|
+
- test/cerubis_test.rb
|
79
|
+
- test/matchers/test_block_name.rb
|
80
|
+
- test/matchers/test_close_block.rb
|
81
|
+
- test/matchers/test_conditions.rb
|
82
|
+
- test/matchers/test_helpers.rb
|
83
|
+
- test/matchers/test_object_method.rb
|
84
|
+
- test/matchers/test_open_block.rb
|
85
|
+
- test/matchers/test_operators.rb
|
86
|
+
- test/matchers/test_variable.rb
|
87
|
+
- test/methods/test_array_methods.rb
|
88
|
+
- test/methods/test_fixnum_methods.rb
|
89
|
+
- test/methods/test_float_methods.rb
|
90
|
+
- test/methods/test_hash_methods.rb
|
91
|
+
- test/methods/test_string_methods.rb
|
92
|
+
- test/nodes/test_node_defaults.rb
|
93
|
+
- test/rendered_test.rb
|
94
|
+
- test/test_helper.rb
|
95
|
+
homepage: ''
|
96
|
+
licenses: []
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 1.9.2
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project: cerubis
|
115
|
+
rubygems_version: 1.8.10
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: A simple, secure, non-evaluating template engine
|
119
|
+
test_files:
|
120
|
+
- test/all.rb
|
121
|
+
- test/cerubis/block_node_test.rb
|
122
|
+
- test/cerubis/blocks/if_test.rb
|
123
|
+
- test/cerubis/blocks/loop_test.rb
|
124
|
+
- test/cerubis/blocks/unless_test.rb
|
125
|
+
- test/cerubis/condition_test.rb
|
126
|
+
- test/cerubis/context_test.rb
|
127
|
+
- test/cerubis/helper_test.rb
|
128
|
+
- test/cerubis/matcher_test.rb
|
129
|
+
- test/cerubis/method_test.rb
|
130
|
+
- test/cerubis/parser_test.rb
|
131
|
+
- test/cerubis/template_test.rb
|
132
|
+
- test/cerubis/text_node_test.rb
|
133
|
+
- test/cerubis_test.rb
|
134
|
+
- test/matchers/test_block_name.rb
|
135
|
+
- test/matchers/test_close_block.rb
|
136
|
+
- test/matchers/test_conditions.rb
|
137
|
+
- test/matchers/test_helpers.rb
|
138
|
+
- test/matchers/test_object_method.rb
|
139
|
+
- test/matchers/test_open_block.rb
|
140
|
+
- test/matchers/test_operators.rb
|
141
|
+
- test/matchers/test_variable.rb
|
142
|
+
- test/methods/test_array_methods.rb
|
143
|
+
- test/methods/test_fixnum_methods.rb
|
144
|
+
- test/methods/test_float_methods.rb
|
145
|
+
- test/methods/test_hash_methods.rb
|
146
|
+
- test/methods/test_string_methods.rb
|
147
|
+
- test/nodes/test_node_defaults.rb
|
148
|
+
- test/rendered_test.rb
|
149
|
+
- test/test_helper.rb
|