h2o 0.2 → 0.3.0
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/.autotest +11 -0
- data/.gitignore +1 -0
- data/.project +17 -0
- data/README.md +0 -0
- data/Rakefile +32 -0
- data/TODO.md +5 -0
- data/VERSION +1 -0
- data/benchmark/parser.rb +57 -0
- data/benchmark/source.html +4212 -0
- data/example/h2o/base.html +0 -1
- data/example/h2o/index.html +10 -0
- data/example/h2o/layout.html +11 -0
- data/example/request.html +0 -0
- data/example/server +1 -1
- data/h2o.gemspec +101 -41
- data/init.rb +1 -0
- data/lib/.DS_Store +0 -0
- data/lib/core_ext/object.rb +0 -0
- data/lib/h2o.rb +29 -39
- data/lib/h2o/constants.rb +2 -2
- data/lib/h2o/context.rb +3 -10
- data/lib/h2o/error.rb +9 -0
- data/lib/h2o/filters/default.rb +0 -0
- data/lib/h2o/nodes.rb +5 -1
- data/lib/h2o/tags.rb +1 -6
- data/lib/h2o/tags/block.rb +0 -30
- data/lib/h2o/tags/extends.rb +33 -0
- data/lib/h2o/tags/for.rb +7 -6
- data/lib/h2o/tags/with.rb +0 -0
- data/lib/h2o/template.rb +33 -0
- data/spec/fixtures/_partial.html +0 -0
- data/spec/fixtures/a.html +1 -0
- data/spec/fixtures/b.html +0 -0
- data/spec/fixtures/deep/folder/c.html +0 -0
- data/spec/h2o/context_spec.rb +134 -0
- data/spec/h2o/default.html +93 -0
- data/spec/h2o/file_loader_spec.rb +35 -0
- data/spec/h2o/filters_spec.rb +57 -0
- data/spec/h2o/parser_spec.rb +78 -0
- data/spec/h2o/tags/block_spec.rb +26 -0
- data/spec/h2o/tags/for_spec.rb +65 -0
- data/spec/h2o/tags/if_spec.rb +58 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +24 -0
- metadata +81 -27
- data/lib/h2o/errors.rb +0 -7
- data/lib/h2o/tags/recurse.rb +0 -55
data/example/h2o/base.html
CHANGED
data/example/request.html
CHANGED
File without changes
|
data/example/server
CHANGED
data/h2o.gemspec
CHANGED
@@ -1,43 +1,103 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
1
6
|
Gem::Specification.new do |s|
|
2
|
-
s.name
|
3
|
-
s.version
|
4
|
-
|
5
|
-
s.
|
6
|
-
s.
|
7
|
-
s.
|
8
|
-
s.description =
|
9
|
-
s.
|
10
|
-
s.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
7
|
+
s.name = %q{h2o}
|
8
|
+
s.version = "0.3.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Taylor luk"]
|
12
|
+
s.date = %q{2010-08-30}
|
13
|
+
s.description = %q{h2o is a django inspired template that offers natural template syntax and easy to integrate.}
|
14
|
+
s.email = %q{subjective@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.md"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".autotest",
|
20
|
+
".gitignore",
|
21
|
+
".project",
|
22
|
+
"README.md",
|
23
|
+
"Rakefile",
|
24
|
+
"TODO.md",
|
25
|
+
"VERSION",
|
26
|
+
"benchmark/parser.rb",
|
27
|
+
"benchmark/source.html",
|
28
|
+
"example/erb/base.html",
|
29
|
+
"example/h2o/base.html",
|
30
|
+
"example/h2o/index.html",
|
31
|
+
"example/h2o/inherit.html",
|
32
|
+
"example/h2o/layout.html",
|
33
|
+
"example/liquid/base.html",
|
34
|
+
"example/request.html",
|
35
|
+
"example/run.rb",
|
36
|
+
"example/server",
|
37
|
+
"example/server.bat",
|
38
|
+
"example/server.rb",
|
39
|
+
"h2o.gemspec",
|
40
|
+
"init.rb",
|
41
|
+
"lib/.DS_Store",
|
42
|
+
"lib/core_ext/object.rb",
|
43
|
+
"lib/h2o.rb",
|
44
|
+
"lib/h2o/constants.rb",
|
45
|
+
"lib/h2o/context.rb",
|
46
|
+
"lib/h2o/datatype.rb",
|
47
|
+
"lib/h2o/error.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/with.rb",
|
58
|
+
"lib/h2o/template.rb",
|
59
|
+
"spec/fixtures/_partial.html",
|
60
|
+
"spec/fixtures/a.html",
|
61
|
+
"spec/fixtures/b.html",
|
62
|
+
"spec/fixtures/deep/folder/c.html",
|
63
|
+
"spec/h2o/context_spec.rb",
|
64
|
+
"spec/h2o/default.html",
|
65
|
+
"spec/h2o/file_loader_spec.rb",
|
66
|
+
"spec/h2o/filters_spec.rb",
|
67
|
+
"spec/h2o/parser_spec.rb",
|
68
|
+
"spec/h2o/tags/block_spec.rb",
|
69
|
+
"spec/h2o/tags/for_spec.rb",
|
70
|
+
"spec/h2o/tags/if_spec.rb",
|
71
|
+
"spec/spec.opts",
|
72
|
+
"spec/spec_helper.rb"
|
73
|
+
]
|
74
|
+
s.homepage = %q{http://www.h2o-template.org}
|
75
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
76
|
+
s.require_paths = ["lib"]
|
77
|
+
s.rubygems_version = %q{1.3.7}
|
78
|
+
s.summary = %q{h2o is a django inspired template}
|
79
|
+
s.test_files = [
|
80
|
+
"spec/h2o/context_spec.rb",
|
81
|
+
"spec/h2o/file_loader_spec.rb",
|
82
|
+
"spec/h2o/filters_spec.rb",
|
83
|
+
"spec/h2o/parser_spec.rb",
|
84
|
+
"spec/h2o/tags/block_spec.rb",
|
85
|
+
"spec/h2o/tags/for_spec.rb",
|
86
|
+
"spec/h2o/tags/if_spec.rb",
|
87
|
+
"spec/spec_helper.rb"
|
88
|
+
]
|
89
|
+
|
90
|
+
if s.respond_to? :specification_version then
|
91
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
92
|
+
s.specification_version = 3
|
93
|
+
|
94
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
95
|
+
s.add_runtime_dependency(%q<schacon-git>, [">= 0"])
|
96
|
+
else
|
97
|
+
s.add_dependency(%q<schacon-git>, [">= 0"])
|
98
|
+
end
|
99
|
+
else
|
100
|
+
s.add_dependency(%q<schacon-git>, [">= 0"])
|
101
|
+
end
|
43
102
|
end
|
103
|
+
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/lib/h2o'
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/core_ext/object.rb
CHANGED
File without changes
|
data/lib/h2o.rb
CHANGED
@@ -1,43 +1,33 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'pathname'
|
2
|
+
require 'core_ext/object'
|
3
|
+
require 'h2o/constants'
|
3
4
|
|
4
|
-
|
5
|
-
attr_reader :context
|
6
|
-
|
7
|
-
def initialize (filename, env = {})
|
8
|
-
@file = Pathname.new(filename)
|
9
|
-
env[:search_path] = @file.dirname
|
10
|
-
@nodelist = Template.load(@file, env)
|
11
|
-
end
|
12
|
-
|
13
|
-
def render (context = {})
|
14
|
-
@context = Context.new(context)
|
15
|
-
output_stream = []
|
16
|
-
@nodelist.render(@context, output_stream)
|
17
|
-
output_stream.join
|
18
|
-
end
|
5
|
+
$:.unshift File.dirname(__FILE__) unless $:.include?(File.dirname(__FILE__))
|
19
6
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
7
|
+
module H2o
|
8
|
+
autoload :Template, 'h2o/template'
|
9
|
+
autoload :FileLoader, 'h2o/file_loader'
|
10
|
+
autoload :Error, 'h2o/error'
|
11
|
+
autoload :Context, 'h2o/context'
|
12
|
+
autoload :Parser, 'h2o/parser'
|
13
|
+
autoload :Node, 'h2o/nodes'
|
14
|
+
autoload :DataObject, 'h2o/context'
|
15
|
+
autoload :Filters, 'h2o/filters'
|
16
|
+
autoload :Tags, 'h2o/tags'
|
17
|
+
|
18
|
+
module Tags
|
19
|
+
require 'h2o/tags/if'
|
20
|
+
require 'h2o/tags/for'
|
21
|
+
require 'h2o/tags/with'
|
22
|
+
require 'h2o/tags/block'
|
23
|
+
require 'h2o/tags/extends'
|
30
24
|
end
|
31
|
-
end
|
32
|
-
|
33
|
-
require File.dirname(__FILE__) + '/core_ext/object'
|
34
|
-
|
35
|
-
require File.dirname(__FILE__) + '/h2o/constants'
|
36
|
-
require File.dirname(__FILE__) + '/h2o/errors'
|
37
|
-
require File.dirname(__FILE__) + '/h2o/nodes'
|
38
|
-
require File.dirname(__FILE__) + '/h2o/tags'
|
39
|
-
require File.dirname(__FILE__) + '/h2o/parser'
|
40
|
-
require File.dirname(__FILE__) + '/h2o/context'
|
41
|
-
require File.dirname(__FILE__) + '/h2o/filters'
|
42
|
-
|
43
25
|
|
26
|
+
def self.loader
|
27
|
+
@loader
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.loader=(loader)
|
31
|
+
@loader = loader
|
32
|
+
end
|
33
|
+
end
|
data/lib/h2o/constants.rb
CHANGED
data/lib/h2o/context.rb
CHANGED
@@ -111,7 +111,7 @@ module H2o
|
|
111
111
|
|
112
112
|
class DataObject
|
113
113
|
INTERNAL_METHOD = /^__/
|
114
|
-
@@required_methods = [:__send__, :__id__, :object_id, :respond_to?, :extend, :methods, :class, :nil?, :is_a
|
114
|
+
@@required_methods = [:__send__, :__id__, :object_id, :respond_to?, :extend, :methods, :class, :nil?, :is_a?, :to_h2o]
|
115
115
|
|
116
116
|
def respond_to?(method)
|
117
117
|
method_name = method.to_s
|
@@ -129,21 +129,14 @@ module H2o
|
|
129
129
|
end
|
130
130
|
|
131
131
|
class BlockContext < DataObject
|
132
|
-
|
133
|
-
def self.h2o_safe_methods
|
134
|
-
[:super]
|
135
|
-
end
|
136
|
-
|
137
|
-
def to_h2o
|
138
|
-
self
|
139
|
-
end
|
132
|
+
h2o_expose :super, :depth, :name
|
140
133
|
|
141
134
|
def initialize(block, context, stream, index)
|
142
135
|
@block, @context, @stream, @index = block, context, stream, index
|
143
136
|
end
|
144
137
|
|
145
138
|
def super
|
146
|
-
@block.parent.render(@context, @stream, @index-1) if @block.parent
|
139
|
+
@block.parent.render(@context, @stream, @index-1) if @block.parent.stack_size > @index.abs
|
147
140
|
nil
|
148
141
|
end
|
149
142
|
|
data/lib/h2o/error.rb
ADDED
data/lib/h2o/filters/default.rb
CHANGED
File without changes
|
data/lib/h2o/nodes.rb
CHANGED
data/lib/h2o/tags.rb
CHANGED
@@ -12,11 +12,6 @@ module H2o
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class Tag < Node; end
|
15
|
+
|
15
16
|
end
|
16
17
|
end
|
17
|
-
|
18
|
-
require File.dirname(__FILE__) + '/tags/if'
|
19
|
-
require File.dirname(__FILE__) + '/tags/for'
|
20
|
-
require File.dirname(__FILE__) + '/tags/block'
|
21
|
-
require File.dirname(__FILE__) + '/tags/with'
|
22
|
-
require File.dirname(__FILE__) + '/tags/recurse'
|
data/lib/h2o/tags/block.rb
CHANGED
@@ -30,35 +30,5 @@ module H2o
|
|
30
30
|
end
|
31
31
|
Tags.register(self, :block)
|
32
32
|
end
|
33
|
-
|
34
|
-
class Extends < Tag
|
35
|
-
Syntax = /\"(.*?)\"|\'(.*?)\'/
|
36
|
-
|
37
|
-
def initialize parser, argstring
|
38
|
-
unless parser.first?
|
39
|
-
raise SyntaxError, "extend tag needs to be at the beginning of the document"
|
40
|
-
end
|
41
|
-
# parser the entire subtemplate
|
42
|
-
parser.parse()
|
43
|
-
|
44
|
-
# load the parent template into nodelist
|
45
|
-
@nodelist = Template.load(argstring[1...-1], parser.env)
|
46
|
-
|
47
|
-
blocks = @nodelist.parser.storage[:blocks] || {}
|
48
|
-
|
49
|
-
(parser.storage[:blocks] || []).each do |name, block|
|
50
|
-
if blocks.include? name
|
51
|
-
blocks[name].add_layer(block)
|
52
|
-
block.parent = blocks[name]
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def render context, stream
|
58
|
-
@nodelist.render(context, stream)
|
59
|
-
end
|
60
|
-
|
61
|
-
Tags.register(self, :extends)
|
62
|
-
end
|
63
33
|
end
|
64
34
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module H2o
|
2
|
+
module Tags
|
3
|
+
class Extends < Tag
|
4
|
+
Syntax = /\"(.*?)\"|\'(.*?)\'/
|
5
|
+
|
6
|
+
def initialize parser, argstring
|
7
|
+
unless parser.first?
|
8
|
+
raise SyntaxError, "extend tag needs to be at the beginning of the document"
|
9
|
+
end
|
10
|
+
# parser the entire subtemplate
|
11
|
+
parser.parse()
|
12
|
+
|
13
|
+
# load the parent template into nodelist
|
14
|
+
@nodelist = Template.load(argstring[1...-1], parser.env)
|
15
|
+
|
16
|
+
blocks = @nodelist.parser.storage[:blocks] || {}
|
17
|
+
|
18
|
+
(parser.storage[:blocks] || []).each do |name, block|
|
19
|
+
if blocks.include? name
|
20
|
+
blocks[name].add_layer(block)
|
21
|
+
block.parent = blocks[name]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def render context, stream
|
27
|
+
@nodelist.render(context, stream)
|
28
|
+
end
|
29
|
+
|
30
|
+
Tags.register(self, :extends)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/h2o/tags/for.rb
CHANGED
@@ -29,20 +29,20 @@ module H2o
|
|
29
29
|
length = 0
|
30
30
|
|
31
31
|
if iteratable.respond_to?(:each)
|
32
|
-
length = iteratable.size ||
|
32
|
+
length = iteratable.size || iteratable.length
|
33
33
|
end
|
34
34
|
|
35
35
|
if length > 0
|
36
36
|
parent = context[:loop]
|
37
|
+
index = 0
|
37
38
|
# Main iteration
|
38
39
|
context.stack do
|
39
|
-
iteratable.
|
40
|
-
|
41
|
-
|
42
|
-
if args.first.is_a? Array
|
43
|
-
key, value = value
|
40
|
+
iteratable.each do |item|
|
41
|
+
if item.is_a?(Array)
|
42
|
+
key, value = item
|
44
43
|
else
|
45
44
|
key = index
|
45
|
+
value = item
|
46
46
|
end
|
47
47
|
|
48
48
|
is_even = index % 2 != 0
|
@@ -61,6 +61,7 @@ module H2o
|
|
61
61
|
:odd => !is_even
|
62
62
|
}
|
63
63
|
@body.render(context, stream)
|
64
|
+
index += 1
|
64
65
|
end
|
65
66
|
end
|
66
67
|
else
|