radiant 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of radiant might be problematic. Click here for more details.

Files changed (208) hide show
  1. data/CHANGELOG +15 -0
  2. data/CONTRIBUTORS +8 -0
  3. data/app/controllers/admin/page_controller.rb +1 -11
  4. data/app/controllers/admin/welcome_controller.rb +5 -6
  5. data/app/controllers/application.rb +2 -0
  6. data/app/controllers/site_controller.rb +1 -0
  7. data/app/helpers/admin/page_helper.rb +36 -0
  8. data/app/helpers/admin/regions_helper.rb +28 -0
  9. data/app/helpers/admin/user_helper.rb +6 -0
  10. data/app/helpers/application_helper.rb +2 -1
  11. data/app/models/user.rb +7 -8
  12. data/app/views/admin/extension/index.html.haml +28 -0
  13. data/app/views/admin/layout/edit.html.haml +44 -0
  14. data/app/views/admin/layout/index.html.haml +25 -0
  15. data/app/views/admin/layout/remove.html.haml +16 -0
  16. data/app/views/admin/page/_meta_row.html.haml +6 -0
  17. data/app/views/admin/page/_node.html.haml +25 -0
  18. data/app/views/admin/page/_part.html.haml +17 -0
  19. data/app/views/admin/page/_tag_reference.html.haml +3 -0
  20. data/app/views/admin/page/children.html.haml +2 -0
  21. data/app/views/admin/page/edit.html.haml +114 -0
  22. data/app/views/admin/page/index.html.haml +28 -0
  23. data/app/views/admin/page/remove.html.haml +20 -0
  24. data/app/views/admin/snippet/edit.html.haml +36 -0
  25. data/app/views/admin/snippet/index.html.haml +20 -0
  26. data/app/views/admin/snippet/remove.html.haml +19 -0
  27. data/app/views/admin/user/edit.html.haml +80 -0
  28. data/app/views/admin/user/index.html.haml +23 -0
  29. data/app/views/admin/user/preferences.html.haml +28 -0
  30. data/app/views/admin/user/remove.html.haml +18 -0
  31. data/app/views/admin/welcome/login.html.haml +44 -0
  32. data/app/views/layouts/application.html.haml +54 -0
  33. data/app/views/site/not_found.html.haml +3 -0
  34. data/db/migrate/019_add_salt_to_users.rb +11 -0
  35. data/db/schema.rb +2 -1
  36. data/lib/login_system.rb +1 -0
  37. data/lib/radiant.rb +1 -1
  38. data/lib/radiant/admin_ui.rb +65 -0
  39. data/lib/radiant/admin_ui/region_partials.rb +18 -0
  40. data/lib/radiant/admin_ui/region_set.rb +35 -0
  41. data/lib/tasks/extensions.rake +33 -0
  42. data/public/javascripts/admin/admin.js +8 -2
  43. data/public/javascripts/admin/sitemap.js +2 -1
  44. data/public/stylesheets/admin/main.css +4 -0
  45. data/spec/controllers/admin/abstract_model_controller_spec.rb +2 -0
  46. data/spec/controllers/admin/page_controller_spec.rb +3 -28
  47. data/spec/controllers/admin/user_controller_spec.rb +1 -1
  48. data/spec/controllers/admin/welcome_controller_spec.rb +26 -0
  49. data/spec/helpers/admin/page_helper_spec.rb +4 -0
  50. data/spec/helpers/admin/regions_helper_spec.rb +47 -0
  51. data/spec/helpers/admin/user_helper_spec.rb +7 -0
  52. data/spec/helpers/application_helper_spec.rb +7 -3
  53. data/spec/lib/login_system_spec.rb +5 -0
  54. data/spec/lib/radiant/admin_ui/region_partials_spec.rb +35 -0
  55. data/spec/lib/radiant/admin_ui/region_set_spec.rb +61 -0
  56. data/spec/lib/radiant/admin_ui_spec.rb +74 -18
  57. data/spec/models/user_spec.rb +11 -4
  58. data/spec/scenarios/users_scenario.rb +2 -2
  59. data/vendor/plugins/haml/MIT-LICENSE +20 -0
  60. data/vendor/plugins/haml/README.rdoc +319 -0
  61. data/vendor/plugins/haml/Rakefile +158 -0
  62. data/vendor/plugins/haml/TODO +9 -0
  63. data/vendor/plugins/haml/VERSION +1 -0
  64. data/vendor/plugins/haml/bin/css2sass +7 -0
  65. data/vendor/plugins/haml/bin/haml +8 -0
  66. data/vendor/plugins/haml/bin/html2haml +7 -0
  67. data/vendor/plugins/haml/bin/sass +8 -0
  68. data/vendor/plugins/haml/extra/haml-mode.el +328 -0
  69. data/vendor/plugins/haml/extra/sass-mode.el +88 -0
  70. data/vendor/plugins/haml/init.rb +2 -0
  71. data/vendor/plugins/haml/lib/haml.rb +977 -0
  72. data/vendor/plugins/haml/lib/haml/buffer.rb +229 -0
  73. data/vendor/plugins/haml/lib/haml/engine.rb +274 -0
  74. data/vendor/plugins/haml/lib/haml/error.rb +23 -0
  75. data/vendor/plugins/haml/lib/haml/exec.rb +347 -0
  76. data/vendor/plugins/haml/lib/haml/filters.rb +249 -0
  77. data/vendor/plugins/haml/lib/haml/helpers.rb +413 -0
  78. data/vendor/plugins/haml/lib/haml/helpers/action_view_extensions.rb +45 -0
  79. data/vendor/plugins/haml/lib/haml/helpers/action_view_mods.rb +122 -0
  80. data/vendor/plugins/haml/lib/haml/html.rb +188 -0
  81. data/vendor/plugins/haml/lib/haml/precompiler.rb +757 -0
  82. data/vendor/plugins/haml/lib/haml/template.rb +43 -0
  83. data/vendor/plugins/haml/lib/haml/template/patch.rb +58 -0
  84. data/vendor/plugins/haml/lib/haml/template/plugin.rb +72 -0
  85. data/vendor/plugins/haml/lib/sass.rb +833 -0
  86. data/vendor/plugins/haml/lib/sass/constant.rb +245 -0
  87. data/vendor/plugins/haml/lib/sass/constant/color.rb +101 -0
  88. data/vendor/plugins/haml/lib/sass/constant/literal.rb +53 -0
  89. data/vendor/plugins/haml/lib/sass/constant/number.rb +87 -0
  90. data/vendor/plugins/haml/lib/sass/constant/operation.rb +30 -0
  91. data/vendor/plugins/haml/lib/sass/constant/string.rb +22 -0
  92. data/vendor/plugins/haml/lib/sass/css.rb +378 -0
  93. data/vendor/plugins/haml/lib/sass/engine.rb +459 -0
  94. data/vendor/plugins/haml/lib/sass/error.rb +35 -0
  95. data/vendor/plugins/haml/lib/sass/plugin.rb +165 -0
  96. data/vendor/plugins/haml/lib/sass/plugin/merb.rb +56 -0
  97. data/vendor/plugins/haml/lib/sass/plugin/rails.rb +24 -0
  98. data/vendor/plugins/haml/lib/sass/tree/attr_node.rb +53 -0
  99. data/vendor/plugins/haml/lib/sass/tree/comment_node.rb +20 -0
  100. data/vendor/plugins/haml/lib/sass/tree/directive_node.rb +46 -0
  101. data/vendor/plugins/haml/lib/sass/tree/node.rb +42 -0
  102. data/vendor/plugins/haml/lib/sass/tree/rule_node.rb +89 -0
  103. data/vendor/plugins/haml/lib/sass/tree/value_node.rb +16 -0
  104. data/vendor/plugins/haml/test/benchmark.rb +82 -0
  105. data/vendor/plugins/haml/test/haml/engine_test.rb +587 -0
  106. data/vendor/plugins/haml/test/haml/helper_test.rb +187 -0
  107. data/vendor/plugins/haml/test/haml/html2haml_test.rb +60 -0
  108. data/vendor/plugins/haml/test/haml/markaby/standard.mab +52 -0
  109. data/vendor/plugins/haml/test/haml/mocks/article.rb +6 -0
  110. data/vendor/plugins/haml/test/haml/results/content_for_layout.xhtml +16 -0
  111. data/vendor/plugins/haml/test/haml/results/eval_suppressed.xhtml +11 -0
  112. data/vendor/plugins/haml/test/haml/results/filters.xhtml +82 -0
  113. data/vendor/plugins/haml/test/haml/results/helpers.xhtml +94 -0
  114. data/vendor/plugins/haml/test/haml/results/helpful.xhtml +10 -0
  115. data/vendor/plugins/haml/test/haml/results/just_stuff.xhtml +64 -0
  116. data/vendor/plugins/haml/test/haml/results/list.xhtml +12 -0
  117. data/vendor/plugins/haml/test/haml/results/original_engine.xhtml +22 -0
  118. data/vendor/plugins/haml/test/haml/results/partials.xhtml +21 -0
  119. data/vendor/plugins/haml/test/haml/results/silent_script.xhtml +74 -0
  120. data/vendor/plugins/haml/test/haml/results/standard.xhtml +42 -0
  121. data/vendor/plugins/haml/test/haml/results/tag_parsing.xhtml +28 -0
  122. data/vendor/plugins/haml/test/haml/results/very_basic.xhtml +7 -0
  123. data/vendor/plugins/haml/test/haml/results/whitespace_handling.xhtml +94 -0
  124. data/vendor/plugins/haml/test/haml/rhtml/_av_partial_1.rhtml +12 -0
  125. data/vendor/plugins/haml/test/haml/rhtml/_av_partial_2.rhtml +8 -0
  126. data/vendor/plugins/haml/test/haml/rhtml/action_view.rhtml +62 -0
  127. data/vendor/plugins/haml/test/haml/rhtml/standard.rhtml +54 -0
  128. data/vendor/plugins/haml/test/haml/template_test.rb +168 -0
  129. data/vendor/plugins/haml/test/haml/templates/_av_partial_1.haml +9 -0
  130. data/vendor/plugins/haml/test/haml/templates/_av_partial_2.haml +5 -0
  131. data/vendor/plugins/haml/test/haml/templates/_partial.haml +8 -0
  132. data/vendor/plugins/haml/test/haml/templates/_text_area.haml +3 -0
  133. data/vendor/plugins/haml/test/haml/templates/action_view.haml +47 -0
  134. data/vendor/plugins/haml/test/haml/templates/breakage.haml +8 -0
  135. data/vendor/plugins/haml/test/haml/templates/content_for_layout.haml +10 -0
  136. data/vendor/plugins/haml/test/haml/templates/eval_suppressed.haml +11 -0
  137. data/vendor/plugins/haml/test/haml/templates/filters.haml +81 -0
  138. data/vendor/plugins/haml/test/haml/templates/helpers.haml +69 -0
  139. data/vendor/plugins/haml/test/haml/templates/helpful.haml +11 -0
  140. data/vendor/plugins/haml/test/haml/templates/just_stuff.haml +77 -0
  141. data/vendor/plugins/haml/test/haml/templates/list.haml +12 -0
  142. data/vendor/plugins/haml/test/haml/templates/original_engine.haml +17 -0
  143. data/vendor/plugins/haml/test/haml/templates/partialize.haml +1 -0
  144. data/vendor/plugins/haml/test/haml/templates/partials.haml +12 -0
  145. data/vendor/plugins/haml/test/haml/templates/silent_script.haml +40 -0
  146. data/vendor/plugins/haml/test/haml/templates/standard.haml +42 -0
  147. data/vendor/plugins/haml/test/haml/templates/tag_parsing.haml +24 -0
  148. data/vendor/plugins/haml/test/haml/templates/very_basic.haml +4 -0
  149. data/vendor/plugins/haml/test/haml/templates/whitespace_handling.haml +87 -0
  150. data/vendor/plugins/haml/test/haml/test_helper.rb +15 -0
  151. data/vendor/plugins/haml/test/profile.rb +65 -0
  152. data/vendor/plugins/haml/test/sass/engine_test.rb +276 -0
  153. data/vendor/plugins/haml/test/sass/plugin_test.rb +159 -0
  154. data/vendor/plugins/haml/test/sass/results/alt.css +4 -0
  155. data/vendor/plugins/haml/test/sass/results/basic.css +9 -0
  156. data/vendor/plugins/haml/test/sass/results/compact.css +5 -0
  157. data/vendor/plugins/haml/test/sass/results/complex.css +87 -0
  158. data/vendor/plugins/haml/test/sass/results/compressed.css +1 -0
  159. data/vendor/plugins/haml/test/sass/results/constants.css +14 -0
  160. data/vendor/plugins/haml/test/sass/results/expanded.css +19 -0
  161. data/vendor/plugins/haml/test/sass/results/import.css +29 -0
  162. data/vendor/plugins/haml/test/sass/results/mixins.css +95 -0
  163. data/vendor/plugins/haml/test/sass/results/multiline.css +24 -0
  164. data/vendor/plugins/haml/test/sass/results/nested.css +22 -0
  165. data/vendor/plugins/haml/test/sass/results/parent_ref.css +13 -0
  166. data/vendor/plugins/haml/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
  167. data/vendor/plugins/haml/test/sass/results/subdir/subdir.css +1 -0
  168. data/vendor/plugins/haml/test/sass/templates/_partial.sass +2 -0
  169. data/vendor/plugins/haml/test/sass/templates/alt.sass +16 -0
  170. data/vendor/plugins/haml/test/sass/templates/basic.sass +23 -0
  171. data/vendor/plugins/haml/test/sass/templates/bork.sass +2 -0
  172. data/vendor/plugins/haml/test/sass/templates/bork2.sass +2 -0
  173. data/vendor/plugins/haml/test/sass/templates/compact.sass +17 -0
  174. data/vendor/plugins/haml/test/sass/templates/complex.sass +310 -0
  175. data/vendor/plugins/haml/test/sass/templates/compressed.sass +15 -0
  176. data/vendor/plugins/haml/test/sass/templates/constants.sass +97 -0
  177. data/vendor/plugins/haml/test/sass/templates/expanded.sass +17 -0
  178. data/vendor/plugins/haml/test/sass/templates/import.sass +11 -0
  179. data/vendor/plugins/haml/test/sass/templates/importee.sass +14 -0
  180. data/vendor/plugins/haml/test/sass/templates/mixins.sass +76 -0
  181. data/vendor/plugins/haml/test/sass/templates/multiline.sass +20 -0
  182. data/vendor/plugins/haml/test/sass/templates/nested.sass +25 -0
  183. data/vendor/plugins/haml/test/sass/templates/parent_ref.sass +25 -0
  184. data/vendor/plugins/haml/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
  185. data/vendor/plugins/haml/test/sass/templates/subdir/subdir.sass +6 -0
  186. metadata +185 -24
  187. data/app/views/admin/extension/index.html.erb +0 -40
  188. data/app/views/admin/layout/edit.html.erb +0 -39
  189. data/app/views/admin/layout/index.html.erb +0 -38
  190. data/app/views/admin/layout/remove.html.erb +0 -17
  191. data/app/views/admin/page/_meta_row.html.erb +0 -4
  192. data/app/views/admin/page/_node.html.erb +0 -28
  193. data/app/views/admin/page/_part.html.erb +0 -13
  194. data/app/views/admin/page/_tag_reference.html.erb +0 -4
  195. data/app/views/admin/page/children.html.erb +0 -4
  196. data/app/views/admin/page/edit.html.erb +0 -140
  197. data/app/views/admin/page/index.html.erb +0 -31
  198. data/app/views/admin/page/remove.html.erb +0 -14
  199. data/app/views/admin/snippet/edit.html.erb +0 -29
  200. data/app/views/admin/snippet/index.html.erb +0 -36
  201. data/app/views/admin/snippet/remove.html.erb +0 -16
  202. data/app/views/admin/user/edit.html.erb +0 -54
  203. data/app/views/admin/user/index.html.erb +0 -43
  204. data/app/views/admin/user/preferences.html.erb +0 -29
  205. data/app/views/admin/user/remove.html.erb +0 -16
  206. data/app/views/admin/welcome/login.html.erb +0 -51
  207. data/app/views/layouts/application.html.erb +0 -83
  208. data/app/views/site/not_found.html.erb +0 -3
