mini-max-gem 0.0.1

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.
Files changed (127) hide show
  1. checksums.yaml +7 -0
  2. data/mini-max-gem.gemspec +11 -0
  3. data/slim-5.2.1/CHANGES +496 -0
  4. data/slim-5.2.1/Gemfile +43 -0
  5. data/slim-5.2.1/LICENSE +21 -0
  6. data/slim-5.2.1/README.jp.md +1276 -0
  7. data/slim-5.2.1/README.md +1313 -0
  8. data/slim-5.2.1/Rakefile +80 -0
  9. data/slim-5.2.1/bin/slimrb +6 -0
  10. data/slim-5.2.1/doc/include.md +20 -0
  11. data/slim-5.2.1/doc/jp/include.md +20 -0
  12. data/slim-5.2.1/doc/jp/logic_less.md +137 -0
  13. data/slim-5.2.1/doc/jp/smart.md +102 -0
  14. data/slim-5.2.1/doc/jp/translator.md +28 -0
  15. data/slim-5.2.1/doc/logic_less.md +137 -0
  16. data/slim-5.2.1/doc/smart.md +120 -0
  17. data/slim-5.2.1/doc/translator.md +28 -0
  18. data/slim-5.2.1/lib/slim/code_attributes.rb +68 -0
  19. data/slim-5.2.1/lib/slim/command.rb +122 -0
  20. data/slim-5.2.1/lib/slim/controls.rb +61 -0
  21. data/slim-5.2.1/lib/slim/do_inserter.rb +34 -0
  22. data/slim-5.2.1/lib/slim/embedded.rb +248 -0
  23. data/slim-5.2.1/lib/slim/end_inserter.rb +63 -0
  24. data/slim-5.2.1/lib/slim/engine.rb +42 -0
  25. data/slim-5.2.1/lib/slim/erb_converter.rb +15 -0
  26. data/slim-5.2.1/lib/slim/filter.rb +31 -0
  27. data/slim-5.2.1/lib/slim/grammar.rb +24 -0
  28. data/slim-5.2.1/lib/slim/include.rb +58 -0
  29. data/slim-5.2.1/lib/slim/interpolation.rb +36 -0
  30. data/slim-5.2.1/lib/slim/logic_less/context.rb +126 -0
  31. data/slim-5.2.1/lib/slim/logic_less/filter.rb +81 -0
  32. data/slim-5.2.1/lib/slim/logic_less.rb +6 -0
  33. data/slim-5.2.1/lib/slim/parser.rb +535 -0
  34. data/slim-5.2.1/lib/slim/railtie.rb +19 -0
  35. data/slim-5.2.1/lib/slim/smart/escaper.rb +42 -0
  36. data/slim-5.2.1/lib/slim/smart/filter.rb +97 -0
  37. data/slim-5.2.1/lib/slim/smart/parser.rb +35 -0
  38. data/slim-5.2.1/lib/slim/smart.rb +9 -0
  39. data/slim-5.2.1/lib/slim/splat/builder.rb +115 -0
  40. data/slim-5.2.1/lib/slim/splat/filter.rb +93 -0
  41. data/slim-5.2.1/lib/slim/template.rb +6 -0
  42. data/slim-5.2.1/lib/slim/translator.rb +119 -0
  43. data/slim-5.2.1/lib/slim/version.rb +6 -0
  44. data/slim-5.2.1/lib/slim.rb +164 -0
  45. data/slim-5.2.1/slim.gemspec +33 -0
  46. data/slim-5.2.1/test/core/helper.rb +201 -0
  47. data/slim-5.2.1/test/core/test_code_blocks.rb +194 -0
  48. data/slim-5.2.1/test/core/test_code_escaping.rb +162 -0
  49. data/slim-5.2.1/test/core/test_code_evaluation.rb +181 -0
  50. data/slim-5.2.1/test/core/test_code_output.rb +168 -0
  51. data/slim-5.2.1/test/core/test_code_structure.rb +203 -0
  52. data/slim-5.2.1/test/core/test_commands.rb +219 -0
  53. data/slim-5.2.1/test/core/test_embedded_engines.rb +247 -0
  54. data/slim-5.2.1/test/core/test_encoding.rb +28 -0
  55. data/slim-5.2.1/test/core/test_erb_converter.rb +65 -0
  56. data/slim-5.2.1/test/core/test_html_attributes.rb +276 -0
  57. data/slim-5.2.1/test/core/test_html_escaping.rb +65 -0
  58. data/slim-5.2.1/test/core/test_html_structure.rb +599 -0
  59. data/slim-5.2.1/test/core/test_parser_errors.rb +148 -0
  60. data/slim-5.2.1/test/core/test_pretty.rb +163 -0
  61. data/slim-5.2.1/test/core/test_ruby_errors.rb +200 -0
  62. data/slim-5.2.1/test/core/test_slim_template.rb +78 -0
  63. data/slim-5.2.1/test/core/test_splat_prefix_option.rb +155 -0
  64. data/slim-5.2.1/test/core/test_tabs.rb +169 -0
  65. data/slim-5.2.1/test/core/test_text_interpolation.rb +79 -0
  66. data/slim-5.2.1/test/core/test_thread_options.rb +18 -0
  67. data/slim-5.2.1/test/core/test_unicode.rb +15 -0
  68. data/slim-5.2.1/test/include/files/recursive.slim +1 -0
  69. data/slim-5.2.1/test/include/files/slimfile.slim +3 -0
  70. data/slim-5.2.1/test/include/files/subdir/test.slim +1 -0
  71. data/slim-5.2.1/test/include/files/textfile +1 -0
  72. data/slim-5.2.1/test/include/test_include.rb +24 -0
  73. data/slim-5.2.1/test/literate/TESTS.md +1323 -0
  74. data/slim-5.2.1/test/literate/helper.rb +15 -0
  75. data/slim-5.2.1/test/literate/run.rb +92 -0
  76. data/slim-5.2.1/test/logic_less/test_logic_less.rb +330 -0
  77. data/slim-5.2.1/test/rails/Rakefile +7 -0
  78. data/slim-5.2.1/test/rails/app/assets/config/manifest.js +1 -0
  79. data/slim-5.2.1/test/rails/app/controllers/application_controller.rb +2 -0
  80. data/slim-5.2.1/test/rails/app/controllers/entries_controller.rb +5 -0
  81. data/slim-5.2.1/test/rails/app/controllers/slim_controller.rb +46 -0
  82. data/slim-5.2.1/test/rails/app/helpers/application_helper.rb +5 -0
  83. data/slim-5.2.1/test/rails/app/models/entry.rb +16 -0
  84. data/slim-5.2.1/test/rails/app/views/entries/edit.html.slim +3 -0
  85. data/slim-5.2.1/test/rails/app/views/layouts/application.html+testvariant.slim +10 -0
  86. data/slim-5.2.1/test/rails/app/views/layouts/application.html.slim +10 -0
  87. data/slim-5.2.1/test/rails/app/views/slim/_partial.html.slim +1 -0
  88. data/slim-5.2.1/test/rails/app/views/slim/attributes.html.slim +3 -0
  89. data/slim-5.2.1/test/rails/app/views/slim/content_for.html.slim +7 -0
  90. data/slim-5.2.1/test/rails/app/views/slim/erb.html.erb +1 -0
  91. data/slim-5.2.1/test/rails/app/views/slim/form_for.html.slim +2 -0
  92. data/slim-5.2.1/test/rails/app/views/slim/helper.html.slim +4 -0
  93. data/slim-5.2.1/test/rails/app/views/slim/integers.html.slim +1 -0
  94. data/slim-5.2.1/test/rails/app/views/slim/no_layout.html.slim +1 -0
  95. data/slim-5.2.1/test/rails/app/views/slim/normal.html.slim +1 -0
  96. data/slim-5.2.1/test/rails/app/views/slim/partial.html.slim +2 -0
  97. data/slim-5.2.1/test/rails/app/views/slim/splat.html.slim +2 -0
  98. data/slim-5.2.1/test/rails/app/views/slim/splat_with_delimiter.slim +1 -0
  99. data/slim-5.2.1/test/rails/app/views/slim/thread_options.html.slim +1 -0
  100. data/slim-5.2.1/test/rails/app/views/slim/variables.html.slim +1 -0
  101. data/slim-5.2.1/test/rails/app/views/slim/xml.slim +1 -0
  102. data/slim-5.2.1/test/rails/config/application.rb +44 -0
  103. data/slim-5.2.1/test/rails/config/boot.rb +10 -0
  104. data/slim-5.2.1/test/rails/config/environment.rb +5 -0
  105. data/slim-5.2.1/test/rails/config/environments/test.rb +34 -0
  106. data/slim-5.2.1/test/rails/config/initializers/backtrace_silencers.rb +7 -0
  107. data/slim-5.2.1/test/rails/config/initializers/inflections.rb +10 -0
  108. data/slim-5.2.1/test/rails/config/initializers/mime_types.rb +5 -0
  109. data/slim-5.2.1/test/rails/config/initializers/session_store.rb +8 -0
  110. data/slim-5.2.1/test/rails/config/locales/en.yml +5 -0
  111. data/slim-5.2.1/test/rails/config/routes.rb +60 -0
  112. data/slim-5.2.1/test/rails/config.ru +4 -0
  113. data/slim-5.2.1/test/rails/script/rails +6 -0
  114. data/slim-5.2.1/test/rails/test/helper.rb +34 -0
  115. data/slim-5.2.1/test/rails/test/test_slim.rb +102 -0
  116. data/slim-5.2.1/test/sinatra/contest.rb +91 -0
  117. data/slim-5.2.1/test/sinatra/helper.rb +143 -0
  118. data/slim-5.2.1/test/sinatra/test_core.rb +91 -0
  119. data/slim-5.2.1/test/sinatra/test_include.rb +16 -0
  120. data/slim-5.2.1/test/sinatra/views/embed_include_js.slim +8 -0
  121. data/slim-5.2.1/test/sinatra/views/embed_js.slim +11 -0
  122. data/slim-5.2.1/test/sinatra/views/footer.slim +1 -0
  123. data/slim-5.2.1/test/sinatra/views/hello.slim +1 -0
  124. data/slim-5.2.1/test/sinatra/views/layout2.slim +3 -0
  125. data/slim-5.2.1/test/smart/test_smart_text.rb +294 -0
  126. data/slim-5.2.1/test/translator/test_translator.rb +76 -0
  127. metadata +165 -0
