Sha256: c4be164c04bb1ba719a94f7c601f7dd1df4f760894b5d531e1ec8919fa554bd4

Contents?: true

Size: 1.75 KB

Versions: 8

Compression:

Stored size: 1.75 KB

Contents

require 'ostruct'
require 'helper'
require 'test/unit'
require 'webgen/tree'
require 'webgen/page'
require 'webgen/contentprocessor'

class TestContentProcessorErubis < Test::Unit::TestCase

  include Test::WebsiteHelper

  def test_call
    obj = Webgen::ContentProcessor::Erubis.new
    root = Webgen::Node.new(Webgen::Tree.new.dummy_root, '/', '/')
    node = Webgen::Node.new(root, 'test', 'test')
    context = Webgen::ContentProcessor::Context.new(:doit => 'hallo', :chain => [node])

    context.content = '<%= context[:doit] %>6'
    assert_equal('hallo6', obj.call(context).content)

    context.content = '<%= 5* %>'
    assert_raise(RuntimeError) { obj.call(context) }

    context.content = "<% for i in [1] %>\n<%= i %>\n<% end %>"
    assert_equal("1\n", obj.call(context).content)
    @website.config['contentprocessor.erubis.options'][:trim] = false
    context.content = "<% for i in [1] %>\n<%== i %>\n<% end %>"
    assert_equal("\n1\n", obj.call(context).content)

    context[:block] = OpenStruct.new
    context[:block].options = {'erubis_trim' => true}
    context.content = "<% for i in [1] %>\n<%== i %>\n<% end %>"
    assert_equal("1\n", obj.call(context).content)
    context[:block].options['erubis_use_pi'] = true
    context.content = "<?rb for i in [1] ?>\n@{i}@\n<?rb end ?>"
    assert_equal("1\n", obj.call(context).content)
    context[:block] = nil

    @website.config['contentprocessor.erubis.use_pi'] = true
    context.content = "<?rb for i in [1] ?>\n@{i}@\n<?rb end ?>"
    assert_equal("1\n", obj.call(context).content)

    page = Webgen::Page.from_data("--- pipeline:erubis erubis_trim:false erubis_use_pi:false\n<% for i in [1] %>\n<%== i %>\n<% end %>")
    assert_equal("\n1\n", page.blocks['content'].render(context).content)
  end

end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
gettalong-webgen-0.5.4.20080929 test/test_contentprocessor_erubis.rb
gettalong-webgen-0.5.5.20081001 test/test_contentprocessor_erubis.rb
gettalong-webgen-0.5.5.20081010 test/test_contentprocessor_erubis.rb
gettalong-webgen-0.5.5.20081012 test/test_contentprocessor_erubis.rb
gettalong-webgen-0.5.6.20081020 test/test_contentprocessor_erubis.rb
webgen-0.5.4 test/test_contentprocessor_erubis.rb
webgen-0.5.6 test/test_contentprocessor_erubis.rb
webgen-0.5.5 test/test_contentprocessor_erubis.rb