h2o 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/h2o.gemspec +66 -67
- data/lib/h2o.rb +1 -0
- data/lib/h2o/filters/default.rb +3 -0
- data/lib/h2o/parser.rb +2 -2
- data/lib/h2o/tags.rb +4 -0
- data/lib/h2o/tags/if.rb +9 -1
- data/lib/h2o/tags/raw.rb +19 -0
- data/spec/h2o/tags/if_spec.rb +25 -0
- data/spec/h2o/tags/raw_spec.rb +20 -0
- metadata +9 -16
- data/.gitignore +0 -1
- data/spec/spec.opts +0 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
data/h2o.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Taylor luk"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-03-14}
|
13
13
|
s.description = %q{h2o is a django inspired template that offers natural template syntax and easy to integrate.}
|
14
14
|
s.email = %q{subjective@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -17,80 +17,79 @@ Gem::Specification.new do |s|
|
|
17
17
|
]
|
18
18
|
s.files = [
|
19
19
|
".autotest",
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
20
|
+
".project",
|
21
|
+
"README.md",
|
22
|
+
"Rakefile",
|
23
|
+
"TODO.md",
|
24
|
+
"VERSION",
|
25
|
+
"benchmark/parser.rb",
|
26
|
+
"benchmark/source.html",
|
27
|
+
"example/erb/base.html",
|
28
|
+
"example/h2o/base.html",
|
29
|
+
"example/h2o/index.html",
|
30
|
+
"example/h2o/inherit.html",
|
31
|
+
"example/h2o/layout.html",
|
32
|
+
"example/liquid/base.html",
|
33
|
+
"example/request.html",
|
34
|
+
"example/run.rb",
|
35
|
+
"example/server",
|
36
|
+
"example/server.bat",
|
37
|
+
"example/server.rb",
|
38
|
+
"h2o.gemspec",
|
39
|
+
"init.rb",
|
40
|
+
"lib/.DS_Store",
|
41
|
+
"lib/core_ext/object.rb",
|
42
|
+
"lib/h2o.rb",
|
43
|
+
"lib/h2o/constants.rb",
|
44
|
+
"lib/h2o/context.rb",
|
45
|
+
"lib/h2o/datatype.rb",
|
46
|
+
"lib/h2o/error.rb",
|
47
|
+
"lib/h2o/file_loader.rb",
|
48
|
+
"lib/h2o/filters.rb",
|
49
|
+
"lib/h2o/filters/default.rb",
|
50
|
+
"lib/h2o/nodes.rb",
|
51
|
+
"lib/h2o/parser.rb",
|
52
|
+
"lib/h2o/tags.rb",
|
53
|
+
"lib/h2o/tags/block.rb",
|
54
|
+
"lib/h2o/tags/extends.rb",
|
55
|
+
"lib/h2o/tags/for.rb",
|
56
|
+
"lib/h2o/tags/if.rb",
|
57
|
+
"lib/h2o/tags/raw.rb",
|
58
|
+
"lib/h2o/tags/with.rb",
|
59
|
+
"lib/h2o/template.rb",
|
60
|
+
"spec/fixtures/_partial.html",
|
61
|
+
"spec/fixtures/a.html",
|
62
|
+
"spec/fixtures/b.html",
|
63
|
+
"spec/fixtures/deep/folder/c.html",
|
64
|
+
"spec/h2o/context_spec.rb",
|
65
|
+
"spec/h2o/default.html",
|
66
|
+
"spec/h2o/file_loader_spec.rb",
|
67
|
+
"spec/h2o/file_loader_spec.rbc",
|
68
|
+
"spec/h2o/filters_spec.rb",
|
69
|
+
"spec/h2o/parser_spec.rb",
|
70
|
+
"spec/h2o/tags/block_spec.rb",
|
71
|
+
"spec/h2o/tags/for_spec.rb",
|
72
|
+
"spec/h2o/tags/if_spec.rb",
|
73
|
+
"spec/h2o/tags/raw_spec.rb",
|
74
|
+
"spec/spec_helper.rb"
|
75
75
|
]
|
76
76
|
s.homepage = %q{http://www.h2o-template.org}
|
77
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
78
77
|
s.require_paths = ["lib"]
|
79
|
-
s.rubygems_version = %q{1.
|
78
|
+
s.rubygems_version = %q{1.5.0}
|
80
79
|
s.summary = %q{h2o is a django inspired template}
|
81
80
|
s.test_files = [
|
82
81
|
"spec/h2o/context_spec.rb",
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
82
|
+
"spec/h2o/file_loader_spec.rb",
|
83
|
+
"spec/h2o/filters_spec.rb",
|
84
|
+
"spec/h2o/parser_spec.rb",
|
85
|
+
"spec/h2o/tags/block_spec.rb",
|
86
|
+
"spec/h2o/tags/for_spec.rb",
|
87
|
+
"spec/h2o/tags/if_spec.rb",
|
88
|
+
"spec/h2o/tags/raw_spec.rb",
|
89
|
+
"spec/spec_helper.rb"
|
90
90
|
]
|
91
91
|
|
92
92
|
if s.respond_to? :specification_version then
|
93
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
94
93
|
s.specification_version = 3
|
95
94
|
|
96
95
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
data/lib/h2o.rb
CHANGED
data/lib/h2o/filters/default.rb
CHANGED
data/lib/h2o/parser.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module H2o
|
2
2
|
class Parser
|
3
|
-
attr_reader :token, :env
|
3
|
+
attr_reader :token, :env, :source
|
4
4
|
attr_accessor :storage
|
5
5
|
|
6
6
|
ParseRegex = /\G
|
@@ -96,7 +96,7 @@ module H2o
|
|
96
96
|
|
97
97
|
tag = Tags[name]
|
98
98
|
raise "Unknow tag #{name}" if tag.nil?
|
99
|
-
|
99
|
+
|
100
100
|
nodelist << tag.new(self, args) if tag
|
101
101
|
when :comment
|
102
102
|
nodelist << CommentNode.new(content)
|
data/lib/h2o/tags.rb
CHANGED
data/lib/h2o/tags/if.rb
CHANGED
@@ -10,13 +10,17 @@ module H2o
|
|
10
10
|
@body = parser.parse(:else, :endif)
|
11
11
|
@else = parser.parse(:endif) if parser.token.include? 'else'
|
12
12
|
@args = Parser.parse_arguments(argstring)
|
13
|
-
|
13
|
+
|
14
14
|
# Negated condition
|
15
15
|
first = @args.first
|
16
16
|
if first.is_a?(Hash) && first[:operator] && [:"!", :not].include?(first[:operator])
|
17
17
|
@negated = true
|
18
18
|
@args.shift
|
19
19
|
end
|
20
|
+
|
21
|
+
if @args[1].is_a?(Array)
|
22
|
+
@filters = [@args.pop]
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
def render(context, stream)
|
@@ -30,7 +34,11 @@ module H2o
|
|
30
34
|
def evaluate(context)
|
31
35
|
# Implicity evaluation
|
32
36
|
if @args.size == 1
|
37
|
+
|
33
38
|
object = context.resolve(@args.first)
|
39
|
+
|
40
|
+
object = context.apply_filters(object, @filters) if @filters
|
41
|
+
|
34
42
|
if object == false
|
35
43
|
result = false
|
36
44
|
elsif object == true
|
data/lib/h2o/tags/raw.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module H2o
|
2
|
+
module Tags
|
3
|
+
class Raw < Tag
|
4
|
+
def initialize(parser, argstring)
|
5
|
+
@body = parser.parse(:endraw)
|
6
|
+
end
|
7
|
+
|
8
|
+
def render(context, stream)
|
9
|
+
raw_body = @body.parser.source.gsub(/\{%\s?(:?end)?raw\s?%\}/sm, '')
|
10
|
+
|
11
|
+
stream << raw_body
|
12
|
+
end
|
13
|
+
|
14
|
+
Tags.register(self, :raw)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/spec/h2o/tags/if_spec.rb
CHANGED
@@ -55,4 +55,29 @@ describe H2o::Tags::If do
|
|
55
55
|
parse('{% if ! 2 > 3 %}Y{% endif %}').render.should == 'Y'
|
56
56
|
end
|
57
57
|
end
|
58
|
+
|
59
|
+
describe "filter#contain" do
|
60
|
+
context "When array" do
|
61
|
+
it "checks existence of item in a list" do
|
62
|
+
parse(
|
63
|
+
"{% if items|contain 1 %}true{% endif %}"
|
64
|
+
).render(:items => [1,2,3]).should == "true"
|
65
|
+
parse(
|
66
|
+
"{% if items|contain 4 %}true{% else %}false{%endif%}"
|
67
|
+
).render(:items => [1,2,3]).should == "false"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "When string" do
|
72
|
+
it "checks existence of item in a list" do
|
73
|
+
parse(
|
74
|
+
"{% if 'test'|contain 'est' %}true{% endif %}"
|
75
|
+
).render.should == "true"
|
76
|
+
parse(
|
77
|
+
"{% if 'test'|contain 'tet' %}true{% else %}false{%endif%}"
|
78
|
+
).render.should == "false"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
58
83
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe H2o::Tags::Raw do
|
4
|
+
it "should skip h2o render between raw tag" do
|
5
|
+
result = parse('{% raw %}{{ greeting }}{% endraw %}').render(:greeting => 'hello')
|
6
|
+
|
7
|
+
result.should_not == 'hello'
|
8
|
+
result.should == '{{ greeting }}'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should skip h2o render across multi-line" do
|
12
|
+
result = parse(<<-eos).render(:person => 'john smith')
|
13
|
+
{% raw %}
|
14
|
+
<h1>{{ person }}</h1>
|
15
|
+
{% endraw %}
|
16
|
+
eos
|
17
|
+
result.strip.should == '<h1>{{ person }}</h1>'
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: h2o
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 3
|
8
|
-
- 1
|
9
|
-
version: 0.3.1
|
4
|
+
prerelease:
|
5
|
+
version: 0.3.2
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Taylor luk
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date:
|
13
|
+
date: 2011-03-14 00:00:00 +11:00
|
18
14
|
default_executable:
|
19
15
|
dependencies: []
|
20
16
|
|
@@ -28,7 +24,6 @@ extra_rdoc_files:
|
|
28
24
|
- README.md
|
29
25
|
files:
|
30
26
|
- .autotest
|
31
|
-
- .gitignore
|
32
27
|
- .project
|
33
28
|
- README.md
|
34
29
|
- Rakefile
|
@@ -66,6 +61,7 @@ files:
|
|
66
61
|
- lib/h2o/tags/extends.rb
|
67
62
|
- lib/h2o/tags/for.rb
|
68
63
|
- lib/h2o/tags/if.rb
|
64
|
+
- lib/h2o/tags/raw.rb
|
69
65
|
- lib/h2o/tags/with.rb
|
70
66
|
- lib/h2o/template.rb
|
71
67
|
- spec/fixtures/_partial.html
|
@@ -81,15 +77,15 @@ files:
|
|
81
77
|
- spec/h2o/tags/block_spec.rb
|
82
78
|
- spec/h2o/tags/for_spec.rb
|
83
79
|
- spec/h2o/tags/if_spec.rb
|
84
|
-
- spec/
|
80
|
+
- spec/h2o/tags/raw_spec.rb
|
85
81
|
- spec/spec_helper.rb
|
86
82
|
has_rdoc: true
|
87
83
|
homepage: http://www.h2o-template.org
|
88
84
|
licenses: []
|
89
85
|
|
90
86
|
post_install_message:
|
91
|
-
rdoc_options:
|
92
|
-
|
87
|
+
rdoc_options: []
|
88
|
+
|
93
89
|
require_paths:
|
94
90
|
- lib
|
95
91
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -97,21 +93,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
93
|
requirements:
|
98
94
|
- - ">="
|
99
95
|
- !ruby/object:Gem::Version
|
100
|
-
segments:
|
101
|
-
- 0
|
102
96
|
version: "0"
|
103
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
98
|
none: false
|
105
99
|
requirements:
|
106
100
|
- - ">="
|
107
101
|
- !ruby/object:Gem::Version
|
108
|
-
segments:
|
109
|
-
- 0
|
110
102
|
version: "0"
|
111
103
|
requirements: []
|
112
104
|
|
113
105
|
rubyforge_project:
|
114
|
-
rubygems_version: 1.
|
106
|
+
rubygems_version: 1.5.0
|
115
107
|
signing_key:
|
116
108
|
specification_version: 3
|
117
109
|
summary: h2o is a django inspired template
|
@@ -123,4 +115,5 @@ test_files:
|
|
123
115
|
- spec/h2o/tags/block_spec.rb
|
124
116
|
- spec/h2o/tags/for_spec.rb
|
125
117
|
- spec/h2o/tags/if_spec.rb
|
118
|
+
- spec/h2o/tags/raw_spec.rb
|
126
119
|
- spec/spec_helper.rb
|
data/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
*/.DS_STORE
|
data/spec/spec.opts
DELETED