Sha256: 838bc7a8e26906677dec1766e4d3bf739003420df73afaa67a1c0da52613bbc6

Contents?: true

Size: 1.99 KB

Versions: 26

Compression:

Stored size: 1.99 KB

Contents

require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))

begin
  require 'tilt/erb'
rescue LoadError
  warn "tilt not installed, skipping named_templates plugin test"  
else
describe "named_templates plugin" do 
  it "adds template method method for naming templates, and have render recognize it" do
    app(:bare) do
      plugin :named_templates

      template :foo do
        @b = 2
        "foo<%= @a %><%= @b %>"
      end
      template :layout, :engine=>:str do
        @c = 3
        'bar#{@a}#{@c}-#{yield}-baz'
      end

      route do |r|
        @a = 1
        view(:foo)
      end
    end

    body.must_equal 'bar13-foo12-baz'
    @app = Class.new(@app)
    body.must_equal 'bar13-foo12-baz'
  end

  it "works when freezing the app" do
    app(:bare) do
      plugin :named_templates

      template :foo do
        @b = 2
        "foo<%= @a %><%= @b %>"
      end
      template :layout, :engine=>:str do
        @c = 3
        'bar#{@a}#{@c}-#{yield}-baz'
      end

      route do |r|
        @a = 1
        view(:foo)
      end
    end

    app.freeze
    body.must_equal 'bar13-foo12-baz'

    proc{app.template(:b){"a"}}.must_raise
  end

  it "works with the view_subdirs plugin" do
    app(:bare) do
      plugin :render
      plugin :view_subdirs
      plugin :named_templates

      template "foo/bar" do
        @b = 2
        "foobar<%= @a %><%= @b %>"
      end
      template "foo/layout", :engine=>:str do
        @c = 3
        'foo#{@a}#{@c}-#{yield}-baz'
      end
      template "bar/layout", :engine=>:str do
        @c = 3
        'bar#{@a}#{@c}-#{yield}-baz'
      end

      route do |r|
        r.is 'foo' do
          set_view_subdir :foo
          @a = 1
          view(:bar)
        end
        r.is 'bar' do
          set_view_subdir :bar
          @a = 4
          @b = 2
          view(:inline=>"barfoo<%= @a %><%= @b %>")
        end
      end
    end

    body('/foo').must_equal 'foo13-foobar12-baz'
    body('/bar').must_equal 'bar43-barfoo42-baz'
  end
end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
roda-2.28.0 spec/plugin/named_templates_spec.rb
roda-2.27.0 spec/plugin/named_templates_spec.rb
roda-2.26.0 spec/plugin/named_templates_spec.rb
roda-2.25.0 spec/plugin/named_templates_spec.rb
roda-2.24.0 spec/plugin/named_templates_spec.rb
roda-2.23.0 spec/plugin/named_templates_spec.rb
roda-2.22.0 spec/plugin/named_templates_spec.rb
roda-2.21.0 spec/plugin/named_templates_spec.rb
roda-2.20.0 spec/plugin/named_templates_spec.rb
roda-2.19.0 spec/plugin/named_templates_spec.rb
roda-2.18.0 spec/plugin/named_templates_spec.rb
roda-2.17.0 spec/plugin/named_templates_spec.rb
roda-2.16.0 spec/plugin/named_templates_spec.rb
roda-2.15.0 spec/plugin/named_templates_spec.rb
roda-2.14.0 spec/plugin/named_templates_spec.rb
roda-2.13.0 spec/plugin/named_templates_spec.rb
roda-2.12.0 spec/plugin/named_templates_spec.rb
roda-2.11.0 spec/plugin/named_templates_spec.rb
roda-2.10.0 spec/plugin/named_templates_spec.rb
roda-2.9.0 spec/plugin/named_templates_spec.rb