From 0d6e8edc2a47a4b4c6824936632bfb83850db343 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sat, 4 May 2013 15:09:22 +0200 Subject: Move actionpack/lib/action_view* into actionview/lib --- actionpack/lib/action_view.rb | 93 - actionpack/lib/action_view/base.rb | 201 --- actionpack/lib/action_view/buffers.rb | 49 - actionpack/lib/action_view/context.rb | 36 - actionpack/lib/action_view/dependency_tracker.rb | 93 - actionpack/lib/action_view/digestor.rb | 85 - actionpack/lib/action_view/flows.rb | 76 - actionpack/lib/action_view/helpers.rb | 58 - .../lib/action_view/helpers/active_model_helper.rb | 49 - .../lib/action_view/helpers/asset_tag_helper.rb | 316 ---- .../lib/action_view/helpers/asset_url_helper.rb | 355 ---- .../lib/action_view/helpers/atom_feed_helper.rb | 203 --- actionpack/lib/action_view/helpers/cache_helper.rb | 196 -- .../lib/action_view/helpers/capture_helper.rb | 216 --- .../lib/action_view/helpers/controller_helper.rb | 25 - actionpack/lib/action_view/helpers/csrf_helper.rb | 30 - actionpack/lib/action_view/helpers/date_helper.rb | 1083 ----------- actionpack/lib/action_view/helpers/debug_helper.rb | 39 - actionpack/lib/action_view/helpers/form_helper.rb | 1880 -------------------- .../lib/action_view/helpers/form_options_helper.rb | 832 --------- .../lib/action_view/helpers/form_tag_helper.rb | 744 -------- .../lib/action_view/helpers/javascript_helper.rb | 75 - .../lib/action_view/helpers/number_helper.rb | 441 ----- .../action_view/helpers/output_safety_helper.rb | 38 - .../lib/action_view/helpers/record_tag_helper.rb | 106 -- .../lib/action_view/helpers/rendering_helper.rb | 90 - .../lib/action_view/helpers/sanitize_helper.rb | 256 --- actionpack/lib/action_view/helpers/tag_helper.rb | 176 -- actionpack/lib/action_view/helpers/tags.rb | 39 - actionpack/lib/action_view/helpers/tags/base.rb | 147 -- .../lib/action_view/helpers/tags/check_box.rb | 64 - .../lib/action_view/helpers/tags/checkable.rb | 16 - .../helpers/tags/collection_check_boxes.rb | 43 - .../action_view/helpers/tags/collection_helpers.rb | 84 - .../helpers/tags/collection_radio_buttons.rb | 36 - .../action_view/helpers/tags/collection_select.rb | 28 - .../lib/action_view/helpers/tags/color_field.rb | 25 - .../lib/action_view/helpers/tags/date_field.rb | 13 - .../lib/action_view/helpers/tags/date_select.rb | 72 - .../lib/action_view/helpers/tags/datetime_field.rb | 22 - .../helpers/tags/datetime_local_field.rb | 19 - .../action_view/helpers/tags/datetime_select.rb | 8 - .../lib/action_view/helpers/tags/email_field.rb | 8 - .../lib/action_view/helpers/tags/file_field.rb | 8 - .../helpers/tags/grouped_collection_select.rb | 29 - .../lib/action_view/helpers/tags/hidden_field.rb | 8 - actionpack/lib/action_view/helpers/tags/label.rb | 65 - .../lib/action_view/helpers/tags/month_field.rb | 13 - .../lib/action_view/helpers/tags/number_field.rb | 18 - .../lib/action_view/helpers/tags/password_field.rb | 12 - .../lib/action_view/helpers/tags/radio_button.rb | 31 - .../lib/action_view/helpers/tags/range_field.rb | 8 - .../lib/action_view/helpers/tags/search_field.rb | 24 - actionpack/lib/action_view/helpers/tags/select.rb | 40 - .../lib/action_view/helpers/tags/tel_field.rb | 8 - .../lib/action_view/helpers/tags/text_area.rb | 18 - .../lib/action_view/helpers/tags/text_field.rb | 29 - .../lib/action_view/helpers/tags/time_field.rb | 13 - .../lib/action_view/helpers/tags/time_select.rb | 8 - .../action_view/helpers/tags/time_zone_select.rb | 20 - .../lib/action_view/helpers/tags/url_field.rb | 8 - .../lib/action_view/helpers/tags/week_field.rb | 13 - actionpack/lib/action_view/helpers/text_helper.rb | 442 ----- .../lib/action_view/helpers/translation_helper.rb | 107 -- actionpack/lib/action_view/helpers/url_helper.rb | 616 ------- actionpack/lib/action_view/locale/en.yml | 56 - actionpack/lib/action_view/log_subscriber.rb | 30 - actionpack/lib/action_view/lookup_context.rb | 241 --- actionpack/lib/action_view/model_naming.rb | 12 - actionpack/lib/action_view/path_set.rb | 77 - actionpack/lib/action_view/railtie.rb | 39 - actionpack/lib/action_view/record_identifier.rb | 84 - .../lib/action_view/renderer/abstract_renderer.rb | 47 - .../lib/action_view/renderer/partial_renderer.rb | 492 ----- actionpack/lib/action_view/renderer/renderer.rb | 50 - .../renderer/streaming_template_renderer.rb | 103 -- .../lib/action_view/renderer/template_renderer.rb | 96 - actionpack/lib/action_view/routing_url_for.rb | 107 -- actionpack/lib/action_view/template.rb | 340 ---- actionpack/lib/action_view/template/error.rb | 138 -- actionpack/lib/action_view/template/handlers.rb | 53 - .../lib/action_view/template/handlers/builder.rb | 26 - .../lib/action_view/template/handlers/erb.rb | 146 -- .../lib/action_view/template/handlers/raw.rb | 11 - actionpack/lib/action_view/template/resolver.rb | 326 ---- actionpack/lib/action_view/template/text.rb | 34 - actionpack/lib/action_view/template/types.rb | 57 - actionpack/lib/action_view/test_case.rb | 272 --- actionpack/lib/action_view/testing/resolvers.rb | 50 - actionpack/lib/action_view/vendor/html-scanner.rb | 20 - .../vendor/html-scanner/html/document.rb | 68 - .../action_view/vendor/html-scanner/html/node.rb | 532 ------ .../vendor/html-scanner/html/sanitizer.rb | 188 -- .../vendor/html-scanner/html/selector.rb | 830 --------- .../vendor/html-scanner/html/tokenizer.rb | 107 -- .../vendor/html-scanner/html/version.rb | 11 - 96 files changed, 14646 deletions(-) delete mode 100644 actionpack/lib/action_view.rb delete mode 100644 actionpack/lib/action_view/base.rb delete mode 100644 actionpack/lib/action_view/buffers.rb delete mode 100644 actionpack/lib/action_view/context.rb delete mode 100644 actionpack/lib/action_view/dependency_tracker.rb delete mode 100644 actionpack/lib/action_view/digestor.rb delete mode 100644 actionpack/lib/action_view/flows.rb delete mode 100644 actionpack/lib/action_view/helpers.rb delete mode 100644 actionpack/lib/action_view/helpers/active_model_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/asset_tag_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/asset_url_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/atom_feed_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/cache_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/capture_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/controller_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/csrf_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/date_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/debug_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/form_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/form_options_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/form_tag_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/javascript_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/number_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/output_safety_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/record_tag_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/rendering_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/sanitize_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/tag_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/tags.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/base.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/check_box.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/checkable.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/collection_helpers.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/collection_radio_buttons.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/collection_select.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/color_field.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/date_field.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/date_select.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/datetime_field.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/datetime_local_field.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/datetime_select.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/email_field.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/file_field.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/grouped_collection_select.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/hidden_field.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/label.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/month_field.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/number_field.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/password_field.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/radio_button.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/range_field.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/search_field.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/select.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/tel_field.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/text_area.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/text_field.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/time_field.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/time_select.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/time_zone_select.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/url_field.rb delete mode 100644 actionpack/lib/action_view/helpers/tags/week_field.rb delete mode 100644 actionpack/lib/action_view/helpers/text_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/translation_helper.rb delete mode 100644 actionpack/lib/action_view/helpers/url_helper.rb delete mode 100644 actionpack/lib/action_view/locale/en.yml delete mode 100644 actionpack/lib/action_view/log_subscriber.rb delete mode 100644 actionpack/lib/action_view/lookup_context.rb delete mode 100644 actionpack/lib/action_view/model_naming.rb delete mode 100644 actionpack/lib/action_view/path_set.rb delete mode 100644 actionpack/lib/action_view/railtie.rb delete mode 100644 actionpack/lib/action_view/record_identifier.rb delete mode 100644 actionpack/lib/action_view/renderer/abstract_renderer.rb delete mode 100644 actionpack/lib/action_view/renderer/partial_renderer.rb delete mode 100644 actionpack/lib/action_view/renderer/renderer.rb delete mode 100644 actionpack/lib/action_view/renderer/streaming_template_renderer.rb delete mode 100644 actionpack/lib/action_view/renderer/template_renderer.rb delete mode 100644 actionpack/lib/action_view/routing_url_for.rb delete mode 100644 actionpack/lib/action_view/template.rb delete mode 100644 actionpack/lib/action_view/template/error.rb delete mode 100644 actionpack/lib/action_view/template/handlers.rb delete mode 100644 actionpack/lib/action_view/template/handlers/builder.rb delete mode 100644 actionpack/lib/action_view/template/handlers/erb.rb delete mode 100644 actionpack/lib/action_view/template/handlers/raw.rb delete mode 100644 actionpack/lib/action_view/template/resolver.rb delete mode 100644 actionpack/lib/action_view/template/text.rb delete mode 100644 actionpack/lib/action_view/template/types.rb delete mode 100644 actionpack/lib/action_view/test_case.rb delete mode 100644 actionpack/lib/action_view/testing/resolvers.rb delete mode 100644 actionpack/lib/action_view/vendor/html-scanner.rb delete mode 100644 actionpack/lib/action_view/vendor/html-scanner/html/document.rb delete mode 100644 actionpack/lib/action_view/vendor/html-scanner/html/node.rb delete mode 100644 actionpack/lib/action_view/vendor/html-scanner/html/sanitizer.rb delete mode 100644 actionpack/lib/action_view/vendor/html-scanner/html/selector.rb delete mode 100644 actionpack/lib/action_view/vendor/html-scanner/html/tokenizer.rb delete mode 100644 actionpack/lib/action_view/vendor/html-scanner/html/version.rb (limited to 'actionpack') diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb deleted file mode 100644 index 4aafbcb655..0000000000 --- a/actionpack/lib/action_view.rb +++ /dev/null @@ -1,93 +0,0 @@ -#-- -# Copyright (c) 2004-2013 David Heinemeier Hansson -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -#++ - -require 'active_support' -require 'active_support/rails' -require 'action_pack' - -module ActionView - extend ActiveSupport::Autoload - - eager_autoload do - autoload :Base - autoload :Context - autoload :CompiledTemplates, "action_view/context" - autoload :Digestor - autoload :Helpers - autoload :LookupContext - autoload :PathSet - autoload :RecordIdentifier - autoload :RoutingUrlFor - autoload :Template - - autoload_under "renderer" do - autoload :Renderer - autoload :AbstractRenderer - autoload :PartialRenderer - autoload :TemplateRenderer - autoload :StreamingTemplateRenderer - end - - autoload_at "action_view/template/resolver" do - autoload :Resolver - autoload :PathResolver - autoload :FileSystemResolver - autoload :OptimizedFileSystemResolver - autoload :FallbackFileSystemResolver - end - - autoload_at "action_view/buffers" do - autoload :OutputBuffer - autoload :StreamingBuffer - end - - autoload_at "action_view/flows" do - autoload :OutputFlow - autoload :StreamingFlow - end - - autoload_at "action_view/template/error" do - autoload :MissingTemplate - autoload :ActionViewError - autoload :EncodingError - autoload :MissingRequestError - autoload :TemplateError - autoload :WrongEncodingError - end - end - - autoload :TestCase - - ENCODING_FLAG = '#.*coding[:=]\s*(\S+)[ \t]*' - - def self.eager_load! - super - ActionView::Template.eager_load! - end -end - -require 'active_support/core_ext/string/output_safety' - -ActiveSupport.on_load(:i18n) do - I18n.load_path << "#{File.dirname(__FILE__)}/action_view/locale/en.yml" -end diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb deleted file mode 100644 index 08253de3f4..0000000000 --- a/actionpack/lib/action_view/base.rb +++ /dev/null @@ -1,201 +0,0 @@ -require 'active_support/core_ext/module/attr_internal' -require 'active_support/core_ext/class/attribute_accessors' -require 'active_support/ordered_options' -require 'action_view/log_subscriber' - -module ActionView #:nodoc: - # = Action View Base - # - # Action View templates can be written in several ways. If the template file has a .erb extension then it uses a mixture of ERB - # (included in Ruby) and HTML. If the template file has a .builder extension then Jim Weirich's Builder::XmlMarkup library is used. - # - # == ERB - # - # 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 - # <% @people.each do |person| %> - # Name: <%= person.name %>
- # <% 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: - # - # <%# WRONG %> - # Hi, Mr. <% puts "Frodo" %> - # - # If you absolutely must write from within a function use +concat+. - # - # <%- and -%> suppress leading and trailing whitespace, including the trailing newline, and can be used interchangeably with <% and %>. - # - # === Using sub templates - # - # Using sub templates allows you to sidestep tedious replication and extract common display structures in shared templates. The - # classic example is the use of a header and footer (even though the Action Pack-way would be to use Layouts): - # - # <%= render "shared/header" %> - # Something really specific and terrific - # <%= render "shared/footer" %> - # - # As you see, we use the output embeddings for the render methods. The render call itself will just return a string holding the - # result of the rendering. The output embedding writes it to the current template. - # - # But you don't have to restrict yourself to static includes. Templates can share variables amongst themselves by using instance - # variables defined using the regular embedding tags. Like this: - # - # <% @page_title = "A Wonderful Hello" %> - # <%= render "shared/header" %> - # - # Now the header can pick up on the @page_title variable and use it for outputting a title tag: - # - # <%= @page_title %> - # - # === Passing local variables to sub templates - # - # You can pass local variables to sub templates by using a hash with the variable names as keys and the objects as values: - # - # <%= render "shared/header", { headline: "Welcome", person: person } %> - # - # These can now be accessed in shared/header with: - # - # Headline: <%= headline %> - # First name: <%= person.first_name %> - # - # If you need to find out whether a certain local variable has been assigned a value in a particular render call, - # you need to use the following pattern: - # - # <% if local_assigns.has_key? :headline %> - # Headline: <%= headline %> - # <% end %> - # - # Testing using defined? headline will not work. This is an implementation restriction. - # - # === Template caching - # - # By default, Rails will compile each template to a method in order to render it. When you alter a template, - # Rails will check the file's modification time and recompile it in development mode. - # - # == Builder - # - # 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: - # - # xml.em("emphasized") # => emphasized - # xml.em { xml.b("emph & bold") } # => emph & bold - # xml.a("A Link", "href" => "http://onestepback.org") # => A Link - # xml.target("name" => "compile", "option" => "fast") # => - # # NOTE: order of attributes is not specified. - # - # Any method with a block will be treated as an XML markup tag with nested markup in the block. For example, the following: - # - # xml.div do - # xml.h1(@person.name) - # xml.p(@person.bio) - # end - # - # would produce something like: - # - #
- #

