hamlet 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +25 -0
  3. data/LICENSE +21 -0
  4. data/README.md +52 -0
  5. data/Rakefile +57 -0
  6. data/bin/hamletrb +7 -0
  7. data/extra/slim-mode.el +409 -0
  8. data/extra/test.hamlet +50 -0
  9. data/hamlet.gemspec +36 -0
  10. data/lib/hamlet.rb +7 -0
  11. data/lib/hamlet/engine.rb +3 -0
  12. data/lib/hamlet/parser.rb +147 -0
  13. data/lib/hamlet/template.rb +19 -0
  14. data/test/rails/Rakefile +7 -0
  15. data/test/rails/app/controllers/application_controller.rb +3 -0
  16. data/test/rails/app/controllers/parents_controller.rb +84 -0
  17. data/test/rails/app/controllers/slim_controller.rb +32 -0
  18. data/test/rails/app/helpers/application_helper.rb +2 -0
  19. data/test/rails/app/models/child.rb +3 -0
  20. data/test/rails/app/models/parent.rb +4 -0
  21. data/test/rails/app/views/layouts/application.html.slim +10 -0
  22. data/test/rails/app/views/parents/_form.html.slim +7 -0
  23. data/test/rails/app/views/parents/edit.html.slim +1 -0
  24. data/test/rails/app/views/parents/new.html.slim +1 -0
  25. data/test/rails/app/views/parents/show.html.slim +5 -0
  26. data/test/rails/app/views/slim/_partial.html.slim +1 -0
  27. data/test/rails/app/views/slim/content_for.html.slim +7 -0
  28. data/test/rails/app/views/slim/erb.html.erb +1 -0
  29. data/test/rails/app/views/slim/integers.html.slim +1 -0
  30. data/test/rails/app/views/slim/nil.html.slim +1 -0
  31. data/test/rails/app/views/slim/no_layout.html.slim +1 -0
  32. data/test/rails/app/views/slim/normal.html.slim +1 -0
  33. data/test/rails/app/views/slim/partial.html.slim +2 -0
  34. data/test/rails/app/views/slim/variables.html.slim +1 -0
  35. data/test/rails/config.ru +4 -0
  36. data/test/rails/config/application.rb +45 -0
  37. data/test/rails/config/boot.rb +10 -0
  38. data/test/rails/config/database.yml +4 -0
  39. data/test/rails/config/environment.rb +5 -0
  40. data/test/rails/config/environments/development.rb +26 -0
  41. data/test/rails/config/environments/production.rb +49 -0
  42. data/test/rails/config/environments/test.rb +35 -0
  43. data/test/rails/config/initializers/backtrace_silencers.rb +7 -0
  44. data/test/rails/config/initializers/inflections.rb +10 -0
  45. data/test/rails/config/initializers/mime_types.rb +5 -0
  46. data/test/rails/config/initializers/secret_token.rb +7 -0
  47. data/test/rails/config/initializers/session_store.rb +8 -0
  48. data/test/rails/config/locales/en.yml +5 -0
  49. data/test/rails/config/routes.rb +60 -0
  50. data/test/rails/db/migrate/20101220223037_parents_and_children.rb +17 -0
  51. data/test/rails/script/rails +6 -0
  52. data/test/rails/test/helper.rb +10 -0
  53. data/test/rails/test/test_slim.rb +77 -0
  54. data/test/slim/helper.rb +200 -0
  55. data/test/slim/test_chain_manipulation.rb +42 -0
  56. data/test/slim/test_code_blocks.rb +68 -0
  57. data/test/slim/test_code_escaping.rb +53 -0
  58. data/test/slim/test_code_evaluation.rb +281 -0
  59. data/test/slim/test_code_output.rb +159 -0
  60. data/test/slim/test_code_structure.rb +95 -0
  61. data/test/slim/test_embedded_engines.rb +141 -0
  62. data/test/slim/test_html_escaping.rb +40 -0
  63. data/test/slim/test_html_structure.rb +438 -0
  64. data/test/slim/test_parser_errors.rb +107 -0
  65. data/test/slim/test_pretty.rb +75 -0
  66. data/test/slim/test_ruby_errors.rb +187 -0
  67. data/test/slim/test_sections.rb +90 -0
  68. data/test/slim/test_slim_template.rb +118 -0
  69. data/test/slim/test_text_interpolation.rb +78 -0
  70. data/test/slim/test_wrapper.rb +39 -0
  71. metadata +230 -0
