Permalink
Browse files

Start refactoring the method of configuring ActionView

  • Loading branch information...
1 parent 54302ef commit b160663bd13d08bf845bc8cdf87a2c5e7e46f901 Carlhuda committed with Carl Lerche Mar 4, 2010
@@ -17,7 +17,21 @@ class Railtie < Rails::Railtie
ActionController::Base.logger ||= Rails.logger
end
+ # assets_dir = defined?(Rails.public_path) ? Rails.public_path : "public"
+ # ActionView::DEFAULT_CONFIG = {
+ # :assets_dir => assets_dir,
+ # :javascripts_dir => "#{assets_dir}/javascripts",
+ # :stylesheets_dir => "#{assets_dir}/stylesheets",
+ # }
+
+
initializer "action_controller.set_configs" do |app|
+ paths = app.config.paths
+ ac = app.config.action_controller
+ ac.assets_dir = paths.public
+ ac.javascripts_dir = paths.public.javascripts
+ ac.stylesheets_dir = paths.public.stylesheets
+
app.config.action_controller.each do |k,v|
ActionController::Base.send "#{k}=", v
end
@@ -175,15 +175,6 @@ module Subclasses
include Helpers, Rendering, Partials, ::ERB::Util
- def config
- self.config = DEFAULT_CONFIG unless @config
- @config
- end
-
- def config=(config)
- @config = ActiveSupport::OrderedOptions.new.merge(config)
- end
-
extend ActiveSupport::Memoizable
attr_accessor :base_path, :assigns, :template_extension
@@ -306,12 +297,13 @@ def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil,
@helpers = self.class.helpers || Module.new
@_controller = controller
+ @_config = controller.config if controller
@_content_for = Hash.new {|h,k| h[k] = ActiveSupport::SafeBuffer.new }
@_virtual_path = nil
self.view_paths = view_paths
end
- attr_internal :controller, :template
+ attr_internal :controller, :template, :config
attr_reader :view_paths
def view_paths=(paths)
@@ -133,13 +133,6 @@ module Helpers #:nodoc:
# change. You can use something like Live HTTP Headers for Firefox to verify
# that the cache is indeed working.
module AssetTagHelper
- assets_dir = defined?(Rails.public_path) ? Rails.public_path : "public"
- ActionView::DEFAULT_CONFIG = {
- :assets_dir => assets_dir,
- :javascripts_dir => "#{assets_dir}/javascripts",
- :stylesheets_dir => "#{assets_dir}/stylesheets",
- }
-
JAVASCRIPT_DEFAULT_SOURCES = ['prototype', 'effects', 'dragdrop', 'controls', 'rails'].freeze unless const_defined?(:JAVASCRIPT_DEFAULT_SOURCES)
# Returns a link tag that browsers and news readers can use to auto-detect
@@ -62,6 +62,10 @@ def setup_with_controller
make_test_case_available_to_view!
end
+ def config
+ @controller.config
+ end
+
def render(options = {}, local_assigns = {}, &block)
@rendered << output = _view.render(options, local_assigns, &block)
output
@@ -105,6 +105,21 @@ def call(env)
end
end
+class BasicController
+ attr_accessor :request
+
+ def config
+ @config ||= ActiveSupport::InheritableOptions.new(ActionController::Metal.config).tap do |config|
+ # VIEW TODO: View tests should not require a controller
+ public_dir = File.expand_path("../fixtures/public", __FILE__)
+ config.assets_dir = public_dir
+ config.javascripts_dir = "#{public_dir}/javascripts"
+ config.stylesheets_dir = "#{public_dir}/stylesheets"
+ config
+ end
+ end
+end
+
class ActionController::IntegrationTest < ActiveSupport::TestCase
def self.build_app(routes = nil)
RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new) do |middleware|
@@ -12,13 +12,6 @@ def config
class AssetTagHelperTest < ActionView::TestCase
tests ActionView::Helpers::AssetTagHelper
- DEFAULT_CONFIG = ActionView::DEFAULT_CONFIG.merge(
- :assets_dir => File.dirname(__FILE__) + "/../fixtures/public",
- :javascripts_dir => File.dirname(__FILE__) + "/../fixtures/public/javascripts",
- :stylesheets_dir => File.dirname(__FILE__) + "/../fixtures/public/stylesheets")
-
- include ActiveSupport::Configurable
-
def setup
super
silence_warnings do
@@ -41,7 +34,7 @@ def setup
)
end
- @controller = Class.new(FakeController) do
+ @controller = Class.new(BasicController) do
def url_for(*args) "http://www.example.com" end
end.new
@@ -883,12 +876,9 @@ def test_caching_stylesheet_include_tag_when_caching_off
class AssetTagHelperNonVhostTest < ActionView::TestCase
tests ActionView::Helpers::AssetTagHelper
- DEFAULT_CONFIG = ActionView::DEFAULT_CONFIG
- include ActiveSupport::Configurable
-
def setup
super
- @controller = Class.new(FakeController) do
+ @controller = Class.new(BasicController) do
def url_for(options)
"http://www.example.com/collaboration/hieraki"
end
@@ -3,17 +3,16 @@
class FormTagHelperTest < ActionView::TestCase
tests ActionView::Helpers::FormTagHelper
- include ActiveSupport::Configurable
- DEFAULT_CONFIG = ActionView::DEFAULT_CONFIG
+ # include ActiveSupport::Configurable
+ # DEFAULT_CONFIG = ActionView::DEFAULT_CONFIG
def setup
super
- @controller = Class.new do
+ @controller = Class.new(BasicController) do
def url_for(options)
"http://www.example.com"
end
- end
- @controller = @controller.new
+ end.new
end
VALID_HTML_ID = /^[A-Za-z][-_:.A-Za-z0-9]*$/ # see http://www.w3.org/TR/html4/types.html#type-name
@@ -4,19 +4,14 @@
require 'controller/fake_controllers'
class UrlHelperTest < ActionView::TestCase
- include ActiveSupport::Configurable
- DEFAULT_CONFIG = ActionView::DEFAULT_CONFIG
def setup
super
- @controller = Class.new do
- attr_accessor :url, :request
+ @controller = Class.new(BasicController) do
+ attr_accessor :url
def url_for(options)
url
end
- def config
- ActiveSupport::InheritableOptions.new({})
- end
end
@controller = @controller.new
@@ -26,6 +26,9 @@ def paths
paths.config.initializers "config/initializers", :glob => "**/*.rb"
paths.config.locales "config/locales", :glob => "*.{rb,yml}"
paths.config.routes "config/routes.rb"
+ paths.public "public"
+ paths.public.javascripts "public/javascripts"
+ paths.public.stylesheets "public/stylesheets"
paths
end
end

0 comments on commit b160663

Please sign in to comment.