Skip to content

Commit

Permalink
Revert "Revert "Whitespace!""
Browse files Browse the repository at this point in the history
This reverts commit 0cac68d.
  • Loading branch information
josh committed May 28, 2009
1 parent dd98280 commit de20324
Show file tree
Hide file tree
Showing 23 changed files with 270 additions and 264 deletions.
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/abstract.rb
Expand Up @@ -11,4 +11,4 @@ module AbstractController
autoload :Renderer, "action_controller/abstract/renderer"
# === Exceptions
autoload :ActionNotFound, "action_controller/abstract/exceptions"
end
end
34 changes: 16 additions & 18 deletions actionpack/lib/action_controller/abstract/base.rb
Expand Up @@ -2,28 +2,27 @@

module AbstractController
class Error < StandardError; end

class DoubleRenderError < Error
DEFAULT_MESSAGE = "Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like \"redirect_to(...) and return\"."

def initialize(message = nil)
super(message || DEFAULT_MESSAGE)
end
end
end

class Base

attr_internal :response_body
attr_internal :response_obj
attr_internal :action_name

class << self
attr_reader :abstract
attr_reader :abstract

def abstract!
@abstract = true
end

alias_method :abstract?, :abstract

def inherited(klass)
Expand All @@ -34,21 +33,21 @@ def inherited(klass)
def subclasses
@subclasses ||= []
end

def internal_methods
controller = self
controller = controller.superclass until controller.abstract?
controller.public_instance_methods(true)
end

def process(action)
new.process(action.to_s)
end

def hidden_actions
[]
end

def action_methods
@action_methods ||=
# All public instance methods of this class, including ancestors
Expand All @@ -61,13 +60,13 @@ def action_methods
hidden_actions
end
end

abstract!

def initialize
self.response_obj = {}
end

def process(action)
@_action_name = action_name = action.to_s

Expand All @@ -78,17 +77,16 @@ def process(action)
process_action(action_name)
self
end

private

def action_methods
self.class.action_methods
end

def action_method?(action)
action_methods.include?(action)
end

# It is possible for respond_to?(action_name) to be false and
# respond_to?(:action_missing) to be false if respond_to_action?
# is overridden in a subclass. For instance, ActionController::Base
Expand All @@ -114,4 +112,4 @@ def method_for_action(action_name)
end
end
end
end
end
6 changes: 3 additions & 3 deletions actionpack/lib/action_controller/abstract/benchmarker.rb
@@ -1,9 +1,9 @@
module AbstractController
module Benchmarker
extend ActiveSupport::DependencyModule

depends_on Logger

module ClassMethods
def benchmark(title, log_level = ::Logger::DEBUG, use_silence = true)
if logger && logger.level >= log_level
Expand All @@ -25,4 +25,4 @@ def silence
end
end
end
end
end
8 changes: 4 additions & 4 deletions actionpack/lib/action_controller/abstract/callbacks.rb
Expand Up @@ -13,19 +13,19 @@ def process_action(method_name)
super
end
end

module ClassMethods
def _normalize_callback_options(options)
if only = options[:only]
only = Array(only).map {|o| "action_name == '#{o}'"}.join(" || ")
options[:per_key] = {:if => only}
end
if except = options[:except]
except = Array(except).map {|e| "action_name == '#{e}'"}.join(" || ")
except = Array(except).map {|e| "action_name == '#{e}'"}.join(" || ")
options[:per_key] = {:unless => except}
end
end

[:before, :after, :around].each do |filter|
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
def #{filter}_filter(*names, &blk)
Expand Down Expand Up @@ -60,4 +60,4 @@ def skip_#{filter}_filter(*names, &blk)
end
end
end
end
end
4 changes: 2 additions & 2 deletions actionpack/lib/action_controller/abstract/exceptions.rb
@@ -1,3 +1,3 @@
module AbstractController
class ActionNotFound < StandardError ; end
end
class ActionNotFound < StandardError; end
end
9 changes: 4 additions & 5 deletions actionpack/lib/action_controller/abstract/helpers.rb
Expand Up @@ -16,12 +16,12 @@ def _action_view
av
end
end

module ClassMethods
def inherited(klass)
klass.master_helper_module = Module.new
klass.master_helper_module.__send__ :include, master_helper_module

super
end

Expand Down Expand Up @@ -57,7 +57,7 @@ def #{meth}(*args, &blk)
ruby_eval
end
end

def helper(*args, &block)
args.flatten.each do |arg|
case arg
Expand All @@ -68,6 +68,5 @@ def helper(*args, &block)
master_helper_module.module_eval(&block) if block_given?
end
end

end
end
end
25 changes: 13 additions & 12 deletions actionpack/lib/action_controller/abstract/layouts.rb
Expand Up @@ -17,18 +17,18 @@ def layout(layout, conditions = {})

