super-pro-kit 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/slim-5.2.1/CHANGES +496 -0
  3. data/slim-5.2.1/Gemfile +43 -0
  4. data/slim-5.2.1/LICENSE +21 -0
  5. data/slim-5.2.1/README.jp.md +1276 -0
  6. data/slim-5.2.1/README.md +1313 -0
  7. data/slim-5.2.1/Rakefile +80 -0
  8. data/slim-5.2.1/bin/slimrb +6 -0
  9. data/slim-5.2.1/doc/include.md +20 -0
  10. data/slim-5.2.1/doc/jp/include.md +20 -0
  11. data/slim-5.2.1/doc/jp/logic_less.md +137 -0
  12. data/slim-5.2.1/doc/jp/smart.md +102 -0
  13. data/slim-5.2.1/doc/jp/translator.md +28 -0
  14. data/slim-5.2.1/doc/logic_less.md +137 -0
  15. data/slim-5.2.1/doc/smart.md +120 -0
  16. data/slim-5.2.1/doc/translator.md +28 -0
  17. data/slim-5.2.1/lib/slim/code_attributes.rb +68 -0
  18. data/slim-5.2.1/lib/slim/command.rb +122 -0
  19. data/slim-5.2.1/lib/slim/controls.rb +61 -0
  20. data/slim-5.2.1/lib/slim/do_inserter.rb +34 -0
  21. data/slim-5.2.1/lib/slim/embedded.rb +248 -0
  22. data/slim-5.2.1/lib/slim/end_inserter.rb +63 -0
  23. data/slim-5.2.1/lib/slim/engine.rb +42 -0
  24. data/slim-5.2.1/lib/slim/erb_converter.rb +15 -0
  25. data/slim-5.2.1/lib/slim/filter.rb +31 -0
  26. data/slim-5.2.1/lib/slim/grammar.rb +24 -0
  27. data/slim-5.2.1/lib/slim/include.rb +58 -0
  28. data/slim-5.2.1/lib/slim/interpolation.rb +36 -0
  29. data/slim-5.2.1/lib/slim/logic_less/context.rb +126 -0
  30. data/slim-5.2.1/lib/slim/logic_less/filter.rb +81 -0
  31. data/slim-5.2.1/lib/slim/logic_less.rb +6 -0
  32. data/slim-5.2.1/lib/slim/parser.rb +535 -0
  33. data/slim-5.2.1/lib/slim/railtie.rb +19 -0
  34. data/slim-5.2.1/lib/slim/smart/escaper.rb +42 -0
  35. data/slim-5.2.1/lib/slim/smart/filter.rb +97 -0
  36. data/slim-5.2.1/lib/slim/smart/parser.rb +35 -0
  37. data/slim-5.2.1/lib/slim/smart.rb +9 -0
  38. data/slim-5.2.1/lib/slim/splat/builder.rb +115 -0
  39. data/slim-5.2.1/lib/slim/splat/filter.rb +93 -0
  40. data/slim-5.2.1/lib/slim/template.rb +6 -0
  41. data/slim-5.2.1/lib/slim/translator.rb +119 -0
  42. data/slim-5.2.1/lib/slim/version.rb +6 -0
  43. data/slim-5.2.1/lib/slim.rb +16 -0
  44. data/slim-5.2.1/slim.gemspec +33 -0
  45. data/slim-5.2.1/test/core/helper.rb +201 -0
  46. data/slim-5.2.1/test/core/test_code_blocks.rb +194 -0
  47. data/slim-5.2.1/test/core/test_code_escaping.rb +162 -0
  48. data/slim-5.2.1/test/core/test_code_evaluation.rb +181 -0
  49. data/slim-5.2.1/test/core/test_code_output.rb +168 -0
  50. data/slim-5.2.1/test/core/test_code_structure.rb +203 -0
  51. data/slim-5.2.1/test/core/test_commands.rb +219 -0
  52. data/slim-5.2.1/test/core/test_embedded_engines.rb +247 -0
  53. data/slim-5.2.1/test/core/test_encoding.rb +28 -0
  54. data/slim-5.2.1/test/core/test_erb_converter.rb +65 -0
  55. data/slim-5.2.1/test/core/test_html_attributes.rb +276 -0
  56. data/slim-5.2.1/test/core/test_html_escaping.rb +65 -0
  57. data/slim-5.2.1/test/core/test_html_structure.rb +599 -0
  58. data/slim-5.2.1/test/core/test_parser_errors.rb +148 -0
  59. data/slim-5.2.1/test/core/test_pretty.rb +163 -0
  60. data/slim-5.2.1/test/core/test_ruby_errors.rb +200 -0
  61. data/slim-5.2.1/test/core/test_slim_template.rb +78 -0
  62. data/slim-5.2.1/test/core/test_splat_prefix_option.rb +155 -0
  63. data/slim-5.2.1/test/core/test_tabs.rb +169 -0
  64. data/slim-5.2.1/test/core/test_text_interpolation.rb +79 -0
  65. data/slim-5.2.1/test/core/test_thread_options.rb +18 -0
  66. data/slim-5.2.1/test/core/test_unicode.rb +15 -0
  67. data/slim-5.2.1/test/include/files/recursive.slim +1 -0
  68. data/slim-5.2.1/test/include/files/slimfile.slim +3 -0
  69. data/slim-5.2.1/test/include/files/subdir/test.slim +1 -0
  70. data/slim-5.2.1/test/include/files/textfile +1 -0
  71. data/slim-5.2.1/test/include/test_include.rb +24 -0
  72. data/slim-5.2.1/test/literate/TESTS.md +1323 -0
  73. data/slim-5.2.1/test/literate/helper.rb +15 -0
  74. data/slim-5.2.1/test/literate/run.rb +92 -0
  75. data/slim-5.2.1/test/logic_less/test_logic_less.rb +330 -0
  76. data/slim-5.2.1/test/rails/Rakefile +7 -0
  77. data/slim-5.2.1/test/rails/app/assets/config/manifest.js +1 -0
  78. data/slim-5.2.1/test/rails/app/controllers/application_controller.rb +2 -0
  79. data/slim-5.2.1/test/rails/app/controllers/entries_controller.rb +5 -0
  80. data/slim-5.2.1/test/rails/app/controllers/slim_controller.rb +46 -0
  81. data/slim-5.2.1/test/rails/app/helpers/application_helper.rb +5 -0
  82. data/slim-5.2.1/test/rails/app/models/entry.rb +16 -0
  83. data/slim-5.2.1/test/rails/app/views/entries/edit.html.slim +3 -0
  84. data/slim-5.2.1/test/rails/app/views/layouts/application.html+testvariant.slim +10 -0
  85. data/slim-5.2.1/test/rails/app/views/layouts/application.html.slim +10 -0
  86. data/slim-5.2.1/test/rails/app/views/slim/_partial.html.slim +1 -0
  87. data/slim-5.2.1/test/rails/app/views/slim/attributes.html.slim +3 -0
  88. data/slim-5.2.1/test/rails/app/views/slim/content_for.html.slim +7 -0
  89. data/slim-5.2.1/test/rails/app/views/slim/erb.html.erb +1 -0
  90. data/slim-5.2.1/test/rails/app/views/slim/form_for.html.slim +2 -0
  91. data/slim-5.2.1/test/rails/app/views/slim/helper.html.slim +4 -0
  92. data/slim-5.2.1/test/rails/app/views/slim/integers.html.slim +1 -0
  93. data/slim-5.2.1/test/rails/app/views/slim/no_layout.html.slim +1 -0
  94. data/slim-5.2.1/test/rails/app/views/slim/normal.html.slim +1 -0
  95. data/slim-5.2.1/test/rails/app/views/slim/partial.html.slim +2 -0
  96. data/slim-5.2.1/test/rails/app/views/slim/splat.html.slim +2 -0
  97. data/slim-5.2.1/test/rails/app/views/slim/splat_with_delimiter.slim +1 -0
  98. data/slim-5.2.1/test/rails/app/views/slim/thread_options.html.slim +1 -0
  99. data/slim-5.2.1/test/rails/app/views/slim/variables.html.slim +1 -0
  100. data/slim-5.2.1/test/rails/app/views/slim/xml.slim +1 -0
  101. data/slim-5.2.1/test/rails/config/application.rb +44 -0
  102. data/slim-5.2.1/test/rails/config/boot.rb +10 -0
  103. data/slim-5.2.1/test/rails/config/environment.rb +5 -0
  104. data/slim-5.2.1/test/rails/config/environments/test.rb +34 -0
  105. data/slim-5.2.1/test/rails/config/initializers/backtrace_silencers.rb +7 -0
  106. data/slim-5.2.1/test/rails/config/initializers/inflections.rb +10 -0
  107. data/slim-5.2.1/test/rails/config/initializers/mime_types.rb +5 -0
  108. data/slim-5.2.1/test/rails/config/initializers/session_store.rb +8 -0
  109. data/slim-5.2.1/test/rails/config/locales/en.yml +5 -0
  110. data/slim-5.2.1/test/rails/config/routes.rb +60 -0
  111. data/slim-5.2.1/test/rails/config.ru +4 -0
  112. data/slim-5.2.1/test/rails/script/rails +6 -0
  113. data/slim-5.2.1/test/rails/test/helper.rb +34 -0
  114. data/slim-5.2.1/test/rails/test/test_slim.rb +102 -0
  115. data/slim-5.2.1/test/sinatra/contest.rb +91 -0
  116. data/slim-5.2.1/test/sinatra/helper.rb +143 -0
  117. data/slim-5.2.1/test/sinatra/test_core.rb +91 -0
  118. data/slim-5.2.1/test/sinatra/test_include.rb +16 -0
  119. data/slim-5.2.1/test/sinatra/views/embed_include_js.slim +8 -0
  120. data/slim-5.2.1/test/sinatra/views/embed_js.slim +11 -0
  121. data/slim-5.2.1/test/sinatra/views/footer.slim +1 -0
  122. data/slim-5.2.1/test/sinatra/views/hello.slim +1 -0
  123. data/slim-5.2.1/test/sinatra/views/layout2.slim +3 -0
  124. data/slim-5.2.1/test/smart/test_smart_text.rb +294 -0
  125. data/slim-5.2.1/test/translator/test_translator.rb +76 -0
  126. data/super-pro-kit.gemspec +11 -0
  127. metadata +165 -0
