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-1.0.0 lib/roda/plugins/symbol_views.rb
roda-cj-0.9.6 lib/roda/plugins/symbol_views.rb
roda-cj-0.9.5 lib/roda/plugins/symbol_views.rb
roda-cj-0.9.4 lib/roda/plugins/symbol_views.rb