@@ -0,0 +1,187 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/test_helper'
3
+ require 'haml/template'
4
+
5
+ class HelperTest < Test::Unit::TestCase
6
+ include Haml::Helpers
7
+ Post = Struct.new('Post', :body)
8
+
9
+ def setup
10
+ @base = ActionView::Base.new
11
+ @base.controller = ActionController::Base.new
12
+ @base.instance_variable_set('@post', Post.new("Foo bar\nbaz"))
13
+ end
14
+
15
+ def render(text, options = {})
16
+ if options == :action_view
17
+ @base.render :inline => text, :type => :haml
18
+ else
19
+ scope = options.delete :scope_object
20
+ Haml::Engine.new(text, options).to_html(scope ? scope : Object.new)
21
+ end
22
+ end
23
+
24
+ def test_flatten
25
+ assert_equal("FooBar", flatten("FooBar"))
26
+
27
+ assert_equal("FooBar", flatten("Foo\rBar"))
28
+
29
+ assert_equal("Foo&#x000A;Bar", flatten("Foo\nBar"))
30
+
31
+ assert_equal("Hello&#x000A;World!&#x000A;YOU ARE FLAT?&#x000A;OMGZ!",
32
+ flatten("Hello\nWorld!\nYOU ARE \rFLAT?\n\rOMGZ!"))
33
+ end
34
+
35
+ def test_list_of_should_render_correctly
36
+ assert_equal("<li>1</li>\n<li>2</li>\n", render("= list_of([1, 2]) do |i|\n = i"))
37
+ assert_equal("<li>[1]</li>\n", render("= list_of([[1]]) do |i|\n = i.inspect"))
38
+ assert_equal("<li>\n <h1>Fee</h1>\n <p>A word!</p>\n</li>\n<li>\n <h1>Fi</h1>\n <p>A word!</p>\n</li>\n<li>\n <h1>Fo</h1>\n <p>A word!</p>\n</li>\n<li>\n <h1>Fum</h1>\n <p>A word!</p>\n</li>\n",
39
+ render("= list_of(['Fee', 'Fi', 'Fo', 'Fum']) do |title|\n %h1= title\n %p A word!"))
40
+ end
41
+
42
+ def test_buffer_access
43
+ assert(render("= buffer") =~ /#<Haml::Buffer:0x[a-z0-9]+>/)
44
+ assert_equal(render("= (buffer == _hamlout)"), "true\n")
45
+ end
46
+
47
+ def test_tabs
48
+ assert_equal("foo\n bar\nbaz\n", render("foo\n- tab_up\nbar\n- tab_down\nbaz"))
49
+ assert_equal(" <p>tabbed</p>\n", render("- buffer.tabulation=5\n%p tabbed"))
50
+ end
51
+
52
+ def test_helpers_dont_leak
53
+ # Haml helpers shouldn't be accessible from ERB
54
+ render("foo")
55
+ proper_behavior = false
56
+
57
+ begin
58
+ ActionView::Base.new.render(:inline => "<%= flatten('Foo\\nBar') %>")
59
+ rescue NoMethodError
60
+ proper_behavior = true
61
+ end
62
+ assert(proper_behavior)
63
+
64
+ begin
65
+ ActionView::Base.new.render(:inline => "<%= concat('foo') %>")
66
+ rescue ArgumentError, NameError
67
+ proper_behavior = true
68
+ end
69
+ assert(proper_behavior)
70
+ end
71
+
72
+ def test_action_view_included
73
+ assert(Haml::Helpers.action_view?)
74
+ end
75
+
76
+ def test_form_tag
77
+ # This is usually provided by ActionController::Base.
78
+ def @base.protect_against_forgery?; false; end
79
+ result = render("- form_tag 'foo' do\n %p bar\n %strong baz", :action_view)
80
+ should_be = "<form action=\"foo\" method=\"post\">\n <p>bar</p>\n <strong>baz</strong>\n</form>\n"
81
+ assert_equal(should_be, result)
82
+ end
83
+
84
+ def test_text_area
85
+ assert_equal(%(<textarea id="body" name="body">Foo&#x000A;Bar&#x000A; Baz&#x000A; Boom</textarea>\n),
86
+ render('= text_area_tag "body", "Foo\nBar\n Baz\n Boom"', :action_view))
87
+
88
+ assert_equal(%(<textarea cols="40" id="post_body" name="post[body]" rows="20">Foo bar&#x000A;baz</textarea>\n),
89
+ render('= text_area :post, :body', :action_view))
90
+
91
+ assert_equal(%(<pre>Foo bar&#x000A; baz</pre>\n),
92
+ render('= content_tag "pre", "Foo bar\n baz"', :action_view))
93
+ end
94
+
95
+ def test_capture_haml
96
+ assert_equal("\"<p>13</p>\\n\"\n", render("- foo = capture_haml(13) do |a|\n %p= a\n= foo.dump"))
97
+ end
98
+
99
+ def test_haml_tag_attribute_html_escaping
100
+ assert_equal("<p id='foo&amp;bar'>baz</p>\n", render("%p{:id => 'foo&bar'} baz", :escape_html => true))
101
+ end
102
+
103
+ def test_haml_tag_autoclosed_tags_are_closed
104
+ assert_equal("<br class='foo' />\n", render("- haml_tag :br, :class => 'foo'"))
105
+ end
106
+
107
+ def test_haml_tag_non_autoclosed_tags_arent_closed
108
+ assert_equal("<p>\n</p>\n", render("- haml_tag :p"))
109
+ end
110
+
111
+ def test_is_haml
112
+ assert(!ActionView::Base.new.is_haml?)
113
+ assert_equal("true\n", render("= is_haml?"))
114
+ assert_equal("true\n", render("= is_haml?", :action_view))
115
+ assert_equal("false", @base.render(:inline => '<%= is_haml? %>'))
116
+ assert_equal("false\n", render("= render :inline => '<%= is_haml? %>'", :action_view))
117
+ end
118
+
119
+ def test_page_class
120
+ controller = Struct.new(:controller_name, :action_name).new('troller', 'tion')
121
+ scope = Struct.new(:controller).new(controller)
122
+ result = render("%div{:class => page_class} MyDiv", :scope_object => scope)
123
+ expected = "<div class='troller tion'>MyDiv</div>\n"
124
+ assert_equal expected, result
125
+ end
126
+
127
+ def test_indented_capture
128
+ assert_equal(" \n Foo\n ", @base.render(:inline => " <% res = capture do %>\n Foo\n <% end %><%= res %>"))
129
+ end
130
+
131
+ def test_capture_deals_properly_with_collections
132
+ Haml::Helpers.module_eval do
133
+ def trc(collection, &block)
134
+ collection.each do |record|
135
+ puts capture_haml(record, &block)
136
+ end
137
+ end
138
+ end
139
+
140
+ assert_equal("1\n\n2\n\n3\n\n", render("- trc([1, 2, 3]) do |i|\n = i.inspect"))
141
+ end
142
+
143
+ def test_find_and_preserve_with_block
144
+ assert_equal("<pre>&#x000A; Foo&#x000A; Bar&#x000A;</pre>\nFoo\nBar\n",
145
+ render("= find_and_preserve do\n %pre\n Foo\n Bar\n Foo\n Bar"))
146
+ end
147
+
148
+ def test_preserve_with_block
149
+ assert_equal("<pre>&#x000A; Foo&#x000A; Bar&#x000A;</pre>&#x000A;Foo&#x000A;Bar&#x000A;\n",
150
+ render("= preserve do\n %pre\n Foo\n Bar\n Foo\n Bar"))
151
+ end
152
+
153
+ def test_init_haml_helpers
154
+ context = Object.new
155
+ class << context
156
+ include Haml::Helpers
157
+ end
158
+ context.init_haml_helpers
159
+
160
+ result = context.capture_haml do
161
+ context.haml_tag :p, :attr => "val" do
162
+ context.puts "Blah"
163
+ end
164
+ end
165
+
166
+ assert_equal("<p attr='val'>\n Blah\n</p>\n", result)
167
+ end
168
+
169
+ def test_non_haml
170
+ assert_equal("false\n", render("= non_haml { is_haml? }"))
171
+ end
172
+
173
+ class ActsLikeTag
174
+ # We want to be able to have people include monkeypatched ActionView helpers
175
+ # without redefining is_haml?.
176
+ # This is accomplished via Object#is_haml?, and this is a test for it.
177
+ include ActionView::Helpers::TagHelper
178
+ def to_s
179
+ content_tag :p, 'some tag content'
180
+ end
181
+ end
182
+
183
+ def test_random_class_includes_tag_helper
184
+ assert_equal "<p>some tag content</p>", ActsLikeTag.new.to_s
185
+ end
186
+ end
187
+
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require File.dirname(__FILE__) + '/../../lib/haml'
5
+ require 'haml/html'
6
+
7
+ class Html2HamlTest < Test::Unit::TestCase
8
+
9
+ def test_empty_render_should_remain_empty
10
+ assert_equal '', render('')
11
+ end
12
+
13
+ def test_id_and_class_should_be_removed_from_hash
14
+ assert_equal '%span#foo.bar', render('<span id="foo" class="bar"> </span>')
15
+ end
16
+
17
+ def test_no_tag_name_for_div_if_class_or_id_is_present
18
+ assert_equal '#foo', render('<div id="foo"> </div>')
19
+ assert_equal '.foo', render('<div class="foo"> </div>')
20
+ end
21
+
22
+ def test_multiple_class_names
23
+ assert_equal '.foo.bar.baz', render('<div class=" foo bar baz "> </div>')
24
+ end
25
+
26
+ def test_should_have_pretty_attributes
27
+ assert_equal_attributes('%input{ :type => "text", :name => "login" }/',
28
+ render('<input type="text" name="login" />'))
29
+ assert_equal_attributes('%meta{ "http-equiv" => "Content-Type", :content => "text/html" }/',
30
+ render('<meta http-equiv="Content-Type" content="text/html" />'))
31
+ assert_equal_attributes('%div{ "xml:lang" => "hr" }/',
32
+ render('<div xml:lang="hr" />'))
33
+ end
34
+
35
+ def test_sqml_comment
36
+ assert_equal "/\n IE sucks", render('<!-- IE sucks -->')
37
+ end
38
+
39
+ def test_rhtml
40
+ assert_equal '- foo = bar', render_rhtml('<% foo = bar %>')
41
+ assert_equal '- foo = bar', render_rhtml('<% foo = bar -%>')
42
+ assert_equal '= h @item.title', render_rhtml('<%=h @item.title %>')
43
+ assert_equal '= h @item.title', render_rhtml('<%=h @item.title -%>')
44
+ end
45
+
46
+ protected
47
+
48
+ def render(text, options = {})
49
+ Haml::HTML.new(text, options).render.rstrip
50
+ end
51
+
52
+ def render_rhtml(text)
53
+ render(text, :rhtml => true)
54
+ end
55
+
56
+ def assert_equal_attributes(expected, result)
57
+ assert_equal *[expected, result].map { |s| s.gsub!(/\{ (.+) \}/, ''); $1.split(', ').sort }
58
+ assert_equal expected, result
59
+ end
60
+ end
@@ -0,0 +1,52 @@
1
+ self << '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
2
+ html(:xmlns=>'http://www.w3.org/1999/xhtml', 'xml:lang'=>'en-US') do
3
+ head do
4
+ title "Hampton Catlin Is Totally Awesome"
5
+ meta("http-equiv" => "Content-Type", :content => "text/html; charset=utf-8")
6
+ end
7
+ body do
8
+ # You're In my house now!
9
+ div :class => "header" do
10
+ self << %|Yes, ladies and gentileman. He is just that egotistical.
11
+ Fantastic! This should be multi-line output
12
+ The question is if this would translate! Ahah!|
13
+ self << 1 + 9 + 8 + 2 #numbers should work and this should be ignored
14
+ end
15
+ div(:id => "body") { self << "Quotes should be loved! Just like people!"}
16
+ 120.times do |number|
17
+ number
18
+ end
19
+ self << "Wow.|"
20
+ p do
21
+ self << "Holy cow " +
22
+ "multiline " +
23
+ "tags! " +
24
+ "A pipe (|) even!"
25
+ self << [1, 2, 3].collect { |n| "PipesIgnored|" }
26
+ self << [1, 2, 3].collect { |n|
27
+ n.to_s
28
+ }.join("|")
29
+ end
30
+ div(:class => "silent") do
31
+ foo = String.new
32
+ foo << "this"
33
+ foo << " shouldn't"
34
+ foo << " evaluate"
35
+ self << foo + " but now it should!"
36
+ # Woah crap a comment!
37
+ end
38
+ # That was a line that shouldn't close everything.
39
+ ul(:class => "really cool") do
40
+ ('a'..'f').each do |a|
41
+ li a
42
+ end
43
+ end
44
+ div((@should_eval = "with this text"), :id => "combo", :class => "of_divs_with_underscore")
45
+ [ 104, 101, 108, 108, 111 ].map do |byte|
46
+ byte.chr
47
+ end
48
+ div(:class => "footer") do
49
+ strong("This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid. \nSo, I'm just making it *really* long. God, I hope this works", :class => "shout")
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,6 @@
1
+ class Article
2
+ attr_accessor :id, :title, :body
3
+ def initialize
4
+ @id, @title, @body = 1, 'Hello', 'World'
5
+ end
6
+ end
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html>
3
+ <head>
4
+ </head>
5
+ <body>
6
+ <div id='content'>
7
+ Lorem ipsum dolor sit amet
8
+ </div>
9
+ <div id='yieldy'>
10
+ Lorem ipsum dolor sit amet
11
+ </div>
12
+ <div id='nosym'>
13
+ Lorem ipsum dolor sit amet
14
+ </div>
15
+ </body>
16
+ </html>
@@ -0,0 +1,11 @@
1
+ <p>
2
+ </p>
3
+ <p>
4
+ </p>
5
+ <h1>Me!</h1>
6
+ <div id='foo'>
7
+ <p id='bar'>All</p>
8
+ <br />
9
+ <p class='baz'>This</p>
10
+ Should render
11
+ </div>
@@ -0,0 +1,82 @@
1
+ <style>
2
+ p {
3
+ border-style: dotted;
4
+ border-width: 22px;
5
+ border-color: #ff00ff; }
6
+
7
+ h1 {
8
+ font-weight: normal; }
9
+ </style>
10
+ TESTING HAHAHAHA!
11
+ <h1>Foo</h1>
12
+
13
+
14
+ <pre><code>This is preformatted!
15
+ Look at that!
16
+ Wowie-zowie!</code></pre>
17
+
18
+
19
+ <p><strong>boldilicious!</strong></p>
20
+ <h1>Yeah</h1>
21
+
22
+
23
+ <p><em>pretty much the same as above</em></p>
24
+ <p>
25
+ <script type='text/javascript'>
26
+ //<![CDATA[
27
+ function newline(str) {
28
+ return "\n" + str;
29
+ }
30
+ //]]>
31
+ </script>
32
+ </p>
33
+ This
34
+ Is
35
+ Plain
36
+ Text
37
+ %strong right?
38
+ #{not interpolated}
39
+ \3
40
+ \#{also not}
41
+ \\
42
+ <p>
43
+ <pre>
44
+ This pre is pretty deeply&#x000A; nested.&#x000A; Does interpolation work?&#x000A;
45
+ This one is, too.&#x000A;Nested, that is.&#x000A;&#x000A;
46
+ </pre>
47
+ </p>
48
+ <ul>
49
+
50
+ <li>a</li>
51
+
52
+ <li>b</li>
53
+
54
+ <li>c</li>
55
+
56
+ <li>d</li>
57
+
58
+ <li>e</li>
59
+
60
+ <li>f</li>
61
+
62
+ <li>g</li>
63
+
64
+ <li>h</li>
65
+
66
+ <li>i</li>
67
+
68
+ <li>j</li>
69
+
70
+
71
+
72
+ </ul>
73
+ <div class='res'>178</div>
74
+ <ul>
75
+ <li>Foo</li>
76
+ <li>Bar</li>
77
+ <li>BAZ!</li>
78
+ </ul>
79
+ Text!
80
+ Hello, World!
81
+ How are you doing today?
82
+
@@ -0,0 +1,94 @@
1
+ &amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;
2
+ <div>
3
+ <p class='title'>Title</p>
4
+ <p class='text'>
5
+ Woah this is really crazy
6
+ I mean wow,
7
+ man.
8
+ </p>
9
+ </div>
10
+ <div>
11
+ <p class='title'>Title</p>
12
+ <p class='text'>
13
+ Woah this is really crazy
14
+ I mean wow,
15
+ man.
16
+ </p>
17
+ </div>
18
+ <div>
19
+ <p class='title'>Title</p>
20
+ <p class='text'>
21
+ Woah this is really crazy
22
+ I mean wow,
23
+ man.
24
+ </p>
25
+ </div>
26
+ <p>foo</p>
27
+ <p>reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeally loooooooooooooooooong</p>
28
+ <div class='woah'>
29
+ <div id='funky'>
30
+ <div>
31
+ <h1>Big!</h1>
32
+ <p>Small</p>
33
+ <!-- Invisible -->
34
+ </div>
35
+ <div class='dilly'>
36
+ <p>foo</p>
37
+ <h1>bar</h1>
38
+ </div>
39
+ </div>
40
+ (<strong>parentheses!</strong>)
41
+ </div>
42
+ *<span class='small'>Not really</span>
43
+ click
44
+ <a href='thing'>here</a>.
45
+ <p>baz</p>
46
+ <p>boom</p>
47
+ foo
48
+ <p>
49
+ <form action="" method="post">
50
+ </p>
51
+ <form action="" method="post">
52
+ <div><input name="commit" type="submit" value="save" /></div>
53
+ <p>
54
+ @foo =
55
+ value one
56
+ </p>
57
+ Toplevel? false
58
+ <p>
59
+ @foo =
60
+ value three
61
+ </p>
62
+ </form>
63
+ <form action="" method="post">
64
+ Title:
65
+ <input id="article_title" name="article[title]" size="30" type="text" value="Hello" />
66
+ Body:
67
+ <input id="article_body" name="article[body]" size="30" type="text" value="World" />
68
+ </form>
69
+ <li><a href='http://www.google.com'>google</a></li>
70
+ <p>
71
+ foo
72
+ <div>
73
+ bar
74
+ </div>
75
+ boom
76
+ baz
77
+ boom, again
78
+ </p>
79
+ <table>
80
+ <tr>
81
+ <td class='cell'>
82
+ <strong>
83
+ strong!
84
+ </strong>
85
+ data
86
+ </td>
87
+ <td>
88
+ more_data
89
+ </td>
90
+ </tr>
91
+ </table>
92
+ <hr />
93
+ <div>
94
+ </div>