@@ -0,0 +1,118 @@
1
+ require 'helper'
2
+
3
+ class ::MockError < NameError
4
+ end
5
+
6
+ class TestSlimTemplate < TestSlim
7
+ class Scope
8
+ end
9
+
10
+ def test_registered_extension
11
+ assert_equal Hamlet::Template, Tilt['test.hamlet']
12
+ end
13
+
14
+ def test_preparing_and_evaluating
15
+ template = Hamlet::Template.new { |t| "<p>Hello World!\n" }
16
+ assert_equal "<p>Hello World!</p>", template.render
17
+ end
18
+
19
+ def test_passing_locals
20
+ template = Hamlet::Template.new { "<p>= 'Hey ' + name + '!'\n" }
21
+ assert_equal "<p>Hey Joe!</p>", template.render(Object.new, :name => 'Joe')
22
+ end
23
+
24
+ def test_evaluating_in_an_object_scope
25
+ template = Hamlet::Template.new { "<p = 'Hey ' + @name + '!'\n" }
26
+ scope = Object.new
27
+ scope.instance_variable_set :@name, 'Joe'
28
+ assert_equal "<p>Hey Joe!</p>", template.render(scope)
29
+ end
30
+
31
+ def test_passing_a_block_for_yield
32
+ template = Hamlet::Template.new { "<p = 'Hey ' + yield + '!'\n" }
33
+ assert_equal "<p>Hey Joe!</p>", template.render { 'Joe' }
34
+ end
35
+
36
+ def test_backtrace_file_and_line_reporting_without_locals
37
+ data = File.read(__FILE__).split("\n__END__\n").last
38
+ fail unless data[0] == ?h
39
+ template = Hamlet::Template.new('test.slim', 10) { data }
40
+ begin
41
+ template.render
42
+ fail 'should have raised an exception'
43
+ rescue => ex
44
+ assert_kind_of NameError, ex
45
+ assert_backtrace(ex, 'test.slim:12')
46
+ end
47
+ end
48
+
49
+ def test_backtrace_file_and_line_reporting_with_locals
50
+ data = File.read(__FILE__).split("\n__END__\n").last
51
+ fail unless data[0] == ?h
52
+ template = Hamlet::Template.new('test.slim') { data }
53
+ begin
54
+ res = template.render(Object.new, :name => 'Joe', :foo => 'bar')
55
+ rescue => ex
56
+ assert_kind_of MockError, ex
57
+ assert_backtrace(ex, 'test.slim:4')
58
+ end
59
+ end
60
+
61
+ def test_compiling_template_source_to_a_method
62
+ template = Hamlet::Template.new { |t| "Hello World!" }
63
+ template.render(Scope.new)
64
+ method = template.send(:compiled_method, [])
65
+ assert_kind_of UnboundMethod, method
66
+ end
67
+
68
+ def test_passing_locals
69
+ template = Hamlet::Template.new { "<p = 'Hey ' + name + '!'\n" }
70
+ assert_equal "<p>Hey Joe!</p>", template.render(Scope.new, :name => 'Joe')
71
+ end
72
+
73
+ def test_evaluating_in_an_object_scope
74
+ template = Hamlet::Template.new { "<p = 'Hey ' + @name + '!'\n" }
75
+ scope = Scope.new
76
+ scope.instance_variable_set :@name, 'Joe'
77
+ assert_equal "<p>Hey Joe!</p>", template.render(scope)
78
+ end
79
+
80
+ def test_passing_a_block_for_yield
81
+ template = Hamlet::Template.new { "<p = 'Hey ' + yield + '!'\n" }
82
+ assert_equal "<p>Hey Joe!</p>", template.render(Scope.new) { 'Joe' }
83
+ end
84
+
85
+ def test_backtrace_file_and_line_reporting_without_locals
86
+ data = File.read(__FILE__).split("\n__END__\n").last
87
+ fail unless data[0] == ?h
88
+ template = Hamlet::Template.new('test.slim', 10) { data }
89
+ begin
90
+ template.render(Scope.new)
91
+ fail 'should have raised an exception'
92
+ rescue => ex
93
+ assert_kind_of NameError, ex
94
+ assert_backtrace(ex, 'test.slim:12')
95
+ end
96
+ end
97
+
98
+ def test_backtrace_file_and_line_reporting_with_locals
99
+ data = File.read(__FILE__).split("\n__END__\n").last
100
+ fail unless data[0] == ?h
101
+ template = Hamlet::Template.new('test.slim') { data }
102
+ begin
103
+ res = template.render(Scope.new, :name => 'Joe', :foo => 'bar')
104
+ rescue => ex
105
+ assert_kind_of MockError, ex
106
+ assert_backtrace(ex, 'test.slim:5')
107
+ end
108
+ end
109
+ end
110
+
111
+ __END__
112
+ html
113
+ body
114
+ <h1>= "Hey #{name}"
115
+
116
+ = raise MockError
117
+
118
+ <p>we never get here
@@ -0,0 +1,78 @@
1
+ require 'helper'
2
+
3
+ class TestSlimTextInterpolation < TestSlim
4
+ def test_interpolation_in_attribute
5
+ source = %q{
6
+ <p id="a#{id_helper}b" = hello_world
7
+ }
8
+
9
+ assert_html '<p id="anoticeb">Hello World from @env</p>', source
10
+ end
11
+
12
+ def test_nested_interpolation_in_attribute
13
+ source = %q{
14
+ <p id="#{"abc#{1+1}" + "("}" = hello_world
15
+ }
16
+
17
+ assert_html '<p id="abc2(">Hello World from @env</p>', source
18
+ end
19
+
20
+ def test_interpolation_in_text
21
+ source = %q{
22
+ <p
23
+ > #{hello_world} with "quotes"
24
+ <p
25
+
26
+ >A message from the compiler: #{hello_world}
27
+ }
28
+
29
+ assert_html '<p>Hello World from @env with "quotes"</p><p>A message from the compiler: Hello World from @env</p>', source
30
+ end
31
+
32
+ def test_interpolation_in_tag
33
+ source = %q{
34
+ <p #{hello_world}
35
+ }
36
+
37
+ assert_html '<p>Hello World from @env</p>', source
38
+ end
39
+
40
+ def test_escape_interpolation
41
+ source = %q{
42
+ <p \\#{hello_world}
43
+ }
44
+
45
+ assert_html '<p>#{hello_world}</p>', source
46
+ end
47
+
48
+ def test_complex_interpolation
49
+ source = %q{
50
+ <p Message: #{message('hello', "user #{output_number}")}
51
+ }
52
+
53
+ assert_html '<p>Message: hello user 1337</p>', source
54
+ end
55
+
56
+ def test_interpolation_with_escaping
57
+ source = %q{
58
+ > #{evil_method}
59
+ }
60
+
61
+ assert_html '&lt;script&gt;do_something_evil();&lt;&#47;script&gt;', source
62
+ end
63
+
64
+ def test_interpolation_without_escaping
65
+ source = %q{
66
+ > #{{evil_method}}
67
+ }
68
+
69
+ assert_html '<script>do_something_evil();</script>', source
70
+ end
71
+
72
+ def test_interpolation_with_escaping_and_delimiter
73
+ source = %q{
74
+ > #{(evil_method)}
75
+ }
76
+ assert_html '&lt;script&gt;do_something_evil();&lt;&#47;script&gt;', source
77
+ end
78
+ end
@@ -0,0 +1,39 @@
1
+ require 'helper'
2
+
3
+
4
+ class TestSlimWrapper < TestSlim
5
+ def setup
6
+ Slim::Sections.set_default_options(:dictionary => 'ViewEnv.new')
7
+ end
8
+
9
+ def teardown
10
+ Slim::Sections.set_default_options(:dictionary => 'self')
11
+ end
12
+
13
+ def test_sections
14
+ source = %q{
15
+ <p
16
+ - person
17
+ <.name = name
18
+ }
19
+ assert_html '<p><div class="name">Joe</div><div class="name">Jack</div></p>', source, :sections => true
20
+ end
21
+
22
+ def test_with_array
23
+ source = %q{
24
+ <ul
25
+ - people_with_locations
26
+ <li = name
27
+ <li = city
28
+ }
29
+ assert_html '<ul><li>Andy</li><li>Atlanta</li><li>Fred</li><li>Melbourne</li><li>Daniel</li><li>Karlsruhe</li></ul>', source, :sections => true
30
+ end
31
+
32
+ def test_method
33
+ source = %q{
34
+ <a href=output_number Link
35
+ }
36
+ assert_html '<a href="1337">Link</a>', source, :sections => true
37
+ end
38
+
39
+ end
metadata ADDED
@@ -0,0 +1,230 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hamlet
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Greg Weber
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: slim
16
+ requirement: &4263040 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *4263040
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &4261800 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.8.7
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *4261800
36
+ - !ruby/object:Gem::Dependency
37
+ name: sass
38
+ requirement: &4260580 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 3.1.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *4260580
47
+ - !ruby/object:Gem::Dependency
48
+ name: minitest
49
+ requirement: &4259280 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *4259280
58
+ - !ruby/object:Gem::Dependency
59
+ name: kramdown
60
+ requirement: &4258240 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *4258240
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: &4257160 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *4257160
80
+ - !ruby/object:Gem::Dependency
81
+ name: creole
82
+ requirement: &4253900 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *4253900
91
+ - !ruby/object:Gem::Dependency
92
+ name: builder
93
+ requirement: &4253060 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *4253060
102
+ - !ruby/object:Gem::Dependency
103
+ name: pry
104
+ requirement: &4252560 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *4252560
113
+ - !ruby/object:Gem::Dependency
114
+ name: rcov
115
+ requirement: &4251980 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *4251980
124
+ description: Hamlet is a template language whose goal is reduce HTML syntax to the
125
+ essential parts.
126
+ email:
127
+ - greg@gregweber.info
128
+ executables:
129
+ - hamletrb
130
+ extensions: []
131
+ extra_rdoc_files:
132
+ - README.md
133
+ files:
134
+ - .gitignore
135
+ - Gemfile
136
+ - LICENSE
137
+ - README.md
138
+ - Rakefile
139
+ - bin/hamletrb
140
+ - extra/slim-mode.el
141
+ - extra/test.hamlet
142
+ - hamlet.gemspec
143
+ - lib/hamlet.rb
144
+ - lib/hamlet/engine.rb
145
+ - lib/hamlet/parser.rb
146
+ - lib/hamlet/template.rb
147
+ - test/rails/Rakefile
148
+ - test/rails/app/controllers/application_controller.rb
149
+ - test/rails/app/controllers/parents_controller.rb
150
+ - test/rails/app/controllers/slim_controller.rb
151
+ - test/rails/app/helpers/application_helper.rb
152
+ - test/rails/app/models/child.rb
153
+ - test/rails/app/models/parent.rb
154
+ - test/rails/app/views/layouts/application.html.slim
155
+ - test/rails/app/views/parents/_form.html.slim
156
+ - test/rails/app/views/parents/edit.html.slim
157
+ - test/rails/app/views/parents/new.html.slim
158
+ - test/rails/app/views/parents/show.html.slim
159
+ - test/rails/app/views/slim/_partial.html.slim
160
+ - test/rails/app/views/slim/content_for.html.slim
161
+ - test/rails/app/views/slim/erb.html.erb
162
+ - test/rails/app/views/slim/integers.html.slim
163
+ - test/rails/app/views/slim/nil.html.slim
164
+ - test/rails/app/views/slim/no_layout.html.slim
165
+ - test/rails/app/views/slim/normal.html.slim
166
+ - test/rails/app/views/slim/partial.html.slim
167
+ - test/rails/app/views/slim/variables.html.slim
168
+ - test/rails/config.ru
169
+ - test/rails/config/application.rb
170
+ - test/rails/config/boot.rb
171
+ - test/rails/config/database.yml
172
+ - test/rails/config/environment.rb
173
+ - test/rails/config/environments/development.rb
174
+ - test/rails/config/environments/production.rb
175
+ - test/rails/config/environments/test.rb
176
+ - test/rails/config/initializers/backtrace_silencers.rb
177
+ - test/rails/config/initializers/inflections.rb
178
+ - test/rails/config/initializers/mime_types.rb
179
+ - test/rails/config/initializers/secret_token.rb
180
+ - test/rails/config/initializers/session_store.rb
181
+ - test/rails/config/locales/en.yml
182
+ - test/rails/config/routes.rb
183
+ - test/rails/db/migrate/20101220223037_parents_and_children.rb
184
+ - test/rails/script/rails
185
+ - test/rails/test/helper.rb
186
+ - test/rails/test/test_slim.rb
187
+ - test/slim/helper.rb
188
+ - test/slim/test_chain_manipulation.rb
189
+ - test/slim/test_code_blocks.rb
190
+ - test/slim/test_code_escaping.rb
191
+ - test/slim/test_code_evaluation.rb
192
+ - test/slim/test_code_output.rb
193
+ - test/slim/test_code_structure.rb
194
+ - test/slim/test_embedded_engines.rb
195
+ - test/slim/test_html_escaping.rb
196
+ - test/slim/test_html_structure.rb
197
+ - test/slim/test_parser_errors.rb
198
+ - test/slim/test_pretty.rb
199
+ - test/slim/test_ruby_errors.rb
200
+ - test/slim/test_sections.rb
201
+ - test/slim/test_slim_template.rb
202
+ - test/slim/test_text_interpolation.rb
203
+ - test/slim/test_wrapper.rb
204
+ homepage: http://github.com/gregwebs/hamlet.rb
205
+ licenses: []
206
+ post_install_message:
207
+ rdoc_options:
208
+ - --charset=UTF-8
209
+ require_paths:
210
+ - lib
211
+ required_ruby_version: !ruby/object:Gem::Requirement
212
+ none: false
213
+ requirements:
214
+ - - ! '>='
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
217
+ required_rubygems_version: !ruby/object:Gem::Requirement
218
+ none: false
219
+ requirements:
220
+ - - ! '>='
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ requirements: []
224
+ rubyforge_project: hamlet
225
+ rubygems_version: 1.8.10
226
+ signing_key:
227
+ specification_version: 3
228
+ summary: Hamlet is a DRY HTML template language.
229
+ test_files: []
230
+ has_rdoc: