Sha256: b4e755088080e844dca19fc9ac7160adfa69f5d5fbffce9d114a38586fb69cfb

Contents?: true

Size: 883 Bytes

Versions: 24

Compression:

Stored size: 883 Bytes

Contents

class Roda
  module RodaPlugins
    # The symbol_views plugin allows match blocks to return
    # symbols, and consider those symbols as views to use for the
    # response body.  So you can take code like:
    #
    #   r.root do
    #     view :index
    #   end
    #   r.is "foo" do
    #     view :foo
    #   end
    #
    # and DRY it up:
    #
    #   r.root do
    #     :index
    #   end
    #   r.is "foo" do
    #     :foo
    #   end
    module SymbolViews
      module RequestMethods
        private

        # If the block result is a symbol, consider the symbol a
        # template name and use the template view as the body.
        def block_result_body(result)
          if result.is_a?(Symbol)
            scope.view(result)
          else
            super
          end
        end
      end
    end

    register_plugin(:symbol_views, SymbolViews)
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
roda-2.9.0 lib/roda/plugins/symbol_views.rb
roda-2.8.0 lib/roda/plugins/symbol_views.rb
roda-2.7.0 lib/roda/plugins/symbol_views.rb
roda-2.6.0 lib/roda/plugins/symbol_views.rb
roda-2.5.1 lib/roda/plugins/symbol_views.rb
roda-2.5.0 lib/roda/plugins/symbol_views.rb
roda-2.4.0 lib/roda/plugins/symbol_views.rb
roda-2.3.0 lib/roda/plugins/symbol_views.rb
roda-2.2.0 lib/roda/plugins/symbol_views.rb
roda-2.1.0 lib/roda/plugins/symbol_views.rb
roda-2.0.0 lib/roda/plugins/symbol_views.rb
roda-1.3.0 lib/roda/plugins/symbol_views.rb
roda-1.2.0 lib/roda/plugins/symbol_views.rb
roda-1.1.0 lib/roda/plugins/symbol_views.rb
roda-cj-1.0.5 lib/roda/plugins/symbol_views.rb
roda-cj-1.0.4 lib/roda/plugins/symbol_views.rb
roda-cj-1.0.3 lib/roda/plugins/symbol_views.rb
roda-cj-1.0.2 lib/roda/plugins/symbol_views.rb
roda-cj-1.0.1 lib/roda/plugins/symbol_views.rb
roda-cj-1.0.0 lib/roda/plugins/symbol_views.rb