conditions.each {|k, v| conditions[k] = Array(v).map {|a| a.to_s} }
self._layout_conditions = conditions

@_layout = layout || false # Converts nil to false
_write_layout_method
end

def _implied_layout_name
name.underscore
end

# Takes the specified layout and creates a _layout method to be called
# by _default_layout
#
#
# If the specified layout is a:
# String:: return the string
# Symbol:: call the method specified by the symbol
Expand Down Expand Up @@ -57,27 +57,28 @@ def _layout(details)
end
end
end

private

def _layout(details) end # This will be overwritten

# This will be overwritten
def _layout(details)
end

# :api: plugin
# ====
# Override this to mutate the inbound layout name
def _layout_for_name(name, details = {:formats => formats})
unless [String, FalseClass, NilClass].include?(name.class)
raise ArgumentError, "String, false, or nil expected; you passed #{name.inspect}"
end

name && view_paths.find_by_parts(name, details, _layout_prefix(name))
end

# TODO: Decide if this is the best hook point for the feature
def _layout_prefix(name)
"layouts"
end

def _default_layout(require_layout = false, details = {:formats => formats})
if require_layout && _action_has_layout? && !_layout(details)
raise ArgumentError,
Expand All @@ -87,7 +88,7 @@ def _default_layout(require_layout = false, details = {:formats => formats})
begin
_layout_for_name(_layout(details), details) if _action_has_layout?
rescue NameError => e
raise NoMethodError,
raise NoMethodError,
"You specified #{@_layout.inspect} as the layout, but no such method was found"
end
end
Expand All @@ -103,4 +104,4 @@ def _action_has_layout?
end
end
end
end
end
12 changes: 6 additions & 6 deletions actionpack/lib/action_controller/abstract/logger.rb
Expand Up @@ -9,7 +9,7 @@ class DelayedLog
def initialize(&blk)
@blk = blk
end

def to_s
@blk.call
end
Expand All @@ -19,10 +19,10 @@ def to_s
included do
cattr_accessor :logger
end

def process(action)
ret = super

if logger
log = DelayedLog.new do
"\n\nProcessing #{self.class.name}\##{action_name} " \
Expand All @@ -32,14 +32,14 @@ def process(action)

logger.info(log)
end

ret
end

def request_origin
# this *needs* to be cached!
# otherwise you'd get different results if calling it more than once
@request_origin ||= "#{request.remote_ip} at #{Time.now.to_s(:db)}"
end
end
end
end
24 changes: 12 additions & 12 deletions actionpack/lib/action_controller/abstract/renderer.rb
Expand Up @@ -15,22 +15,22 @@ module Renderer
end

def _action_view
@_action_view ||= ActionView::Base.new(self.class.view_paths, {}, self)
@_action_view ||= ActionView::Base.new(self.class.view_paths, {}, self)
end

def render(*args)
if response_body
raise AbstractController::DoubleRenderError, "OMG"
end

self.response_body = render_to_body(*args)
end

# Raw rendering of a template to a Rack-compatible body.
# ====
# @option _prefix<String> The template's path prefix
# @option _layout<String> The relative path to the layout template to use
#
#
# :api: plugin
def render_to_body(options = {})
# TODO: Refactor so we can just use the normal template logic for this
Expand All @@ -46,7 +46,7 @@ def render_to_body(options = {})
# ====
# @option _prefix<String> The template's path prefix
# @option _layout<String> The relative path to the layout template to use
#
#
# :api: plugin
def render_to_string(options = {})
AbstractController::Renderer.body_to_s(render_to_body(options))
Expand All @@ -55,8 +55,10 @@ def render_to_string(options = {})
def _render_template(options)
_action_view._render_template_from_controller(options[:_template], options[:_layout], options, options[:_partial])
end

def view_paths() _view_paths end

def view_paths()
_view_paths
end

# Return a string representation of a Rack-compatible response body.
def self.body_to_s(body)
Expand All @@ -71,7 +73,6 @@ def self.body_to_s(body)
end

private

def _determine_template(options)
name = (options[:_template_name] || action_name).to_s

Expand All @@ -81,19 +82,18 @@ def _determine_template(options)
end

module ClassMethods

def append_view_path(path)
self.view_paths << path
end

def prepend_view_path(path)
self.view_paths.unshift(path)
end

def view_paths
self._view_paths
end

def view_paths=(paths)
self._view_paths = paths.is_a?(ActionView::PathSet) ?
paths : ActionView::Base.process_view_paths(paths)
Expand Down

1 comment on commit de20324

@jerodsanto
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Now I'm waiting for:

Revert "Revert "Revert "Whitespace!"""

http://www.youtube.com/watch?v=1tqxzWdKKu8

Please sign in to comment.