David Heinemeier Hansson

- #

A product of Danish Design during the Winter of '79...

- #
- # - # A full-length RSS example actually used on Basecamp: - # - # xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do - # xml.channel do - # xml.title(@feed_title) - # xml.link(@url) - # xml.description "Basecamp: Recent items" - # xml.language "en-us" - # xml.ttl "40" - # - # @recent_items.each do |item| - # xml.item do - # xml.title(item_title(item)) - # xml.description(item_description(item)) if item_description(item) - # xml.pubDate(item_pubDate(item)) - # xml.guid(@person.firm.account.url + @recent_items.url(item)) - # xml.link(@person.firm.account.url + @recent_items.url(item)) - # - # xml.tag!("dc:creator", item.author_name) if item_has_creator?(item) - # end - # end - # end - # end - # - # More builder documentation can be found at http://builder.rubyforge.org. - class Base - include Helpers, ::ERB::Util, Context - - # Specify the proc used to decorate input tags that refer to attributes with errors. - cattr_accessor :field_error_proc - @@field_error_proc = Proc.new{ |html_tag, instance| "
#{html_tag}
".html_safe } - - # How to complete the streaming when an exception occurs. - # This is our best guess: first try to close the attribute, then the tag. - cattr_accessor :streaming_completion_on_exception - @@streaming_completion_on_exception = %(">) - - # Specify whether rendering within namespaced controllers should prefix - # the partial paths for ActiveModel objects with the namespace. - # (e.g., an Admin::PostsController would render @post using /admin/posts/_post.erb) - cattr_accessor :prefix_partial_path_with_controller_namespace - @@prefix_partial_path_with_controller_namespace = true - - # Specify default_formats that can be rendered. - cattr_accessor :default_formats - - class_attribute :_routes - class_attribute :logger - - class << self - delegate :erb_trim_mode=, :to => 'ActionView::Template::Handlers::ERB' - - def cache_template_loading - ActionView::Resolver.caching? - end - - def cache_template_loading=(value) - ActionView::Resolver.caching = value - end - - def xss_safe? #:nodoc: - true - end - end - - attr_accessor :view_renderer - attr_internal :config, :assigns - - delegate :lookup_context, :to => :view_renderer - delegate :formats, :formats=, :locale, :locale=, :view_paths, :view_paths=, :to => :lookup_context - - def assign(new_assigns) # :nodoc: - @_assigns = new_assigns.each { |key, value| instance_variable_set("@#{key}", value) } - end - - def initialize(context = nil, assigns = {}, controller = nil, formats = nil) #:nodoc: - @_config = ActiveSupport::InheritableOptions.new - - if context.is_a?(ActionView::Renderer) - @view_renderer = context - else - lookup_context = context.is_a?(ActionView::LookupContext) ? - context : ActionView::LookupContext.new(context) - lookup_context.formats = formats if formats - lookup_context.prefixes = controller._prefixes if controller - @view_renderer = ActionView::Renderer.new(lookup_context) - end - - assign(assigns) - assign_controller(controller) - _prepare_context - end - - ActiveSupport.run_load_hooks(:action_view, self) - end -end diff --git a/actionpack/lib/action_view/buffers.rb b/actionpack/lib/action_view/buffers.rb deleted file mode 100644 index 361a0dccbe..0000000000 --- a/actionpack/lib/action_view/buffers.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'active_support/core_ext/string/output_safety' - -module ActionView - class OutputBuffer < ActiveSupport::SafeBuffer #:nodoc: - def initialize(*) - super - encode! - end - - def <<(value) - return self if value.nil? - super(value.to_s) - end - alias :append= :<< - - def safe_concat(value) - return self if value.nil? - super(value.to_s) - end - alias :safe_append= :safe_concat - end - - class StreamingBuffer #:nodoc: - def initialize(block) - @block = block - end - - def <<(value) - value = value.to_s - value = ERB::Util.h(value) unless value.html_safe? - @block.call(value) - end - alias :concat :<< - alias :append= :<< - - def safe_concat(value) - @block.call(value.to_s) - end - alias :safe_append= :safe_concat - - def html_safe? - true - end - - def html_safe - self - end - end -end diff --git a/actionpack/lib/action_view/context.rb b/actionpack/lib/action_view/context.rb deleted file mode 100644 index ee263df484..0000000000 --- a/actionpack/lib/action_view/context.rb +++ /dev/null @@ -1,36 +0,0 @@ -module ActionView - module CompiledTemplates #:nodoc: - # holds compiled template code - end - - # = Action View Context - # - # Action View contexts are supplied to Action Controller to render a template. - # The default Action View context is ActionView::Base. - # - # In order to work with ActionController, a Context must just include this module. - # The initialization of the variables used by the context (@output_buffer, @view_flow, - # and @virtual_path) is responsibility of the object that includes this module - # (although you can call _prepare_context defined below). - module Context - include CompiledTemplates - attr_accessor :output_buffer, :view_flow - - # Prepares the context by setting the appropriate instance variables. - # :api: plugin - def _prepare_context - @view_flow = OutputFlow.new - @output_buffer = nil - @virtual_path = nil - end - - # Encapsulates the interaction with the view flow so it - # returns the correct buffer on +yield+. This is usually - # overwritten by helpers to add more behavior. - # :api: plugin - def _layout_for(name=nil) - name ||= :layout - view_flow.get(name).html_safe - end - end -end diff --git a/actionpack/lib/action_view/dependency_tracker.rb b/actionpack/lib/action_view/dependency_tracker.rb deleted file mode 100644 index b2e8334077..0000000000 --- a/actionpack/lib/action_view/dependency_tracker.rb +++ /dev/null @@ -1,93 +0,0 @@ -require 'thread_safe' - -module ActionView - class DependencyTracker - @trackers = ThreadSafe::Cache.new - - def self.find_dependencies(name, template) - tracker = @trackers[template.handler] - - if tracker.present? - tracker.call(name, template) - else - [] - end - end - - def self.register_tracker(extension, tracker) - handler = Template.handler_for_extension(extension) - @trackers[handler] = tracker - end - - def self.remove_tracker(handler) - @trackers.delete(handler) - end - - class ERBTracker - EXPLICIT_DEPENDENCY = /# Template Dependency: (\S+)/ - - # Matches: - # render partial: "comments/comment", collection: commentable.comments - # render "comments/comments" - # render 'comments/comments' - # render('comments/comments') - # - # render(@topic) => render("topics/topic") - # render(topics) => render("topics/topic") - # render(message.topics) => render("topics/topic") - RENDER_DEPENDENCY = / - render\s* # render, followed by optional whitespace - \(? # start an optional parenthesis for the render call - (partial:|:partial\s+=>)?\s* # naming the partial, used with collection -- 1st capture - ([@a-z"'][@\w\/\."']+) # the template name itself -- 2nd capture - /x - - def self.call(name, template) - new(name, template).dependencies - end - - def initialize(name, template) - @name, @template = name, template - end - - def dependencies - render_dependencies + explicit_dependencies - end - - attr_reader :name, :template - private :name, :template - - private - - def source - template.source - end - - def directory - name.split("/")[0..-2].join("/") - end - - def render_dependencies - source.scan(RENDER_DEPENDENCY). - collect(&:second).uniq. - - # render(@topic) => render("topics/topic") - # render(topics) => render("topics/topic") - # render(message.topics) => render("topics/topic") - collect { |name| name.sub(/\A@?([a-z_]+\.)*([a-z_]+)\z/) { "#{$2.pluralize}/#{$2.singularize}" } }. - - # render("headline") => render("message/headline") - collect { |name| name.include?("/") ? name : "#{directory}/#{name}" }. - - # replace quotes from string renders - collect { |name| name.gsub(/["']/, "") } - end - - def explicit_dependencies - source.scan(EXPLICIT_DEPENDENCY).flatten.uniq - end - end - - register_tracker :erb, ERBTracker - end -end diff --git a/actionpack/lib/action_view/digestor.rb b/actionpack/lib/action_view/digestor.rb deleted file mode 100644 index 9324a1ac50..0000000000 --- a/actionpack/lib/action_view/digestor.rb +++ /dev/null @@ -1,85 +0,0 @@ -require 'thread_safe' -require 'action_view/dependency_tracker' - -module ActionView - class Digestor - cattr_reader(:cache) - @@cache = ThreadSafe::Cache.new - - def self.digest(name, format, finder, options = {}) - cache_key = [name, format] + Array.wrap(options[:dependencies]) - @@cache[cache_key.join('.')] ||= begin - klass = options[:partial] || name.include?("/_") ? PartialDigestor : Digestor - klass.new(name, format, finder, options).digest - end - end - - attr_reader :name, :format, :finder, :options - - def initialize(name, format, finder, options={}) - @name, @format, @finder, @options = name, format, finder, options - end - - def digest - Digest::MD5.hexdigest("#{source}-#{dependency_digest}").tap do |digest| - logger.try :info, "Cache digest for #{name}.#{format}: #{digest}" - end - rescue ActionView::MissingTemplate - logger.try :error, "Couldn't find template for digesting: #{name}.#{format}" - '' - end - - def dependencies - DependencyTracker.find_dependencies(name, template) - rescue ActionView::MissingTemplate - [] # File doesn't exist, so no dependencies - end - - def nested_dependencies - dependencies.collect do |dependency| - dependencies = PartialDigestor.new(dependency, format, finder).nested_dependencies - dependencies.any? ? { dependency => dependencies } : dependency - end - end - - private - - def logger - ActionView::Base.logger - end - - def logical_name - name.gsub(%r|/_|, "/") - end - - def partial? - false - end - - def template - @template ||= finder.find(logical_name, [], partial?, formats: [ format ]) - end - - def source - template.source - end - - def dependency_digest - template_digests = dependencies.collect do |template_name| - Digestor.digest(template_name, format, finder, partial: true) - end - - (template_digests + injected_dependencies).join("-") - end - - def injected_dependencies - Array.wrap(options[:dependencies]) - end - end - - class PartialDigestor < Digestor # :nodoc: - def partial? - true - end - end -end diff --git a/actionpack/lib/action_view/flows.rb b/actionpack/lib/action_view/flows.rb deleted file mode 100644 index c0e458cd41..0000000000 --- a/actionpack/lib/action_view/flows.rb +++ /dev/null @@ -1,76 +0,0 @@ -require 'active_support/core_ext/string/output_safety' - -module ActionView - class OutputFlow #:nodoc: - attr_reader :content - - def initialize - @content = Hash.new { |h,k| h[k] = ActiveSupport::SafeBuffer.new } - end - - # Called by _layout_for to read stored values. - def get(key) - @content[key] - end - - # Called by each renderer object to set the layout contents. - def set(key, value) - @content[key] = value - end - - # Called by content_for - def append(key, value) - @content[key] << value - end - alias_method :append!, :append - - end - - class StreamingFlow < OutputFlow #:nodoc: - def initialize(view, fiber) - @view = view - @parent = nil - @child = view.output_buffer - @content = view.view_flow.content - @fiber = fiber - @root = Fiber.current.object_id - end - - # Try to get an stored content. If the content - # is not available and we are inside the layout - # fiber, we set that we are waiting for the given - # key and yield. - def get(key) - return super if @content.key?(key) - - if inside_fiber? - view = @view - - begin - @waiting_for = key - view.output_buffer, @parent = @child, view.output_buffer - Fiber.yield - ensure - @waiting_for = nil - view.output_buffer, @child = @parent, view.output_buffer - end - end - - super - end - - # Appends the contents for the given key. This is called - # by provides and resumes back to the fiber if it is - # the key it is waiting for. - def append!(key, value) - super - @fiber.resume if @waiting_for == key - end - - private - - def inside_fiber? - Fiber.current.object_id != @root - end - end -end \ No newline at end of file diff --git a/actionpack/lib/action_view/helpers.rb b/actionpack/lib/action_view/helpers.rb deleted file mode 100644 index 8a78685ae1..0000000000 --- a/actionpack/lib/action_view/helpers.rb +++ /dev/null @@ -1,58 +0,0 @@ -require 'active_support/benchmarkable' - -module ActionView #:nodoc: - module Helpers #:nodoc: - extend ActiveSupport::Autoload - - autoload :ActiveModelHelper - autoload :AssetTagHelper - autoload :AssetUrlHelper - autoload :AtomFeedHelper - autoload :CacheHelper - autoload :CaptureHelper - autoload :ControllerHelper - autoload :CsrfHelper - autoload :DateHelper - autoload :DebugHelper - autoload :FormHelper - autoload :FormOptionsHelper - autoload :FormTagHelper - autoload :JavaScriptHelper, "action_view/helpers/javascript_helper" - autoload :NumberHelper - autoload :OutputSafetyHelper - autoload :RecordTagHelper - autoload :RenderingHelper - autoload :SanitizeHelper - autoload :TagHelper - autoload :TextHelper - autoload :TranslationHelper - autoload :UrlHelper - - extend ActiveSupport::Concern - - include ActiveSupport::Benchmarkable - include ActiveModelHelper - include AssetTagHelper - include AssetUrlHelper - include AtomFeedHelper - include CacheHelper - include CaptureHelper - include ControllerHelper - include CsrfHelper - include DateHelper - include DebugHelper - include FormHelper - include FormOptionsHelper - include FormTagHelper - include JavaScriptHelper - include NumberHelper - include OutputSafetyHelper - include RecordTagHelper - include RenderingHelper - include SanitizeHelper - include TagHelper - include TextHelper - include TranslationHelper - include UrlHelper - end -end diff --git a/actionpack/lib/action_view/helpers/active_model_helper.rb b/actionpack/lib/action_view/helpers/active_model_helper.rb deleted file mode 100644 index 901f433c70..0000000000 --- a/actionpack/lib/action_view/helpers/active_model_helper.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'active_support/core_ext/class/attribute_accessors' -require 'active_support/core_ext/enumerable' - -module ActionView - # = Active Model Helpers - module Helpers - module ActiveModelHelper - end - - module ActiveModelInstanceTag - def object - @active_model_object ||= begin - object = super - object.respond_to?(:to_model) ? object.to_model : object - end - end - - def content_tag(*) - error_wrapping(super) - end - - def tag(type, options, *) - tag_generate_errors?(options) ? error_wrapping(super) : super - end - - def error_wrapping(html_tag) - if object_has_errors? - Base.field_error_proc.call(html_tag, self) - else - html_tag - end - end - - def error_message - object.errors[@method_name] - end - - private - - def object_has_errors? - object.respond_to?(:errors) && object.errors.respond_to?(:[]) && error_message.present? - end - - def tag_generate_errors?(options) - options['type'] != 'hidden' - end - end - end -end diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb deleted file mode 100644 index 2b3a3c6a29..0000000000 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ /dev/null @@ -1,316 +0,0 @@ -require 'active_support/core_ext/array/extract_options' -require 'active_support/core_ext/hash/keys' -require 'action_view/helpers/asset_url_helper' -require 'action_view/helpers/tag_helper' - -module ActionView - # = Action View Asset Tag Helpers - module Helpers #:nodoc: - # This module provides methods for generating HTML that links views to assets such - # as images, javascripts, stylesheets, and feeds. These methods do not verify - # the assets exist before linking to them: - # - # image_tag("rails.png") - # # => Rails - # stylesheet_link_tag("application") - # # => - module AssetTagHelper - extend ActiveSupport::Concern - - include AssetUrlHelper - include TagHelper - - # Returns an HTML script tag for each of the +sources+ provided. - # - # Sources may be paths to JavaScript files. Relative paths are assumed to be relative - # to assets/javascripts, full paths are assumed to be relative to the document - # root. Relative paths are idiomatic, use absolute paths only when needed. - # - # When passing paths, the ".js" extension is optional. - # - # You can modify the HTML attributes of the script tag by passing a hash as the - # last argument. - # - # When the Asset Pipeline is enabled, you can pass the name of your manifest as - # source, and include other JavaScript or CoffeeScript files inside the manifest. - # - # javascript_include_tag "xmlhr" - # # => - # - # javascript_include_tag "xmlhr.js" - # # => - # - # javascript_include_tag "common.javascript", "/elsewhere/cools" - # # => - # # - # - # javascript_include_tag "http://www.example.com/xmlhr" - # # => - # - # javascript_include_tag "http://www.example.com/xmlhr.js" - # # => - def javascript_include_tag(*sources) - options = sources.extract_options!.stringify_keys - path_options = options.extract!('protocol').symbolize_keys - - sources.uniq.map { |source| - tag_options = { - "src" => path_to_javascript(source, path_options) - }.merge!(options) - content_tag(:script, "", tag_options) - }.join("\n").html_safe - end - - # Returns a stylesheet link tag for the sources specified as arguments. If - # you don't specify an extension, .css will be appended automatically. - # You can modify the link attributes by passing a hash as the last argument. - # For historical reasons, the 'media' attribute will always be present and defaults - # to "screen", so you must explicitly set it to "all" for the stylesheet(s) to - # apply to all media types. - # - # stylesheet_link_tag "style" - # # => - # - # stylesheet_link_tag "style.css" - # # => - # - # stylesheet_link_tag "http://www.example.com/style.css" - # # => - # - # stylesheet_link_tag "style", media: "all" - # # => - # - # stylesheet_link_tag "style", media: "print" - # # => - # - # stylesheet_link_tag "random.styles", "/css/stylish" - # # => - # # - def stylesheet_link_tag(*sources) - options = sources.extract_options!.stringify_keys - path_options = options.extract!('protocol').symbolize_keys - - sources.uniq.map { |source| - tag_options = { - "rel" => "stylesheet", - "media" => "screen", - "href" => path_to_stylesheet(source, path_options) - }.merge!(options) - tag(:link, tag_options) - }.join("\n").html_safe - end - - # Returns a link tag that browsers and news readers can use to auto-detect - # an RSS or Atom feed. The +type+ can either be :rss (default) or - # :atom. Control the link options in url_for format using the - # +url_options+. You can modify the LINK tag itself in +tag_options+. - # - # ==== Options - # - # * :rel - Specify the relation of this link, defaults to "alternate" - # * :type - Override the auto-generated mime type - # * :title - Specify the title of the link, defaults to the +type+ - # - # ==== Examples - # - # auto_discovery_link_tag - # # => - # auto_discovery_link_tag(:atom) - # # => - # auto_discovery_link_tag(:rss, {action: "feed"}) - # # => - # auto_discovery_link_tag(:rss, {action: "feed"}, {title: "My RSS"}) - # # => - # auto_discovery_link_tag(:rss, {controller: "news", action: "feed"}) - # # => - # auto_discovery_link_tag(:rss, "http://www.example.com/feed.rss", {title: "Example RSS"}) - # # => - def auto_discovery_link_tag(type = :rss, url_options = {}, tag_options = {}) - if !(type == :rss || type == :atom) && tag_options[:type].blank? - raise ArgumentError.new("You should pass :type tag_option key explicitly, because you have passed #{type} type other than :rss or :atom.") - end - - tag( - "link", - "rel" => tag_options[:rel] || "alternate", - "type" => tag_options[:type] || Mime::Type.lookup_by_extension(type.to_s).to_s, - "title" => tag_options[:title] || type.to_s.upcase, - "href" => url_options.is_a?(Hash) ? url_for(url_options.merge(:only_path => false)) : url_options - ) - end - - # Returns a link loading a favicon file. You may specify a different file - # in the first argument. The helper accepts an additional options hash where - # you can override "rel" and "type". - # - # ==== Options - # - # * :rel - Specify the relation of this link, defaults to 'shortcut icon' - # * :type - Override the auto-generated mime type, defaults to 'image/vnd.microsoft.icon' - # - # ==== Examples - # - # favicon_link_tag '/myicon.ico' - # # => - # - # Mobile Safari looks for a different tag, pointing to an image that - # will be used if you add the page to the home screen of an iPod Touch, iPhone, or iPad. - # The following call would generate such a tag: - # - # favicon_link_tag '/mb-icon.png', rel: 'apple-touch-icon', type: 'image/png' - # # => - def favicon_link_tag(source='favicon.ico', options={}) - tag('link', { - :rel => 'shortcut icon', - :type => 'image/vnd.microsoft.icon', - :href => path_to_image(source) - }.merge!(options.symbolize_keys)) - end - - # Returns an HTML image tag for the +source+. The +source+ can be a full - # path or a file. - # - # ==== Options - # - # You can add HTML attributes using the +options+. The +options+ supports - # three additional keys for convenience and conformance: - # - # * :alt - If no alt text is given, the file name part of the - # +source+ is used (capitalized and without the extension) - # * :size - Supplied as "{Width}x{Height}" or "{Number}", so "30x45" becomes - # width="30" and height="45", and "50" becomes width="50" and height="50". - # :size will be ignored if the value is not in the correct format. - # - # ==== Examples - # - # image_tag("icon") - # # => Icon - # image_tag("icon.png") - # # => Icon - # image_tag("icon.png", size: "16x10", alt: "Edit Entry") - # # => Edit Entry - # image_tag("/icons/icon.gif", size: "16") - # # => Icon - # image_tag("/icons/icon.gif", height: '32', width: '32') - # # => Icon - # image_tag("/icons/icon.gif", class: "menu_icon") - # # => Icon - def image_tag(source, options={}) - options = options.symbolize_keys - - src = options[:src] = path_to_image(source) - - unless src =~ /^(?:cid|data):/ || src.blank? - options[:alt] = options.fetch(:alt){ image_alt(src) } - end - - if size = options.delete(:size) - options[:width], options[:height] = size.split("x") if size =~ %r{\A\d+x\d+\z} - options[:width] = options[:height] = size if size =~ %r{\A\d+\z} - end - - tag("img", options) - end - - # Returns a string suitable for an html image tag alt attribute. - # The +src+ argument is meant to be an image file path. - # The method removes the basename of the file path and the digest, - # if any. It also removes hyphens and underscores from file names and - # replaces them with spaces, returning a space-separated, titleized - # string. - # - # ==== Examples - # - # image_tag('rails.png') - # # => Rails - # - # image_tag('hyphenated-file-name.png') - # # => Hyphenated file name - # - # image_tag('underscored_file_name.png') - # # => Underscored file name - def image_alt(src) - File.basename(src, '.*').sub(/-[[:xdigit:]]{32}\z/, '').tr('-_', ' ').capitalize - end - - # Returns an html video tag for the +sources+. If +sources+ is a string, - # a single video tag will be returned. If +sources+ is an array, a video - # tag with nested source tags for each source will be returned. The - # +sources+ can be full paths or files that exists in your public videos - # directory. - # - # ==== Options - # You can add HTML attributes using the +options+. The +options+ supports - # two additional keys for convenience and conformance: - # - # * :poster - Set an image (like a screenshot) to be shown - # before the video loads. The path is calculated like the +src+ of +image_tag+. - # * :size - Supplied as "{Width}x{Height}", so "30x45" becomes - # width="30" and height="45". :size will be ignored if the - # value is not in the correct format. - # - # ==== Examples - # - # video_tag("trailer") - # # =>