Permalink
Browse files

documentation project patches, closes #7342, #7319, #7316, #7190 [jer…

…emymcanally]

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-stable@6471 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 24267c4 commit b564d7e1e94a0184b86886943b80563402533f77 @technoweenie technoweenie committed Mar 27, 2007
View
@@ -1,5 +1,9 @@
*SVN*
+* Cleaned up, corrected, and mildly expanded ActionPack documentation. Closes #7190 [jeremymcanally]
+
+* Small collection of ActionController documentation cleanups. Closes #7319 [jeremymcanally]
+
* Performance: patch cgi/session/pstore to require digest/md5 once rather than per #initialize. #7583 [Stefan Kaes]
* Deprecation: verification with :redirect_to => :named_route shouldn't be deprecated. #7525 [Justin French]
@@ -1,7 +1,7 @@
module ActionController
module Assertions
module DomAssertions
- # test 2 html strings to be equivalent, i.e. identical up to reordering of attributes
+ # Test two HTML strings for equivalency (e.g., identical up to reordering of attributes)
def assert_dom_equal(expected, actual, message="")
clean_backtrace do
expected_dom = HTML::Document.new(expected).root
@@ -11,7 +11,7 @@ def assert_dom_equal(expected, actual, message="")
end
end
- # negated form of +assert_dom_equivalent+
+ # The negated form of +assert_dom_equivalent+.
def assert_dom_not_equal(expected, actual, message="")
clean_backtrace do
expected_dom = HTML::Document.new(expected).root
@@ -1,7 +1,7 @@
module ActionController
module Assertions
module ModelAssertions
- # ensures that the passed record is valid by active record standards. returns the error messages if not
+ # Ensures that the passed record is valid by ActiveRecord standards and returns any error messages if it is not.
def assert_valid(record)
clean_backtrace do
assert record.valid?, record.errors.full_messages.join("\n")
@@ -120,6 +120,7 @@ def assert_template(expected = nil, message=nil)
end
private
+ # Recognizes the route for a given path.
def recognized_request_for(path, request_method = nil)
path = "/#{path}" unless path.first == '/'
@@ -132,6 +133,7 @@ def recognized_request_for(path, request_method = nil)
request
end
+ # Proxy to to_param if the object will respond to it.
def parameterize(value)
value.respond_to?(:to_param) ? value.to_param : value
end
@@ -82,6 +82,7 @@ def assert_routing(path, options, defaults={}, extras={}, message=nil)
end
private
+ # Recognizes the route for a given path.
def recognized_request_for(path, request_method = nil)
path = "/#{path}" unless path.first == '/'
@@ -538,6 +538,7 @@ def controller_path
self.class.controller_path
end
+ # Test whether the session is enabled for this request.
def session_enabled?
request.session_options && request.session_options[:disabled] != false
end
@@ -76,6 +76,7 @@ def to_str
alias_method :to_s, :to_str
private
+ # Given a path and options, returns a rewritten URL string
def rewrite_url(path, options)
rewritten_url = ""
unless options[:only_path]
@@ -91,6 +92,7 @@ def rewrite_url(path, options)
rewritten_url
end
+ # Given a Hash of options, generates a route
def rewrite_path(options)
options = options.symbolize_keys
options.update(options[:params].symbolize_keys) if options[:params]
@@ -148,7 +148,7 @@ class ActionViewError < StandardError #:nodoc:
#
# This refreshes the sidebar, removes a person element and highlights the user list.
#
- # See the ActionView::Helpers::PrototypeHelper::JavaScriptGenerator documentation for more details.
+ # See the ActionView::Helpers::PrototypeHelper::GeneratorMethods documentation for more details.
class Base
include ERB::Util
@@ -160,7 +160,7 @@ class Base
attr_internal *ActionController::Base::DEPRECATED_INSTANCE_VARIABLES
# Specify trim mode for the ERB compiler. Defaults to '-'.
- # See ERB documentation for suitable values.
+ # See ERb documentation for suitable values.
@@erb_trim_mode = '-'
cattr_accessor :erb_trim_mode
@@ -191,17 +191,17 @@ module CompiledTemplates #:nodoc:
end
include CompiledTemplates
- # maps inline templates to their method names
+ # Maps inline templates to their method names
@@method_names = {}
- # map method names to their compile time
+ # Map method names to their compile time
@@compile_time = {}
- # map method names to the names passed in local assigns so far
+ # Map method names to the names passed in local assigns so far
@@template_args = {}
- # count the number of inline templates
+ # Count the number of inline templates
@@inline_template_count = 0
- # maps template paths without extension to their file extension returned by pick_template_extension.
- # if for a given path, path.ext1 and path.ext2 exist on the file system, the order of extensions
- # used by pick_template_extension determines whether ext1 or ext2 will be stored
+ # Maps template paths without extension to their file extension returned by pick_template_extension.
+ # If for a given path, path.ext1 and path.ext2 exist on the file system, the order of extensions
+ # used by pick_template_extension determines whether ext1 or ext2 will be stored.
@@cached_template_extension = {}
class ObjectWrapper < Struct.new(:value) #:nodoc:
@@ -305,7 +305,6 @@ def render_template(template_extension, template, file_path = nil, local_assigns
# Render the provided template with the given local assigns. If the template has not been rendered with the provided
# local assigns yet, or if the template has been updated on disk, then the template will be compiled to a method.
#
-
# Either, but not both, of template and file_path may be nil. If file_path is given, the template
# will only be read if it has to be compiled.
#
@@ -371,10 +370,12 @@ def file_public?(template_path)#:nodoc:
end
private
+ # Builds a string holding the full path of the template including extension
def full_template_path(template_path, extension)
"#{@base_path}/#{template_path}.#{extension}"
end
+ # Asserts the existence of a template.
def template_exists?(template_path, extension)
file_path = full_template_path(template_path, extension)
@@method_names.has_key?(file_path) || FileTest.exists?(file_path)
@@ -389,6 +390,7 @@ def cached_template_extension(template_path)
@@cache_template_extensions && @@cached_template_extension[template_path]
end
+ # Determines the template's file extension, such as rhtml, rxml, or rjs.
def find_template_extension_for(template_path)
if match = delegate_template_exists?(template_path)
match.first.to_sym
@@ -405,6 +407,7 @@ def read_template_file(template_path, extension)
File.read(template_path)
end
+ # Evaluate the local assigns and pushes them to the view.
def evaluate_assigns
unless @assigns_added
assign_variables_from_controller
@@ -416,6 +419,7 @@ def delegate_render(handler, template, local_assigns)
handler.new(self).render(template, local_assigns)
end
+ # Assigns instance variables from the controller to the view.
def assign_variables_from_controller
@assigns.each { |key, value| instance_variable_set("@#{key}", value) }
end
@@ -427,10 +431,10 @@ def supports_local_assigns?(render_symbol, local_assigns)
((args = @@template_args[render_symbol]) && local_assigns.all? { |k,_| args.has_key?(k) })
end
- # Check whether compilation is necessary.
- # Compile if the inline template or file has not been compiled yet.
- # Or if local_assigns has a new key, which isn't supported by the compiled code yet.
- # Or if the file has changed on disk and checking file mods hasn't been disabled.
+ # Method to check whether template compilation is necessary.
+ # The template will be compiled if the inline template or file has not been compiled yet,
+ # if local_assigns has a new key, which isn't supported by the compiled code yet,
+ # or if the file has changed on disk and checking file mods hasn't been disabled.
def compile_template?(template, file_name, local_assigns)
method_key = file_name || template
render_symbol = @@method_names[method_key]
@@ -445,7 +449,7 @@ def compile_template?(template, file_name, local_assigns)
end
end
- # Create source code for given template
+ # Method to create the source code for a given template.
def create_template_source(extension, template, render_symbol, locals)
if template_requires_setup?(extension)
body = case extension.to_sym
@@ -473,11 +477,11 @@ def create_template_source(extension, template, render_symbol, locals)
"def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend"
end
- def template_requires_setup?(extension)
+ def template_requires_setup?(extension) #:nodoc:
templates_requiring_setup.include? extension.to_s
end
- def templates_requiring_setup
+ def templates_requiring_setup #:nodoc:
%w(rxml rjs)
end
@@ -501,6 +505,7 @@ def compiled_method_name_file_path_segment(file_name)
end
end
+ # Compile and evaluate the template's code
def compile_template(extension, template, file_name, local_assigns)
render_symbol = assign_method_name(extension, template, file_name)
render_source = create_template_source(extension, template, render_symbol, local_assigns.keys)
@@ -3,14 +3,14 @@ module ActionView
# CompiledTemplates modules hold methods that have been compiled.
# Templates are compiled into these methods so that they do not need to be
- # re-read and re-parsed each request.
+ # read and parsed for each request.
#
# Each template may be compiled into one or more methods. Each method accepts a given
# set of parameters which is used to implement local assigns passing.
#
# To use a compiled template module, create a new instance and include it into the class
# in which you want the template to be rendered.
- class CompiledTemplates < Module #:nodoc:
+ class CompiledTemplates < Module
attr_reader :method_names
def initialize
@@ -13,17 +13,18 @@ module Helpers
# is a great of making the record quickly available for editing, but likely to prove lackluster for a complicated real-world form.
# In that case, it's better to use the input method and the specialized form methods in link:classes/ActionView/Helpers/FormHelper.html
module ActiveRecordHelper
- # Returns a default input tag for the type of object returned by the method. Example
- # (title is a VARCHAR column and holds "Hello World"):
+ # Returns a default input tag for the type of object returned by the method. For example, let's say you have a model
+ # that has an attribute +title+ of type VARCHAR column, and this instance holds "Hello World":
# input("post", "title") =>
# <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />
def input(record_name, method, options = {})
InstanceTag.new(record_name, method, self).to_tag(options)
end
- # Returns an entire form with input tags and everything for a specified Active Record object. Example
- # (post is a new record that has a title using VARCHAR and a body using TEXT):
- # form("post") =>
+ # Returns an entire form with all needed input tags for a specified Active Record object. For example, let's say you
+ # have a table model <tt>Post</tt> with attributes named <tt>title</tt> of type <tt>VARCHAR</tt> and <tt>body</tt> of type <tt>TEXT</tt>:
+ # form("post")
+ # That line would yield a form like the following:
# <form action='/post/create' method='post'>
# <p>
# <label for="post_title">Title</label><br />
@@ -32,14 +33,13 @@ def input(record_name, method, options = {})
# <p>
# <label for="post_body">Body</label><br />
# <textarea cols="40" id="post_body" name="post[body]" rows="20">
- # Back to the hill and over it again!
# </textarea>
# </p>
# <input type='submit' value='Create' />
# </form>
#
# It's possible to specialize the form builder by using a different action name and by supplying another
- # block renderer. Example (entry is a new record that has a message attribute using VARCHAR):
+ # block renderer. For example, let's say you have a model <tt>Entry</tt> with an attribute <tt>message</tt> of type <tt>VARCHAR</tt>:
#
# form("entry", :action => "sign", :input_block =>
# Proc.new { |record, column| "#{column.human_name}: #{input(record, column.name)}<br />" }) =>
@@ -74,16 +74,16 @@ def form(record_name, options = {})
content_tag('form', contents, :action => action, :method => 'post', :enctype => options[:multipart] ? 'multipart/form-data': nil)
end
- # Returns a string containing the error message attached to the +method+ on the +object+, if one exists.
- # This error message is wrapped in a DIV tag, which can be specialized to include both a +prepend_text+ and +append_text+
- # to properly introduce the error and a +css_class+ to style it accordingly. Examples (post has an error message
- # "can't be empty" on the title attribute):
+ # Returns a string containing the error message attached to the +method+ on the +object+ if one exists.
+ # This error message is wrapped in a <tt>DIV</tt> tag, which can be extended to include a +prepend_text+ and/or +append_text+
+ # (to properly explain the error), and a +css_class+ to style it accordingly. As an example, let's say you have a model
+ # +post+ that has an error message on the +title+ attribute:
#
# <%= error_message_on "post", "title" %> =>
# <div class="formError">can't be empty</div>
#
- # <%= error_message_on "post", "title", "Title simply ", " (or it won't work)", "inputError" %> =>
- # <div class="inputError">Title simply can't be empty (or it won't work)</div>
+ # <%= error_message_on "post", "title", "Title simply ", " (or it won't work).", "inputError" %> =>
+ # <div class="inputError">Title simply can't be empty (or it won't work).</div>
def error_message_on(object, method, prepend_text = "", append_text = "", css_class = "formError")
if (obj = instance_variable_get("@#{object}")) && (errors = obj.errors.on(method))
content_tag("div", "#{prepend_text}#{errors.is_a?(Array) ? errors.first : errors}#{append_text}", :class => css_class)
@@ -92,11 +92,11 @@ def error_message_on(object, method, prepend_text = "", append_text = "", css_cl
end
end
- # Returns a string with a div containing all of the error messages for the objects located as instance variables by the names
+ # Returns a string with a <tt>DIV</tt> containing all of the error messages for the objects located as instance variables by the names
# given. If more than one object is specified, the errors for the objects are displayed in the order that the object names are
# provided.
#
- # This div can be tailored by the following options:
+ # This <tt>DIV</tt> can be tailored by the following options:
#
# * <tt>header_tag</tt> - Used for the header of the error div (default: h2)
# * <tt>id</tt> - The id of the error div (default: errorExplanation)
@@ -105,12 +105,12 @@ def error_message_on(object, method, prepend_text = "", append_text = "", css_cl
# any text that you prefer. If <tt>object_name</tt> is not set, the name of
# the first object will be used.
#
- # Specifying one object:
+ # To specify the display for one object, you simply provide its name as a parameter. For example, for the +User+ model:
#
# error_messages_for 'user'
#
- # Specifying more than one object (and using the name 'user' in the
- # header as the <tt>object_name</tt> instead of 'user_common'):
+ # To specify more than one object, you simply list them; optionally, you can add an extra +object_name+ parameter, which
+ # be the name in the header.
#
# error_messages_for 'user_common', 'user', :object_name => 'user'
#
@@ -3,6 +3,16 @@ module Helpers
# Provides a set of methods for making it easier to locate problems.
module DebugHelper
# Returns a <pre>-tag set with the +object+ dumped by YAML. Very readable way to inspect an object.
+ # my_hash = {'first' => 1, 'second' => 'two', 'third' => [1,2,3]}
+ # debug(my_hash)
+ # => <pre class='debug_dump'>---
+ # first: 1
+ # second: two
+ # third:
+ # - 1
+ # - 2
+ # - 3
+ # </pre>
def debug(object)
begin
Marshal::dump(object)
@@ -2,6 +2,9 @@ module ActionView
module Helpers
module PrototypeHelper
+ # Method to execute an element update using Prototype.
+ # DEPRECATION WARNING: This helper has been depercated; use RJS instead.
+ # See ActionView::Helpers::PrototypeHelper::JavaScriptGenerator::GeneratorMethods for more information.
def update_element_function(element_id, options = {}, &block)
content = escape_javascript(options[:content] || '')
content = escape_javascript(capture(&block)) if block
View
@@ -1,5 +1,7 @@
*SVN*
+* Small additions and fixes for ActiveRecord documentation. Closes #7342 [jeremymcanally]
+
* SQLite: binary escaping works with $KCODE='u'. #7862 [tsuka]
Oops, something went wrong.

0 comments on commit b564d7e

Please sign in to comment.