Class: ActionView::Helpers::Tags::Base
Constant Summary
::ActionView::Helpers::TagHelper
- Included
ARIA_PREFIXES, BOOLEAN_ATTRIBUTES, DATA_PREFIXES, PRE_CONTENT_STRINGS, TAG_TYPES
::ActionView::Helpers::ContentExfiltrationPreventionHelper
- Included
CLOSE_CDATA_COMMENT, CLOSE_FORM_TAG, CLOSE_OPTION_TAG, CLOSE_QUOTES_COMMENT, CONTENT_EXFILTRATION_PREVENTION_MARKUP
::ActionView::Helpers::UrlHelper
- Included
Class Method Summary
Instance Attribute Summary
- #object readonly
- #generate_ids? ⇒ Boolean readonly private
- #value_came_from_user? ⇒ Boolean readonly private
::ActionView::Helpers::ActiveModelInstanceTag
- Included
::ActionView::Helpers::FormTagHelper
- Included
::ActionView::Helpers::SanitizeHelper
- Included
::ActionView::Helpers::UrlHelper
- Included
::ActionView::Helpers::ContentExfiltrationPreventionHelper
- Included
Instance Method Summary
-
#render
This is what child classes implement.
- #add_default_name_and_id(options) private
- #add_default_name_and_id_for_value(tag_value, options) private
- #name_and_id_index(options) private
- #retrieve_autoindex(pre_match) private
- #retrieve_object(object) private
- #sanitized_method_name private
- #sanitized_value(value) private
- #tag_id(index = nil, namespace = nil) private
- #tag_name(multiple = false, index = nil) private
- #value private
- #value_before_type_cast private
::ActionView::Helpers::ActiveModelInstanceTag
- Included
#content_tag, #error_message, #error_wrapping, #object, #tag, #select_markup_helper?, #tag_generate_errors? |
::ActionView::Helpers::FormTagHelper
- Included
#button_tag | Creates a button element that defines a |
#check_box_tag | Alias for FormTagHelper#checkbox_tag. |
#checkbox_tag | Creates a check box form input tag. |
#color_field_tag | Creates a text field of type “color”. |
#date_field_tag | Creates a text field of type “date”. |
#datetime_field_tag | Creates a text field of type “datetime-local”. |
#datetime_local_field_tag | Alias for FormTagHelper#datetime_field_tag. |
#email_field_tag | Creates a text field of type “email”. |
#field_id | Generate an HTML |
#field_name | Generate an HTML |
#field_set_tag | Creates a field set for grouping HTML form elements. |
#fieldset_tag | Alias for FormTagHelper#field_set_tag. |
#file_field_tag | Creates a file upload field. |
#form_tag | Starts a form tag that points the action to a URL configured with |
#hidden_field_tag | Creates a hidden form input field used to transmit data that would be lost due to HTTP’s statelessness or data that should be hidden from the user. |
#image_submit_tag | Displays an image which when clicked will submit the form. |
#label_tag | Creates a label element. |
#month_field_tag | Creates a text field of type “month”. |
#number_field_tag | Creates a number field. |
#password_field_tag | Creates a password field, a masked text field that will hide the users input behind a mask character. |
#phone_field_tag | Alias for FormTagHelper#telephone_field_tag. |
#radio_button_tag | Creates a radio button; use groups of radio buttons named the same to allow users to select from a group of options. |
#range_field_tag | Creates a range form element. |
#search_field_tag | Creates a text field of type “search”. |
#select_tag | Creates a dropdown selection box, or if the |
#submit_tag | Creates a submit button with the text #value as the caption. |
#telephone_field_tag | Creates a text field of type “tel”. |
#text_area_tag | Alias for FormTagHelper#textarea_tag. |
#text_field_tag | Creates a standard text field; use these text fields to input smaller chunks of text like a username or a search query. |
#textarea_tag | Creates a text input area; use a textarea for longer text inputs such as blog posts or descriptions. |
#time_field_tag | Creates a text field of type “time”. |
#url_field_tag | Creates a text field of type “url”. |
#utf8_enforcer_tag | Creates the hidden UTF-8 enforcer tag. |
#week_field_tag | Creates a text field of type “week”. |
#convert_direct_upload_option_to_url, #extra_tags_for_form, #form_tag_html, #form_tag_with_body, #html_options_for_form, | |
#sanitize_to_id | |
#set_default_disable_with |
::ActionView::Helpers::TextHelper
- Included
#concat | The preferred method of outputting text in your views is to use the |
#current_cycle | Returns the current cycle string after a cycle has been started. |
#cycle | Creates a Cycle object whose |
#excerpt | Extracts the first occurrence of |
#highlight | Highlights occurrences of |
#pluralize | Attempts to pluralize the |
#reset_cycle | Resets a cycle so that it starts from the first element the next time it is called. |
#safe_concat, | |
#simple_format | Returns |
#truncate | Truncates |
#word_wrap | Wraps the |
#cut_excerpt_part, | |
#get_cycle | The cycle helpers need to store the cycles in a place that is guaranteed to be reset every time a page is rendered, so it uses an instance variable of |
#set_cycle, #split_paragraphs |
::ActionView::Helpers::SanitizeHelper
- Included
#sanitize | Sanitizes HTML input, stripping all but known-safe tags and attributes. |
#sanitize_css | Sanitizes a block of CSS code. |
#strip_links | Strips all link tags from |
#strip_tags | Strips all HTML tags from |
::ActionView::Helpers::UrlHelper
- Included
#button_to | Generates a form containing a single button that submits to the URL created by the set of |
#current_page? | True if the current request URI was generated by the given |
#link_to | Creates an anchor element of the given |
#link_to_if | Creates a link tag of the given |
#link_to_unless | Creates a link tag of the given |
#link_to_unless_current | Creates a link tag of the given |
#mail_to | Creates a mailto link tag to the specified |
#phone_to | Creates a TEL anchor link tag to the specified |
#sms_to | Creates an SMS anchor link tag to the specified |
#add_method_to_attributes!, #convert_options_to_data_attributes, #link_to_remote_options?, #method_for_options, #method_not_get_method?, #method_tag, #remove_trailing_slash!, | |
#to_form_params | Returns an array of hashes each containing |
#token_tag, #url_target, | |
#url_for | Basic implementation of url_for to allow use helpers without routes existence. |
#_back_url, #_filtered_referrer |
::ActionView::Helpers::ContentExfiltrationPreventionHelper
- Included
::ActionView::Helpers::TagHelper
- Included
#cdata_section | Returns a CDATA section with the given |
#class_names | Alias for ActionView::Helpers::TagHelper#token_list. |
#content_tag | Returns an HTML block tag of type |
#escape_once | Returns an escaped version of |
#tag | Returns an HTML tag. |
#token_list | Returns a string of tokens built from |
#build_tag_values, #ensure_valid_html5_tag_name, #tag_builder |
::ActionView::Helpers::OutputSafetyHelper
- Included
#raw | This method outputs without escaping a string. |
#safe_join | This method returns an HTML safe string similar to what |
#to_sentence | Converts the array to a comma-separated sentence where the last element is joined by the connector word. |
::ActionView::Helpers::CaptureHelper
- Included
#capture | The capture method extracts part of a template as a string object. |
#content_for | Calling |
#content_for? |
|
#provide | The same as |
#with_output_buffer | Use an alternate output buffer for the duration of the block. |
Constructor Details
.new(object_name, method_name, template_object, options = {}) ⇒ Base
# File 'actionview/lib/action_view/helpers/tags/base.rb', line 11
def initialize(object_name, method_name, template_object, = {}) @object_name, @method_name = object_name.to_s.dup, method_name.to_s.dup @template_object = template_object @object_name.sub!(/\[\]$/, "") || @object_name.sub!(/\[\]\]$/, "]") @object = retrieve_object( .delete(:object)) @skip_default_ids = .delete(:skip_default_ids) @allow_method_names_outside_object = .delete(:allow_method_names_outside_object) @options = if Regexp.last_match @generate_indexed_names = true @auto_index = retrieve_autoindex(Regexp.last_match.pre_match) else @generate_indexed_names = false @auto_index = nil end end
Instance Attribute Details
#generate_ids? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'actionview/lib/action_view/helpers/tags/base.rb', line 132
def generate_ids? !@skip_default_ids end
#object (readonly)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/base.rb', line 9
attr_reader :object
#value_came_from_user? ⇒ Boolean
(readonly, private)
[ GitHub ]
Instance Method Details
#add_default_name_and_id(options) (private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/base.rb', line 96
def add_default_name_and_id( ) index = name_and_id_index( ) ["name"] = .fetch("name") { tag_name( ["multiple"], index) } if generate_ids? ["id"] = .fetch("id") { tag_id(index, .delete("namespace")) } if namespace = .delete("namespace") ["id"] = ["id"] ? "#{namespace}_#{ ['id']}" : namespace end end end
#add_default_name_and_id_for_value(tag_value, options) (private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/base.rb', line 83
def add_default_name_and_id_for_value(tag_value, ) if tag_value.nil? add_default_name_and_id( ) else specified_id = ["id"] add_default_name_and_id( ) if specified_id.blank? && ["id"].present? ["id"] += "_#{sanitized_value(tag_value)}" end end end
#name_and_id_index(options) (private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/base.rb', line 124
def name_and_id_index( ) if .key?("index") .delete("index") || "" elsif @generate_indexed_names @auto_index || "" end end
#render
This is what child classes implement.
# File 'actionview/lib/action_view/helpers/tags/base.rb', line 31
def render raise NotImplementedError, "Subclasses must implement a render method" end
#retrieve_autoindex(pre_match) (private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/base.rb', line 74
def retrieve_autoindex(pre_match) object = self.object || @template_object.instance_variable_get("@#{pre_match}") if object && object.respond_to?(:to_param) object.to_param else raise ArgumentError, "object[] naming but object param and @object var don't exist or don't respond to to_param: #{object.inspect}" end end
#retrieve_object(object) (private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/base.rb', line 63
def retrieve_object(object) if object object elsif @template_object.instance_variable_defined?("@#{@object_name}") @template_object.instance_variable_get("@#{@object_name}") end rescue NameError # As @object_name may contain the nested syntax (item[subobject]) we need to fallback to nil. nil end
#sanitized_method_name (private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/base.rb', line 116
def sanitized_method_name @sanitized_method_name ||= @method_name.delete_suffix("?") end
#sanitized_value(value) (private)
[ GitHub ]#tag_id(index = nil, namespace = nil) (private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/base.rb', line 112
def tag_id(index = nil, namespace = nil) @template_object.field_id(@object_name, @method_name, index: index, namespace: namespace) end
#tag_name(multiple = false, index = nil) (private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/base.rb', line 108
def tag_name(multiple = false, index = nil) @template_object.field_name(@object_name, sanitized_method_name, multiple: multiple, index: index) end
#value (private)
[ GitHub ]#value_before_type_cast (private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/base.rb', line 46
def value_before_type_cast return unless object method_before_type_cast = @method_name + "_before_type_cast" if value_came_from_user? && object.respond_to?(method_before_type_cast) object.public_send(method_before_type_cast) else value end end