From 628c31b353706877322e7613702d1bd4a59e3514 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 22 Mar 2011 15:43:40 -0500 Subject: Add sprockets md5s to asset tags --- .../helpers/asset_tag_helpers/javascript_tag_helpers.rb | 10 ++++++++++ .../helpers/asset_tag_helpers/stylesheet_tag_helpers.rb | 10 ++++++++++ 2 files changed, 20 insertions(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb index 82bbfcc7d2..2187887b49 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb @@ -173,6 +173,16 @@ module ActionView # # javascript_include_tag :all, :cache => true, :recursive => true def javascript_include_tag(*sources) + if config.perform_caching + sources = sources.map do |source| + if source =~ /^\/assets\/(.+)/ + "/assets/#{Rails.application.assets.url($1)}" + else + source + end + end + end + @javascript_include ||= JavascriptIncludeTag.new(config, asset_paths) @javascript_include.include_tag(*sources) end diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb index a48c87b49a..b9f49f37b4 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb @@ -136,6 +136,16 @@ module ActionView # stylesheet_link_tag :all, :concat => true # def stylesheet_link_tag(*sources) + if config.perform_caching + sources = sources.map do |source| + if source =~ /^\/assets\/(.+)/ + "/assets/#{Rails.application.assets.url($1)}" + else + source + end + end + end + @stylesheet_include ||= StylesheetIncludeTag.new(config, asset_paths) @stylesheet_include.include_tag(*sources) end -- cgit v1.2.3 From 41cc6430650d0e90e892e0bd9a29ddcefd8a9c64 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 28 Mar 2011 13:54:58 -0500 Subject: Remove sprockets exception from main asset helpers --- .../helpers/asset_tag_helpers/javascript_tag_helpers.rb | 10 ---------- .../helpers/asset_tag_helpers/stylesheet_tag_helpers.rb | 10 ---------- 2 files changed, 20 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb index 2187887b49..82bbfcc7d2 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb @@ -173,16 +173,6 @@ module ActionView # # javascript_include_tag :all, :cache => true, :recursive => true def javascript_include_tag(*sources) - if config.perform_caching - sources = sources.map do |source| - if source =~ /^\/assets\/(.+)/ - "/assets/#{Rails.application.assets.url($1)}" - else - source - end - end - end - @javascript_include ||= JavascriptIncludeTag.new(config, asset_paths) @javascript_include.include_tag(*sources) end diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb index b9f49f37b4..a48c87b49a 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb @@ -136,16 +136,6 @@ module ActionView # stylesheet_link_tag :all, :concat => true # def stylesheet_link_tag(*sources) - if config.perform_caching - sources = sources.map do |source| - if source =~ /^\/assets\/(.+)/ - "/assets/#{Rails.application.assets.url($1)}" - else - source - end - end - end - @stylesheet_include ||= StylesheetIncludeTag.new(config, asset_paths) @stylesheet_include.include_tag(*sources) end -- cgit v1.2.3 From 9cb264555dbc630ff5e44d96b0d70061856f568c Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 28 Mar 2011 15:19:34 -0500 Subject: Add SprocketsHelper --- actionpack/lib/action_view/helpers.rb | 2 + .../lib/action_view/helpers/sprockets_helper.rb | 77 ++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 actionpack/lib/action_view/helpers/sprockets_helper.rb (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers.rb b/actionpack/lib/action_view/helpers.rb index d338ce616a..cb1ab64121 100644 --- a/actionpack/lib/action_view/helpers.rb +++ b/actionpack/lib/action_view/helpers.rb @@ -22,6 +22,7 @@ module ActionView #:nodoc: autoload :RecordTagHelper autoload :SanitizeHelper autoload :ScriptaculousHelper + autoload :SprocketsHelper autoload :TagHelper autoload :TextHelper autoload :TranslationHelper @@ -52,6 +53,7 @@ module ActionView #:nodoc: include RecordTagHelper include SanitizeHelper include ScriptaculousHelper + include SprocketsHelper include TagHelper include TextHelper include TranslationHelper diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/action_view/helpers/sprockets_helper.rb new file mode 100644 index 0000000000..4abc09e9a5 --- /dev/null +++ b/actionpack/lib/action_view/helpers/sprockets_helper.rb @@ -0,0 +1,77 @@ +require 'uri' + +module ActionView + module Helpers + module SprocketsHelper + def sprockets_javascript_path(source) + compute_sprockets_path source, 'javascripts', 'js' + end + + def sprockets_javascript_include_tag(source, options = {}) + options = { + 'type' => "application/javascript", + 'src' => sprockets_javascript_path(source) + }.merge(options.stringify_keys) + + content_tag 'script', "", options + end + + def sprockets_stylesheet_path(source) + compute_sprockets_path source, 'stylesheets', 'css' + end + + def sprockets_stylesheet_link_tag(source, options = {}) + options = { + 'rel' => "stylesheet", + 'type' => "text/css", + 'media' => "screen", + 'href' => sprockets_stylesheet_path(source) + }.merge(options.stringify_keys) + + tag 'link', options + end + + private + def compute_sprockets_path(source, dir, default_ext) + return source if URI.parse(source).host + + # Add /javscripts to relative paths + if source[0] != ?/ + source = "/#{dir}/#{source}" + end + + # Add default extension if there isn't one + if default_ext && File.extname(source).empty? + source = "#{source}.#{default_ext}" + end + + # Fingerprint url + source = Rails.application.assets.url(source) + + host = compute_asset_host(source) + + if controller.respond_to?(:request) && host && URI.parse(host).host.nil? + host = "#{controller.request.protocol}#{host}" + end + + "#{host}#{source}" + end + + def compute_asset_host(source) + if host = config.asset_host + if host.is_a?(Proc) || host.respond_to?(:call) + case host.is_a?(Proc) ? host.arity : host.method(:call).arity + when 2 + request = controller.respond_to?(:request) && controller.request + host.call(source, request) + else + host.call(source) + end + else + (host =~ /%d/) ? host % (source.hash % 4) : host + end + end + end + end + end +end -- cgit v1.2.3 From 3b4e1a91590b27f6f874927dc51f6f1755ae9f19 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 28 Mar 2011 15:58:29 -0500 Subject: Update sprockets path generation method --- actionpack/lib/action_view/helpers/sprockets_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/action_view/helpers/sprockets_helper.rb index 4abc09e9a5..bfc396fad5 100644 --- a/actionpack/lib/action_view/helpers/sprockets_helper.rb +++ b/actionpack/lib/action_view/helpers/sprockets_helper.rb @@ -46,7 +46,7 @@ module ActionView end # Fingerprint url - source = Rails.application.assets.url(source) + source = Rails.application.assets.path(source) host = compute_asset_host(source) -- cgit v1.2.3 From cc446d6c9f10a6258da958ecc8948ef478d9407c Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Mon, 28 Mar 2011 23:48:17 -0400 Subject: Add docs for ActionController::Metal class methods --- actionpack/lib/action_controller/metal.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index e5db31061b..585bd5e5ab 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -201,19 +201,23 @@ module ActionController class_attribute :middleware_stack self.middleware_stack = ActionController::MiddlewareStack.new - def self.inherited(base) + def self.inherited(base) #nodoc: base.middleware_stack = self.middleware_stack.dup super end + # Adds given middleware class and its args to bottom of middleware_stack def self.use(*args, &block) middleware_stack.use(*args, &block) end + # Alias for middleware_stack def self.middleware middleware_stack end + # Makes the controller a rack endpoint that points to the action in + # the given env's action_dispatch.request.path_parameters key. def self.call(env) action(env['action_dispatch.request.path_parameters'][:action]).call(env) end -- cgit v1.2.3 From 07054fe369b0d30562642f15140f7c863dfc4328 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 28 Mar 2011 22:17:20 -0700 Subject: Fix grammar, formatting, and cross references --- actionpack/lib/action_dispatch/testing/integration.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 5c6416a19e..4706112a06 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -26,31 +26,31 @@ module ActionDispatch # object's @response instance variable will point to the same # response object. # - # You can also perform POST, PUT, DELETE, and HEAD requests with +post+, - # +put+, +delete+, and +head+. + # You can also perform POST, PUT, DELETE, and HEAD requests with +#post+, + # +#put+, +#delete+, and +#head+. def get(path, parameters = nil, headers = nil) process :get, path, parameters, headers end - # Performs a POST request with the given parameters. See get() for more + # Performs a POST request with the given parameters. See +#get+ for more # details. def post(path, parameters = nil, headers = nil) process :post, path, parameters, headers end - # Performs a PUT request with the given parameters. See get() for more + # Performs a PUT request with the given parameters. See +#get+ for more # details. def put(path, parameters = nil, headers = nil) process :put, path, parameters, headers end - # Performs a DELETE request with the given parameters. See get() for + # Performs a DELETE request with the given parameters. See +#get+ for # more details. def delete(path, parameters = nil, headers = nil) process :delete, path, parameters, headers end - # Performs a HEAD request with the given parameters. See get() for more + # Performs a HEAD request with the given parameters. See +#get+ for more # details. def head(path, parameters = nil, headers = nil) process :head, path, parameters, headers @@ -59,7 +59,7 @@ module ActionDispatch # Performs an XMLHttpRequest request with the given parameters, mirroring # a request from the Prototype library. # - # The request_method is :get, :post, :put, :delete or :head; the + # The request_method is +:get+, +:post+, +:put+, +:delete+ or +:head+; the # parameters are +nil+, a hash, or a url-encoded or multipart string; # the headers are a hash. Keys are automatically upcased and prefixed # with 'HTTP_' if not already. @@ -384,7 +384,7 @@ module ActionDispatch end end - # An test that spans multiple controllers and actions, + # An integration test spans multiple controllers and actions, # tying them all together to ensure they work together as expected. It tests # more completely than either unit or functional tests do, exercising the # entire stack, from the dispatcher to the database. -- cgit v1.2.3 From 1af295fc9a6772e587e438254cfe354e6da0fa19 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 29 Mar 2011 15:42:31 -0500 Subject: Tests for SprocketsHelper --- .../lib/action_view/helpers/sprockets_helper.rb | 16 ++-- .../app/assets/javascripts/application.js | 0 .../sprockets/app/assets/javascripts/dir/xmlhr.js | 0 .../sprockets/app/assets/javascripts/xmlhr.js | 0 .../app/assets/stylesheets/application.css | 0 .../sprockets/app/assets/stylesheets/dir/style.css | 0 .../sprockets/app/assets/stylesheets/style.css | 0 actionpack/test/template/sprockets_helper_test.rb | 93 ++++++++++++++++++++++ 8 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 actionpack/test/fixtures/sprockets/app/assets/javascripts/application.js create mode 100644 actionpack/test/fixtures/sprockets/app/assets/javascripts/dir/xmlhr.js create mode 100644 actionpack/test/fixtures/sprockets/app/assets/javascripts/xmlhr.js create mode 100644 actionpack/test/fixtures/sprockets/app/assets/stylesheets/application.css create mode 100644 actionpack/test/fixtures/sprockets/app/assets/stylesheets/dir/style.css create mode 100644 actionpack/test/fixtures/sprockets/app/assets/stylesheets/style.css create mode 100644 actionpack/test/template/sprockets_helper_test.rb (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/action_view/helpers/sprockets_helper.rb index bfc396fad5..f6f4f06d6e 100644 --- a/actionpack/lib/action_view/helpers/sprockets_helper.rb +++ b/actionpack/lib/action_view/helpers/sprockets_helper.rb @@ -9,7 +9,7 @@ module ActionView def sprockets_javascript_include_tag(source, options = {}) options = { - 'type' => "application/javascript", + 'type' => "text/javascript", 'src' => sprockets_javascript_path(source) }.merge(options.stringify_keys) @@ -33,6 +33,8 @@ module ActionView private def compute_sprockets_path(source, dir, default_ext) + source = source.to_s + return source if URI.parse(source).host # Add /javscripts to relative paths @@ -46,15 +48,15 @@ module ActionView end # Fingerprint url - source = Rails.application.assets.path(source) + source = assets.path(source) host = compute_asset_host(source) - if controller.respond_to?(:request) && host && URI.parse(host).host.nil? - host = "#{controller.request.protocol}#{host}" + if controller.respond_to?(:request) && host && URI.parse(host).host + source = "#{controller.request.protocol}#{host}#{source}" end - "#{host}#{source}" + source end def compute_asset_host(source) @@ -72,6 +74,10 @@ module ActionView end end end + + def assets + Rails.application.assets + end end end end diff --git a/actionpack/test/fixtures/sprockets/app/assets/javascripts/application.js b/actionpack/test/fixtures/sprockets/app/assets/javascripts/application.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/assets/javascripts/dir/xmlhr.js b/actionpack/test/fixtures/sprockets/app/assets/javascripts/dir/xmlhr.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/assets/javascripts/xmlhr.js b/actionpack/test/fixtures/sprockets/app/assets/javascripts/xmlhr.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/assets/stylesheets/application.css b/actionpack/test/fixtures/sprockets/app/assets/stylesheets/application.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/assets/stylesheets/dir/style.css b/actionpack/test/fixtures/sprockets/app/assets/stylesheets/dir/style.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/assets/stylesheets/style.css b/actionpack/test/fixtures/sprockets/app/assets/stylesheets/style.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb new file mode 100644 index 0000000000..f6fd4f5bb4 --- /dev/null +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -0,0 +1,93 @@ +require 'abstract_unit' +require 'sprockets' + +class SprocketsHelperTest < ActionView::TestCase + tests ActionView::Helpers::SprocketsHelper + + attr_accessor :assets + + def setup + super + + @controller = BasicController.new + + @request = Class.new do + def protocol() 'http://' end + def ssl?() false end + def host_with_port() 'localhost' end + end.new + + @controller.request = @request + + @assets = Sprockets::Environment.new + @assets.paths << FIXTURES.join("sprockets/app/assets") + end + + def url_for(*args) + "http://www.example.com" + end + + test "javascript path" do + assert_equal "/javascripts/application-d41d8cd98f00b204e9800998ecf8427e.js", + sprockets_javascript_path(:application) + + assert_equal "/javascripts/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js", + sprockets_javascript_path("xmlhr") + assert_equal "/javascripts/dir/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js", + sprockets_javascript_path("dir/xmlhr.js") + + assert_equal "/dir/xmlhr.js", + sprockets_javascript_path("/dir/xmlhr") + + assert_equal "http://www.railsapplication.com/js/xmlhr", + sprockets_javascript_path("http://www.railsapplication.com/js/xmlhr") + assert_equal "http://www.railsapplication.com/js/xmlhr.js", + sprockets_javascript_path("http://www.railsapplication.com/js/xmlhr.js") + end + + test "javascript include tag" do + assert_equal '', + sprockets_javascript_include_tag(:application) + + assert_equal '', + sprockets_javascript_include_tag("xmlhr") + assert_equal '', + sprockets_javascript_include_tag("xmlhr.js") + assert_equal '', + sprockets_javascript_include_tag("http://www.railsapplication.com/xmlhr") + end + + test "stylesheet path" do + assert_equal "/stylesheets/application-d41d8cd98f00b204e9800998ecf8427e.css", + sprockets_stylesheet_path(:application) + + assert_equal "/stylesheets/style-d41d8cd98f00b204e9800998ecf8427e.css", + sprockets_stylesheet_path("style") + assert_equal "/stylesheets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css", + sprockets_stylesheet_path("dir/style.css") + assert_equal "/dir/style.css", + sprockets_stylesheet_path("/dir/style.css") + + assert_equal "http://www.railsapplication.com/css/style", + sprockets_stylesheet_path("http://www.railsapplication.com/css/style") + assert_equal "http://www.railsapplication.com/css/style.css", + sprockets_stylesheet_path("http://www.railsapplication.com/css/style.css") + end + + test "stylesheet link tag" do + assert_equal '', + sprockets_stylesheet_link_tag(:application) + + assert_equal '', + sprockets_stylesheet_link_tag("style") + assert_equal '', + sprockets_stylesheet_link_tag("style.css") + + assert_equal '', + sprockets_stylesheet_link_tag("http://www.railsapplication.com/style.css") + assert_equal '', + sprockets_stylesheet_link_tag("style", :media => "all") + assert_equal '', + sprockets_stylesheet_link_tag("style", :media => "print") + end +end -- cgit v1.2.3 From 375443a9c5eb28279d66f5a53677856e9a39d93f Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 29 Mar 2011 15:53:28 -0500 Subject: Use sprockets helpers if config.use_sprockets is set --- .../helpers/asset_tag_helpers/javascript_tag_helpers.rb | 14 +++++++++++--- .../helpers/asset_tag_helpers/stylesheet_tag_helpers.rb | 14 +++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb index 82bbfcc7d2..ed95f1c018 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb @@ -86,7 +86,11 @@ module ActionView # javascript_path "http://www.railsapplication.com/js/xmlhr" # => http://www.railsapplication.com/js/xmlhr # javascript_path "http://www.railsapplication.com/js/xmlhr.js" # => http://www.railsapplication.com/js/xmlhr.js def javascript_path(source) - asset_paths.compute_public_path(source, 'javascripts', 'js') + if config.use_sprockets + sprockets_javascript_path(source) + else + asset_paths.compute_public_path(source, 'javascripts', 'js') + end end alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with a javascript_path named route @@ -173,8 +177,12 @@ module ActionView # # javascript_include_tag :all, :cache => true, :recursive => true def javascript_include_tag(*sources) - @javascript_include ||= JavascriptIncludeTag.new(config, asset_paths) - @javascript_include.include_tag(*sources) + if config.use_sprockets + sprockets_javascript_include_tag(*sources) + else + @javascript_include ||= JavascriptIncludeTag.new(config, asset_paths) + @javascript_include.include_tag(*sources) + end end end diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb index a48c87b49a..a994afb65e 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb @@ -63,7 +63,11 @@ module ActionView # stylesheet_path "http://www.railsapplication.com/css/style" # => http://www.railsapplication.com/css/style # stylesheet_path "http://www.railsapplication.com/css/style.css" # => http://www.railsapplication.com/css/style.css def stylesheet_path(source) - asset_paths.compute_public_path(source, 'stylesheets', 'css') + if config.use_sprockets + sprockets_stylesheet_path(source) + else + asset_paths.compute_public_path(source, 'stylesheets', 'css') + end end alias_method :path_to_stylesheet, :stylesheet_path # aliased to avoid conflicts with a stylesheet_path named route @@ -136,8 +140,12 @@ module ActionView # stylesheet_link_tag :all, :concat => true # def stylesheet_link_tag(*sources) - @stylesheet_include ||= StylesheetIncludeTag.new(config, asset_paths) - @stylesheet_include.include_tag(*sources) + if config.use_sprockets + sprockets_stylesheet_link_tag(*sources) + else + @stylesheet_include ||= StylesheetIncludeTag.new(config, asset_paths) + @stylesheet_include.include_tag(*sources) + end end end -- cgit v1.2.3 From bed7a1acc46c9b211b7feaa21cc10395283392ab Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 29 Mar 2011 16:17:49 -0500 Subject: Copy use_sprockets config --- actionpack/lib/abstract_controller/asset_paths.rb | 4 ++-- actionpack/lib/action_controller/railtie.rb | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/asset_paths.rb b/actionpack/lib/abstract_controller/asset_paths.rb index 9ca2fb742f..ad14cd6d87 100644 --- a/actionpack/lib/abstract_controller/asset_paths.rb +++ b/actionpack/lib/abstract_controller/asset_paths.rb @@ -3,7 +3,7 @@ module AbstractController extend ActiveSupport::Concern included do - config_accessor :asset_host, :asset_path, :assets_dir, :javascripts_dir, :stylesheets_dir + config_accessor :asset_host, :asset_path, :assets_dir, :javascripts_dir, :stylesheets_dir, :use_sprockets end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index f0c29825ba..0f87295d47 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -21,6 +21,7 @@ module ActionController paths = app.config.paths options = app.config.action_controller + options.use_sprockets ||= app.config.use_sprockets options.assets_dir ||= paths["public"].first options.javascripts_dir ||= paths["public/javascripts"].first options.stylesheets_dir ||= paths["public/stylesheets"].first -- cgit v1.2.3 From a5f547cc7937fe1c75ea741b5432e89f7539cb2b Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 29 Mar 2011 17:27:49 -0500 Subject: Only add fingerprints if perform_caching is on --- actionpack/lib/action_view/helpers/sprockets_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/action_view/helpers/sprockets_helper.rb index f6f4f06d6e..9fd5f6759c 100644 --- a/actionpack/lib/action_view/helpers/sprockets_helper.rb +++ b/actionpack/lib/action_view/helpers/sprockets_helper.rb @@ -48,7 +48,7 @@ module ActionView end # Fingerprint url - source = assets.path(source) + source = assets.path(source, config.perform_caching) host = compute_asset_host(source) -- cgit v1.2.3 From db3e310d6b327b2b58cfbc0318abd3b4ddca5e30 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 29 Mar 2011 18:05:23 -0500 Subject: Change back to /assets prefix --- actionpack/lib/action_view/helpers/sprockets_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/action_view/helpers/sprockets_helper.rb index 9fd5f6759c..4f19f4bb21 100644 --- a/actionpack/lib/action_view/helpers/sprockets_helper.rb +++ b/actionpack/lib/action_view/helpers/sprockets_helper.rb @@ -4,7 +4,7 @@ module ActionView module Helpers module SprocketsHelper def sprockets_javascript_path(source) - compute_sprockets_path source, 'javascripts', 'js' + compute_sprockets_path source, 'assets', 'js' end def sprockets_javascript_include_tag(source, options = {}) @@ -17,7 +17,7 @@ module ActionView end def sprockets_stylesheet_path(source) - compute_sprockets_path source, 'stylesheets', 'css' + compute_sprockets_path source, 'assets', 'css' end def sprockets_stylesheet_link_tag(source, options = {}) -- cgit v1.2.3 From 651d371a247b0c473fb35a62076e480d95d84a35 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 29 Mar 2011 21:23:05 -0500 Subject: Rename option to config.asset_pipeline --- actionpack/lib/action_controller/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 0f87295d47..175b7744d7 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -21,7 +21,7 @@ module ActionController paths = app.config.paths options = app.config.action_controller - options.use_sprockets ||= app.config.use_sprockets + options.use_sprockets ||= app.config.asset_pipeline options.assets_dir ||= paths["public"].first options.javascripts_dir ||= paths["public/javascripts"].first options.stylesheets_dir ||= paths["public/stylesheets"].first -- cgit v1.2.3 From 77d8f7a4b71d7f52a7ba6f8bc7f7f6f6ac9b81e0 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 29 Mar 2011 21:40:24 -0500 Subject: Seperate asset directories --- .../lib/action_view/helpers/sprockets_helper.rb | 4 ++- .../app/assets/javascripts/application.js | 0 .../sprockets/app/assets/javascripts/dir/xmlhr.js | 0 .../sprockets/app/assets/javascripts/xmlhr.js | 0 .../app/assets/stylesheets/application.css | 0 .../sprockets/app/assets/stylesheets/dir/style.css | 0 .../sprockets/app/assets/stylesheets/style.css | 0 .../sprockets/app/javascripts/application.js | 0 .../sprockets/app/javascripts/dir/xmlhr.js | 0 .../fixtures/sprockets/app/javascripts/xmlhr.js | 0 .../sprockets/app/stylesheets/application.css | 0 .../sprockets/app/stylesheets/dir/style.css | 0 .../fixtures/sprockets/app/stylesheets/style.css | 0 actionpack/test/template/sprockets_helper_test.rb | 33 ++++++++++++---------- 14 files changed, 21 insertions(+), 16 deletions(-) delete mode 100644 actionpack/test/fixtures/sprockets/app/assets/javascripts/application.js delete mode 100644 actionpack/test/fixtures/sprockets/app/assets/javascripts/dir/xmlhr.js delete mode 100644 actionpack/test/fixtures/sprockets/app/assets/javascripts/xmlhr.js delete mode 100644 actionpack/test/fixtures/sprockets/app/assets/stylesheets/application.css delete mode 100644 actionpack/test/fixtures/sprockets/app/assets/stylesheets/dir/style.css delete mode 100644 actionpack/test/fixtures/sprockets/app/assets/stylesheets/style.css create mode 100644 actionpack/test/fixtures/sprockets/app/javascripts/application.js create mode 100644 actionpack/test/fixtures/sprockets/app/javascripts/dir/xmlhr.js create mode 100644 actionpack/test/fixtures/sprockets/app/javascripts/xmlhr.js create mode 100644 actionpack/test/fixtures/sprockets/app/stylesheets/application.css create mode 100644 actionpack/test/fixtures/sprockets/app/stylesheets/dir/style.css create mode 100644 actionpack/test/fixtures/sprockets/app/stylesheets/style.css (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/action_view/helpers/sprockets_helper.rb index 4f19f4bb21..408a2030ab 100644 --- a/actionpack/lib/action_view/helpers/sprockets_helper.rb +++ b/actionpack/lib/action_view/helpers/sprockets_helper.rb @@ -48,7 +48,9 @@ module ActionView end # Fingerprint url - source = assets.path(source, config.perform_caching) + if source =~ /^\/#{dir}\/(.+)/ + source = assets.path($1, config.perform_caching, dir) + end host = compute_asset_host(source) diff --git a/actionpack/test/fixtures/sprockets/app/assets/javascripts/application.js b/actionpack/test/fixtures/sprockets/app/assets/javascripts/application.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/actionpack/test/fixtures/sprockets/app/assets/javascripts/dir/xmlhr.js b/actionpack/test/fixtures/sprockets/app/assets/javascripts/dir/xmlhr.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/actionpack/test/fixtures/sprockets/app/assets/javascripts/xmlhr.js b/actionpack/test/fixtures/sprockets/app/assets/javascripts/xmlhr.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/actionpack/test/fixtures/sprockets/app/assets/stylesheets/application.css b/actionpack/test/fixtures/sprockets/app/assets/stylesheets/application.css deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/actionpack/test/fixtures/sprockets/app/assets/stylesheets/dir/style.css b/actionpack/test/fixtures/sprockets/app/assets/stylesheets/dir/style.css deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/actionpack/test/fixtures/sprockets/app/assets/stylesheets/style.css b/actionpack/test/fixtures/sprockets/app/assets/stylesheets/style.css deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/actionpack/test/fixtures/sprockets/app/javascripts/application.js b/actionpack/test/fixtures/sprockets/app/javascripts/application.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/javascripts/dir/xmlhr.js b/actionpack/test/fixtures/sprockets/app/javascripts/dir/xmlhr.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/javascripts/xmlhr.js b/actionpack/test/fixtures/sprockets/app/javascripts/xmlhr.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/stylesheets/application.css b/actionpack/test/fixtures/sprockets/app/stylesheets/application.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/stylesheets/dir/style.css b/actionpack/test/fixtures/sprockets/app/stylesheets/dir/style.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/sprockets/app/stylesheets/style.css b/actionpack/test/fixtures/sprockets/app/stylesheets/style.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb index f6fd4f5bb4..67aee86d02 100644 --- a/actionpack/test/template/sprockets_helper_test.rb +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -20,7 +20,10 @@ class SprocketsHelperTest < ActionView::TestCase @controller.request = @request @assets = Sprockets::Environment.new - @assets.paths << FIXTURES.join("sprockets/app/assets") + @assets.paths << FIXTURES.join("sprockets/app/javascripts") + @assets.paths << FIXTURES.join("sprockets/app/stylesheets") + + config.perform_caching = true end def url_for(*args) @@ -28,12 +31,12 @@ class SprocketsHelperTest < ActionView::TestCase end test "javascript path" do - assert_equal "/javascripts/application-d41d8cd98f00b204e9800998ecf8427e.js", + assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.js", sprockets_javascript_path(:application) - assert_equal "/javascripts/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js", + assert_equal "/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js", sprockets_javascript_path("xmlhr") - assert_equal "/javascripts/dir/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js", + assert_equal "/assets/dir/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js", sprockets_javascript_path("dir/xmlhr.js") assert_equal "/dir/xmlhr.js", @@ -46,24 +49,24 @@ class SprocketsHelperTest < ActionView::TestCase end test "javascript include tag" do - assert_equal '', + assert_equal '', sprockets_javascript_include_tag(:application) - assert_equal '', + assert_equal '', sprockets_javascript_include_tag("xmlhr") - assert_equal '', + assert_equal '', sprockets_javascript_include_tag("xmlhr.js") assert_equal '', sprockets_javascript_include_tag("http://www.railsapplication.com/xmlhr") end test "stylesheet path" do - assert_equal "/stylesheets/application-d41d8cd98f00b204e9800998ecf8427e.css", + assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.css", sprockets_stylesheet_path(:application) - assert_equal "/stylesheets/style-d41d8cd98f00b204e9800998ecf8427e.css", + assert_equal "/assets/style-d41d8cd98f00b204e9800998ecf8427e.css", sprockets_stylesheet_path("style") - assert_equal "/stylesheets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css", + assert_equal "/assets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css", sprockets_stylesheet_path("dir/style.css") assert_equal "/dir/style.css", sprockets_stylesheet_path("/dir/style.css") @@ -75,19 +78,19 @@ class SprocketsHelperTest < ActionView::TestCase end test "stylesheet link tag" do - assert_equal '', + assert_equal '', sprockets_stylesheet_link_tag(:application) - assert_equal '', + assert_equal '', sprockets_stylesheet_link_tag("style") - assert_equal '', + assert_equal '', sprockets_stylesheet_link_tag("style.css") assert_equal '', sprockets_stylesheet_link_tag("http://www.railsapplication.com/style.css") - assert_equal '', + assert_equal '', sprockets_stylesheet_link_tag("style", :media => "all") - assert_equal '', + assert_equal '', sprockets_stylesheet_link_tag("style", :media => "print") end end -- cgit v1.2.3 From 28fee29e383258c38649e20dc9508188010020c8 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 30 Mar 2011 21:56:15 -0500 Subject: Unify sprockets config options --- actionpack/lib/action_controller/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 175b7744d7..0dd13fa9bf 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -21,7 +21,7 @@ module ActionController paths = app.config.paths options = app.config.action_controller - options.use_sprockets ||= app.config.asset_pipeline + options.use_sprockets ||= app.config.assets.enabled options.assets_dir ||= paths["public"].first options.javascripts_dir ||= paths["public/javascripts"].first options.stylesheets_dir ||= paths["public/stylesheets"].first -- cgit v1.2.3 From a64abdda2505895fec6f0243db5928316c4df90a Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Thu, 31 Mar 2011 13:19:19 +0200 Subject: Explain in the method doc that you need to call respond_to at the class level in order to use respond_with. --- actionpack/lib/action_controller/metal/mime_responds.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb index a2e06fe0a6..998bef6556 100644 --- a/actionpack/lib/action_controller/metal/mime_responds.rb +++ b/actionpack/lib/action_controller/metal/mime_responds.rb @@ -222,6 +222,9 @@ module ActionController #:nodoc: # is quite simple (it just needs to respond to call), you can even give # a proc to it. # + # In order to use respond_with, first you need to declare the formats your + # controller responds to in the class level with a call to respond_to. + # def respond_with(*resources, &block) raise "In order to use respond_with, first you need to declare the formats your " << "controller responds to in the class level" if self.class.mimes_for_respond_to.empty? -- cgit v1.2.3 From c17b8e4047443b416685e30c8825ae01909f8d27 Mon Sep 17 00:00:00 2001 From: Jon Cooper Date: Thu, 31 Mar 2011 16:19:18 -0700 Subject: Trivial fix to HTTP Digest auth MD5 example --- actionpack/lib/action_controller/metal/http_authentication.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb index 39c804d707..c305abf5eb 100644 --- a/actionpack/lib/action_controller/metal/http_authentication.rb +++ b/actionpack/lib/action_controller/metal/http_authentication.rb @@ -77,7 +77,7 @@ module ActionController # class PostsController < ApplicationController # REALM = "SuperSecret" # USERS = {"dhh" => "secret", #plain text password - # "dap" => Digest:MD5::hexdigest(["dap",REALM,"secret"].join(":")) #ha1 digest password + # "dap" => Digest::MD5.hexdigest(["dap",REALM,"secret"].join(":")) #ha1 digest password # # before_filter :authenticate, :except => [:index] # -- cgit v1.2.3 From cc58fe79ac6f4d5fd54a39ff6e7f087c6a04fee8 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 2 Apr 2011 23:45:07 -0300 Subject: Implicit actions named not_implemented can be rendered --- actionpack/CHANGELOG | 2 ++ actionpack/lib/abstract_controller/base.rb | 2 ++ .../test/controller/new_base/render_implicit_action_test.rb | 13 +++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 3eba2281c4..25e2d27a01 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.1.0 (unreleased)* +* Implicit actions named not_implemented can be rendered [Santiago Pastorino] + * Wildcard route will always matching the optional format segment by default. For example if you have this route: map '*pages' => 'pages#show' diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb index 07ff5ad9f3..0951267fea 100644 --- a/actionpack/lib/abstract_controller/base.rb +++ b/actionpack/lib/abstract_controller/base.rb @@ -1,3 +1,4 @@ +require 'erubis' require 'active_support/configurable' require 'active_support/descendants_tracker' require 'active_support/core_ext/module/anonymous' @@ -18,6 +19,7 @@ module AbstractController include ActiveSupport::Configurable extend ActiveSupport::DescendantsTracker + undef_method :not_implemented class << self attr_reader :abstract alias_method :abstract?, :abstract diff --git a/actionpack/test/controller/new_base/render_implicit_action_test.rb b/actionpack/test/controller/new_base/render_implicit_action_test.rb index 667a9021be..3bb3016fdb 100644 --- a/actionpack/test/controller/new_base/render_implicit_action_test.rb +++ b/actionpack/test/controller/new_base/render_implicit_action_test.rb @@ -3,8 +3,9 @@ require 'abstract_unit' module RenderImplicitAction class SimpleController < ::ApplicationController self.view_paths = [ActionView::FixtureResolver.new( - "render_implicit_action/simple/hello_world.html.erb" => "Hello world!", - "render_implicit_action/simple/hyphen-ated.html.erb" => "Hello hyphen-ated!" + "render_implicit_action/simple/hello_world.html.erb" => "Hello world!", + "render_implicit_action/simple/hyphen-ated.html.erb" => "Hello hyphen-ated!", + "render_implicit_action/simple/not_implemented.html.erb" => "Not Implemented" )] def hello_world() end @@ -25,9 +26,17 @@ module RenderImplicitAction assert_status 200 end + test "render an action called not_implemented" do + get "/render_implicit_action/simple/not_implemented" + + assert_body "Not Implemented" + assert_status 200 + end + test "action_method? returns true for implicit actions" do assert SimpleController.new.action_method?(:hello_world) assert SimpleController.new.action_method?(:"hyphen-ated") + assert SimpleController.new.action_method?(:not_implemented) end end end -- cgit v1.2.3 From a000fc58b8bc288ca9c60566afc1e1943f5d6083 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 2 Apr 2011 23:56:52 -0300 Subject: Bump up erubis to 2.7.0 --- actionpack/actionpack.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/actionpack.gemspec b/actionpack/actionpack.gemspec index 6c55842eea..d3c66800d9 100644 --- a/actionpack/actionpack.gemspec +++ b/actionpack/actionpack.gemspec @@ -26,5 +26,5 @@ Gem::Specification.new do |s| s.add_dependency('rack-test', '~> 0.5.7') s.add_dependency('rack-mount', '~> 0.7.1') s.add_dependency('tzinfo', '~> 0.3.23') - s.add_dependency('erubis', '~> 2.6.6') + s.add_dependency('erubis', '~> 2.7.0') end -- cgit v1.2.3 From bd3cdeea354ebff97b0d5102a0857ce85eedcfa4 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sun, 3 Apr 2011 12:47:51 +0900 Subject: s/ERb/ERB/g The author of ERB sais, his eRuby implementation was originally named "ERb/ERbLight" and then renamed to "ERB" when started bundled as a Ruby standard lib. http://www2a.biglobe.ne.jp/~seki/ruby/erb.html --- actionpack/lib/action_controller/base.rb | 4 ++-- actionpack/lib/action_view/base.rb | 10 +++++----- actionpack/lib/action_view/helpers/atom_feed_helper.rb | 2 +- actionpack/lib/action_view/helpers/capture_helper.rb | 2 +- actionpack/lib/action_view/helpers/prototype_helper.rb | 2 +- actionpack/lib/action_view/helpers/url_helper.rb | 2 +- actionpack/lib/action_view/template/handlers/erb.rb | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index e6523e56d2..5f9e082cd3 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -105,7 +105,7 @@ module ActionController # == Renders # # Action Controller sends content to the user by using one of five rendering methods. The most versatile and common is the rendering - # of a template. Included in the Action Pack is the Action View, which enables rendering of ERb templates. It's automatically configured. + # of a template. Included in the Action Pack is the Action View, which enables rendering of ERB templates. It's automatically configured. # The controller passes objects to the view by assigning instance variables: # # def show @@ -128,7 +128,7 @@ module ActionController # end # end # - # Read more about writing ERb and Builder templates in ActionView::Base. + # Read more about writing ERB and Builder templates in ActionView::Base. # # == Redirects # diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index ab8c6259c5..5519103627 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -8,13 +8,13 @@ require 'action_view/log_subscriber' module ActionView #:nodoc: # = Action View Base # - # Action View templates can be written in three ways. If the template file has a .erb (or .rhtml) extension then it uses a mixture of ERb + # Action View templates can be written in three ways. If the template file has a .erb (or .rhtml) extension then it uses a mixture of ERB # (included in Ruby) and HTML. If the template file has a .builder (or .rxml) extension then Jim Weirich's Builder::XmlMarkup library is used. # If the template file has a .rjs extension then it will use ActionView::Helpers::PrototypeHelper::JavaScriptGenerator. # - # == ERb + # == ERB # - # You trigger ERb by using embeddings such as <% %>, <% -%>, and <%= %>. The <%= %> tag set is used when you want output. Consider the + # You trigger ERB by using embeddings such as <% %>, <% -%>, and <%= %>. The <%= %> tag set is used when you want output. Consider the # following loop for names: # # Names of all the people @@ -23,7 +23,7 @@ module ActionView #:nodoc: # <% end %> # # The loop is setup in regular embedding tags <% %> and the name is written using the output embedding tag <%= %>. Note that this - # is not just a usage suggestion. Regular output functions like print or puts won't work with ERb templates. So this would be wrong: + # is not just a usage suggestion. Regular output functions like print or puts won't work with ERB templates. So this would be wrong: # # <%# WRONG %> # Hi, Mr. <% puts "Frodo" %> @@ -81,7 +81,7 @@ module ActionView #:nodoc: # # == Builder # - # Builder templates are a more programmatic alternative to ERb. They are especially useful for generating XML content. An XmlMarkup object + # Builder templates are a more programmatic alternative to ERB. They are especially useful for generating XML content. An XmlMarkup object # named +xml+ is automatically made available to templates with a .builder extension. # # Here are some basic examples: diff --git a/actionpack/lib/action_view/helpers/atom_feed_helper.rb b/actionpack/lib/action_view/helpers/atom_feed_helper.rb index db9d7a08ff..96e5722252 100644 --- a/actionpack/lib/action_view/helpers/atom_feed_helper.rb +++ b/actionpack/lib/action_view/helpers/atom_feed_helper.rb @@ -4,7 +4,7 @@ module ActionView # = Action View Atom Feed Helpers module Helpers #:nodoc: module AtomFeedHelper - # Adds easy defaults to writing Atom feeds with the Builder template engine (this does not work on ERb or any other + # Adds easy defaults to writing Atom feeds with the Builder template engine (this does not work on ERB or any other # template languages). # # Full usage example: diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index c88bd1efd5..9ac7dff1ec 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -14,7 +14,7 @@ module ActionView # variable. You can then use this variable anywhere in your templates or layout. # # ==== Examples - # The capture method can be used in ERb templates... + # The capture method can be used in ERB templates... # # <% @greeting = capture do %> # Welcome to my shiny new web page! The date and time is diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index 18e303778c..506db24dc2 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -584,7 +584,7 @@ module ActionView # Works like update_page but wraps the generated JavaScript in a # \ + # javascript_include_tag "xmlhr" + # # => # - # javascript_include_tag "xmlhr.js" # => - # + # javascript_include_tag "xmlhr.js" + # # => # - # javascript_include_tag "common.javascript", "/elsewhere/cools" # => - # - # + # javascript_include_tag "common.javascript", "/elsewhere/cools" + # # => + # # # - # javascript_include_tag "http://www.railsapplication.com/xmlhr" # => - # + # javascript_include_tag "http://www.railsapplication.com/xmlhr" + # # => # - # javascript_include_tag "http://www.railsapplication.com/xmlhr.js" # => - # + # javascript_include_tag "http://www.railsapplication.com/xmlhr.js" + # # => # - # javascript_include_tag :defaults # => - # - # - # ... - # + # javascript_include_tag :defaults + # # => + # # + # # # # * = The application.js file is only referenced if it exists # - # You can also include all javascripts in the +javascripts+ directory using :all as the source: + # You can also include all JavaScripts in the +javascripts+ directory using :all as the source: # - # javascript_include_tag :all # => - # - # - # ... - # - # - # + # javascript_include_tag :all + # # => + # # + # # + # # + # # # - # Note that the default javascript files will be included first. So Prototype and Scriptaculous are available to - # all subsequently included files. + # Note that your defaults of choice will be included first, so they will be available to all subsequently + # included files. # - # If you want Rails to search in all the subdirectories under javascripts, you should explicitly set :recursive: + # If you want Rails to search in all the subdirectories under public/javascripts, you should + # explicitly set :recursive: # # javascript_include_tag :all, :recursive => true # - # == Caching multiple javascripts into one + # == Caching multiple JavaScripts into one # - # You can also cache multiple javascripts into one file, which requires less HTTP connections to download and can better be - # compressed by gzip (leading to faster transfers). Caching will only happen if config.perform_caching - # is set to true (which is the case by default for the Rails production environment, but not for the development - # environment). + # You can also cache multiple JavaScripts into one file, which requires less HTTP connections to download + # and can better be compressed by gzip (leading to faster transfers). Caching will only happen if + # config.perform_caching is set to true (which is the case by default for the Rails + # production environment, but not for the development environment). # # ==== Examples - # javascript_include_tag :all, :cache => true # when config.perform_caching is false => - # - # - # ... - # - # - # # - # javascript_include_tag :all, :cache => true # when config.perform_caching is true => - # + # # assuming config.perform_caching is false + # javascript_include_tag :all, :cache => true + # # => + # # + # # + # # + # # + # + # # assuming config.perform_caching is true + # javascript_include_tag :all, :cache => true + # # => # - # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when config.perform_caching is false => - # - # - # + # # assuming config.perform_caching is false + # javascript_include_tag "jquery", "cart", "checkout", :cache => "shop" + # # => + # # + # # # - # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when config.perform_caching is true => - # + # # assuming config.perform_caching is true + # javascript_include_tag "jquery", "cart", "checkout", :cache => "shop" + # # => # # The :recursive option is also available for caching: # @@ -184,9 +198,7 @@ module ActionView @javascript_include.include_tag(*sources) end end - end - end end end diff --git a/actionpack/lib/action_view/railtie.rb b/actionpack/lib/action_view/railtie.rb index 501ec07b09..f20ba7e6d3 100644 --- a/actionpack/lib/action_view/railtie.rb +++ b/actionpack/lib/action_view/railtie.rb @@ -6,7 +6,7 @@ module ActionView class Railtie < Rails::Railtie config.action_view = ActiveSupport::OrderedOptions.new config.action_view.stylesheet_expansions = {} - config.action_view.javascript_expansions = { :defaults => ['prototype', 'effects', 'dragdrop', 'controls', 'rails'] } + config.action_view.javascript_expansions = { :defaults => %w(jquery rails) } initializer "action_view.cache_asset_ids" do |app| unless app.config.cache_classes -- cgit v1.2.3 From 8449da929efddb7f1eb6e6e7e39d8e480bec9484 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 24 Mar 2011 23:48:07 +0100 Subject: removes support for RJS in link_to_function --- .../lib/action_view/helpers/javascript_helper.rb | 53 ++++------------------ actionpack/test/template/javascript_helper_test.rb | 25 +--------- 2 files changed, 10 insertions(+), 68 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index a19ba7a968..3d77d5c13b 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -129,54 +129,19 @@ module ActionView tag(:input, html_options.merge(:type => 'button', :value => name, :onclick => onclick)) end - # Returns a link of the given +name+ that will trigger a JavaScript +function+ using the - # onclick handler and return false after the fact. + # Returns a link whose +onclick+ handler triggers the passed JavaScript. # - # The first argument +name+ is used as the link text. - # - # The next arguments are optional and may include the javascript function definition and a hash of html_options. - # - # The +function+ argument can be omitted in favor of an +update_page+ - # block, which evaluates to a string when the template is rendered - # (instead of making an Ajax request first). - # - # The +html_options+ will accept a hash of html attributes for the link tag. Some examples are :class => "nav_button", :id => "articles_nav_button" - # - # Note: if you choose to specify the javascript function in a block, but would like to pass html_options, set the +function+ parameter to nil + # The helper receives a name, JavaScript code, and an optional hash of HTML options. The + # name is used as the link text and the JavaScript code goes into the +onclick+ attribute. + # If +html_options+ has an :onclick, that one is put before +function+. Once all + # the JavaScript is set, the helper appends "; return false;". # + # The +href+ attribute of the tag is set to "#" unles +html_options+ has one. # - # Examples: - # link_to_function "Greeting", "alert('Hello world!')" - # Produces: - # Greeting - # - # link_to_function(image_tag("delete"), "if (confirm('Really?')) do_delete()") - # Produces: - # - # Delete - # - # - # link_to_function("Show me more", nil, :id => "more_link") do |page| - # page[:details].visual_effect :toggle_blind - # page[:more_link].replace_html "Show me less" - # end + # link_to_function "Greeting", "alert('Hello world!')", :class => "nav_link" # Produces: - # Show me more - # - def link_to_function(name, *args, &block) - html_options = args.extract_options!.symbolize_keys - - function = block_given? ? update_page(&block) : args[0] || '' + # Greeting + def link_to_function(name, function, html_options={}) onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;" href = html_options[:href] || '#' diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index 8aa2730da1..65b8074dbb 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -69,34 +69,11 @@ class JavaScriptHelperTest < ActionView::TestCase link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')") end - def test_link_to_function_with_rjs_block - html = link_to_function( "Greet me!" ) do |page| - page.replace_html 'header', "

Greetings

" - end - assert_dom_equal %(Greet me!), html - end - - def test_link_to_function_with_rjs_block_and_options - html = link_to_function( "Greet me!", :class => "updater" ) do |page| - page.replace_html 'header', "

Greetings

" - end - assert_dom_equal %(Greet me!), html - end - - def test_link_to_function_with_href + def test_finction_with_href assert_dom_equal %(Greeting), link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/') end - def test_link_to_function_with_inner_block_does_not_raise_exception - html = link_to_function( "Greet me!" ) do |page| - page.replace_html 'header', (content_tag :h1 do - 'Greetings' - end) - end - assert_dom_equal %(Greet me!), html - end - def test_javascript_tag self.output_buffer = 'foo' -- cgit v1.2.3 From b878757c5073eac7e4fcfd2093d38d8b841db846 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 24 Mar 2011 23:51:17 +0100 Subject: removes assert_select_rjs --- .../action_dispatch/testing/assertions/selector.rb | 140 +------- actionpack/test/controller/assert_select_test.rb | 351 --------------------- 2 files changed, 1 insertion(+), 490 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index f41d3e5ddb..39a2a9884a 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -19,7 +19,7 @@ module ActionDispatch # from the response HTML or elements selected by the enclosing assertion. # # In addition to HTML responses, you can make the following assertions: - # * +assert_select_rjs+ - Assertions on HTML content of RJS update and insertion operations. + # # * +assert_select_encoded+ - Assertions on HTML encoded inside XML, for example for dealing with feed item descriptions. # * +assert_select_email+ - Assertions on the HTML body of an e-mail. # @@ -326,144 +326,6 @@ module ActionDispatch end end - # Selects content from the RJS response. - # - # === Narrowing down - # - # With no arguments, asserts that one or more elements are updated or - # inserted by RJS statements. - # - # Use the +id+ argument to narrow down the assertion to only statements - # that update or insert an element with that identifier. - # - # Use the first argument to narrow down assertions to only statements - # of that type. Possible values are :replace, :replace_html, - # :show, :hide, :toggle, :remove, - # :insert_html and :redirect. - # - # Use the argument :insert followed by an insertion position to narrow - # down the assertion to only statements that insert elements in that - # position. Possible values are :top, :bottom, :before - # and :after. - # - # Use the argument :redirect followed by a path to check that an statement - # which redirects to the specified path is generated. - # - # Using the :remove statement, you will be able to pass a block, but it will - # be ignored as there is no HTML passed for this statement. - # - # === Using blocks - # - # Without a block, +assert_select_rjs+ merely asserts that the response - # contains one or more RJS statements that replace or update content. - # - # With a block, +assert_select_rjs+ also selects all elements used in - # these statements and passes them to the block. Nested assertions are - # supported. - # - # Calling +assert_select_rjs+ with no arguments and using nested asserts - # asserts that the HTML content is returned by one or more RJS statements. - # Using +assert_select+ directly makes the same assertion on the content, - # but without distinguishing whether the content is returned in an HTML - # or JavaScript. - # - # ==== Examples - # - # # Replacing the element foo. - # # page.replace 'foo', ... - # assert_select_rjs :replace, "foo" - # - # # Replacing with the chained RJS proxy. - # # page[:foo].replace ... - # assert_select_rjs :chained_replace, 'foo' - # - # # Inserting into the element bar, top position. - # assert_select_rjs :insert, :top, "bar" - # - # # Remove the element bar - # assert_select_rjs :remove, "bar" - # - # # Changing the element foo, with an image. - # assert_select_rjs "foo" do - # assert_select "img[src=/images/logo.gif"" - # end - # - # # RJS inserts or updates a list with four items. - # assert_select_rjs do - # assert_select "ol>li", 4 - # end - # - # # The same, but shorter. - # assert_select "ol>li", 4 - # - # # Checking for a redirect. - # assert_select_rjs :redirect, root_path - def assert_select_rjs(*args, &block) - rjs_type = args.first.is_a?(Symbol) ? args.shift : nil - id = args.first.is_a?(String) ? args.shift : nil - - # If the first argument is a symbol, it's the type of RJS statement we're looking - # for (update, replace, insertion, etc). Otherwise, we're looking for just about - # any RJS statement. - if rjs_type - if rjs_type == :insert - position = args.shift - id = args.shift - insertion = "insert_#{position}".to_sym - raise ArgumentError, "Unknown RJS insertion type #{position}" unless RJS_STATEMENTS[insertion] - statement = "(#{RJS_STATEMENTS[insertion]})" - else - raise ArgumentError, "Unknown RJS statement type #{rjs_type}" unless RJS_STATEMENTS[rjs_type] - statement = "(#{RJS_STATEMENTS[rjs_type]})" - end - else - statement = "#{RJS_STATEMENTS[:any]}" - end - - # Next argument we're looking for is the element identifier. If missing, we pick - # any element, otherwise we replace it in the statement. - pattern = Regexp.new( - id ? statement.gsub(RJS_ANY_ID, "\"#{id}\"") : statement - ) - - # Duplicate the body since the next step involves destroying it. - matches = nil - case rjs_type - when :remove, :show, :hide, :toggle - matches = @response.body.match(pattern) - else - @response.body.gsub(pattern) do |match| - html = unescape_rjs(match) - matches ||= [] - matches.concat HTML::Document.new(html).root.children.select { |n| n.tag? } - "" - end - end - - if matches - assert_block("") { true } # to count the assertion - if block_given? && !rjs_type.among?(:remove, :show, :hide, :toggle) - begin - @selected ||= nil - in_scope, @selected = @selected, matches - yield matches - ensure - @selected = in_scope - end - end - matches - else - # RJS statement not found. - case rjs_type - when :remove, :show, :hide, :toggle - flunk_message = "No RJS statement that #{rjs_type.to_s}s '#{id}' was rendered." - else - flunk_message = "No RJS statement that replaces or inserts HTML content." - end - flunk args.shift || flunk_message - end - end - # Extracts the content of an element, treats it as encoded HTML and runs # nested assertion on it. # diff --git a/actionpack/test/controller/assert_select_test.rb b/actionpack/test/controller/assert_select_test.rb index f63321c78b..c72370e49d 100644 --- a/actionpack/test/controller/assert_select_test.rb +++ b/actionpack/test/controller/assert_select_test.rb @@ -248,21 +248,6 @@ class AssertSelectTest < ActionController::TestCase end end - def test_assert_select_rjs_for_positioned_insert_should_fail_when_mixing_arguments - render_rjs do |page| - page.insert_html :top, "test1", "
foo
" - page.insert_html :bottom, "test2", "
foo
" - end - assert_raise(Assertion) {assert_select_rjs :insert, :top, "test2"} - end - - def test_assert_select_rjs_for_redirect_to - render_rjs do |page| - page.redirect_to '/' - end - assert_select_rjs :redirect, '/' - end - def test_elect_with_xml_namespace_attributes render_html %Q{} assert_nothing_raised { assert_select "link[xlink:href=http://nowhere.com]" } @@ -318,342 +303,6 @@ class AssertSelectTest < ActionController::TestCase assert_equal 1, css_select("#2").size end - # - # Test assert_select_rjs. - # - - # Test that we can pick up all statements in the result. - def test_assert_select_rjs_picks_up_all_statements - render_rjs do |page| - page.replace "test", "
foo
" - page.replace_html "test2", "
foo
" - page.insert_html :top, "test3", "
foo
" - end - - found = false - assert_select_rjs do - assert_select "#1" - assert_select "#2" - assert_select "#3" - found = true - end - assert found - end - - # Test that we fail if there is nothing to pick. - def test_assert_select_rjs_fails_if_nothing_to_pick - render_rjs { } - assert_raise(Assertion) { assert_select_rjs } - end - - def test_assert_select_rjs_with_unicode - # Test that non-ascii characters (which are converted into \uXXXX in RJS) are decoded correctly. - render_rjs do |page| - page.replace "test", "
\343\203\201\343\202\261\343\203\203\343\203\210
" - end - assert_select_rjs do - str = "#1" - assert_select str, :text => "\343\203\201\343\202\261\343\203\203\343\203\210" - assert_select str, "\343\203\201\343\202\261\343\203\203\343\203\210" - if str.respond_to?(:force_encoding) - assert_select str, /\343\203\201..\343\203\210/u - assert_raise(Assertion) { assert_select str, /\343\203\201.\343\203\210/u } - else - assert_select str, Regexp.new("\343\203\201..\343\203\210",0,'U') - assert_raise(Assertion) { assert_select str, Regexp.new("\343\203\201.\343\203\210",0,'U') } - end - end - end - - def test_assert_select_rjs_with_id - # Test that we can pick up all statements in the result. - render_rjs do |page| - page.replace "test1", "
foo
" - page.replace_html "test2", "
foo
" - page.insert_html :top, "test3", "
foo
" - end - assert_select_rjs "test1" do - assert_select "div", 1 - assert_select "#1" - end - assert_select_rjs "test2" do - assert_select "div", 1 - assert_select "#2" - end - assert_select_rjs "test3" do - assert_select "div", 1 - assert_select "#3" - end - assert_raise(Assertion) { assert_select_rjs "test4" } - end - - def test_assert_select_rjs_for_replace - render_rjs do |page| - page.replace "test1", "
foo
" - page.replace_html "test2", "
foo
" - page.insert_html :top, "test3", "
foo
" - end - # Replace. - assert_select_rjs :replace do - assert_select "div", 1 - assert_select "#1" - end - assert_select_rjs :replace, "test1" do - assert_select "div", 1 - assert_select "#1" - end - assert_raise(Assertion) { assert_select_rjs :replace, "test2" } - # Replace HTML. - assert_select_rjs :replace_html do - assert_select "div", 1 - assert_select "#2" - end - assert_select_rjs :replace_html, "test2" do - assert_select "div", 1 - assert_select "#2" - end - assert_raise(Assertion) { assert_select_rjs :replace_html, "test1" } - end - - def test_assert_select_rjs_for_chained_replace - render_rjs do |page| - page['test1'].replace "
foo
" - page['test2'].replace_html "
foo
" - page.insert_html :top, "test3", "
foo
" - end - # Replace. - assert_select_rjs :chained_replace do - assert_select "div", 1 - assert_select "#1" - end - assert_select_rjs :chained_replace, "test1" do - assert_select "div", 1 - assert_select "#1" - end - assert_raise(Assertion) { assert_select_rjs :chained_replace, "test2" } - # Replace HTML. - assert_select_rjs :chained_replace_html do - assert_select "div", 1 - assert_select "#2" - end - assert_select_rjs :chained_replace_html, "test2" do - assert_select "div", 1 - assert_select "#2" - end - assert_raise(Assertion) { assert_select_rjs :replace_html, "test1" } - end - - # Simple remove - def test_assert_select_rjs_for_remove - render_rjs do |page| - page.remove "test1" - end - - assert_select_rjs :remove, "test1" - end - - def test_assert_select_rjs_for_remove_offers_useful_error_when_assertion_fails - render_rjs do |page| - page.remove "test_with_typo" - end - - assert_select_rjs :remove, "test1" - - rescue Assertion => e - assert_equal "No RJS statement that removes 'test1' was rendered.", e.message - end - - def test_assert_select_rjs_for_remove_ignores_block - render_rjs do |page| - page.remove "test1" - end - - assert_nothing_raised do - assert_select_rjs :remove, "test1" do - assert_select "p" - end - end - end - - # Simple show - def test_assert_select_rjs_for_show - render_rjs do |page| - page.show "test1" - end - - assert_select_rjs :show, "test1" - end - - def test_assert_select_rjs_for_show_offers_useful_error_when_assertion_fails - render_rjs do |page| - page.show "test_with_typo" - end - - assert_select_rjs :show, "test1" - - rescue Assertion => e - assert_equal "No RJS statement that shows 'test1' was rendered.", e.message - end - - def test_assert_select_rjs_for_show_ignores_block - render_rjs do |page| - page.show "test1" - end - - assert_nothing_raised do - assert_select_rjs :show, "test1" do - assert_select "p" - end - end - end - - # Simple hide - def test_assert_select_rjs_for_hide - render_rjs do |page| - page.hide "test1" - end - - assert_select_rjs :hide, "test1" - end - - def test_assert_select_rjs_for_hide_offers_useful_error_when_assertion_fails - render_rjs do |page| - page.hide "test_with_typo" - end - - assert_select_rjs :hide, "test1" - - rescue Assertion => e - assert_equal "No RJS statement that hides 'test1' was rendered.", e.message - end - - def test_assert_select_rjs_for_hide_ignores_block - render_rjs do |page| - page.hide "test1" - end - - assert_nothing_raised do - assert_select_rjs :hide, "test1" do - assert_select "p" - end - end - end - - # Simple toggle - def test_assert_select_rjs_for_toggle - render_rjs do |page| - page.toggle "test1" - end - - assert_select_rjs :toggle, "test1" - end - - def test_assert_select_rjs_for_toggle_offers_useful_error_when_assertion_fails - render_rjs do |page| - page.toggle "test_with_typo" - end - - assert_select_rjs :toggle, "test1" - - rescue Assertion => e - assert_equal "No RJS statement that toggles 'test1' was rendered.", e.message - end - - def test_assert_select_rjs_for_toggle_ignores_block - render_rjs do |page| - page.toggle "test1" - end - - assert_nothing_raised do - assert_select_rjs :toggle, "test1" do - assert_select "p" - end - end - end - - # Non-positioned insert. - def test_assert_select_rjs_for_nonpositioned_insert - render_rjs do |page| - page.replace "test1", "
foo
" - page.replace_html "test2", "
foo
" - page.insert_html :top, "test3", "
foo
" - end - assert_select_rjs :insert_html do - assert_select "div", 1 - assert_select "#3" - end - assert_select_rjs :insert_html, "test3" do - assert_select "div", 1 - assert_select "#3" - end - assert_raise(Assertion) { assert_select_rjs :insert_html, "test1" } - end - - # Positioned insert. - def test_assert_select_rjs_for_positioned_insert - render_rjs do |page| - page.insert_html :top, "test1", "
foo
" - page.insert_html :bottom, "test2", "
foo
" - page.insert_html :before, "test3", "
foo
" - page.insert_html :after, "test4", "
foo
" - end - assert_select_rjs :insert, :top do - assert_select "div", 1 - assert_select "#1" - end - assert_select_rjs :insert, :bottom do - assert_select "div", 1 - assert_select "#2" - end - assert_select_rjs :insert, :before do - assert_select "div", 1 - assert_select "#3" - end - assert_select_rjs :insert, :after do - assert_select "div", 1 - assert_select "#4" - end - assert_select_rjs :insert_html do - assert_select "div", 4 - end - end - - def test_assert_select_rjs_raise_errors - assert_raise(ArgumentError) { assert_select_rjs(:destroy) } - assert_raise(ArgumentError) { assert_select_rjs(:insert, :left) } - end - - # Simple selection from a single result. - def test_nested_assert_select_rjs_with_single_result - render_rjs do |page| - page.replace_html "test", "
foo
\n
foo
" - end - - assert_select_rjs "test" do |elements| - assert_equal 2, elements.size - assert_select "#1" - assert_select "#2" - end - end - - # Deal with two results. - def test_nested_assert_select_rjs_with_two_results - render_rjs do |page| - page.replace_html "test", "
foo
" - page.replace_html "test2", "
foo
" - end - - assert_select_rjs "test" do |elements| - assert_equal 1, elements.size - assert_select "#1" - end - - assert_select_rjs "test2" do |elements| - assert_equal 1, elements.size - assert_select "#2" - end - end - def test_feed_item_encoded render_xml <<-EOF -- cgit v1.2.3 From 3223e04a21c27a2e612fcd341e06c46433659f8d Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 25 Mar 2011 00:28:47 +0100 Subject: removes support for RJS in button_to_function --- .../lib/action_view/helpers/javascript_helper.rb | 32 +++++----------------- actionpack/test/template/javascript_helper_test.rb | 14 ---------- 2 files changed, 7 insertions(+), 39 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 3d77d5c13b..136d006ad1 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -96,34 +96,16 @@ module ActionView "\n//#{cdata_section("\n#{content}\n//")}\n".html_safe end - # Returns a button with the given +name+ text that'll trigger a JavaScript +function+ using the - # onclick handler. + # Returns a button whose +onclick+ handler triggers the passed JavaScript. # - # The first argument +name+ is used as the button's value or display text. - # - # The next arguments are optional and may include the javascript function definition and a hash of html_options. - # - # The +function+ argument can be omitted in favor of an +update_page+ - # block, which evaluates to a string when the template is rendered - # (instead of making an Ajax request first). - # - # The +html_options+ will accept a hash of html attributes for the link tag. Some examples are :class => "nav_button", :id => "articles_nav_button" + # The helper receives a name, JavaScript code, and an optional hash of HTML options. The + # name is used as button label and the JavaScript code goes into its +onclick+ attribute. + # If +html_options+ has an :onclick, that one is put before +function+. # - # Note: if you choose to specify the javascript function in a block, but would like to pass html_options, set the +function+ parameter to nil + # button_to_function "Greeting", "alert('Hello world!')", :class => "ok" + # # => # - # Examples: - # button_to_function "Greeting", "alert('Hello world!')" - # button_to_function "Delete", "if (confirm('Really?')) do_delete()" - # button_to_function "Details" do |page| - # page[:details].visual_effect :toggle_slide - # end - # button_to_function "Details", :class => "details_button" do |page| - # page[:details].visual_effect :toggle_slide - # end - def button_to_function(name, *args, &block) - html_options = args.extract_options!.symbolize_keys - - function = block_given? ? update_page(&block) : args[0] || '' + def button_to_function(name, function='', html_options={}) onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function};" tag(:input, html_options.merge(:type => 'button', :value => name, :onclick => onclick)) diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index 65b8074dbb..e8500b2d9d 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -35,20 +35,6 @@ class JavaScriptHelperTest < ActionView::TestCase button_to_function("Greeting", "alert('Hello world!')") end - def test_button_to_function_with_rjs_block - html = button_to_function( "Greet me!" ) do |page| - page.replace_html 'header', "

Greetings

" - end - assert_dom_equal %(), html - end - - def test_button_to_function_with_rjs_block_and_options - html = button_to_function( "Greet me!", :class => "greeter" ) do |page| - page.replace_html 'header', "

Greetings

" - end - assert_dom_equal %(), html - end - def test_button_to_function_with_onclick assert_dom_equal "", button_to_function("Greeting", "alert('Hello world!')", :onclick => "alert('Goodbye World :(')") -- cgit v1.2.3 From f9472f064fae12d0890075d698d8e5fd81289392 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 25 Mar 2011 00:30:29 +0100 Subject: applies API guidelines to example --- actionpack/lib/action_view/helpers/javascript_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 136d006ad1..5a1d07fd24 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -121,8 +121,8 @@ module ActionView # The +href+ attribute of the tag is set to "#" unles +html_options+ has one. # # link_to_function "Greeting", "alert('Hello world!')", :class => "nav_link" - # Produces: - # Greeting + # # => Greeting + # def link_to_function(name, function, html_options={}) onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;" href = html_options[:href] || '#' -- cgit v1.2.3 From 25181cafee9ef087a14b5134b9fa1f85f758705a Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 25 Mar 2011 09:44:43 +0100 Subject: let the default function in button_to_function be nil I don't know which is the use case for button_to_function(name) but there's a test for it. I am focused now on RJS extraction and do not want to introduce a backwards incompatible change at this moment. Perhaps worth revisiting when the whole thing is done. --- actionpack/lib/action_view/helpers/javascript_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 5a1d07fd24..066f0ab409 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -105,7 +105,7 @@ module ActionView # button_to_function "Greeting", "alert('Hello world!')", :class => "ok" # # => # - def button_to_function(name, function='', html_options={}) + def button_to_function(name, function=nil, html_options={}) onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function};" tag(:input, html_options.merge(:type => 'button', :value => name, :onclick => onclick)) -- cgit v1.2.3 From eea66892c80d51c1b959171c2e3feac67124aaba Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 25 Mar 2011 20:08:13 +0100 Subject: removes support for render :update --- .../lib/action_controller/metal/renderers.rb | 9 +- actionpack/test/controller/assert_select_test.rb | 63 ------ .../test/controller/new_base/render_rjs_test.rb | 71 ------ actionpack/test/controller/render_js_test.rb | 9 - actionpack/test/controller/render_other_test.rb | 237 --------------------- actionpack/test/controller/render_test.rb | 9 - actionpack/test/fixtures/test/delete_with_js.rjs | 2 - actionpack/test/fixtures/test/enum_rjs_test.rjs | 6 - actionpack/test/fixtures/test/greeting.js.rjs | 1 - .../test/render_explicit_html_template.js.rjs | 1 - .../test/render_implicit_html_template.js.rjs | 1 - 11 files changed, 1 insertion(+), 408 deletions(-) delete mode 100644 actionpack/test/controller/new_base/render_rjs_test.rb delete mode 100644 actionpack/test/fixtures/test/delete_with_js.rjs delete mode 100644 actionpack/test/fixtures/test/enum_rjs_test.rjs delete mode 100644 actionpack/test/fixtures/test/greeting.js.rjs delete mode 100644 actionpack/test/fixtures/test/render_explicit_html_template.js.rjs delete mode 100644 actionpack/test/fixtures/test/render_implicit_html_template.js.rjs (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/renderers.rb b/actionpack/lib/action_controller/metal/renderers.rb index 38711c8462..dfda6618e7 100644 --- a/actionpack/lib/action_controller/metal/renderers.rb +++ b/actionpack/lib/action_controller/metal/renderers.rb @@ -41,7 +41,7 @@ module ActionController end # Hash of available renderers, mapping a renderer name to its proc. - # Default keys are :json, :js, :xml and :update. + # Default keys are :json, :js, :xml. RENDERERS = {} # Adds a new renderer to call within controller actions. @@ -107,12 +107,5 @@ module ActionController self.content_type ||= Mime::XML self.response_body = xml.respond_to?(:to_xml) ? xml.to_xml(options) : xml end - - add :update do |proc, options| - view_context = self.view_context - generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(view_context, &proc) - self.content_type = Mime::JS - self.response_body = generator.to_s - end end end diff --git a/actionpack/test/controller/assert_select_test.rb b/actionpack/test/controller/assert_select_test.rb index c72370e49d..878484eb57 100644 --- a/actionpack/test/controller/assert_select_test.rb +++ b/actionpack/test/controller/assert_select_test.rb @@ -34,13 +34,6 @@ class AssertSelectTest < ActionController::TestCase @content = nil end - def rjs() - render :update do |page| - @update.call page - end - @update = nil - end - def xml() render :text=>@content, :layout=>false, :content_type=>Mime::XML @content = nil @@ -219,35 +212,6 @@ class AssertSelectTest < ActionController::TestCase end end - # With single result. - def test_assert_select_from_rjs_with_single_result - render_rjs do |page| - page.replace_html "test", "
foo
\n
foo
" - end - assert_select "div" do |elements| - assert elements.size == 2 - assert_select "#1" - assert_select "#2" - end - assert_select "div#?", /\d+/ do |elements| - assert_select "#1" - assert_select "#2" - end - end - - # With multiple results. - def test_assert_select_from_rjs_with_multiple_results - render_rjs do |page| - page.replace_html "test", "
foo
" - page.replace_html "test2", "
foo
" - end - assert_select "div" do |elements| - assert elements.size == 2 - assert_select "#1" - assert_select "#2" - end - end - def test_elect_with_xml_namespace_attributes render_html %Q{} assert_nothing_raised { assert_select "link[xlink:href=http://nowhere.com]" } @@ -281,28 +245,6 @@ class AssertSelectTest < ActionController::TestCase end end - # With one result. - def test_css_select_from_rjs_with_single_result - render_rjs do |page| - page.replace_html "test", "
foo
\n
foo
" - end - assert_equal 2, css_select("div").size - assert_equal 1, css_select("#1").size - assert_equal 1, css_select("#2").size - end - - # With multiple results. - def test_css_select_from_rjs_with_multiple_results - render_rjs do |page| - page.replace_html "test", "
foo
" - page.replace_html "test2", "
foo
" - end - - assert_equal 2, css_select("div").size - assert_equal 1, css_select("#1").size - assert_equal 1, css_select("#2").size - end - def test_feed_item_encoded render_xml <<-EOF @@ -377,11 +319,6 @@ EOF get :html end - def render_rjs(&block) - @controller.response_with(&block) - get :rjs - end - def render_xml(xml) @controller.response_with = xml get :xml diff --git a/actionpack/test/controller/new_base/render_rjs_test.rb b/actionpack/test/controller/new_base/render_rjs_test.rb deleted file mode 100644 index 74bf865b54..0000000000 --- a/actionpack/test/controller/new_base/render_rjs_test.rb +++ /dev/null @@ -1,71 +0,0 @@ -require 'abstract_unit' - -module RenderRjs - class BasicController < ActionController::Base - layout "application", :only => :index_respond_to - - self.view_paths = [ActionView::FixtureResolver.new( - "layouts/application.html.erb" => "", - "render_rjs/basic/index.js.rjs" => "page[:customer].replace_html render(:partial => 'customer')", - "render_rjs/basic/index_html.js.rjs" => "page[:customer].replace_html :partial => 'customer'", - "render_rjs/basic/index_no_js.js.erb" => "<%= render(:partial => 'developer') %>", - "render_rjs/basic/_customer.js.erb" => "JS Partial", - "render_rjs/basic/_customer.html.erb" => "HTML Partial", - "render_rjs/basic/_developer.html.erb" => "HTML Partial", - "render_rjs/basic/index_locale.js.rjs" => "page[:customer].replace_html :partial => 'customer'", - "render_rjs/basic/_customer.da.html.erb" => "Danish HTML Partial", - "render_rjs/basic/_customer.da.js.erb" => "Danish JS Partial" - )] - - def index - render - end - - def index_respond_to - respond_to do |format| - format.js { render :action => "index_no_js" } - end - end - - def index_locale - self.locale = :da - end - end - - class TestBasic < Rack::TestCase - testing BasicController - - def setup - @old_locale = I18n.locale - end - - def teardown - I18n.locale = @old_locale - end - - test "rendering a partial in an RJS template should pick the JS template over the HTML one" do - get :index, "format" => "js" - assert_response("$(\"customer\").update(\"JS Partial\");") - end - - test "rendering a partial in an RJS template should pick the HTML one if no JS is available" do - get :index_no_js, "format" => "js" - assert_response("HTML Partial") - end - - test "rendering a partial in an RJS template should pick the HTML one if no JS is available on respond_to" do - get :index_respond_to, "format" => "js" - assert_response("HTML Partial") - end - - test "replacing an element with a partial in an RJS template should pick the HTML template over the JS one" do - get :index_html, "format" => "js" - assert_response("$(\"customer\").update(\"HTML Partial\");") - end - - test "replacing an element with a partial in an RJS template with a locale should pick the localed HTML template" do - get :index_locale, "format" => "js" - assert_response("$(\"customer\").update(\"Danish HTML Partial\");") - end - end -end diff --git a/actionpack/test/controller/render_js_test.rb b/actionpack/test/controller/render_js_test.rb index 491c98a0fd..f070109b27 100644 --- a/actionpack/test/controller/render_js_test.rb +++ b/actionpack/test/controller/render_js_test.rb @@ -14,10 +14,6 @@ class RenderJSTest < ActionController::TestCase render :js => "alert('hello')" end - def greeting - # let's just rely on the template - end - def show_partial render :partial => 'partial' end @@ -31,11 +27,6 @@ class RenderJSTest < ActionController::TestCase assert_equal "text/javascript", @response.content_type end - def test_render_with_default_from_accept_header - xhr :get, :greeting - assert_equal "$(\"body\").visualEffect(\"highlight\");", @response.body - end - def test_should_render_js_partial xhr :get, :show_partial, :format => 'js' assert_equal 'partial js', @response.body diff --git a/actionpack/test/controller/render_other_test.rb b/actionpack/test/controller/render_other_test.rb index eda777e7a7..b5e74e373d 100644 --- a/actionpack/test/controller/render_other_test.rb +++ b/actionpack/test/controller/render_other_test.rb @@ -1,6 +1,4 @@ require 'abstract_unit' -require 'controller/fake_models' -require 'pathname' ActionController.add_renderer :simon do |says, options| self.content_type = Mime::TEXT @@ -9,248 +7,13 @@ end class RenderOtherTest < ActionController::TestCase class TestController < ActionController::Base - protect_from_forgery - - def self.controller_path - 'test' - end - - layout :determine_layout - - module RenderTestHelper - def rjs_helper_method_from_module - page.visual_effect :highlight - end - end - - helper RenderTestHelper - helper do - def rjs_helper_method(value) - page.visual_effect :highlight, value - end - end - - def enum_rjs_test - render :update do |page| - page.select('.product').each do |value| - page.rjs_helper_method_from_module - page.rjs_helper_method(value) - page.sortable(value, :url => { :action => "order" }) - page.draggable(value) - end - end - end - - def render_explicit_html_template - end - - def render_custom_code_rjs - render :update, :status => 404 do |page| - page.replace :foo, :partial => 'partial' - end - end - - def render_implicit_html_template - end - - def render_js_with_explicit_template - @project_id = 4 - render :template => 'test/delete_with_js' - end - - def render_js_with_explicit_action_template - @project_id = 4 - render :action => 'delete_with_js' - end - - def delete_with_js - @project_id = 4 - end - - def update_page - render :update do |page| - page.replace_html 'balance', '$37,000,000.00' - page.visual_effect :highlight, 'balance' - end - end - - def update_page_with_instance_variables - @money = '$37,000,000.00' - @div_id = 'balance' - render :update do |page| - page.replace_html @div_id, @money - page.visual_effect :highlight, @div_id - end - end - - def update_page_with_view_method - render :update do |page| - page.replace_html 'person', pluralize(2, 'person') - end - end - - def partial_as_rjs - render :update do |page| - page.replace :foo, :partial => 'partial' - end - end - - def respond_to_partial_as_rjs - respond_to do |format| - format.js do - render :update do |page| - page.replace :foo, :partial => 'partial' - end - end - end - end - - def render_alternate_default - # For this test, the method "default_render" is overridden: - @alternate_default_render = lambda do - render :update do |page| - page.replace :foo, :partial => 'partial' - end - end - end - def render_simon_says render :simon => "foo" end - - private - def default_render - @alternate_default_render ||= nil - if @alternate_default_render - @alternate_default_render.call - else - super - end - end - - def determine_layout - case action_name - when "hello_world", "layout_test", "rendering_without_layout", - "rendering_nothing_on_layout", "render_text_hello_world", - "render_text_hello_world_with_layout", - "hello_world_with_layout_false", - "partial_only", "partial_only_with_layout", - "accessing_params_in_template", - "accessing_params_in_template_with_layout", - "render_with_explicit_template", - "render_with_explicit_string_template", - "update_page", "update_page_with_instance_variables" - - "layouts/standard" - when "action_talk_to_layout", "layout_overriding_layout" - "layouts/talk_from_action" - when "render_implicit_html_template_from_xhr_request" - (request.xhr? ? 'layouts/xhr' : 'layouts/standard') - end - end end tests TestController - def setup - # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get - # a more accurate simulation of what happens in "real life". - super - @controller.logger = Logger.new(nil) - - @request.host = "www.nextangle.com" - end - - def test_enum_rjs_test - ActiveSupport::SecureRandom.stubs(:base64).returns("asdf") - get :enum_rjs_test - body = %{ - $$(".product").each(function(value, index) { - new Effect.Highlight(element,{}); - new Effect.Highlight(value,{}); - Sortable.create(value, {onUpdate:function(){new Ajax.Request('/render_other_test/test/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(value) + '&authenticity_token=' + encodeURIComponent('asdf')})}}); - new Draggable(value, {}); - }); - }.gsub(/^ /, '').strip - assert_equal body, @response.body - end - - def test_explicitly_rendering_an_html_template_with_implicit_html_template_renders_should_be_possible_from_an_rjs_template - [:js, "js"].each do |format| - assert_nothing_raised do - get :render_explicit_html_template, :format => format - assert_equal %(document.write("Hello world\\n");), @response.body - end - end - end - - def test_render_custom_code_rjs - get :render_custom_code_rjs - assert_response 404 - assert_equal %(Element.replace("foo", "partial html");), @response.body - end - - def test_render_in_an_rjs_template_should_pick_html_templates_when_available - [:js, "js"].each do |format| - assert_nothing_raised do - get :render_implicit_html_template, :format => format - assert_equal %(document.write("Hello world\\n");), @response.body - end - end - end - - def test_render_rjs_template_explicitly - get :render_js_with_explicit_template - assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body - end - - def test_rendering_rjs_action_explicitly - get :render_js_with_explicit_action_template - assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body - end - - def test_render_rjs_with_default - get :delete_with_js - assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body - end - - def test_update_page - get :update_page - assert_template nil - assert_equal 'text/javascript; charset=utf-8', @response.headers['Content-Type'] - assert_equal 2, @response.body.split($/).length - end - - def test_update_page_with_instance_variables - get :update_page_with_instance_variables - assert_template nil - assert_equal 'text/javascript; charset=utf-8', @response.headers["Content-Type"] - assert_match(/balance/, @response.body) - assert_match(/\$37/, @response.body) - end - - def test_update_page_with_view_method - get :update_page_with_view_method - assert_template nil - assert_equal 'text/javascript; charset=utf-8', @response.headers["Content-Type"] - assert_match(/2 people/, @response.body) - end - - def test_should_render_html_formatted_partial_with_rjs - xhr :get, :partial_as_rjs - assert_equal %(Element.replace("foo", "partial html");), @response.body - end - - def test_should_render_html_formatted_partial_with_rjs_and_js_format - xhr :get, :respond_to_partial_as_rjs - assert_equal %(Element.replace("foo", "partial html");), @response.body - end - - def test_should_render_with_alternate_default_render - xhr :get, :render_alternate_default - assert_equal %(Element.replace("foo", "partial html");), @response.body - end - def test_using_custom_render_option get :render_simon_says assert_equal "Simon says: foo", @response.body diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index be492152f2..e62f3155c5 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -517,15 +517,6 @@ class TestController < ActionController::Base render :partial => 'partial' end - def render_alternate_default - # For this test, the method "default_render" is overridden: - @alternate_default_render = lambda do - render :update do |page| - page.replace :foo, :partial => 'partial' - end - end - end - def render_to_string_with_partial @partial_only = render_to_string :partial => "partial_only" @partial_with_locals = render_to_string :partial => "customer", :locals => { :customer => Customer.new("david") } diff --git a/actionpack/test/fixtures/test/delete_with_js.rjs b/actionpack/test/fixtures/test/delete_with_js.rjs deleted file mode 100644 index 4b75a955ad..0000000000 --- a/actionpack/test/fixtures/test/delete_with_js.rjs +++ /dev/null @@ -1,2 +0,0 @@ -page.remove 'person' -page.visual_effect :highlight, "project-#{@project_id}" diff --git a/actionpack/test/fixtures/test/enum_rjs_test.rjs b/actionpack/test/fixtures/test/enum_rjs_test.rjs deleted file mode 100644 index e3004076a8..0000000000 --- a/actionpack/test/fixtures/test/enum_rjs_test.rjs +++ /dev/null @@ -1,6 +0,0 @@ -page.select('.product').each do |value| - page.visual_effect :highlight - page.visual_effect :highlight, value - page.sortable(value, :url => { :action => "order" }) - page.draggable(value) -end \ No newline at end of file diff --git a/actionpack/test/fixtures/test/greeting.js.rjs b/actionpack/test/fixtures/test/greeting.js.rjs deleted file mode 100644 index 469fcd8e15..0000000000 --- a/actionpack/test/fixtures/test/greeting.js.rjs +++ /dev/null @@ -1 +0,0 @@ -page[:body].visual_effect :highlight \ No newline at end of file diff --git a/actionpack/test/fixtures/test/render_explicit_html_template.js.rjs b/actionpack/test/fixtures/test/render_explicit_html_template.js.rjs deleted file mode 100644 index 4eb12fd6af..0000000000 --- a/actionpack/test/fixtures/test/render_explicit_html_template.js.rjs +++ /dev/null @@ -1 +0,0 @@ -page.call "document.write", render(:partial => "one.html.erb") diff --git a/actionpack/test/fixtures/test/render_implicit_html_template.js.rjs b/actionpack/test/fixtures/test/render_implicit_html_template.js.rjs deleted file mode 100644 index 3d68041756..0000000000 --- a/actionpack/test/fixtures/test/render_implicit_html_template.js.rjs +++ /dev/null @@ -1 +0,0 @@ -page.call "document.write", render(:partial => "one") -- cgit v1.2.3 From 5850f1693546f14420bf0bc630a48650f0d606d5 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 25 Mar 2011 23:12:09 +0100 Subject: removes the RJS template handler --- .../lib/action_controller/metal/mime_responds.rb | 8 +++--- actionpack/lib/action_view/template/handlers.rb | 2 -- .../lib/action_view/template/handlers/rjs.rb | 13 ---------- actionpack/test/controller/caching_test.rb | 14 ----------- actionpack/test/controller/content_type_test.rb | 9 ------- actionpack/test/controller/mime_responds_test.rb | 29 +--------------------- .../test/controller/new_base/content_type_test.rb | 9 +------ .../test/controller/new_base/render_layout_test.rb | 16 ++++++------ .../formatted_fragment_cached.js.rjs | 6 ----- .../js_fragment_cached_with_partial.js.rjs | 1 - .../old_content_type/render_default_for_rjs.rjs | 1 - .../respond_to/all_types_with_layout.js.rjs | 1 - .../test/fixtures/respond_to/using_defaults.js.rjs | 1 - .../using_defaults_with_type_list.js.rjs | 1 - .../fixtures/respond_with/using_resource.js.rjs | 1 - 15 files changed, 15 insertions(+), 97 deletions(-) delete mode 100644 actionpack/lib/action_view/template/handlers/rjs.rb delete mode 100644 actionpack/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs delete mode 100644 actionpack/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs delete mode 100644 actionpack/test/fixtures/old_content_type/render_default_for_rjs.rjs delete mode 100644 actionpack/test/fixtures/respond_to/all_types_with_layout.js.rjs delete mode 100644 actionpack/test/fixtures/respond_to/using_defaults.js.rjs delete mode 100644 actionpack/test/fixtures/respond_to/using_defaults_with_type_list.js.rjs delete mode 100644 actionpack/test/fixtures/respond_with/using_resource.js.rjs (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb index 618a6cdb7d..16d48e4677 100644 --- a/actionpack/lib/action_controller/metal/mime_responds.rb +++ b/actionpack/lib/action_controller/metal/mime_responds.rb @@ -33,10 +33,10 @@ module ActionController #:nodoc: # and all actions except :edit respond to :xml and # :json. # - # respond_to :rjs, :only => :create + # respond_to :json, :only => :create # # This specifies that the :create action and no other responds - # to :rjs. + # to :json. def respond_to(*mimes) options = mimes.extract_options! @@ -106,8 +106,8 @@ module ActionController #:nodoc: # end # end # - # If the client wants HTML, we just redirect them back to the person list. If they want Javascript - # (format.js), then it is an RJS request and we render the RJS template associated with this action. + # If the client wants HTML, we just redirect them back to the person list. If they want JavaScript, + # then it is an Ajax request and we render the JavaScript template associated with this action. # Lastly, if the client wants XML, we render the created person as XML, but with a twist: we also # include the person's company in the rendered XML, so you get something like this: # diff --git a/actionpack/lib/action_view/template/handlers.rb b/actionpack/lib/action_view/template/handlers.rb index 4438199497..959afa734e 100644 --- a/actionpack/lib/action_view/template/handlers.rb +++ b/actionpack/lib/action_view/template/handlers.rb @@ -3,12 +3,10 @@ module ActionView #:nodoc: class Template module Handlers #:nodoc: autoload :ERB, 'action_view/template/handlers/erb' - autoload :RJS, 'action_view/template/handlers/rjs' autoload :Builder, 'action_view/template/handlers/builder' def self.extended(base) base.register_default_template_handler :erb, ERB.new - base.register_template_handler :rjs, RJS.new base.register_template_handler :builder, Builder.new end diff --git a/actionpack/lib/action_view/template/handlers/rjs.rb b/actionpack/lib/action_view/template/handlers/rjs.rb deleted file mode 100644 index 9d71059134..0000000000 --- a/actionpack/lib/action_view/template/handlers/rjs.rb +++ /dev/null @@ -1,13 +0,0 @@ -module ActionView - module Template::Handlers - class RJS - # Default format used by RJS. - class_attribute :default_format - self.default_format = Mime::JS - - def call(template) - "update_page do |page|;#{template.source}\nend" - end - end - end -end diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 01f3e8f2b6..fada0c7748 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -713,17 +713,10 @@ class FunctionalCachingController < CachingController end end - def js_fragment_cached_with_partial - respond_to do |format| - format.js - end - end - def formatted_fragment_cached respond_to do |format| format.html format.xml - format.js end end @@ -770,13 +763,6 @@ CACHED assert_match("Some cached content", @store.read('views/test.host/functional_caching/inline_fragment_cached')) end - def test_fragment_caching_in_rjs_partials - xhr :get, :js_fragment_cached_with_partial - assert_response :success - assert_match(/Old fragment caching in a partial/, @response.body) - assert_match("Old fragment caching in a partial", @store.read('views/test.host/functional_caching/js_fragment_cached_with_partial')) - end - def test_html_formatted_fragment_caching get :formatted_fragment_cached, :format => "html" assert_response :success diff --git a/actionpack/test/controller/content_type_test.rb b/actionpack/test/controller/content_type_test.rb index 9500c25a32..b12c798302 100644 --- a/actionpack/test/controller/content_type_test.rb +++ b/actionpack/test/controller/content_type_test.rb @@ -35,9 +35,6 @@ class OldContentTypeController < ActionController::Base def render_default_for_builder end - def render_default_for_rjs - end - def render_change_for_builder response.content_type = Mime::HTML render :action => "render_default_for_builder" @@ -129,12 +126,6 @@ class ContentTypeTest < ActionController::TestCase assert_equal "utf-8", @response.charset end - def test_default_for_rjs - xhr :post, :render_default_for_rjs - assert_equal Mime::JS, @response.content_type - assert_equal "utf-8", @response.charset - end - def test_change_for_builder get :render_change_for_builder assert_equal Mime::HTML, @response.content_type diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index be5866e5aa..9e09fc39ed 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -73,13 +73,12 @@ class RespondToController < ActionController::Base def using_defaults respond_to do |type| type.html - type.js type.xml end end def using_defaults_with_type_list - respond_to(:html, :js, :xml) + respond_to(:html, :xml) end def made_for_content_type @@ -130,7 +129,6 @@ class RespondToController < ActionController::Base def all_types_with_layout respond_to do |type| type.html - type.js end end @@ -299,11 +297,6 @@ class RespondToControllerTest < ActionController::TestCase assert_equal "text/html", @response.content_type assert_equal 'Hello world!', @response.body - @request.accept = "text/javascript" - get :using_defaults - assert_equal "text/javascript", @response.content_type - assert_equal '$("body").visualEffect("highlight");', @response.body - @request.accept = "application/xml" get :using_defaults assert_equal "application/xml", @response.content_type @@ -316,11 +309,6 @@ class RespondToControllerTest < ActionController::TestCase assert_equal "text/html", @response.content_type assert_equal 'Hello world!', @response.body - @request.accept = "text/javascript" - get :using_defaults_with_type_list - assert_equal "text/javascript", @response.content_type - assert_equal '$("body").visualEffect("highlight");', @response.body - @request.accept = "application/xml" get :using_defaults_with_type_list assert_equal "application/xml", @response.content_type @@ -428,13 +416,6 @@ class RespondToControllerTest < ActionController::TestCase assert_equal 'HTML', @response.body end - - def test_rjs_type_skips_layout - @request.accept = "text/javascript" - get :all_types_with_layout - assert_equal 'RJS for all_types_with_layout', @response.body - end - def test_html_type_with_layout @request.accept = "text/html" get :all_types_with_layout @@ -444,9 +425,6 @@ class RespondToControllerTest < ActionController::TestCase def test_xhr xhr :get, :js_or_html assert_equal 'JS', @response.body - - xhr :get, :using_defaults - assert_equal '$("body").visualEffect("highlight");', @response.body end def test_custom_constant @@ -643,11 +621,6 @@ class RespondWithControllerTest < ActionController::TestCase end def test_using_resource - @request.accept = "text/javascript" - get :using_resource - assert_equal "text/javascript", @response.content_type - assert_equal '$("body").visualEffect("highlight");', @response.body - @request.accept = "application/xml" get :using_resource assert_equal "application/xml", @response.content_type diff --git a/actionpack/test/controller/new_base/content_type_test.rb b/actionpack/test/controller/new_base/content_type_test.rb index 8ba30944f5..4b70031c90 100644 --- a/actionpack/test/controller/new_base/content_type_test.rb +++ b/actionpack/test/controller/new_base/content_type_test.rb @@ -23,8 +23,7 @@ module ContentType "content_type/implied/i_am_html_erb.html.erb" => "Hello world!", "content_type/implied/i_am_xml_erb.xml.erb" => "Hello world!", "content_type/implied/i_am_html_builder.html.builder" => "xml.p 'Hello'", - "content_type/implied/i_am_xml_builder.xml.builder" => "xml.awesome 'Hello'", - "content_type/implied/i_am_js_rjs.js.rjs" => "page.alert 'hello'" + "content_type/implied/i_am_xml_builder.xml.builder" => "xml.awesome 'Hello'" )] end @@ -93,12 +92,6 @@ module ContentType assert_header "Content-Type", "application/xml; charset=utf-8" end - - test "sets Content-Type as text/javascript when rendering *.js" do - get "/content_type/implied/i_am_js_rjs", "format" => "js" - - assert_header "Content-Type", "text/javascript; charset=utf-8" - end end class ExplicitCharsetTest < Rack::TestCase diff --git a/actionpack/test/controller/new_base/render_layout_test.rb b/actionpack/test/controller/new_base/render_layout_test.rb index bb2a953536..d3dcb5cad6 100644 --- a/actionpack/test/controller/new_base/render_layout_test.rb +++ b/actionpack/test/controller/new_base/render_layout_test.rb @@ -70,8 +70,8 @@ module ControllerLayouts class MismatchFormatController < ::ApplicationController self.view_paths = [ActionView::FixtureResolver.new( "layouts/application.html.erb" => "<%= yield %>", - "controller_layouts/mismatch_format/index.js.rjs" => "page[:test].ext", - "controller_layouts/mismatch_format/implicit.rjs" => "page[:test].ext" + "controller_layouts/mismatch_format/index.xml.builder" => "xml.instruct!", + "controller_layouts/mismatch_format/implicit.builder" => "xml.instruct!" )] def explicit @@ -81,15 +81,17 @@ module ControllerLayouts class MismatchFormatTest < Rack::TestCase testing ControllerLayouts::MismatchFormatController + + XML_INSTRUCT = %Q(\n) - test "if JS is selected, an HTML template is not also selected" do - get :index, "format" => "js" - assert_response "$(\"test\").ext();" + test "if XML is selected, an HTML template is not also selected" do + get :index, :format => "xml" + assert_response XML_INSTRUCT end - test "if JS is implicitly selected, an HTML template is not also selected" do + test "if XML is implicitly selected, an HTML template is not also selected" do get :implicit - assert_response "$(\"test\").ext();" + assert_response XML_INSTRUCT end test "if an HTML template is explicitly provides for a JS template, an error is raised" do diff --git a/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs b/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs deleted file mode 100644 index 057f15e62f..0000000000 --- a/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs +++ /dev/null @@ -1,6 +0,0 @@ -page.assign 'title', 'Hey' -cache do - page['element_1'].visual_effect :highlight - page['element_2'].visual_effect :highlight -end -page.assign 'footer', 'Bye' diff --git a/actionpack/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs b/actionpack/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs deleted file mode 100644 index 248842c9da..0000000000 --- a/actionpack/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs +++ /dev/null @@ -1 +0,0 @@ -page.replace_html 'notices', :partial => 'partial' \ No newline at end of file diff --git a/actionpack/test/fixtures/old_content_type/render_default_for_rjs.rjs b/actionpack/test/fixtures/old_content_type/render_default_for_rjs.rjs deleted file mode 100644 index 8d614d04ad..0000000000 --- a/actionpack/test/fixtures/old_content_type/render_default_for_rjs.rjs +++ /dev/null @@ -1 +0,0 @@ -page.alert 'hello world!' \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/all_types_with_layout.js.rjs b/actionpack/test/fixtures/respond_to/all_types_with_layout.js.rjs deleted file mode 100644 index b7aec7c505..0000000000 --- a/actionpack/test/fixtures/respond_to/all_types_with_layout.js.rjs +++ /dev/null @@ -1 +0,0 @@ -page << "RJS for all_types_with_layout" \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/using_defaults.js.rjs b/actionpack/test/fixtures/respond_to/using_defaults.js.rjs deleted file mode 100644 index 469fcd8e15..0000000000 --- a/actionpack/test/fixtures/respond_to/using_defaults.js.rjs +++ /dev/null @@ -1 +0,0 @@ -page[:body].visual_effect :highlight \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.js.rjs b/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.js.rjs deleted file mode 100644 index 469fcd8e15..0000000000 --- a/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.js.rjs +++ /dev/null @@ -1 +0,0 @@ -page[:body].visual_effect :highlight \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_with/using_resource.js.rjs b/actionpack/test/fixtures/respond_with/using_resource.js.rjs deleted file mode 100644 index 737c175a4e..0000000000 --- a/actionpack/test/fixtures/respond_with/using_resource.js.rjs +++ /dev/null @@ -1 +0,0 @@ -page[:body].visual_effect :highlight -- cgit v1.2.3 From 06bdaae071a43d5e149def2ac97001d04e26fa42 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 26 Mar 2011 22:19:18 +0100 Subject: removes ActionView::Helpers::ScriptaculousHelper --- actionpack/lib/action_view/helpers.rb | 2 - .../lib/action_view/helpers/capture_helper.rb | 4 +- .../lib/action_view/helpers/javascript_helper.rb | 32 --- .../action_view/helpers/scriptaculous_helper.rb | 263 --------------------- .../test/template/scriptaculous_helper_test.rb | 86 ------- 5 files changed, 2 insertions(+), 385 deletions(-) delete mode 100644 actionpack/lib/action_view/helpers/scriptaculous_helper.rb delete mode 100644 actionpack/test/template/scriptaculous_helper_test.rb (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers.rb b/actionpack/lib/action_view/helpers.rb index cb1ab64121..88aafc82d5 100644 --- a/actionpack/lib/action_view/helpers.rb +++ b/actionpack/lib/action_view/helpers.rb @@ -21,7 +21,6 @@ module ActionView #:nodoc: autoload :OutputSafetyHelper autoload :RecordTagHelper autoload :SanitizeHelper - autoload :ScriptaculousHelper autoload :SprocketsHelper autoload :TagHelper autoload :TextHelper @@ -52,7 +51,6 @@ module ActionView #:nodoc: include OutputSafetyHelper include RecordTagHelper include SanitizeHelper - include ScriptaculousHelper include SprocketsHelper include TagHelper include TextHelper diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index 9ac7dff1ec..3808e231f1 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -107,8 +107,8 @@ module ActionView # <%= javascript_include_tag :defaults %> # <% end %> # - # That will place script tags for Prototype, Scriptaculous, and application.js (if it exists) - # on the page; this technique is useful if you'll only be using these scripts in a few views. + # That will place +script+ tags for your default set of JavaScript files on the page; + # this technique is useful if you'll only be using these scripts in a few views. # # Note that content_for concatenates the blocks it is given for a particular # identifier in order. For example: diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 066f0ab409..ea8f31c45b 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -1,39 +1,7 @@ require 'action_view/helpers/tag_helper' module ActionView - # = Action View JavaScript Helpers module Helpers - # Provides functionality for working with JavaScript in your views. - # - # == Ajax, controls and visual effects - # - # * For information on using Ajax, see - # ActionView::Helpers::PrototypeHelper. - # * For information on using controls and visual effects, see - # ActionView::Helpers::ScriptaculousHelper. - # - # == Including the JavaScript libraries into your pages - # - # Rails includes the Prototype JavaScript framework and the Scriptaculous - # JavaScript controls and visual effects library. If you wish to use - # these libraries and their helpers (ActionView::Helpers::PrototypeHelper - # and ActionView::Helpers::ScriptaculousHelper), you must do one of the - # following: - # - # * Use <%= javascript_include_tag :defaults %> in the HEAD - # section of your page (recommended): This function will return - # references to the JavaScript files created by the +rails+ command in - # your public/javascripts directory. Using it is recommended as - # the browser can then cache the libraries instead of fetching all the - # functions anew on every request. - # * Use <%= javascript_include_tag 'prototype' %>: As above, but - # will only include the Prototype core library, which means you are able - # to use all basic AJAX functionality. For the Scriptaculous-based - # JavaScript helpers, like visual effects, autocompletion, drag and drop - # and so on, you should use the method described above. - # - # For documentation on +javascript_include_tag+ see - # ActionView::Helpers::AssetTagHelper. module JavaScriptHelper include PrototypeHelper diff --git a/actionpack/lib/action_view/helpers/scriptaculous_helper.rb b/actionpack/lib/action_view/helpers/scriptaculous_helper.rb deleted file mode 100644 index 8610c2469e..0000000000 --- a/actionpack/lib/action_view/helpers/scriptaculous_helper.rb +++ /dev/null @@ -1,263 +0,0 @@ -require 'action_view/helpers/javascript_helper' -require 'active_support/json' - -module ActionView - # = Action View Scriptaculous Helpers - module Helpers - # Provides a set of helpers for calling Scriptaculous[http://script.aculo.us/] - # JavaScript functions, including those which create Ajax controls and visual - # effects. - # - # To be able to use these helpers, you must include the Prototype - # JavaScript framework and the Scriptaculous JavaScript library in your - # pages. See the documentation for ActionView::Helpers::JavaScriptHelper - # for more information on including the necessary JavaScript. - # - # The Scriptaculous helpers' behavior can be tweaked with various options. - # - # See the documentation at http://script.aculo.us for more information on - # using these helpers in your application. - module ScriptaculousHelper - TOGGLE_EFFECTS = [:toggle_appear, :toggle_slide, :toggle_blind] - - # Returns a JavaScript snippet to be used on the Ajax callbacks for - # starting visual effects. - # - # If no +element_id+ is given, it assumes "element" which should be a local - # variable in the generated JavaScript execution context. This can be - # used for example with +drop_receiving_element+: - # - # <%= drop_receiving_element (...), :loading => visual_effect(:fade) %> - # - # This would fade the element that was dropped on the drop receiving - # element. - # - # For toggling visual effects, you can use :toggle_appear, :toggle_slide, and - # :toggle_blind which will alternate between appear/fade, slidedown/slideup, and - # blinddown/blindup respectively. - # - # You can change the behaviour with various options, see - # http://script.aculo.us for more documentation. - def visual_effect(name, element_id = false, js_options = {}) - element = element_id ? ActiveSupport::JSON.encode(element_id) : "element" - - js_options[:queue] = if js_options[:queue].is_a?(Hash) - '{' + js_options[:queue].map {|k, v| k == :limit ? "#{k}:#{v}" : "#{k}:'#{v}'" }.join(',') + '}' - elsif js_options[:queue] - "'#{js_options[:queue]}'" - end if js_options[:queue] - - [:endcolor, :direction, :startcolor, :scaleMode, :restorecolor].each do |option| - js_options[option] = "'#{js_options[option]}'" if js_options[option] - end - - if TOGGLE_EFFECTS.include? name.to_sym - "Effect.toggle(#{element},'#{name.to_s.gsub(/^toggle_/,'')}',#{options_for_javascript(js_options)});" - else - "new Effect.#{name.to_s.camelize}(#{element},#{options_for_javascript(js_options)});" - end - end - - # Makes the element with the DOM ID specified by +element_id+ sortable - # by drag-and-drop and make an Ajax call whenever the sort order has - # changed. By default, the action called gets the serialized sortable - # element as parameters. - # - # Example: - # - # <%= sortable_element("my_list", :url => { :action => "order" }) %> - # - # In the example, the action gets a "my_list" array parameter - # containing the values of the ids of elements the sortable consists - # of, in the current order. - # - # Important: For this to work, the sortable elements must have id - # attributes in the form "string_identifier". For example, "item_1". Only - # the identifier part of the id attribute will be serialized. - # - # Additional +options+ are: - # - # * :format - A regular expression to determine what to send as the - # serialized id to the server (the default is /^[^_]*_(.*)$/). - # - # * :constraint - Whether to constrain the dragging to either - # :horizontal or :vertical (or false to make it unconstrained). - # - # * :overlap - Calculate the item overlap in the :horizontal - # or :vertical direction. - # - # * :tag - Which children of the container element to treat as - # sortable (default is li). - # - # * :containment - Takes an element or array of elements to treat as - # potential drop targets (defaults to the original target element). - # - # * :only - A CSS class name or array of class names used to filter - # out child elements as candidates. - # - # * :scroll - Determines whether to scroll the list during drag - # operations if the list runs past the visual border. - # - # * :tree - Determines whether to treat nested lists as part of the - # main sortable list. This means that you can create multi-layer lists, - # and not only sort items at the same level, but drag and sort items - # between levels. - # - # * :hoverclass - If set, the Droppable will have this additional CSS class - # when an accepted Draggable is hovered over it. - # - # * :handle - Sets whether the element should only be draggable by an - # embedded handle. The value may be a string referencing a CSS class value - # (as of script.aculo.us V1.5). The first child/grandchild/etc. element - # found within the element that has this CSS class value will be used as - # the handle. - # - # * :ghosting - Clones the element and drags the clone, leaving - # the original in place until the clone is dropped (default is false). - # - # * :dropOnEmpty - If true the Sortable container will be made into - # a Droppable, that can receive a Draggable (as according to the containment - # rules) as a child element when there are no more elements inside (default - # is false). - # - # * :onChange - Called whenever the sort order changes while dragging. When - # dragging from one Sortable to another, the callback is called once on each - # Sortable. Gets the affected element as its parameter. - # - # * :onUpdate - Called when the drag ends and the Sortable's order is - # changed in any way. When dragging from one Sortable to another, the callback - # is called once on each Sortable. Gets the container as its parameter. - # - # See http://script.aculo.us for more documentation. - def sortable_element(element_id, options = {}) - javascript_tag(sortable_element_js(element_id, options).chop!) - end - - def sortable_element_js(element_id, options = {}) #:nodoc: - options[:with] ||= "Sortable.serialize(#{ActiveSupport::JSON.encode(element_id)})" - options[:onUpdate] ||= "function(){" + remote_function(options) + "}" - options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) } - - [:tag, :overlap, :constraint, :handle].each do |option| - options[option] = "'#{options[option]}'" if options[option] - end - - options[:containment] = array_or_string_for_javascript(options[:containment]) if options[:containment] - options[:only] = array_or_string_for_javascript(options[:only]) if options[:only] - - %(Sortable.create(#{ActiveSupport::JSON.encode(element_id)}, #{options_for_javascript(options)});) - end - - # Makes the element with the DOM ID specified by +element_id+ draggable. - # - # Example: - # <%= draggable_element("my_image", :revert => true) - # - # You can change the behaviour with various options, see - # http://script.aculo.us for more documentation. - def draggable_element(element_id, options = {}) - javascript_tag(draggable_element_js(element_id, options).chop!) - end - - def draggable_element_js(element_id, options = {}) #:nodoc: - %(new Draggable(#{ActiveSupport::JSON.encode(element_id)}, #{options_for_javascript(options)});) - end - - # Makes the element with the DOM ID specified by +element_id+ receive - # dropped draggable elements (created by +draggable_element+). - # and make an AJAX call. By default, the action called gets the DOM ID - # of the element as parameter. - # - # Example: - # <%= drop_receiving_element("my_cart", :url => - # { :controller => "cart", :action => "add" }) %> - # - # You can change the behaviour with various options, see - # http://script.aculo.us for more documentation. - # - # Some of these +options+ include: - # * :accept - Set this to a string or an array of strings describing the - # allowable CSS classes that the +draggable_element+ must have in order - # to be accepted by this +drop_receiving_element+. - # - # * :confirm - Adds a confirmation dialog. Example: - # - # :confirm => "Are you sure you want to do this?" - # - # * :hoverclass - If set, the +drop_receiving_element+ will have - # this additional CSS class when an accepted +draggable_element+ is - # hovered over it. - # - # * :onDrop - Called when a +draggable_element+ is dropped onto - # this element. Override this callback with a JavaScript expression to - # change the default drop behaviour. Example: - # - # :onDrop => "function(draggable_element, droppable_element, event) { alert('I like bananas') }" - # - # This callback gets three parameters: The Draggable element, the Droppable - # element and the Event object. You can extract additional information about - # the drop - like if the Ctrl or Shift keys were pressed - from the Event object. - # - # * :with - A JavaScript expression specifying the parameters for - # the XMLHttpRequest. Any expressions should return a valid URL query string. - def drop_receiving_element(element_id, options = {}) - javascript_tag(drop_receiving_element_js(element_id, options).chop!) - end - - def drop_receiving_element_js(element_id, options = {}) #:nodoc: - options[:with] ||= "'id=' + encodeURIComponent(element.id)" - options[:onDrop] ||= "function(element){" + remote_function(options) + "}" - options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) } - - options[:accept] = array_or_string_for_javascript(options[:accept]) if options[:accept] - options[:hoverclass] = "'#{options[:hoverclass]}'" if options[:hoverclass] - - # Confirmation happens during the onDrop callback, so it can be removed from the options - options.delete(:confirm) if options[:confirm] - - %(Droppables.add(#{ActiveSupport::JSON.encode(element_id)}, #{options_for_javascript(options)});) - end - - protected - def array_or_string_for_javascript(option) - if option.kind_of?(Array) - "['#{option.join('\',\'')}']" - elsif !option.nil? - "'#{option}'" - end - end - end - - module PrototypeHelper - class JavaScriptGenerator - module GeneratorMethods - # Starts a script.aculo.us visual effect. See - # ActionView::Helpers::ScriptaculousHelper for more information. - def visual_effect(name, id = nil, options = {}) - record @context.send(:visual_effect, name, id, options) - end - - # Creates a script.aculo.us sortable element. Useful - # to recreate sortable elements after items get added - # or deleted. - # See ActionView::Helpers::ScriptaculousHelper for more information. - def sortable(id, options = {}) - record @context.send(:sortable_element_js, id, options) - end - - # Creates a script.aculo.us draggable element. - # See ActionView::Helpers::ScriptaculousHelper for more information. - def draggable(id, options = {}) - record @context.send(:draggable_element_js, id, options) - end - - # Creates a script.aculo.us drop receiving element. - # See ActionView::Helpers::ScriptaculousHelper for more information. - def drop_receiving(id, options = {}) - record @context.send(:drop_receiving_element_js, id, options) - end - end - end - end - end -end diff --git a/actionpack/test/template/scriptaculous_helper_test.rb b/actionpack/test/template/scriptaculous_helper_test.rb deleted file mode 100644 index 233012bfdd..0000000000 --- a/actionpack/test/template/scriptaculous_helper_test.rb +++ /dev/null @@ -1,86 +0,0 @@ -require 'abstract_unit' - -class ScriptaculousHelperTest < ActionView::TestCase - tests ActionView::Helpers::ScriptaculousHelper - - def url_for(options) - url = "http://www.example.com/" - url << options[:action].to_s if options and options[:action] - url - end - - def test_effect - assert_equal "new Effect.Highlight(\"posts\",{});", visual_effect(:highlight, "posts") - assert_equal "new Effect.Highlight(\"posts\",{});", visual_effect("highlight", :posts) - assert_equal "new Effect.Highlight(\"posts\",{});", visual_effect(:highlight, :posts) - assert_equal "new Effect.Fade(\"fademe\",{duration:4.0});", visual_effect(:fade, "fademe", :duration => 4.0) - assert_equal "new Effect.Shake(element,{});", visual_effect(:shake) - assert_equal "new Effect.DropOut(\"dropme\",{queue:'end'});", visual_effect(:drop_out, 'dropme', :queue => :end) - assert_equal "new Effect.Highlight(\"status\",{endcolor:'#EEEEEE'});", visual_effect(:highlight, 'status', :endcolor => '#EEEEEE') - assert_equal "new Effect.Highlight(\"status\",{restorecolor:'#500000', startcolor:'#FEFEFE'});", visual_effect(:highlight, 'status', :restorecolor => '#500000', :startcolor => '#FEFEFE') - - # chop the queue params into a comma separated list - beginning, ending = 'new Effect.DropOut("dropme",{queue:{', '}});' - ve = [ - visual_effect(:drop_out, 'dropme', :queue => {:position => "end", :scope => "test", :limit => 2}), - visual_effect(:drop_out, 'dropme', :queue => {:scope => :list, :limit => 2}), - visual_effect(:drop_out, 'dropme', :queue => {:position => :end, :scope => :test, :limit => 2}) - ].collect { |v| v[beginning.length..-ending.length-1].split(',') } - - assert ve[0].include?("limit:2") - assert ve[0].include?("scope:'test'") - assert ve[0].include?("position:'end'") - - assert ve[1].include?("limit:2") - assert ve[1].include?("scope:'list'") - - assert ve[2].include?("limit:2") - assert ve[2].include?("scope:'test'") - assert ve[2].include?("position:'end'") - end - - def test_toggle_effects - assert_equal "Effect.toggle(\"posts\",'appear',{});", visual_effect(:toggle_appear, "posts") - assert_equal "Effect.toggle(\"posts\",'slide',{});", visual_effect(:toggle_slide, "posts") - assert_equal "Effect.toggle(\"posts\",'blind',{});", visual_effect(:toggle_blind, "posts") - assert_equal "Effect.toggle(\"posts\",'appear',{});", visual_effect("toggle_appear", "posts") - assert_equal "Effect.toggle(\"posts\",'slide',{});", visual_effect("toggle_slide", "posts") - assert_equal "Effect.toggle(\"posts\",'blind',{});", visual_effect("toggle_blind", "posts") - end - - - def test_sortable_element - assert_dom_equal %(), - sortable_element("mylist", :url => { :action => "order" }) - assert_equal %(), - sortable_element("mylist", :tag => "div", :constraint => "horizontal", :url => { :action => "order" }) - assert_dom_equal %||, - sortable_element("mylist", :containment => ['list1','list2'], :constraint => "horizontal", :url => { :action => "order" }) - assert_dom_equal %(), - sortable_element("mylist", :containment => 'list1', :constraint => "horizontal", :url => { :action => "order" }) - end - - def test_draggable_element - assert_dom_equal %(), - draggable_element("product_13") - assert_equal %(), - draggable_element("product_13", :revert => true) - end - - def test_drop_receiving_element - assert_dom_equal %(), - drop_receiving_element("droptarget1") - assert_dom_equal %(), - drop_receiving_element("droptarget1", :accept => 'products') - assert_dom_equal %(), - drop_receiving_element("droptarget1", :accept => 'products', :update => 'infobox') - assert_dom_equal %(), - drop_receiving_element("droptarget1", :accept => ['tshirts','mugs'], :update => 'infobox') - assert_dom_equal %(), - drop_receiving_element('droptarget1', :hoverclass=>'dropready', :url=>{:action=>'update_drop'}, :confirm => 'Are you sure?') - - end - def protect_against_forgery? - false - end -end -- cgit v1.2.3 From 90de26703e6e5243ebb5fffc513780f8c69c71b4 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 26 Mar 2011 22:25:32 +0100 Subject: removes ActionView::Helpers::PrototypeHelper --- actionpack/lib/action_view/helpers.rb | 2 - .../lib/action_view/helpers/javascript_helper.rb | 2 - .../lib/action_view/helpers/prototype_helper.rb | 852 --------------------- actionpack/test/template/prototype_helper_test.rb | 476 ------------ 4 files changed, 1332 deletions(-) delete mode 100644 actionpack/lib/action_view/helpers/prototype_helper.rb delete mode 100644 actionpack/test/template/prototype_helper_test.rb (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers.rb b/actionpack/lib/action_view/helpers.rb index 88aafc82d5..205116f610 100644 --- a/actionpack/lib/action_view/helpers.rb +++ b/actionpack/lib/action_view/helpers.rb @@ -17,7 +17,6 @@ module ActionView #:nodoc: autoload :FormTagHelper autoload :JavaScriptHelper, "action_view/helpers/javascript_helper" autoload :NumberHelper - autoload :PrototypeHelper autoload :OutputSafetyHelper autoload :RecordTagHelper autoload :SanitizeHelper @@ -47,7 +46,6 @@ module ActionView #:nodoc: include FormTagHelper include JavaScriptHelper include NumberHelper - include PrototypeHelper include OutputSafetyHelper include RecordTagHelper include SanitizeHelper diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index ea8f31c45b..d7228bab67 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -3,8 +3,6 @@ require 'action_view/helpers/tag_helper' module ActionView module Helpers module JavaScriptHelper - include PrototypeHelper - JS_ESCAPE_MAP = { '\\' => '\\\\', ' '<\/', diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb deleted file mode 100644 index 506db24dc2..0000000000 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ /dev/null @@ -1,852 +0,0 @@ -require 'set' -require 'active_support/json' -require 'active_support/core_ext/object/blank' -require 'active_support/core_ext/string/output_safety' - -module ActionView - # = Action View Prototype Helpers - module Helpers - # Prototype[http://www.prototypejs.org/] is a JavaScript library that provides - # DOM[http://en.wikipedia.org/wiki/Document_Object_Model] manipulation, - # Ajax[http://www.adaptivepath.com/publications/essays/archives/000385.php] - # functionality, and more traditional object-oriented facilities for JavaScript. - # This module provides a set of helpers to make it more convenient to call - # functions from Prototype using Rails, including functionality to call remote - # Rails methods (that is, making a background request to a Rails action) using Ajax. - # This means that you can call actions in your controllers without - # reloading the page, but still update certain parts of it using - # injections into the DOM. A common use case is having a form that adds - # a new element to a list without reloading the page or updating a shopping - # cart total when a new item is added. - # - # == Usage - # To be able to use these helpers, you must first include the Prototype - # JavaScript framework in your pages. - # - # javascript_include_tag 'prototype' - # - # (See the documentation for - # ActionView::Helpers::JavaScriptHelper for more information on including - # this and other JavaScript files in your Rails templates.) - # - # Now you're ready to call a remote action either through a link... - # - # link_to_remote "Add to cart", - # :url => { :action => "add", :id => product.id }, - # :update => { :success => "cart", :failure => "error" } - # - # ...through a form... - # - # <%= form_remote_tag :url => '/shipping' do -%> - #
<%= submit_tag 'Recalculate Shipping' %>
- # <% end -%> - # - # As you can see, there are numerous ways to use Prototype's Ajax functions (and actually more than - # are listed here); check out the documentation for each method to find out more about its usage and options. - # - # === Common Options - # See link_to_remote for documentation of options common to all Ajax - # helpers; any of the options specified by link_to_remote can be used - # by the other helpers. - # - # == Designing your Rails actions for Ajax - # When building your action handlers (that is, the Rails actions that receive your background requests), it's - # important to remember a few things. First, whatever your action would normally return to the browser, it will - # return to the Ajax call. As such, you typically don't want to render with a layout. This call will cause - # the layout to be transmitted back to your page, and, if you have a full HTML/CSS, will likely mess a lot of things up. - # You can turn the layout off on particular actions by doing the following: - # - # class SiteController < ActionController::Base - # layout "standard", :except => [:ajax_method, :more_ajax, :another_ajax] - # end - # - # Optionally, you could do this in the method you wish to lack a layout: - # - # render :layout => false - # - # You can tell the type of request from within your action using the request.xhr? (XmlHttpRequest, the - # method that Ajax uses to make background requests) method. - # def name - # # Is this an XmlHttpRequest request? - # if (request.xhr?) - # render :text => @name.to_s - # else - # # No? Then render an action. - # render :action => 'view_attribute', :attr => @name - # end - # end - # - # The else clause can be left off and the current action will render with full layout and template. An extension - # to this solution was posted to Ryan Heneise's blog at ArtOfMission["http://www.artofmission.com/"]. - # - # layout proc{ |c| c.request.xhr? ? false : "application" } - # - # Dropping this in your ApplicationController turns the layout off for every request that is an "xhr" request. - # - # If you are just returning a little data or don't want to build a template for your output, you may opt to simply - # render text output, like this: - # - # render :text => 'Return this from my method!' - # - # Since whatever the method returns is injected into the DOM, this will simply inject some text (or HTML, if you - # tell it to). This is usually how small updates, such updating a cart total or a file count, are handled. - # - # == Updating multiple elements - # See JavaScriptGenerator for information on updating multiple elements - # on the page in an Ajax response. - module PrototypeHelper - CALLBACKS = Set.new([ :create, :uninitialized, :loading, :loaded, - :interactive, :complete, :failure, :success ] + - (100..599).to_a) - AJAX_OPTIONS = Set.new([ :before, :after, :condition, :url, - :asynchronous, :method, :insertion, :position, - :form, :with, :update, :script, :type ]).merge(CALLBACKS) - - # Returns the JavaScript needed for a remote function. - # See the link_to_remote documentation at https://github.com/rails/prototype_legacy_helper as it takes the same arguments. - # - # Example: - # # Generates: { :action => :update_options }) %>"> - # - # - # - def remote_function(options) - javascript_options = options_for_ajax(options) - - update = '' - if options[:update] && options[:update].is_a?(Hash) - update = [] - update << "success:'#{options[:update][:success]}'" if options[:update][:success] - update << "failure:'#{options[:update][:failure]}'" if options[:update][:failure] - update = '{' + update.join(',') + '}' - elsif options[:update] - update << "'#{options[:update]}'" - end - - function = update.empty? ? - "new Ajax.Request(" : - "new Ajax.Updater(#{update}, " - - url_options = options[:url] - function << "'#{ERB::Util.html_escape(escape_javascript(url_for(url_options)))}'" - function << ", #{javascript_options})" - - function = "#{options[:before]}; #{function}" if options[:before] - function = "#{function}; #{options[:after]}" if options[:after] - function = "if (#{options[:condition]}) { #{function}; }" if options[:condition] - function = "if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }" if options[:confirm] - - return function.html_safe - end - - # All the methods were moved to GeneratorMethods so that - # #include_helpers_from_context has nothing to overwrite. - class JavaScriptGenerator #:nodoc: - def initialize(context, &block) #:nodoc: - @context, @lines = context, [] - include_helpers_from_context - @context.with_output_buffer(@lines) do - @context.instance_exec(self, &block) - end - end - - private - def include_helpers_from_context - extend @context.helpers if @context.respond_to?(:helpers) - extend GeneratorMethods - end - - # JavaScriptGenerator generates blocks of JavaScript code that allow you - # to change the content and presentation of multiple DOM elements. Use - # this in your Ajax response bodies, either in a \