Skip to content

Commit

Permalink
Whitespace!
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed May 7, 2009
1 parent af40fa6 commit a747ab5
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 95 deletions.
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/abstract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ module AbstractController
autoload :Renderer, "action_controller/abstract/renderer"
# === Exceptions
autoload :ActionNotFound, "action_controller/abstract/exceptions"
end
end
19 changes: 8 additions & 11 deletions actionpack/lib/action_controller/abstract/base.rb
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
module AbstractController
class Base

attr_internal :response_body
attr_internal :response_obj
attr_internal :action_name

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

def self.inherited(klass)
end

def initialize
self.response_obj = {}
end

def process(action_name)
unless respond_to_action?(action_name)
raise ActionNotFound, "The action '#{action_name}' could not be found"
end

@_action_name = action_name
process_action
self.response_obj[:body] = self.response_body
self
end

private

def process_action
respond_to?(action_name) ? send(action_name) : send(:action_missing, action_name)
end

def respond_to_action?(action_name)
respond_to?(action_name) || respond_to?(:action_missing, true)
end

end
end
end
8 changes: 4 additions & 4 deletions actionpack/lib/action_controller/abstract/callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ def process_action
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 All @@ -40,4 +40,4 @@ def #{filter}_filter(*names, &blk)
end
end
end
end
end
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/abstract/exceptions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module AbstractController
class ActionNotFound < StandardError ; end
end
end
17 changes: 8 additions & 9 deletions actionpack/lib/action_controller/abstract/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@ module Helpers
extlib_inheritable_accessor :master_helper_module
self.master_helper_module = Module.new
end

# def self.included(klass)
# klass.class_eval do
# extlib_inheritable_accessor :master_helper_module
# self.master_helper_module = Module.new
# end
# end

def _action_view
@_action_view ||= begin
av = super
av.helpers.send(:include, master_helper_module)
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

def add_template_helper(mod)
master_helper_module.module_eval { include mod }
end

def helper_method(*meths)
meths.flatten.each do |meth|
master_helper_module.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
Expand All @@ -45,7 +45,7 @@ def #{meth}(*args, &blk)
ruby_eval
end
end

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

end
end
end
27 changes: 13 additions & 14 deletions actionpack/lib/action_controller/abstract/layouts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ def layout(layout)
unless [String, Symbol, FalseClass, NilClass].include?(layout.class)
raise ArgumentError, "Layouts must be specified as a String, Symbol, false, or nil"
end

@_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 @@ -49,35 +49,34 @@ def _layout
end
end
end

def _render_template(template, options)
_action_view._render_template_with_layout(template, options[:_layout])
end

private

def _layout() end # This will be overwritten

def _layout_for_name(name)
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, {:formats => formats}, "layouts")
end

def _default_layout(require_layout = false)
if require_layout && !_layout
raise ArgumentError,
raise ArgumentError,
"There was no default layout for #{self.class} in #{view_paths.inspect}"
end

begin
layout = _layout_for_name(_layout)
rescue NameError => e
raise NoMethodError,
raise NoMethodError,
"You specified #{@_layout.inspect} as the layout, but no such method was found"
end
end
end
end
end
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/abstract/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ module Logger
cattr_accessor :logger
end
end
end
end
19 changes: 9 additions & 10 deletions actionpack/lib/action_controller/abstract/renderer.rb
Original file line number Diff line number Diff line change
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(options = {})
self.response_body = render_to_body(options)
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 = {})
name = options[:_template_name] || action_name

template = options[:_template] || view_paths.find_by_parts(name.to_s, {:formats => formats}, options[:_prefix])
_render_template(template, options)
end
Expand All @@ -39,7 +39,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 @@ -48,7 +48,7 @@ def render_to_string(options = {})
def _render_template(template, options)
_action_view._render_template_with_layout(template)
end

def view_paths() _view_paths end

# Return a string representation of a Rack-compatible response body.
Expand All @@ -64,15 +64,14 @@ def self.body_to_s(body)
end

module ClassMethods

def append_view_path(path)
self.view_paths << 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
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/new_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ module ActionController
autoload :Layouts, "action_controller/new_base/layouts"
autoload :Renderer, "action_controller/new_base/renderer"
autoload :UrlFor, "action_controller/new_base/url_for"
end
end
27 changes: 13 additions & 14 deletions actionpack/lib/action_controller/new_base/base.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module ActionController
class AbstractBase < AbstractController::Base

# :api: public
attr_internal :request, :response, :params

