h2o 0.2
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/README.md +52 -0
- data/example/erb/base.html +56 -0
- data/example/h2o/base.html +85 -0
- data/example/h2o/inherit.html +7 -0
- data/example/liquid/base.html +57 -0
- data/example/request.html +0 -0
- data/example/run.rb +103 -0
- data/example/server +3 -0
- data/example/server.bat +1 -0
- data/example/server.rb +37 -0
- data/h2o.gemspec +43 -0
- data/lib/core_ext/object.rb +13 -0
- data/lib/h2o.rb +43 -0
- data/lib/h2o/constants.rb +40 -0
- data/lib/h2o/context.rb +158 -0
- data/lib/h2o/datatype.rb +11 -0
- data/lib/h2o/errors.rb +7 -0
- data/lib/h2o/filters.rb +49 -0
- data/lib/h2o/filters/default.rb +47 -0
- data/lib/h2o/nodes.rb +68 -0
- data/lib/h2o/parser.rb +225 -0
- data/lib/h2o/tags.rb +22 -0
- data/lib/h2o/tags/block.rb +64 -0
- data/lib/h2o/tags/for.rb +76 -0
- data/lib/h2o/tags/if.rb +77 -0
- data/lib/h2o/tags/recurse.rb +55 -0
- data/lib/h2o/tags/with.rb +28 -0
- metadata +82 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
module H2o
|
2
|
+
module Tags
|
3
|
+
# Recurse tag allows rendering of tree structures. The template should look something like this:
|
4
|
+
# {% recurse all_categories with children as category %}
|
5
|
+
# <ul>
|
6
|
+
# {% loop %}
|
7
|
+
# <li>
|
8
|
+
# <h{{ level }}>{{ category.title }}</h{{ level }}>
|
9
|
+
# {% children %}
|
10
|
+
# </li>
|
11
|
+
# {% endloop %}
|
12
|
+
# </ul>
|
13
|
+
# {% endrecurse %}
|
14
|
+
class Recurse < Tag
|
15
|
+
|
16
|
+
Syntax = /(#{H2o::NAME_RE})\s+with\s+(#{H2o::IDENTIFIER_RE})\s+as\s+(#{H2o::IDENTIFIER_RE})/
|
17
|
+
|
18
|
+
def initialize(parser, argstring)
|
19
|
+
@body = parser.parse(:loop, :children, :endloop, :endrecurse)
|
20
|
+
@child = parser.parse(:children, :endloop, :endrecurse) if parser.token && parser.token.include?('loop')
|
21
|
+
@enditem = parser.parse(:endloop, :endrecurse) if parser.token && parser.token.include?('children')
|
22
|
+
@end = parser.parse(:endrecurse) if parser.token && parser.token.include?('endloop')
|
23
|
+
if argstring =~ Syntax
|
24
|
+
@collection_id = $1.to_sym
|
25
|
+
@children_method = $2.to_sym
|
26
|
+
@item_id = $3.to_sym
|
27
|
+
else
|
28
|
+
raise SyntaxError, "Invalid recurse syntax "
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def render(context, stream)
|
33
|
+
collection = context.resolve(@collection_id)
|
34
|
+
@body.render(context, stream)
|
35
|
+
context.stack do
|
36
|
+
level = context[:level] || 1
|
37
|
+
collection.each do |item|
|
38
|
+
context[@item_id] = item
|
39
|
+
context[:level] = level
|
40
|
+
@child.render(context, stream)
|
41
|
+
children = item.respond_to?(@children_method) ? item.send(@children_method) : item[@children_method]
|
42
|
+
unless children.empty?
|
43
|
+
stream << self.render(Context.new({@collection_id => children, :level => (level + 1)}), [])
|
44
|
+
end
|
45
|
+
@enditem.render(context, stream)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
@end.render(context, stream)
|
49
|
+
end
|
50
|
+
|
51
|
+
Tags.register(self, :recurse)
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module H2o
|
2
|
+
module Tags
|
3
|
+
class With < Tag
|
4
|
+
Syntax = /(#{NAME_RE})\s+as\s+(#{NAME_RE})/
|
5
|
+
|
6
|
+
def initialize(parser, argstring)
|
7
|
+
@body = parser.parse(:endwith)
|
8
|
+
|
9
|
+
if argstring =~ Syntax
|
10
|
+
@name = $1.to_sym
|
11
|
+
@shortcut = $2.to_sym
|
12
|
+
else
|
13
|
+
raise SyntaxError, "Invalid with syntax "
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def render(context, stream)
|
18
|
+
object = context.resolve(@name)
|
19
|
+
context.stack do
|
20
|
+
context[@shortcut] = object
|
21
|
+
@body.render(context, stream)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
Tags.register(self, :with)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: h2o
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.2"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Taylor Luk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-09-05 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: h2o is a django inspired template that offers natural template syntax and easy to integrate.
|
17
|
+
email: taylor.luk@idealian.net
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.md
|
24
|
+
files:
|
25
|
+
- README.md
|
26
|
+
- h2o.gemspec
|
27
|
+
- lib/h2o.rb
|
28
|
+
- lib/h2o/constants.rb
|
29
|
+
- lib/h2o/context.rb
|
30
|
+
- lib/h2o/datatype.rb
|
31
|
+
- lib/h2o/errors.rb
|
32
|
+
- lib/h2o/filters.rb
|
33
|
+
- lib/h2o/filters/default.rb
|
34
|
+
- lib/h2o/nodes.rb
|
35
|
+
- lib/h2o/parser.rb
|
36
|
+
- lib/h2o/tags.rb
|
37
|
+
- lib/h2o/tags/block.rb
|
38
|
+
- lib/h2o/tags/for.rb
|
39
|
+
- lib/h2o/tags/if.rb
|
40
|
+
- lib/h2o/tags/with.rb
|
41
|
+
- lib/h2o/tags/recurse.rb
|
42
|
+
- lib/core_ext/object.rb
|
43
|
+
- example/server.rb
|
44
|
+
- example/run.rb
|
45
|
+
- example/server
|
46
|
+
- example/server.bat
|
47
|
+
- example/request.html
|
48
|
+
- example/erb/base.html
|
49
|
+
- example/h2o/base.html
|
50
|
+
- example/h2o/inherit.html
|
51
|
+
- example/liquid/base.html
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://github.com/speedmax/h2o
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options:
|
58
|
+
- --main
|
59
|
+
- README.md
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.3.5
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Django inspired template markup
|
81
|
+
test_files: []
|
82
|
+
|