@@ -0,0 +1,203 @@
1
+ require 'helper'
2
+
3
+ class TestSlimCodeStructure < TestSlim
4
+ def test_render_with_conditional
5
+ source = %q{
6
+ div
7
+ - if show_first?
8
+ p The first paragraph
9
+ - else
10
+ p The second paragraph
11
+ }
12
+
13
+ assert_html '<div><p>The second paragraph</p></div>', source
14
+ end
15
+
16
+ def test_render_with_begin
17
+ source = %q{
18
+ - if true
19
+ - begin
20
+ p A
21
+ - if true
22
+ - begin
23
+ p B
24
+ - if true
25
+ - begin
26
+ p C
27
+ - rescue
28
+ p D
29
+ }
30
+
31
+ assert_html '<p>A</p><p>B</p><p>C</p>', source
32
+ end
33
+
34
+ def test_render_with_consecutive_conditionals
35
+ source = %q{
36
+ div
37
+ - if show_first? true
38
+ p The first paragraph
39
+ - if show_first? true
40
+ p The second paragraph
41
+ }
42
+
43
+ assert_html '<div><p>The first paragraph</p><p>The second paragraph</p></div>', source
44
+ end
45
+
46
+ def test_render_with_parameterized_conditional
47
+ source = %q{
48
+ div
49
+ - if show_first? false
50
+ p The first paragraph
51
+ - else
52
+ p The second paragraph
53
+ }
54
+
55
+ assert_html '<div><p>The second paragraph</p></div>', source
56
+ end
57
+
58
+ def test_render_with_when_string_in_condition
59
+ source = %q{
60
+ - if true
61
+ | Hello
62
+
63
+ - unless 'when' == nil
64
+ | world
65
+ }
66
+
67
+ assert_html 'Hello world', source
68
+ end
69
+
70
+ def test_render_with_conditional_and_following_nonconditonal
71
+ source = %q{
72
+ div
73
+ - if true
74
+ p The first paragraph
75
+ - var = 42
76
+ = var
77
+ }
78
+
79
+ assert_html '<div><p>The first paragraph</p>42</div>', source
80
+ end
81
+
82
+ def test_render_with_inline_condition
83
+ source = %q{
84
+ p = hello_world if true
85
+ }
86
+
87
+ assert_html '<p>Hello World from @env</p>', source
88
+ end
89
+
90
+ def test_render_with_case
91
+ source = %q{
92
+ p
93
+ - case 42
94
+ - when 41
95
+ | 41
96
+ - when 42
97
+ | 42
98
+ | is the answer
99
+ p
100
+ - case 41
101
+ - when 41
102
+ | 41
103
+ - when 42
104
+ | 42
105
+ | is the answer
106
+ p
107
+ - case 42 when 41
108
+ | 41
109
+ - when 42
110
+ | 42
111
+ | is the answer
112
+ p
113
+ - case 41 when 41
114
+ | 41
115
+ - when 42
116
+ | 42
117
+ | is the answer
118
+ }
119
+
120
+ assert_html '<p>42 is the answer</p><p>41 is the answer</p><p>42 is the answer</p><p>41 is the answer</p>', source
121
+ end
122
+
123
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.7")
124
+ def test_render_with_case_in
125
+ source = %q{
126
+ p
127
+ - case [:greet, "world"]
128
+ - in :greet, value if false
129
+ = "Goodbye #{value}"
130
+ - in :greet, value unless true
131
+ = "Top of the morning to you, #{value}"
132
+ - in :greet, value
133
+ = "Hello #{value}"
134
+ }
135
+
136
+ assert_html '<p>Hello world</p>', source
137
+ end
138
+ end
139
+
140
+ def test_render_with_slim_comments
141
+ source = %q{
142
+ p Hello
143
+ / This is a comment
144
+ Another comment
145
+ p World
146
+ }
147
+
148
+ assert_html '<p>Hello</p><p>World</p>', source
149
+ end
150
+
151
+ def test_render_with_yield
152
+ source = %q{
153
+ div
154
+ == yield :menu
155
+ }
156
+
157
+ assert_html '<div>This is the menu</div>', source do
158
+ 'This is the menu'
159
+ end
160
+ end
161
+
162
+ def test_render_with_begin_rescue
163
+ source = %q{
164
+ - begin
165
+ p Begin
166
+ - rescue
167
+ p Rescue
168
+ p After
169
+ }
170
+
171
+ assert_html '<p>Begin</p><p>After</p>', source
172
+ end
173
+
174
+ def test_render_with_begin_rescue_exception
175
+ source = %q{
176
+ - begin
177
+ p Begin
178
+ - raise 'Boom'
179
+ p After Boom
180
+ - rescue => ex
181
+ p = ex.message
182
+ p After
183
+ }
184
+
185
+ assert_html '<p>Begin</p><p>Boom</p><p>After</p>', source
186
+ end
187
+
188
+ def test_render_with_begin_rescue_ensure
189
+ source = %q{
190
+ - begin
191
+ p Begin
192
+ - raise 'Boom'
193
+ p After Boom
194
+ - rescue => ex
195
+ p = ex.message
196
+ - ensure
197
+ p Ensure
198
+ p After
199
+ }
200
+
201
+ assert_html '<p>Begin</p><p>Boom</p><p>Ensure</p><p>After</p>', source
202
+ end
203
+ end
@@ -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