@@ -0,0 +1,219 @@
1
+ require 'helper'
2
+ require 'open3'
3
+ require 'tempfile'
4
+
5
+ class TestSlimCommands < Minitest::Test
6
+ # nothing complex
7
+ STATIC_TEMPLATE = "p Hello World!\n"
8
+
9
+ # requires a `name` variable to exist at render time
10
+ DYNAMIC_TEMPLATE = "p Hello \#{name}!\n"
11
+
12
+ # a more complex example
13
+ LONG_TEMPLATE = "h1 Hello\np\n | World!\n small Tiny text"
14
+
15
+ # exception raising example
16
+ EXCEPTION_TEMPLATE = '- raise NotImplementedError'
17
+
18
+ def test_option_help
19
+ out, err = exec_slimrb '--help'
20
+
21
+ assert err.empty?
22
+ assert_match %r{Show this message}, out
23
+ end
24
+
25
+ def test_option_version
26
+ out, err = exec_slimrb '--version'
27
+
28
+ assert err.empty?
29
+ assert_match %r{\ASlim #{Regexp.escape Slim::VERSION}$}, out
30
+ end
31
+
32
+ def test_render
33
+ prepare_common_test STATIC_TEMPLATE do |out, err|
34
+ assert err.empty?
35
+ assert_equal "<p>Hello World!</p>\n", out
36
+ end
37
+ end
38
+
39
+ # superficial test, we don't want to test Tilt/Temple
40
+ def test_compile
41
+ prepare_common_test STATIC_TEMPLATE, '--compile' do |out, err|
42
+ assert err.empty?
43
+ assert_match %r{\"<p>Hello World!<\/p>\".freeze}, out
44
+ end
45
+ end
46
+
47
+ def test_erb
48
+ prepare_common_test DYNAMIC_TEMPLATE, '--erb' do |out, err|
49
+ assert err.empty?
50
+ assert_equal "<p>Hello <%= ::Temple::Utils.escape_html((name)) %>!</p>\n", out
51
+ end
52
+ end
53
+
54
+ def test_rails
55
+ prepare_common_test DYNAMIC_TEMPLATE, '--rails' do |out, err|
56
+ assert err.empty?
57
+
58
+ if Gem::Version.new(Temple::VERSION) >= Gem::Version.new('0.9')
59
+ assert out.include? %Q{@output_buffer = output_buffer || ActionView::OutputBuffer.new;}
60
+ else
61
+ assert out.include? %Q{@output_buffer = ActiveSupport::SafeBuffer.new;}
62
+ end
63
+ assert out.include? %Q{@output_buffer.safe_concat(("<p>Hello ".freeze));}
64
+ assert out.include? %Q{@output_buffer.safe_concat(((::Temple::Utils.escape_html((name))).to_s));}
65
+ assert out.include? %Q{@output_buffer.safe_concat(("!</p>".freeze));}
66
+ end
67
+ end
68
+
69
+ def test_pretty
70
+ prepare_common_test LONG_TEMPLATE, '--pretty' do |out, err|
71
+ assert err.empty?
72
+ assert_equal "<h1>\n Hello\n</h1>\n<p>\n World!<small>Tiny text</small>\n</p>\n", out
73
+ end
74
+ end
75
+
76
+ def test_locals_json
77
+ data = '{"name":"from slim"}'
78
+ prepare_common_test DYNAMIC_TEMPLATE, '--locals', data do |out, err|
79
+ assert err.empty?
80
+ assert_equal "<p>Hello from slim!</p>\n", out
81
+ end
82
+ end
83
+
84
+ def test_locals_yaml
85
+ data = "name: from slim"
86
+ prepare_common_test DYNAMIC_TEMPLATE, '--locals', data do |out, err|
87
+ assert err.empty?
88
+ assert_equal "<p>Hello from slim!</p>\n", out
89
+ end
90
+ end
91
+
92
+ def test_locals_hash
93
+ data = '{name:"from slim"}'
94
+ prepare_common_test DYNAMIC_TEMPLATE, '--locals', data do |out, err|
95
+ assert err.empty?
96
+ assert_equal "<p>Hello from slim!</p>\n", out
97
+ end
98
+ end
99
+
100
+ def test_require
101
+ with_tempfile 'puts "Not in slim"', 'rb' do |lib|
102
+ prepare_common_test STATIC_TEMPLATE, '--require', lib, stdin_file: false, file_file: false do |out, err|
103
+ assert err.empty?
104
+ assert_equal "Not in slim\n<p>Hello World!</p>\n", out
105
+ end
106
+ end
107
+ end
108
+
109
+ def test_error
110
+ prepare_common_test EXCEPTION_TEMPLATE, stdin_file: false do |out, err|
111
+ assert out.empty?
112
+ assert_match %r{NotImplementedError: NotImplementedError}, err
113
+ assert_match %r{Use --trace for backtrace}, err
114
+ end
115
+ end
116
+
117
+ def test_trace_error
118
+ prepare_common_test EXCEPTION_TEMPLATE, '--trace', stdin_file: false do |out, err|
119
+ assert out.empty?
120
+ assert_match %r{bin\/slimrb}, err
121
+ end
122
+ end
123
+
124
+ private
125
+
126
+ # Whether you call slimrb with a file argument or pass the slim content
127
+ # via $stdin; whether you want the output written to $stdout or into
128
+ # another file given as argument, the output is the same.
129
+ #
130
+ # This method prepares a test with this exact behaviour:
131
+ #
132
+ # It yields the tupel (out, err) once after the `content` was passed
133
+ # in via $stdin and once it was passed as a (temporary) file argument.
134
+ #
135
+ # In effect, this method executes a test (given as block) 4 times:
136
+ #
137
+ # 1. read from $stdin, write to $stdout
138
+ # 2. read from file, write to $stdout
139
+ # 3. read from $stdin, write to file
140
+ # 4. read from file, write to file
141
+ def prepare_common_test(content, *args)
142
+ options = Hash === args.last ? args.pop : {}
143
+
144
+ # case 1. $stdin → $stdout
145
+ unless options[:stdin_stdout] == false
146
+ out, err = exec_slimrb(*args, '--stdin') do |i|
147
+ i.write content
148
+ end
149
+ yield out, err
150
+ end
151
+
152
+ # case 2. file → $stdout
153
+ unless options[:file_stdout] == false
154
+ with_tempfile content do |in_file|
155
+ out, err = exec_slimrb(*args, in_file)
156
+ yield out, err
157
+ end
158
+ end
159
+
160
+ # case 3. $stdin → file
161
+ unless options[:stdin_file] == false
162
+ with_tempfile content do |out_file|
163
+ _, err = exec_slimrb(*args, '--stdin', out_file) do |i|
164
+ i.write content
165
+ end
166
+ yield File.read(out_file), err
167
+ end
168
+ end
169
+
170
+ # case 3. file → file
171
+ unless options[:file_file] == false
172
+ with_tempfile '' do |out_file|
173
+ with_tempfile content do |in_file|
174
+ _, err = exec_slimrb(*args, in_file, out_file) do |i|
175
+ i.write content
176
+ end
177
+ yield File.read(out_file), err
178
+ end
179
+ end
180
+ end
181
+ end
182
+
183
+ # Calls bin/slimrb as a subprocess.
184
+ #
185
+ # Yields $stdin to the caller and returns a tupel (out,err) with the
186
+ # contents of $stdout and $stderr.
187
+ #
188
+ # (I'd like to use Minitest::Assertions#capture_subprecess_io here,
189
+ # but then there's no way to insert data via $stdin.)
190
+ def exec_slimrb(*args)
191
+ out, err = nil, nil
192
+
193
+ Open3.popen3 'ruby', 'bin/slimrb', *args do |i,o,e,t|
194
+ yield i if block_given?
195
+ i.close
196
+ out, err = o.read, e.read
197
+ end
198
+
199
+ return out, err
200
+ end
201
+
202
+ # Creates a temporary file with the given content and yield the path
203
+ # to this file. The file itself is only available inside the block and
204
+ # will be deleted afterwards.
205
+ def with_tempfile(content=nil, extname='slim')
206
+ f = Tempfile.new ['slim', ".#{extname}"]
207
+ if content
208
+ f.write content
209
+ f.flush # ensure content is actually saved to disk
210
+ f.rewind
211
+ end
212
+
213
+ yield f.path
214
+ ensure
215
+ f.close
216
+ f.unlink
217
+ end
218
+
219
+ end
@@ -0,0 +1,247 @@
1
+ require 'helper'
2
+ require 'erb'
3
+
4
+ class TestSlimEmbeddedEngines < TestSlim
5
+
6
+ def test_render_with_markdown
7
+ source = %q{
8
+ markdown:
9
+ #Header
10
+ Hello from #{"Markdown!"}
11
+
12
+ #{1+2}
13
+
14
+ [#{1}](#{"#2"})
15
+
16
+ * one
17
+ * two
18
+ }
19
+ if ::Tilt['md'].name =~ /Redcarpet/
20
+ # redcarpet
21
+ assert_html "<h1>Header</h1>\n\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<p><a href=\"#2\">1</a></p>\n\n<ul>\n<li>one</li>\n<li>two</li>\n</ul>\n", source
22
+ elsif ::Tilt['md'].name =~ /RDiscount/
23
+ # rdiscount
24
+ assert_html "<h1>Header</h1>\n\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<p><a href=\"#2\">1</a></p>\n\n<ul>\n<li>one</li>\n<li>two</li>\n</ul>\n\n", source
25
+ else
26
+ # kramdown, :auto_ids by default
27
+ assert_html "<h1 id=\"header\">Header</h1>\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<p><a href=\"#2\">1</a></p>\n\n<ul>\n <li>one</li>\n <li>two</li>\n</ul>\n", source
28
+
29
+ Slim::Embedded.with_options(markdown: {auto_ids: false}) do
30
+ assert_html "<h1>Header</h1>\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<p><a href=\"#2\">1</a></p>\n\n<ul>\n <li>one</li>\n <li>two</li>\n</ul>\n", source
31
+ end
32
+
33
+ assert_html "<h1 id=\"header\">Header</h1>\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<p><a href=\"#2\">1</a></p>\n\n<ul>\n <li>one</li>\n <li>two</li>\n</ul>\n", source
34
+ end
35
+ end
36
+
37
+ def test_render_with_css
38
+ source = %q{
39
+ css:
40
+ h1 { color: blue }
41
+ }
42
+ assert_html "<style>h1 { color: blue }</style>", source
43
+ end
44
+
45
+ def test_render_with_css_empty_attributes
46
+ source = %q{
47
+ css []:
48
+ h1 { color: blue }
49
+ }
50
+ assert_html "<style>h1 { color: blue }</style>", source
51
+ end
52
+
53
+ def test_render_with_css_attribute
54
+ source = %q{
55
+ css scoped = "true":
56
+ h1 { color: blue }
57
+ }
58
+ assert_html "<style scoped=\"true\">h1 { color: blue }</style>", source
59
+ end
60
+
61
+ def test_render_with_css_multiple_attributes
62
+ source = %q{
63
+ css class="myClass" scoped = "true" :
64
+ h1 { color: blue }
65
+ }
66
+ assert_html "<style class=\"myClass\" scoped=\"true\">h1 { color: blue }</style>", source
67
+ end
68
+
69
+ def test_render_with_javascript
70
+ source = %q{
71
+ javascript:
72
+ $(function() {});
73
+
74
+
75
+ alert('hello')
76
+ p Hi
77
+ }
78
+ assert_html %{<script>$(function() {});\n\n\nalert('hello')</script><p>Hi</p>}, source
79
+ end
80
+
81
+ def test_render_with_javascript_empty_attributes
82
+ source = %q{
83
+ javascript ():
84
+ alert('hello')
85
+ }
86
+ assert_html %{<script>alert('hello')</script>}, source
87
+ end
88
+
89
+ def test_render_with_javascript_attribute
90
+ source = %q{
91
+ javascript [class = "myClass"]:
92
+ alert('hello')
93
+ }
94
+ assert_html %{<script class=\"myClass\">alert('hello')</script>}, source
95
+ end
96
+
97
+ def test_render_with_javascript_multiple_attributes
98
+ source = %q{
99
+ javascript { class = "myClass" id="myId" other-attribute = 'my_other_attribute' } :
100
+ alert('hello')
101
+ }
102
+ assert_html %{<script class=\"myClass\" id=\"myId\" other-attribute=\"my_other_attribute\">alert('hello')</script>}, source
103
+ end
104
+
105
+ def test_render_with_javascript_with_tabs
106
+ source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi"
107
+ assert_html "<script>$(function() {});\nalert('hello')</script><p>Hi</p>", source
108
+ end
109
+
110
+ def test_render_with_javascript_including_variable
111
+ source = %q{
112
+ - func = "alert('hello');"
113
+ javascript:
114
+ $(function() { #{func} });
115
+ }
116
+ assert_html %q|<script>$(function() { alert(&#39;hello&#39;); });</script>|, source
117
+ end
118
+
119
+ def test_render_with_javascript_with_explicit_html_comment
120
+ Slim::Engine.with_options(js_wrapper: :comment) do
121
+ source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi"
122
+ assert_html "<script><!--\n$(function() {});\nalert('hello')\n//--></script><p>Hi</p>", source
123
+ end
124
+ end
125
+
126
+ def test_render_with_javascript_with_explicit_cdata_comment
127
+ Slim::Engine.with_options(js_wrapper: :cdata) do
128
+ source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi"
129
+ assert_html "<script>\n//<![CDATA[\n$(function() {});\nalert('hello')\n//]]>\n</script><p>Hi</p>", source
130
+ end
131
+ end
132
+
133
+ def test_render_with_javascript_with_format_xhtml_comment
134
+ Slim::Engine.with_options(js_wrapper: :guess, format: :xhtml) do
135
+ source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi"
136
+ assert_html "<script>\n//<![CDATA[\n$(function() {});\nalert('hello')\n//]]>\n</script><p>Hi</p>", source
137
+ end
138
+ end
139
+
140
+ def test_render_with_javascript_with_format_html_comment
141
+ Slim::Engine.with_options(js_wrapper: :guess, format: :html) do
142
+ source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi"
143
+ assert_html "<script><!--\n$(function() {});\nalert('hello')\n//--></script><p>Hi</p>", source
144
+ end
145
+ end
146
+
147
+ def test_render_with_ruby
148
+ source = %q{
149
+ ruby:
150
+ variable = 1 +
151
+ 2
152
+ = variable
153
+ }
154
+ assert_html '3', source
155
+ end
156
+
157
+ def test_render_with_ruby_heredoc
158
+ source = %q{
159
+ ruby:
160
+ variable = <<-MSG
161
+ foobar
162
+ MSG
163
+ = variable
164
+ }
165
+ assert_html "foobar\n", source
166
+ end
167
+
168
+ # TODO: Reactivate sass tests
169
+ if false
170
+ def test_render_with_scss
171
+ source = %q{
172
+ scss:
173
+ $color: #f00;
174
+ body { color: $color; }
175
+ }
176
+ assert_html "<style>body{color:red}</style>", source
177
+ end
178
+
179
+ def test_render_with_scss_attribute
180
+ source = %q{
181
+ scss [class="myClass"]:
182
+ $color: #f00;
183
+ body { color: $color; }
184
+ }
185
+ assert_html "<style class=\"myClass\">body{color:red}</style>", source
186
+ end
187
+
188
+ def test_render_with_sass
189
+ source = %q{
190
+ sass:
191
+ $color: #f00
192
+ body
193
+ color: $color
194
+ }
195
+ assert_html "<style>body{color:red}</style>", source
196
+ end
197
+
198
+ def test_render_with_sass_attribute
199
+ source = %q{
200
+ sass [class="myClass"]:
201
+ $color: #f00
202
+ body
203
+ color: $color
204
+ }
205
+ assert_html "<style class=\"myClass\">body{color:red}</style>", source
206
+ end
207
+ end
208
+
209
+ def test_disabled_embedded_engine
210
+ source = %{
211
+ ruby:
212
+ Embedded Ruby
213
+ }
214
+ assert_runtime_error 'Embedded engine ruby is disabled', source, enable_engines: [:javascript]
215
+ assert_runtime_error 'Embedded engine ruby is disabled', source, enable_engines: %w(javascript)
216
+
217
+ source = %{
218
+ ruby:
219
+ Embedded Ruby
220
+ }
221
+ assert_runtime_error 'Embedded engine ruby is disabled', source, enable_engines: [:javascript]
222
+ assert_runtime_error 'Embedded engine ruby is disabled', source, enable_engines: %w(javascript)
223
+
224
+ source = %{
225
+ ruby:
226
+ Embedded Ruby
227
+ }
228
+ assert_runtime_error 'Embedded engine ruby is disabled', source, disable_engines: [:ruby]
229
+ assert_runtime_error 'Embedded engine ruby is disabled', source, disable_engines: %w(ruby)
230
+ end
231
+
232
+ def test_enabled_embedded_engine
233
+ source = %q{
234
+ javascript:
235
+ $(function() {});
236
+ }
237
+ assert_html '<script>$(function() {});</script>', source, disable_engines: [:ruby]
238
+ assert_html '<script>$(function() {});</script>', source, disable_engines: %w(ruby)
239
+
240
+ source = %q{
241
+ javascript:
242
+ $(function() {});
243
+ }
244
+ assert_html '<script>$(function() {});</script>', source, enable_engines: [:javascript]
245
+ assert_html '<script>$(function() {});</script>', source, enable_engines: %w(javascript)
246
+ end
247
+ end
@@ -0,0 +1,28 @@
1
+ require 'helper'
2
+
3
+ class TestSlimEncoding < TestSlim
4
+ def test_windows_crlf
5
+ source = "a href='#' something\r\nbr\r\na href='#' others\r\n"
6
+ result = "<a href=\"#\">something</a><br /><a href=\"#\">others</a>"
7
+ assert_html result, source
8
+ end
9
+
10
+ def test_binary
11
+ source = "| \xFF\xFF".dup
12
+ source.force_encoding(Encoding::BINARY)
13
+
14
+ result = "\xFF\xFF".dup
15
+ result.force_encoding(Encoding::BINARY)
16
+
17
+ out = render(source, default_encoding: 'binary')
18
+ out.force_encoding(Encoding::BINARY)
19
+
20
+ assert_equal result, out
21
+ end
22
+
23
+ def test_bom
24
+ source = "\xEF\xBB\xBFh1 Hello World!"
25
+ result = '<h1>Hello World!</h1>'
26
+ assert_html result, source
27
+ end
28
+ end
@@ -0,0 +1,65 @@
1
+ require 'helper'
2
+ require 'slim/erb_converter'
3
+
4
+ class TestSlimERBConverter < TestSlim
5
+ def test_converter
6
+ source = %q{
7
+ doctype 5
8
+ html
9
+ head
10
+ title Hello World!
11
+ /! Meta tags
12
+ with long explanatory
13
+ multiline comment
14
+ meta name="description" content="template language"
15
+ /! Stylesheets
16
+ link href="style.css" media="screen" rel="stylesheet" type="text/css"
17
+ link href="colors.css" media="screen" rel="stylesheet" type="text/css"
18
+ /! Javascripts
19
+ script src="jquery.js"
20
+ script src="jquery.ui.js"
21
+ /[if lt IE 9]
22
+ script src="old-ie1.js"
23
+ script src="old-ie2.js"
24
+ css:
25
+ body { background-color: red; }
26
+ body
27
+ #container
28
+ p Hello
29
+ World!
30
+ p= "dynamic text with\nnewline"
31
+ }
32
+
33
+ result = %q{
34
+ <!DOCTYPE html>
35
+ <html>
36
+ <head>
37
+ <title>Hello World!</title>
38
+ <!--Meta tags
39
+
40
+ with long explanatory
41
+
42
+ multiline comment-->
43
+ <meta content="template language" name="description" />
44
+ <!--Stylesheets-->
45
+ <link href="style.css" media="screen" rel="stylesheet" type="text/css" />
46
+ <link href="colors.css" media="screen" rel="stylesheet" type="text/css" />
47
+ <!--Javascripts-->
48
+ <script src="jquery.js">
49
+ </script><script src="jquery.ui.js">
50
+ </script><!--[if lt IE 9]>
51
+ <script src="old-ie1.js">
52
+ </script><script src="old-ie2.js">
53
+ </script><![endif]--><style>
54
+ body { background-color: red; }</style>
55
+ </head><body>
56
+ <div id="container">
57
+ <p>Hello
58
+
59
+ World!</p>
60
+ <p><%= ::Temple::Utils.escape_html(("dynamic text with\nnewline")) %>
61
+ </p></div></body></html>}
62
+
63
+ assert_equal result, Slim::ERBConverter.new.call(source)
64
+ end
65
+ end