module Hobo::Controller

Protected Instance Methods

action_has_layout?() click to toggle source

dryml does not use layouts

# File lib/hobo/controller.rb, line 116
def action_has_layout?
  false
end
ajax_update_response(render_specs, results={}, options={}) click to toggle source
# File lib/hobo/controller.rb, line 73
def ajax_update_response(render_specs, results={}, options={})
  if render_specs.blank?
    render :js => ''
    return
  end
  controller, action = controller_action_from_page_path
  identifier = view_context.view_paths.find( action,
                                             controller,
                                             false,
                                             view_context.lookup_context.instance_variable_get('@details')).identifier
  renderer = Dryml.page_renderer(view_context, identifier, [], controller)
  options = options.with_indifferent_access

  headers["Content-Type"] = options['content_type'] if options['content_type']

  page = options[:preamble] || ""
  for spec in render_specs
    function = spec[:function] || "hjq.ajax.update"
    dom_id = spec[:id]

    if spec[:part_context]
      part_content = renderer.refresh_part(spec[:part_context], session, dom_id)
      part_content.gsub!('"', '"') if options[:fix_quotes]
      page << "#{function}(#{dom_id.to_json}, #{part_content.to_json})\n"
    elsif spec[:result]
      result = results[spec[:result].to_sym]
      page << "#{function}(#{dom_id.to_json}, #{result.to_json});\n"
    else
      page << "alert('ajax_update_response: render_spec did not provide action');\n"
    end
  end
  if renderer
    options[:contexts_function] ||= "hjq.ajax.updatePartContexts" unless options[:no_contexts_function]
    if options[:contexts_function]
      storage = renderer.part_contexts_storage_uncoded
      page << "#{options[:contexts_function]}(#{storage.to_json});\n"
    end
  end
  page << options[:postamble] if options[:postamble]
  render :js => page
end
call_tag(name, options={}) click to toggle source
# File lib/hobo/controller.rb, line 144
def call_tag(name, options={})
  tag_renderer.send(name, options)
end
current_user=(new_user) click to toggle source

Store the given user in the session.

# File lib/hobo/controller.rb, line 164
def current_user=(new_user)
  session[:user] = (new_user.nil? || new_user.guest?) ? nil : new_user.typed_id
  @current_user = new_user
end
dryml_context() click to toggle source
# File lib/hobo/controller.rb, line 121
def dryml_context
  @this
end
hobo_ajax_response(options=nil) click to toggle source
# File lib/hobo/controller.rb, line 62
def hobo_ajax_response(options=nil)
  r = params[:render]
  if r
    ajax_update_response(r.is_a?(String) ? [] : r.values, options._?.get(:results) || {}, options || params[:render_options] || {})
    true
  else
    false
  end
end
not_found(error) click to toggle source
# File lib/hobo/controller.rb, line 174
def not_found(error)
  if self.class.superclass.method_defined?("not_found_response")
    super
  elsif render :not_found, :status => 404
    # cool
  else
    render(:text => t("hobo.messages.not_found", :default=>["The page you requested cannot be found."]) , :status => 404)
  end
end
redirect_to_with_object_url(destination, *args) click to toggle source
# File lib/hobo/controller.rb, line 53
def redirect_to_with_object_url(destination, *args)
  if destination.is_one_of?(String, Hash, Symbol)
    redirect_to_without_object_url(destination, *args)
  else
    redirect_to_without_object_url(object_url(destination, *args))
  end
end
render_tags(objects, tag, options={}) click to toggle source
# File lib/hobo/controller.rb, line 126
def render_tags(objects, tag, options={})
  for_type = options.delete(:for_type)
  base_tag = tag

  results = objects.map do |o|
    tag = tag_renderer.find_polymorphic_tag(base_tag, o.class) if for_type
    tag_renderer.send(tag, options.merge(:with => o))
  end.join

  render :text => results + tag_renderer.part_contexts_storage
end
request_no_cache?() click to toggle source
# File lib/hobo/controller.rb, line 170
def request_no_cache?
  request.env['HTTP_CACHE_CONTROL'] =~ /max-age=\s*0/
end
tag_renderer() click to toggle source
# File lib/hobo/controller.rb, line 139
def tag_renderer
  @tag_renderer ||= Dryml.empty_page_renderer(view_context)
end

Public Class Methods

included(base) click to toggle source
# File lib/hobo/controller.rb, line 10
def included(base)
  if base.is_a?(Class)
    included_in_class(base)
  end
end
included_in_class(klass) click to toggle source
# File lib/hobo/controller.rb, line 16
def included_in_class(klass)
  klass.extend(ClassMethods)
  klass.class_eval do
    before_filter :login_from_cookie
    alias_method_chain :redirect_to, :object_url
    private
    def set_mailer_default_url_options
      unless Rails.application.config.action_mailer.default_url_options
        Rails.application.config.action_mailer.default_url_options = { :host => request.host }
        Rails.application.config.action_mailer.default_url_options[:port] = request.port unless request.port == 80
      end
    end
    before_filter :set_mailer_default_url_options
    @included_taglibs = []
    rescue_from ActionController::RoutingError, :with => :not_found unless Rails.env.development?
  end
  HoboRouteHelper.add_to_controller(klass)
  HoboTranslationsHelper.add_to_controller(klass)
  HoboTranslationsNormalizerHelper.add_to_controller(klass)
  HoboPermissionsHelper.add_to_controller(klass)
end
set_mailer_default_url_options() click to toggle source
# File lib/hobo/controller.rb, line 22
def set_mailer_default_url_options
  unless Rails.application.config.action_mailer.default_url_options
    Rails.application.config.action_mailer.default_url_options = { :host => request.host }
    Rails.application.config.action_mailer.default_url_options[:port] = request.port unless request.port == 80
  end
end