drnic-haml 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. data/.yardopts +5 -0
  2. data/CONTRIBUTING +4 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +347 -0
  5. data/REVISION +1 -0
  6. data/Rakefile +371 -0
  7. data/VERSION +1 -0
  8. data/VERSION_NAME +1 -0
  9. data/bin/css2sass +7 -0
  10. data/bin/haml +9 -0
  11. data/bin/html2haml +7 -0
  12. data/bin/sass +8 -0
  13. data/extra/haml-mode.el +663 -0
  14. data/extra/sass-mode.el +205 -0
  15. data/extra/update_watch.rb +13 -0
  16. data/init.rb +8 -0
  17. data/lib/haml.rb +40 -0
  18. data/lib/haml/buffer.rb +307 -0
  19. data/lib/haml/engine.rb +301 -0
  20. data/lib/haml/error.rb +22 -0
  21. data/lib/haml/exec.rb +470 -0
  22. data/lib/haml/filters.rb +341 -0
  23. data/lib/haml/helpers.rb +560 -0
  24. data/lib/haml/helpers/action_view_extensions.rb +40 -0
  25. data/lib/haml/helpers/action_view_mods.rb +176 -0
  26. data/lib/haml/herb.rb +96 -0
  27. data/lib/haml/html.rb +308 -0
  28. data/lib/haml/precompiler.rb +997 -0
  29. data/lib/haml/shared.rb +78 -0
  30. data/lib/haml/template.rb +51 -0
  31. data/lib/haml/template/patch.rb +58 -0
  32. data/lib/haml/template/plugin.rb +71 -0
  33. data/lib/haml/util.rb +244 -0
  34. data/lib/haml/version.rb +64 -0
  35. data/lib/sass.rb +24 -0
  36. data/lib/sass/css.rb +423 -0
  37. data/lib/sass/engine.rb +491 -0
  38. data/lib/sass/environment.rb +79 -0
  39. data/lib/sass/error.rb +162 -0
  40. data/lib/sass/files.rb +133 -0
  41. data/lib/sass/plugin.rb +170 -0
  42. data/lib/sass/plugin/merb.rb +57 -0
  43. data/lib/sass/plugin/rails.rb +23 -0
  44. data/lib/sass/repl.rb +58 -0
  45. data/lib/sass/script.rb +55 -0
  46. data/lib/sass/script/bool.rb +17 -0
  47. data/lib/sass/script/color.rb +183 -0
  48. data/lib/sass/script/funcall.rb +50 -0
  49. data/lib/sass/script/functions.rb +199 -0
  50. data/lib/sass/script/lexer.rb +191 -0
  51. data/lib/sass/script/literal.rb +177 -0
  52. data/lib/sass/script/node.rb +14 -0
  53. data/lib/sass/script/number.rb +381 -0
  54. data/lib/sass/script/operation.rb +45 -0
  55. data/lib/sass/script/parser.rb +222 -0
  56. data/lib/sass/script/string.rb +12 -0
  57. data/lib/sass/script/unary_operation.rb +34 -0
  58. data/lib/sass/script/variable.rb +31 -0
  59. data/lib/sass/tree/comment_node.rb +84 -0
  60. data/lib/sass/tree/debug_node.rb +30 -0
  61. data/lib/sass/tree/directive_node.rb +70 -0
  62. data/lib/sass/tree/for_node.rb +48 -0
  63. data/lib/sass/tree/if_node.rb +54 -0
  64. data/lib/sass/tree/import_node.rb +69 -0
  65. data/lib/sass/tree/mixin_def_node.rb +29 -0
  66. data/lib/sass/tree/mixin_node.rb +48 -0
  67. data/lib/sass/tree/node.rb +252 -0
  68. data/lib/sass/tree/prop_node.rb +106 -0
  69. data/lib/sass/tree/root_node.rb +56 -0
  70. data/lib/sass/tree/rule_node.rb +220 -0
  71. data/lib/sass/tree/variable_node.rb +34 -0
  72. data/lib/sass/tree/while_node.rb +31 -0
  73. data/rails/init.rb +1 -0
  74. data/test/benchmark.rb +99 -0
  75. data/test/haml/engine_test.rb +1129 -0
  76. data/test/haml/helper_test.rb +282 -0
  77. data/test/haml/html2haml_test.rb +258 -0
  78. data/test/haml/markaby/standard.mab +52 -0
  79. data/test/haml/mocks/article.rb +6 -0
  80. data/test/haml/results/content_for_layout.xhtml +12 -0
  81. data/test/haml/results/eval_suppressed.xhtml +9 -0
  82. data/test/haml/results/filters.xhtml +62 -0
  83. data/test/haml/results/helpers.xhtml +93 -0
  84. data/test/haml/results/helpful.xhtml +10 -0
  85. data/test/haml/results/just_stuff.xhtml +68 -0
  86. data/test/haml/results/list.xhtml +12 -0
  87. data/test/haml/results/nuke_inner_whitespace.xhtml +40 -0
  88. data/test/haml/results/nuke_outer_whitespace.xhtml +148 -0
  89. data/test/haml/results/original_engine.xhtml +20 -0
  90. data/test/haml/results/partial_layout.xhtml +5 -0
  91. data/test/haml/results/partials.xhtml +21 -0
  92. data/test/haml/results/render_layout.xhtml +3 -0
  93. data/test/haml/results/silent_script.xhtml +74 -0
  94. data/test/haml/results/standard.xhtml +162 -0
  95. data/test/haml/results/tag_parsing.xhtml +23 -0
  96. data/test/haml/results/very_basic.xhtml +5 -0
  97. data/test/haml/results/whitespace_handling.xhtml +89 -0
  98. data/test/haml/rhtml/_av_partial_1.rhtml +12 -0
  99. data/test/haml/rhtml/_av_partial_2.rhtml +8 -0
  100. data/test/haml/rhtml/action_view.rhtml +62 -0
  101. data/test/haml/rhtml/standard.rhtml +54 -0
  102. data/test/haml/spec_test.rb +44 -0
  103. data/test/haml/template_test.rb +217 -0
  104. data/test/haml/templates/_av_partial_1.haml +9 -0
  105. data/test/haml/templates/_av_partial_1_ugly.haml +9 -0
  106. data/test/haml/templates/_av_partial_2.haml +5 -0
  107. data/test/haml/templates/_av_partial_2_ugly.haml +5 -0
  108. data/test/haml/templates/_layout.erb +3 -0
  109. data/test/haml/templates/_layout_for_partial.haml +3 -0
  110. data/test/haml/templates/_partial.haml +8 -0
  111. data/test/haml/templates/_text_area.haml +3 -0
  112. data/test/haml/templates/action_view.haml +47 -0
  113. data/test/haml/templates/action_view_ugly.haml +47 -0
  114. data/test/haml/templates/breakage.haml +8 -0
  115. data/test/haml/templates/content_for_layout.haml +8 -0
  116. data/test/haml/templates/eval_suppressed.haml +11 -0
  117. data/test/haml/templates/filters.haml +66 -0
  118. data/test/haml/templates/helpers.haml +95 -0
  119. data/test/haml/templates/helpful.haml +11 -0
  120. data/test/haml/templates/just_stuff.haml +83 -0
  121. data/test/haml/templates/list.haml +12 -0
  122. data/test/haml/templates/nuke_inner_whitespace.haml +32 -0
  123. data/test/haml/templates/nuke_outer_whitespace.haml +144 -0
  124. data/test/haml/templates/original_engine.haml +17 -0
  125. data/test/haml/templates/partial_layout.haml +3 -0
  126. data/test/haml/templates/partialize.haml +1 -0
  127. data/test/haml/templates/partials.haml +12 -0
  128. data/test/haml/templates/render_layout.haml +2 -0
  129. data/test/haml/templates/silent_script.haml +40 -0
  130. data/test/haml/templates/standard.haml +42 -0
  131. data/test/haml/templates/standard_ugly.haml +42 -0
  132. data/test/haml/templates/tag_parsing.haml +21 -0
  133. data/test/haml/templates/very_basic.haml +4 -0
  134. data/test/haml/templates/whitespace_handling.haml +87 -0
  135. data/test/haml/util_test.rb +92 -0
  136. data/test/linked_rails.rb +12 -0
  137. data/test/sass/css2sass_test.rb +294 -0
  138. data/test/sass/engine_test.rb +956 -0
  139. data/test/sass/functions_test.rb +126 -0
  140. data/test/sass/more_results/more1.css +9 -0
  141. data/test/sass/more_results/more1_with_line_comments.css +26 -0
  142. data/test/sass/more_results/more_import.css +29 -0
  143. data/test/sass/more_templates/_more_partial.sass +2 -0
  144. data/test/sass/more_templates/more1.sass +23 -0
  145. data/test/sass/more_templates/more_import.sass +11 -0
  146. data/test/sass/plugin_test.rb +229 -0
  147. data/test/sass/results/alt.css +4 -0
  148. data/test/sass/results/basic.css +9 -0
  149. data/test/sass/results/compact.css +5 -0
  150. data/test/sass/results/complex.css +87 -0
  151. data/test/sass/results/compressed.css +1 -0
  152. data/test/sass/results/expanded.css +19 -0
  153. data/test/sass/results/import.css +29 -0
  154. data/test/sass/results/line_numbers.css +49 -0
  155. data/test/sass/results/mixins.css +95 -0
  156. data/test/sass/results/multiline.css +24 -0
  157. data/test/sass/results/nested.css +22 -0
  158. data/test/sass/results/parent_ref.css +13 -0
  159. data/test/sass/results/script.css +16 -0
  160. data/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
  161. data/test/sass/results/subdir/subdir.css +3 -0
  162. data/test/sass/results/units.css +11 -0
  163. data/test/sass/script_test.rb +261 -0
  164. data/test/sass/templates/_partial.sass +2 -0
  165. data/test/sass/templates/alt.sass +16 -0
  166. data/test/sass/templates/basic.sass +23 -0
  167. data/test/sass/templates/bork1.sass +2 -0
  168. data/test/sass/templates/bork2.sass +2 -0
  169. data/test/sass/templates/bork3.sass +2 -0
  170. data/test/sass/templates/compact.sass +17 -0
  171. data/test/sass/templates/complex.sass +307 -0
  172. data/test/sass/templates/compressed.sass +15 -0
  173. data/test/sass/templates/expanded.sass +17 -0
  174. data/test/sass/templates/import.sass +11 -0
  175. data/test/sass/templates/importee.sass +19 -0
  176. data/test/sass/templates/line_numbers.sass +13 -0
  177. data/test/sass/templates/mixins.sass +76 -0
  178. data/test/sass/templates/multiline.sass +20 -0
  179. data/test/sass/templates/nested.sass +25 -0
  180. data/test/sass/templates/nested_bork1.sass +2 -0
  181. data/test/sass/templates/nested_bork2.sass +2 -0
  182. data/test/sass/templates/nested_bork3.sass +2 -0
  183. data/test/sass/templates/parent_ref.sass +25 -0
  184. data/test/sass/templates/script.sass +101 -0
  185. data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
  186. data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
  187. data/test/sass/templates/subdir/subdir.sass +6 -0
  188. data/test/sass/templates/units.sass +11 -0
  189. data/test/test_helper.rb +44 -0
  190. metadata +298 -0
