h2o 0.3.1 → 0.3.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -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 the gemspec command
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{2010-09-14}
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
- ".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/file_loader.rb",
49
- "lib/h2o/filters.rb",
50
- "lib/h2o/filters/default.rb",
51
- "lib/h2o/nodes.rb",
52
- "lib/h2o/parser.rb",
53
- "lib/h2o/tags.rb",
54
- "lib/h2o/tags/block.rb",
55
- "lib/h2o/tags/extends.rb",
56
- "lib/h2o/tags/for.rb",
57
- "lib/h2o/tags/if.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/spec.opts",
74
- "spec/spec_helper.rb"
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.3.7}
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
- "spec/h2o/file_loader_spec.rb",
84
- "spec/h2o/filters_spec.rb",
85
- "spec/h2o/parser_spec.rb",
86
- "spec/h2o/tags/block_spec.rb",
87
- "spec/h2o/tags/for_spec.rb",
88
- "spec/h2o/tags/if_spec.rb",
89
- "spec/spec_helper.rb"
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
@@ -21,6 +21,7 @@ module H2o
21
21
  require 'h2o/tags/with'
22
22
  require 'h2o/tags/block'
23
23
  require 'h2o/tags/extends'
24
+ require 'h2o/tags/raw'
24
25
  end
25
26
 
26
27
  def self.loader
@@ -42,6 +42,9 @@ module DefaultFilters
42
42
  list.last
43
43
  end
44
44
 
45
+ def contain(object, item)
46
+ object.include?(item)
47
+ end
45
48
 
46
49
  H2o::Filters << self
47
50
  end
@@ -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)
@@ -9,6 +9,10 @@ module H2o
9
9
  def register(tag, name)
10
10
  @tags[name] = tag
11
11
  end
12
+
13
+ def all
14
+ @tags
15
+ end
12
16
  end
13
17
 
14
18
  class Tag < Node; end
@@ -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
@@ -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
+
@@ -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: false
5
- segments:
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: 2010-09-14 00:00:00 +10:00
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/spec.opts
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
- - --charset=UTF-8
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.3.7
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
@@ -1,4 +0,0 @@
1
- --colour
2
- --format progress
3
- --loadby mtime
4
- --reverse