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.
@@ -75,7 +75,6 @@ ohoh
75
75
  {% endif %}
76
76
 
77
77
  {% block body %}
78
- {% block.super %}
79
78
  something here
80
79
  <h1>{{ page.title | test "", adsf }}</h1>
81
80
  <small> {{ page.description }} </small>
@@ -0,0 +1,10 @@
1
+ {% extends 'base.html' %}
2
+
3
+
4
+
5
+ {% block title %}{{ block.super }} - child page{% endblock %}
6
+
7
+ {% block body %}
8
+ {{ block.super }}
9
+ extended body
10
+ {% endblock %}
@@ -0,0 +1,11 @@
1
+ <html>
2
+
3
+ <head>
4
+ <title>{% block title }web page{% endblock %}</title>
5
+ </head>
6
+ <body>
7
+ {% block body %}
8
+ default content
9
+ {% endblock %}
10
+ </body>
11
+ </html>
File without changes
@@ -1,3 +1,3 @@
1
1
  #!/bin/sh
2
2
  cd $PWD/example/
3
- ruby run.rb 8080
3
+ ruby run.rb 888
@@ -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 = "h2o"
3
- s.version = "0.2"
4
- s.date = "2008-09-5"
5
- s.summary = "Django inspired template markup"
6
- s.email = "taylor.luk@idealian.net"
7
- s.homepage = "http://github.com/speedmax/h2o"
8
- s.description = "h2o is a django inspired template that offers natural template syntax and easy to integrate."
9
- s.has_rdoc = true
10
- s.authors = ["Taylor Luk"]
11
- s.files = ["README.md",
12
- "h2o.gemspec",
13
- "lib/h2o.rb",
14
- "lib/h2o/",
15
- "lib/h2o/constants.rb",
16
- "lib/h2o/context.rb",
17
- "lib/h2o/datatype.rb",
18
- "lib/h2o/errors.rb",
19
- "lib/h2o/filters.rb",
20
- "lib/h2o/filters/default.rb",
21
- "lib/h2o/nodes.rb",
22
- "lib/h2o/parser.rb",
23
- "lib/h2o/tags.rb",
24
- "lib/h2o/tags/block.rb",
25
- "lib/h2o/tags/for.rb",
26
- "lib/h2o/tags/if.rb",
27
- "lib/h2o/tags/with.rb",
28
- "lib/h2o/tags/recurse.rb",
29
- "lib/core_ext/object.rb",
30
- "example/server.rb",
31
- "example/run.rb",
32
- "example/server",
33
- "example/server.bat",
34
- "example/request.html",
35
- "example/erb/base.html",
36
- "example/h2o/base.html",
37
- "example/h2o/inherit.html",
38
- "example/liquid/base.html",
39
- ]
40
- s.test_files = []
41
- s.rdoc_options = ["--main", "README.md"]
42
- s.extra_rdoc_files = ["README.md"]
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'
Binary file
File without changes
data/lib/h2o.rb CHANGED
@@ -1,43 +1,33 @@
1
- module H2o
2
- require 'pathname'
1
+ require 'pathname'
2
+ require 'core_ext/object'
3
+ require 'h2o/constants'
3
4
 
4
- class Template
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
- def self.parse source, env = {}
21
- parser = Parser.new(source, false, env)
22
- parsed = parser.parse
23
- end
24
-
25
- def self.load file, env = {}
26
- file = env[:search_path] + file if file.is_a? String
27
- parser = Parser.new(file.read, file, env)
28
- parser.parse
29
- end
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
@@ -4,8 +4,8 @@ module H2o
4
4
  BLOCK_END = '%}'
5
5
  VAR_START = '{{'
6
6
  VAR_END = '}}'
7
- COMMENT_START = '{*'
8
- COMMENT_END = '*}'
7
+ COMMENT_START = '{#'
8
+ COMMENT_END = '#}'
9
9
 
10
10
  PIPE_RE = /\|/
11
11
  SEPERATOR_RE = /,/
@@ -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 and @block.parent.stack_size > @index.abs
139
+ @block.parent.render(@context, @stream, @index-1) if @block.parent.stack_size > @index.abs
147
140
  nil
148
141
  end
149
142
 
@@ -0,0 +1,9 @@
1
+ module H2o
2
+ class Error < Exception; end
3
+
4
+ class RuntimeError < Error ;end
5
+ class SyntaxError < Error ;end
6
+ class TemplateNotFound < Error ;end
7
+ class ParserError < Error ;end
8
+ class FilterError < Error ;end
9
+ end
File without changes
@@ -63,6 +63,10 @@ module H2o
63
63
  end
64
64
 
65
65
  class CommentNode < Node
66
+ def initialize()
67
+ end
68
+
69
+ def render(context, stream)
70
+ end
66
71
  end
67
-
68
72
  end
@@ -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'
@@ -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
@@ -29,20 +29,20 @@ module H2o
29
29
  length = 0
30
30
 
31
31
  if iteratable.respond_to?(:each)
32
- length = iteratable.size || iterabe.length
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.each_with_index do |*args|
40
- value, index = args
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