require 'helper' require 'slim/translator' class TestSlimTranslator < TestSlim def setup super Slim::Engine.set_default_options :tr => true, :tr_fn => 'TestSlimTranslator.tr' end def self.tr(s) s.upcase end def self.tr_reverse(s) s.reverse.gsub(/(\d+)%/, '%\1') end def test_no_translation_of_embedded source = %q{ markdown: #Header Hello from #{"Markdown!"} #{1+2} * one * two } assert_html "

Header

\n

Hello from Markdown!

\n\n

3

\n\n\n", source, :tr_mode => :dynamic assert_html "

Header

\n

Hello from Markdown!

\n\n

3

\n\n\n", source, :tr_mode => :static end def test_no_translation_of_attrs source = %q{ ' this is a link to a href="link" page } assert_html "THIS IS\nA LINK TO PAGE", source, :tr_mode => :dynamic assert_html "THIS IS\nA LINK TO PAGE", source, :tr_mode => :static end def test_translation_and_interpolation source = %q{ p translate #{hello_world} this second line third #{1+2} line } assert_html "

translate Hello World from @env this\nsecond line\nthird 3 line

", source, :tr => false assert_html "

TRANSLATE Hello World from @env THIS\nSECOND LINE\nTHIRD 3 LINE

", source, :tr_mode => :dynamic assert_html "

TRANSLATE Hello World from @env THIS\nSECOND LINE\nTHIRD 3 LINE

", source, :tr_mode => :static end def test_translation_reverse source = %q{ ' alpha #{1} beta #{2} gamma #{3} } assert_html "3 ammag 2 ateb 1 ahpla ", source, :tr_mode => :dynamic, :tr_fn => 'TestSlimTranslator.tr_reverse' assert_html "3 ammag 2 ateb 1 ahpla ", source, :tr_mode => :static, :tr_fn => 'TestSlimTranslator.tr_reverse' end end