Expand All @@ -12,46 +11,46 @@ def self.controller_name
# :api: public
def controller_name() self.class.controller_name end

# :api: public
# :api: public
def self.controller_path
@controller_path ||= self.name.sub(/Controller$/, '').underscore
end
# :api: public

# :api: public
def controller_path() self.class.controller_path end
# :api: private

# :api: private
def self.action_methods
@action_names ||= Set.new(self.public_instance_methods - self::CORE_METHODS)
end
# :api: private

# :api: private
def self.action_names() action_methods end
# :api: private

# :api: private
def action_methods() self.class.action_names end

# :api: private
def action_names() action_methods end

# :api: plugin
def self.call(env)
controller = new
controller.call(env).to_rack
end

# :api: plugin
def response_body=(body)
@_response.body = body
end

# :api: private
def call(env)
@_request = ActionDispatch::Request.new(env)
@_response = ActionDispatch::Response.new
process(@_request.parameters[:action])
end

# :api: private
def to_rack
response.to_a
Expand Down
11 changes: 5 additions & 6 deletions actionpack/lib/action_controller/new_base/hide_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,25 @@ module HideActions
end

def action_methods() self.class.action_names end
def action_names() action_methods end
def action_names() action_methods end

private

def respond_to_action?(action_name)
!hidden_actions.include?(action_name) && (super || respond_to?(:method_missing))
end

module ClassMethods
def hide_action(*args)
args.each do |arg|
self.hidden_actions << arg.to_s
end
end

def action_methods
@action_names ||= Set.new(super.reject {|name| self.hidden_actions.include?(name.to_s)})
end

def self.action_names() action_methods end
end
end
end
end
Loading

15 comments on commit a747ab5

@iain
Copy link
Contributor

@iain iain commented on a747ab5 May 7, 2009

Choose a reason for hiding this comment

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

greatest... commit... ever...
no really, I instinctively remove whitespace in libraries and then put it back again, because I should not be touching it. I like it!

@ngocdaothanh
Copy link

Choose a reason for hiding this comment

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

Josh, how did you do that?

Eclipse has a plugin called AnyEdit (http://andrei.gmxhome.de/anyedit/index.html) to automatically remove white space on save. Is there any similar TextMate plugin?

@reagent
Copy link

@reagent reagent commented on a747ab5 May 8, 2009

Choose a reason for hiding this comment

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

@windock
Copy link
Contributor

@windock windock commented on a747ab5 May 8, 2009

Choose a reason for hiding this comment

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

This is the coolest thing I've ever saw!
You're my hero.

@wesrog
Copy link

@wesrog wesrog commented on a747ab5 May 8, 2009

Choose a reason for hiding this comment

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

Nice commit, indeed. Vim'll do this nicely with a swift ggVG=

@radar
Copy link
Contributor

@radar radar commented on a747ab5 May 8, 2009

Choose a reason for hiding this comment

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

Wow, revolutionary to Rails! applaud Love your work! :)

@bjeanes
Copy link
Contributor

@bjeanes bjeanes commented on a747ab5 May 8, 2009

Choose a reason for hiding this comment

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

Best commit ever.

@benhoskings
Copy link

Choose a reason for hiding this comment

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

Nice :)

@ngocdaothanh You can strip trailing whitespace in the open file in TextMate with ⌥⌘W.

@trevmex
Copy link

@trevmex trevmex commented on a747ab5 May 8, 2009

Choose a reason for hiding this comment

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

That just made my night. Awesome job!

@cbartlett
Copy link
Contributor

Choose a reason for hiding this comment

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

Hilarious.

@adrianpacala
Copy link
Contributor

Choose a reason for hiding this comment

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

Can someone backport it to 2.3?

@provideal
Copy link

Choose a reason for hiding this comment

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

@mislav
Copy link
Member

@mislav mislav commented on a747ab5 May 8, 2009

Choose a reason for hiding this comment

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

Will this trigger a flood of contributed whitespace patches

@rsl
Copy link
Contributor

@rsl rsl commented on a747ab5 May 8, 2009

Choose a reason for hiding this comment

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

what mislav said + "a flood of sarcastic comments [as seen above]". ;) oh crap. and i guess this one. :(

@wuputah
Copy link
Contributor

@wuputah wuputah commented on a747ab5 May 8, 2009

Choose a reason for hiding this comment

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

I frequently use TextMate's Find In Project to do this: find \s+$ and replace with nothing.

Adding newlines at the end of a file is a bit more challenging - find ([^\n])\Z, replace $1\n.

Please sign in to comment.