Sha256: 39efeee229b7bf8f6e78d43e69f832483fb2afe605030c334e3af44196f5a40c

Contents?: true

Size: 866 Bytes

Versions: 2

Compression:

Stored size: 866 Bytes

Contents

module Sharp
  class Action < ::Rack::Action

    def respond
      if layout
        view.render(layout, :main => self.class.template_name)
      else
        view.render(self.class.template_name)
      end
    end

    def self.base_name
      @base_name ||= name.sub(/Action\Z/,'')
    end

    def self.view_name
      @view_name ||= "#{base_name}View"
    end

    def self.view_class
      if defined? @view_class
        @view_class
      else
        @view_class = begin
          view_name.constantize
        rescue NameError
          Sharp::View
        end
      end
    end

    def self.template_name
      @template_name ||= "#{base_name.underscore}.erb"
    end

    def template
      self.class.template_name
    end

    def layout
      "layouts/application.erb"
    end

    def view
      @view ||= self.class.view_class.new
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sharp-0.3.7 lib/sharp/action.rb
sharp-0.3.6 lib/sharp/action.rb