require 'helper' require 'erb' #asciidoctor fail to load it randomly class TestSlimEmbeddedEngines < TestSlim def test_render_with_erb source = %q{ p - text = 'before erb block' erb: Hello from <%= text.upcase %>! Second Line! <% if true %><%= true %><% end %> } assert_html "

Hello from BEFORE ERB BLOCK!\nSecond Line!\ntrue

", source end def test_wip_render_with_asciidoc source = %q{ asciidoc: == Header Hello from #{"AsciiDoc!"} #{1+2} * one * two } output = render(source) assert_match 'sect1', output assert_match 'Hello from AsciiDoc!', output end def test_render_with_markdown source = %q{ markdown: #Header Hello from #{"Markdown!"} #{1+2} * one * two } if ::Tilt['md'].name =~ /Redcarpet/ # redcarpet assert_html "

Header

\n\n

Hello from Markdown!

\n\n

3

\n\n\n", source elsif ::Tilt['md'].name =~ /RDiscount/ # rdiscount assert_html "

Header

\n\n

Hello from Markdown!

\n\n

3

\n\n\n\n", source else # kramdown, :auto_ids by default assert_html "

Header

\n

Hello from Markdown!

\n\n

3

\n\n\n", source Slim::Embedded.with_options(markdown: {auto_ids: false}) do assert_html "

Header

\n

Hello from Markdown!

\n\n

3

\n\n\n", source end assert_html "

Header

\n

Hello from Markdown!

\n\n

3

\n\n\n", source end end def test_render_with_creole source = %q{ creole: = head1 == head2 } assert_html "

head1

head2

", source end def test_render_with_creole_one_line source = %q{ creole: Hello **world**, we can write one-line embedded markup now! = Headline Text .nested: creole: **Strong** } assert_html '

Hello world, we can write one-line embedded markup now!

Headline

Text

Strong

', source end def test_render_with_org # HACK: org-ruby registers itself in Tilt require 'org-ruby' source = %q{ org: * point1 * point2 } assert_html "

point1

\n

point2

\n", source end def test_render_with_builder source = %q{ builder: xml.p(id: 'test') { xml.text!('Hello') } } assert_html "

\nHello

\n", source end def test_render_with_wiki source = %q{ wiki: = head1 == head2 } assert_html "

head1

head2

", source end def test_render_with_javascript # Keep the trailing space behind "javascript: "! source = %q{ javascript: $(function() {}); alert('hello') p Hi } assert_html %{

Hi

}, source end def test_render_with_opal begin # HACK: org-ruby registers itself in Tilt require 'opal' rescue LoadError return end source = %q{ opal: puts 'hello from opal' } assert_match '$puts("hello from opal")', render(source) end def test_render_with_javascript_with_tabs source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi" assert_html "

Hi

", source end def test_render_with_javascript_including_variable # Keep the trailing space behind "javascript: "! source = %q{ - func = "alert('hello');" javascript: $(function() { #{func} }); } assert_html %q||, source end def test_render_with_javascript_with_explicit_html_comment Slim::Engine.with_options(js_wrapper: :comment) do source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi" assert_html "

Hi

", source end end def test_render_with_javascript_with_explicit_cdata_comment Slim::Engine.with_options(js_wrapper: :cdata) do source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi" assert_html "

Hi

", source end end def test_render_with_javascript_with_format_xhtml_comment Slim::Engine.with_options(js_wrapper: :guess, format: :xhtml) do source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi" assert_html "

Hi

", source end end def test_render_with_javascript_with_format_html_comment Slim::Engine.with_options(js_wrapper: :guess, format: :html) do source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi" assert_html "

Hi

", source end end def test_render_with_ruby source = %q{ ruby: variable = 1 + 2 = variable } assert_html '3', source end def test_render_with_scss source = %q{ scss: $color: #f00; body { color: $color; } } assert_html "", source end def test_disabled_embedded_engine source = %{ ruby: Embedded Ruby } assert_runtime_error 'Embedded engine ruby is disabled', source, enable_engines: [:javascript] assert_runtime_error 'Embedded engine ruby is disabled', source, enable_engines: %w(javascript) source = %{ ruby: Embedded Ruby } assert_runtime_error 'Embedded engine ruby is disabled', source, enable_engines: [:javascript] assert_runtime_error 'Embedded engine ruby is disabled', source, enable_engines: %w(javascript) source = %{ ruby: Embedded Ruby } assert_runtime_error 'Embedded engine ruby is disabled', source, disable_engines: [:ruby] assert_runtime_error 'Embedded engine ruby is disabled', source, disable_engines: %w(ruby) end def test_enabled_embedded_engine source = %q{ javascript: $(function() {}); } assert_html '', source, disable_engines: [:ruby] assert_html '', source, disable_engines: %w(ruby) source = %q{ javascript: $(function() {}); } assert_html '', source, enable_engines: [:javascript] assert_html '', source, enable_engines: %w(javascript) end end