@@ -0,0 +1,17 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title Stop. haml time
5
+ #content
6
+ %h1 This is a title!
7
+ %p Lorem ipsum dolor sit amet, consectetur adipisicing elit
8
+ %p{:class => 'foo'} Cigarettes!
9
+ %h2 Man alive!
10
+ %ul.things
11
+ %li Slippers
12
+ %li Shoes
13
+ %li Bathrobe
14
+ %li Coffee
15
+ %pre
16
+ This is some text that's in a pre block!
17
+ Let's see what happens when it's rendered! What about now, since we're on a new line?
@@ -0,0 +1,3 @@
1
+ %h1 Partial layout used with for block:
2
+ - render :layout => 'layout_for_partial.haml' do
3
+ %p Some content within a layout
@@ -0,0 +1 @@
1
+ = render :file => "#{name}.haml"
@@ -0,0 +1,12 @@
1
+ - @foo = 'value one'
2
+ %p
3
+ @foo =
4
+ = @foo
5
+ - @foo = 'value two'
6
+ %p
7
+ @foo =
8
+ = @foo
9
+ = test_partial "partial"
10
+ %p
11
+ @foo =
12
+ = @foo
@@ -0,0 +1,2 @@
1
+ = render :layout => 'layout' do
2
+ During
@@ -0,0 +1,40 @@
1
+ %div
2
+ %h1 I can count!
3
+ - (1..20).each do |i|
4
+ = i
5
+ %h1 I know my ABCs!
6
+ %ul
7
+ - ('a'..'z').each do |i|
8
+ %li= i
9
+ %h1 I can catch errors!
10
+ - begin
11
+ - String.silly
12
+ - rescue NameError => e
13
+ = "Oh no! \"#{e}\" happened!"
14
+ %p
15
+ "false" is:
16
+ - if false
17
+ = "true"
18
+ - else
19
+ = "false"
20
+ - if true
21
+ - 5.times do |i|
22
+ - if i % 2 == 1
23
+ Odd!
24
+ - else
25
+ Even!
26
+ - else
27
+ = "This can't happen!"
28
+ - 13 |
29
+ .foo
30
+ %strong foobar
31
+ - 5.times |
32
+ do |
33
+ |a| |
34
+ %strong= a
35
+ .test
36
+ - "foo |
37
+ bar |
38
+ baz" |
39
+
40
+ %p boom
@@ -0,0 +1,42 @@
1
+ !!!
2
+ %html{:xmlns => "http://www.w3.org/1999/xhtml", "xml:lang" => "en-US", "lang" => "en-US"}
3
+ %head
4
+ %title Hampton Catlin Is Totally Awesome
5
+ %meta{"http-equiv" => "Content-Type", :content => "text/html; charset=utf-8"}
6
+ %body
7
+ / You're In my house now!
8
+ .header
9
+ Yes, ladies and gentileman. He is just that egotistical.
10
+ Fantastic! This should be multi-line output
11
+ The question is if this would translate! Ahah!
12
+ = 1 + 9 + 8 + 2 #numbers should work and this should be ignored
13
+ #body= " Quotes should be loved! Just like people!"
14
+ - 120.times do |number|
15
+ = number
16
+ Wow.|
17
+ %p
18
+ = "Holy cow " + |
19
+ "multiline " + |
20
+ "tags! " + |
21
+ "A pipe (|) even!" |
22
+ = [1, 2, 3].collect { |n| "PipesIgnored|" }.join
23
+ = [1, 2, 3].collect { |n| |
24
+ n.to_s |
25
+ }.join("|") |
26
+ %div.silent
27
+ - foo = String.new
28
+ - foo << "this"
29
+ - foo << " shouldn't"
30
+ - foo << " evaluate"
31
+ = foo + " but now it should!"
32
+ -# Woah crap a comment!
33
+
34
+ -# That was a line that shouldn't close everything.
35
+ %ul.really.cool
36
+ - ('a'..'f').each do |a|
37
+ %li= a
38
+ #combo.of_divs_with_underscore= @should_eval = "with this text"
39
+ = "foo".each_line do |line|
40
+ - nil
41
+ .footer
42
+ %strong.shout= "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"
@@ -0,0 +1,42 @@
1
+ !!!
2
+ %html{:xmlns => "http://www.w3.org/1999/xhtml", "xml:lang" => "en-US", "lang" => "en-US"}
3
+ %head
4
+ %title Hampton Catlin Is Totally Awesome
5
+ %meta{"http-equiv" => "Content-Type", :content => "text/html; charset=utf-8"}
6
+ %body
7
+ / You're In my house now!
8
+ .header
9
+ Yes, ladies and gentileman. He is just that egotistical.
10
+ Fantastic! This should be multi-line output
11
+ The question is if this would translate! Ahah!
12
+ = 1 + 9 + 8 + 2 #numbers should work and this should be ignored
13
+ #body= " Quotes should be loved! Just like people!"
14
+ - 120.times do |number|
15
+ = number
16
+ Wow.|
17
+ %p
18
+ = "Holy cow " + |
19
+ "multiline " + |
20
+ "tags! " + |
21
+ "A pipe (|) even!" |
22
+ = [1, 2, 3].collect { |n| "PipesIgnored|" }.join
23
+ = [1, 2, 3].collect { |n| |
24
+ n.to_s |
25
+ }.join("|") |
26
+ %div.silent
27
+ - foo = String.new
28
+ - foo << "this"
29
+ - foo << " shouldn't"
30
+ - foo << " evaluate"
31
+ = foo + " but now it should!"
32
+ -# Woah crap a comment!
33
+
34
+ -# That was a line that shouldn't close everything.
35
+ %ul.really.cool
36
+ - ('a'..'f').each do |a|
37
+ %li= a
38
+ #combo.of_divs_with_underscore= @should_eval = "with this text"
39
+ = "foo".each_line do |line|
40
+ - nil
41
+ .footer
42
+ %strong.shout= "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"
@@ -0,0 +1,21 @@
1
+ %div.tags
2
+ %foo 1
3
+ %FOO 2
4
+ %fooBAR 3
5
+ %fooBar 4
6
+ %foo_bar 5
7
+ %foo-bar 6
8
+ %foo:bar 7
9
+ %foo.bar 8
10
+ %fooBAr_baz:boom_bar 9
11
+ %foo13 10
12
+ %foo2u 11
13
+ %div.classes
14
+ %p.foo.bar#baz#boom
15
+ .fooBar a
16
+ .foo-bar b
17
+ .foo_bar c
18
+ .FOOBAR d
19
+ .foo16 e
20
+ .123 f
21
+ .foo2u g
@@ -0,0 +1,4 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %body
@@ -0,0 +1,87 @@
1
+ #whitespace_test
2
+ = test_partial "text_area", :value => "Oneline"
3
+ = test_partial "text_area", :value => "Two\nlines"
4
+ ~ test_partial "text_area", :value => "Oneline"
5
+ ~ test_partial "text_area", :value => "Two\nlines"
6
+ #flattened~ test_partial "text_area", :value => "Two\nlines"
7
+ .hithere
8
+ ~ "Foo bar"
9
+ ~ "<pre>foo bar</pre>"
10
+ ~ "<pre>foo\nbar</pre>"
11
+ %p~ "<pre>foo\nbar</pre>"
12
+ %p~ "foo\nbar"
13
+ .foo
14
+ ~ 13
15
+ ~ "<textarea>\na\n</textarea>".each_line do |l|
16
+ - haml_concat l.strip
17
+ #whitespace_test
18
+ = test_partial "text_area", :value => "Oneline"
19
+ = test_partial "text_area", :value => "Two\nlines"
20
+ = find_and_preserve test_partial("text_area", :value => "Oneline")
21
+ = find_and_preserve test_partial("text_area", :value => "Two\nlines")
22
+ #flattened= find_and_preserve test_partial("text_area", :value => "Two\nlines")
23
+ .hithere
24
+ = find_and_preserve("Foo bar")
25
+ = find_and_preserve("<pre>foo bar</pre>")
26
+ = find_and_preserve("<pre>foo\nbar</pre>")
27
+ %p= find_and_preserve("<pre>foo\nbar</pre>")
28
+ %p= find_and_preserve("foo\nbar")
29
+ %pre
30
+ :preserve
31
+ ___
32
+ ,o88888
33
+ ,o8888888'
34
+ ,:o:o:oooo. ,8O88Pd8888"
35
+ ,.::.::o:ooooOoOoO. ,oO8O8Pd888'"
36
+ ,.:.::o:ooOoOoOO8O8OOo.8OOPd8O8O"
37
+ , ..:.::o:ooOoOOOO8OOOOo.FdO8O8"
38
+ , ..:.::o:ooOoOO8O888O8O,COCOO"
39
+ , . ..:.::o:ooOoOOOO8OOOOCOCO"
40
+ . ..:.::o:ooOoOoOO8O8OCCCC"o
41
+ . ..:.::o:ooooOoCoCCC"o:o
42
+ . ..:.::o:o:,cooooCo"oo:o:
43
+ ` . . ..:.:cocoooo"'o:o:::'
44
+ .` . ..::ccccoc"'o:o:o:::'
45
+ :.:. ,c:cccc"':.:.:.:.:.'
46
+ ..:.:"'`::::c:"'..:.:.:.:.:.' http://www.chris.com/ASCII/
47
+ ...:.'.:.::::"' . . . . .'
48
+ .. . ....:."' ` . . . ''
49
+ . . . ...."'
50
+ .. . ."' -hrr-
51
+ .
52
+
53
+
54
+ It's a planet!
55
+ %strong This shouldn't be bold!
56
+ %strong This should!
57
+ %textarea
58
+ :preserve
59
+ ___ ___ ___ ___
60
+ /\__\ /\ \ /\__\ /\__\
61
+ /:/ / /::\ \ /::| | /:/ /
62
+ /:/__/ /:/\:\ \ /:|:| | /:/ /
63
+ /::\ \ ___ /::\~\:\ \ /:/|:|__|__ /:/ /
64
+ /:/\:\ /\__\ /:/\:\ \:\__\ /:/ |::::\__\ /:/__/
65
+ \/__\:\/:/ / \/__\:\/:/ / \/__/~~/:/ / \:\ \
66
+ \::/ / \::/ / /:/ / \:\ \
67
+ /:/ / /:/ / /:/ / \:\ \
68
+ /:/ / /:/ / /:/ / \:\__\
69
+ \/__/ \/__/ \/__/ \/__/
70
+
71
+ Many
72
+ thanks
73
+ to
74
+ http://www.network-science.de/ascii/
75
+ %strong indeed!
76
+ .foo
77
+ = find_and_preserve(13)
78
+ %pre
79
+ :preserve
80
+ __ ______ __ ______
81
+ .----.| |--.|__ |.----.| |--..--------.| __ |
82
+ | __|| ||__ || __|| < | || __ |
83
+ |____||__|__||______||____||__|__||__|__|__||______|
84
+ %pre
85
+ :preserve
86
+ foo
87
+ bar
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../test_helper'
3
+ require 'pathname'
4
+
5
+ class UtilTest < Test::Unit::TestCase
6
+ include Haml::Util
7
+
8
+ def test_scope
9
+ assert(File.exist?(scope("Rakefile")))
10
+ end
11
+
12
+ def test_to_hash
13
+ assert_equal({
14
+ :foo => 1,
15
+ :bar => 2,
16
+ :baz => 3
17
+ }, to_hash([[:foo, 1], [:bar, 2], [:baz, 3]]))
18
+ end
19
+
20
+ def test_map_keys
21
+ assert_equal({
22
+ "foo" => 1,
23
+ "bar" => 2,
24
+ "baz" => 3
25
+ }, map_keys({:foo => 1, :bar => 2, :baz => 3}) {|k| k.to_s})
26
+ end
27
+
28
+ def test_map_vals
29
+ assert_equal({
30
+ :foo => "1",
31
+ :bar => "2",
32
+ :baz => "3"
33
+ }, map_vals({:foo => 1, :bar => 2, :baz => 3}) {|k| k.to_s})
34
+ end
35
+
36
+ def test_map_hash
37
+ assert_equal({
38
+ "foo" => "1",
39
+ "bar" => "2",
40
+ "baz" => "3"
41
+ }, map_hash({:foo => 1, :bar => 2, :baz => 3}) {|k, v| [k.to_s, v.to_s]})
42
+ end
43
+
44
+ def test_powerset
45
+ return unless Set[Set[]] == Set[Set[]] # There's a bug in Ruby 1.8.6 that breaks nested set equality
46
+ assert_equal([[].to_set].to_set,
47
+ powerset([]))
48
+ assert_equal([[].to_set, [1].to_set].to_set,
49
+ powerset([1]))
50
+ assert_equal([[].to_set, [1].to_set, [2].to_set, [1, 2].to_set].to_set,
51
+ powerset([1, 2]))
52
+ assert_equal([[].to_set, [1].to_set, [2].to_set, [3].to_set,
53
+ [1, 2].to_set, [2, 3].to_set, [1, 3].to_set, [1, 2, 3].to_set].to_set,
54
+ powerset([1, 2, 3]))
55
+ end
56
+
57
+ def test_has
58
+ assert(has?(:instance_method, String, :chomp!))
59
+ assert(has?(:private_instance_method, Haml::Engine, :set_locals))
60
+ end
61
+
62
+ def test_enum_with_index
63
+ assert_equal(%w[foo0 bar1 baz2],
64
+ enum_with_index(%w[foo bar baz]).map {|s, i| "#{s}#{i}"})
65
+ end
66
+
67
+ def test_def_static_method
68
+ klass = Class.new
69
+ def_static_method(klass, :static_method, [:arg1, :arg2],
70
+ :sarg1, :sarg2, <<RUBY)
71
+ s = "Always " + arg1
72
+ s << " <% if sarg1 %>and<% else %>but never<% end %> " << arg2
73
+
74
+ <% if sarg2 %>
75
+ s << "."
76
+ <% end %>
77
+ RUBY
78
+ c = klass.new
79
+ assert_equal("Always brush your teeth and comb your hair.",
80
+ c.send(static_method_name(:static_method, true, true),
81
+ "brush your teeth", "comb your hair"))
82
+ assert_equal("Always brush your teeth and comb your hair",
83
+ c.send(static_method_name(:static_method, true, false),
84
+ "brush your teeth", "comb your hair"))
85
+ assert_equal("Always brush your teeth but never play with fire.",
86
+ c.send(static_method_name(:static_method, false, true),
87
+ "brush your teeth", "play with fire"))
88
+ assert_equal("Always brush your teeth but never play with fire",
89
+ c.send(static_method_name(:static_method, false, false),
90
+ "brush your teeth", "play with fire"))
91
+ end
92
+ end
@@ -0,0 +1,12 @@
1
+ # allows testing with edge Rails by creating a test/rails symlink
2
+ linked_rails = File.dirname(__FILE__) + '/rails'
3
+
4
+ if File.exists?(linked_rails) && !$:.include?(linked_rails + '/activesupport/lib')
5
+ puts "[ using linked Rails ]"
6
+ $:.unshift linked_rails + '/activesupport/lib'
7
+ $:.unshift linked_rails + '/actionpack/lib'
8
+ else
9
+ require 'rubygems'
10
+ end
11
+ require 'action_controller'
12
+ require 'action_view'
@@ -0,0 +1,294 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../test_helper'
3
+ require 'sass/css'
4
+
5
+ class CSS2SassTest < Test::Unit::TestCase
6
+ def test_basic
7
+ css = <<CSS
8
+ h1 {
9
+ color: red;
10
+ }
11
+ CSS
12
+ assert_equal(<<SASS, css2sass(css))
13
+ h1
14
+ color: red
15
+ SASS
16
+ assert_equal(<<SASS, css2sass(css, :old => true))
17
+ h1
18
+ :color red
19
+ SASS
20
+ end
21
+
22
+ def test_nesting
23
+ assert_equal(<<SASS, css2sass(<<CSS))
24
+ li
25
+ display: none
26
+
27
+ a
28
+ text-decoration: none
29
+
30
+ span
31
+ color: yellow
32
+
33
+ &:hover
34
+ text-decoration: underline
35
+ SASS
36
+ li {
37
+ display: none;
38
+ }
39
+
40
+ li a {
41
+ text-decoration: none;
42
+ }
43
+
44
+ li a span {
45
+ color: yellow;
46
+ }
47
+
48
+ li a:hover {
49
+ text-decoration: underline;
50
+ }
51
+ CSS
52
+ end
53
+
54
+ def test_no_nesting_around_rules
55
+ assert_equal(<<SASS, css2sass(<<CSS))
56
+ div .warning
57
+ color: #d21a19
58
+
59
+
60
+ span .debug
61
+ cursor: crosshair
62
+
63
+
64
+ div .debug
65
+ cursor: default
66
+ SASS
67
+ div .warning {
68
+ color: #d21a19; }
69
+ span .debug {
70
+ cursor: crosshair;}
71
+ div .debug {
72
+ cursor: default; }
73
+ CSS
74
+ end
75
+
76
+ def test_comments_multiline
77
+ css = <<CSS
78
+ /* comment */
79
+ elephant.rawr {
80
+ rampages: excessively;
81
+ }
82
+
83
+ /* actual multiline
84
+ comment */
85
+ span.turkey {
86
+ isdinner: true;
87
+ }
88
+
89
+ .turducken {
90
+ /* Sounds funny
91
+ doesn't it */
92
+ chimera: not_really;
93
+ }
94
+
95
+ #overhere {
96
+ bored: sorta; /* it's for a good
97
+ cause */
98
+ better_than: thread_pools;
99
+ }
100
+
101
+ #one_more {
102
+ finally: srsly;
103
+ } /* just a line here */
104
+ CSS
105
+ sass = <<SASS
106
+ elephant.rawr
107
+ rampages: excessively
108
+
109
+
110
+ span.turkey
111
+ isdinner: true
112
+
113
+
114
+ .turducken
115
+ chimera: not_really
116
+
117
+
118
+ #overhere
119
+ bored: sorta
120
+ better_than: thread_pools
121
+
122
+
123
+ #one_more
124
+ finally: srsly
125
+ SASS
126
+ assert_equal(css2sass(css), sass)
127
+ end
128
+
129
+ def test_fold_commas
130
+ assert_equal(<<SASS, css2sass(<<CSS))
131
+ li
132
+ .one, .two
133
+ color: red
134
+ SASS
135
+ li .one {
136
+ color: red;
137
+ }
138
+ li .two {
139
+ color: red;
140
+ }
141
+ CSS
142
+
143
+ assert_equal(<<SASS, css2sass(<<CSS))
144
+ .one
145
+ color: green
146
+
147
+
148
+ .two
149
+ color: green
150
+ color: red
151
+
152
+
153
+ .three
154
+ color: red
155
+ SASS
156
+ .one, .two {
157
+ color: green;
158
+ }
159
+
160
+ .two, .three {
161
+ color: red;
162
+ }
163
+ CSS
164
+ end
165
+
166
+ def test_bad_formatting
167
+ assert_equal(<<SASS, css2sass(<<CSS))
168
+ hello
169
+ parent: true
170
+
171
+ there
172
+ parent: false
173
+
174
+ who
175
+ hoo: false
176
+
177
+ why
178
+ y: true
179
+
180
+ when
181
+ wen: nao
182
+
183
+
184
+ down_here
185
+ yeah: true
186
+ SASS
187
+ hello {
188
+ parent: true;
189
+ }
190
+
191
+ hello there {
192
+ parent: false;
193
+ }
194
+ hello who {
195
+ hoo: false;
196
+ }
197
+ hello why {
198
+ y: true;
199
+ }
200
+ hello when {
201
+ wen: nao;
202
+ }
203
+
204
+
205
+
206
+ down_here { yeah: true; }
207
+ CSS
208
+ end
209
+
210
+ def test_comments_in_selectors
211
+ assert_equal(<<SASS, css2sass(<<CSS))
212
+ .js
213
+ #location-navigation-form .form-submit, #business-listing-form .form-submit, #detailTabs ul, #detailsEnhanced #addTags, #locationSearchList, #moreHoods
214
+ display: none
215
+
216
+
217
+ #navListLeft
218
+ display: none
219
+ SASS
220
+ .js #location-navigation-form .form-submit,
221
+ .js #business-listing-form .form-submit,
222
+ .js #detailTabs ul,
223
+ /* .js #addReview, */
224
+ /* .js #addTags, */
225
+ .js #detailsEnhanced #addTags,
226
+ .js #locationSearchList,
227
+ .js #moreHoods,
228
+ #navListLeft
229
+ { display: none; }
230
+ CSS
231
+ end
232
+
233
+ # Error reporting
234
+
235
+ def test_error_reporting
236
+ css2sass("foo")
237
+ assert(false, "Expected exception")
238
+ rescue Sass::SyntaxError => err
239
+ assert_equal(1, err.sass_line)
240
+ assert_equal('Invalid CSS after "foo": expected "{", was ""', err.message)
241
+ end
242
+
243
+ def test_error_reporting_in_line
244
+ css2sass("foo\nbar }\nbaz")
245
+ assert(false, "Expected exception")
246
+ rescue Sass::SyntaxError => err
247
+ assert_equal(2, err.sass_line)
248
+ assert_equal('Invalid CSS after "bar ": expected "{", was "}"', err.message)
249
+ end
250
+
251
+ def test_error_truncate_after
252
+ css2sass("#{"a" * 15}foo")
253
+ assert(false, "Expected exception")
254
+ rescue Sass::SyntaxError => err
255
+ assert_equal(1, err.sass_line)
256
+ assert_equal('Invalid CSS after "...aaaaaaaaaaaafoo": expected "{", was ""', err.message)
257
+ end
258
+
259
+ def test_error_truncate_was
260
+ css2sass("foo }#{"a" * 15}")
261
+ assert(false, "Expected exception")
262
+ rescue Sass::SyntaxError => err
263
+ assert_equal(1, err.sass_line)
264
+ assert_equal('Invalid CSS after "foo ": expected "{", was "}aaaaaaaaaaaaaa..."', err.message)
265
+ end
266
+
267
+ # Encodings
268
+
269
+ unless Haml::Util.ruby1_8?
270
+ def test_encoding_error
271
+ css2sass("foo\nbar\nb\xFEaz".force_encoding("utf-8"))
272
+ assert(false, "Expected exception")
273
+ rescue Sass::SyntaxError => e
274
+ assert_equal(3, e.sass_line)
275
+ assert_equal('Invalid UTF-8 character "\xFE"', e.message)
276
+ end
277
+
278
+ def test_ascii_incompatible_encoding_error
279
+ template = "foo\nbar\nb_z".encode("utf-16le")
280
+ template[9] = "\xFE".force_encoding("utf-16le")
281
+ css2sass(template)
282
+ assert(false, "Expected exception")
283
+ rescue Sass::SyntaxError => e
284
+ assert_equal(3, e.sass_line)
285
+ assert_equal('Invalid UTF-16LE character "\xFE"', e.message)
286
+ end
287
+ end
288
+
289
+ private
290
+
291
+ def css2sass(string, opts={})
292
+ Sass::CSS.new(string, opts).render
293
+ end
294
+ end