Sha256: 9ca165fc05dc98a61b458ff88f995e24d0821d09af4e1c3907170ca0fcadae06

Contents?: true

Size: 1.76 KB

Versions: 4

Compression:

Stored size: 1.76 KB

Contents

class RtmlController < (defined? Rails) ? ApplicationController : ActionController::Base
  unless include?(Rtml::Controller::RenderHelpers)
    include Rtml::Controller::BeforeFilters
    include Rtml::Controller::RenderHelpers
    include Rtml::Controller::RtmlHelpers
    include Rtml::Controller::State
    include Rtml::Controller::CacheHelpers
    include Rtml::Controller::TemplateHelpers
    include Rtml::Controller::UrlHelpers
    extend Rtml::Controller::ClassMethods::RtmlActionHelpers
  end

  hide_action :rtml_document, :rtml_exception
  hide_action :screen_layout, :embedded_app
  helper_method :screen_layout, :embedded_app

  rescue_from Exception, :with => :rtml_exception

  def rtml_exception
    add_view_path(File.expand_path(File.join(Rtml.root, 'builtin/views')))

    method = (ENV['RAILS_ENV'] == 'production') ? 'rescue_action_in_public' : 'rescue_action_locally'

    # to address the scenario "what if these methods were not defined due to a failing before_filter"
    rtml = false
    rtml = request.rtml? if request.respond_to?(:rtml?)
    rtml = response.rtml? if response.respond_to?(:rtml?)

    if (params[:error_mode] == 'rtml' || rtml) && rtml_helpers.respond_to?(method)
      @exception = $!
      rtml_document.reset!
      erase_results
      render :rtml => method
    else
      raise $!
    end
  end

  def embedded_app
    "emb://embedded.tml"
  end

  def screen_layout
    "rtml/#{state[:model]}"
  end

  def rtml_document
    @rtml_document ||= Rtml::Document.new(:name => "#{controller_name}/#{action_name}",
                                          :view_paths => view_paths,
                                          :controller => self)
  end

  protected
  def add_view_path(path)
    view_paths << path
    rtml_document.view_paths << path
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rtml-2.0.3 builtin/controllers/rtml_controller.rb
rtml-2.0.2 builtin/controllers/rtml_controller.rb
rtml-2.0.1 builtin/controllers/rtml_controller.rb
rtml-2.0.0.alpha.1 builtin/controllers/rtml_controller.rb