Skip to content

Commit

Permalink
Use 2 spaces for identation in ActionView code examples [ci-skip]
Browse files Browse the repository at this point in the history
For consistency use 2 spaces for indentation (+ 1 default space after `#`)
Some of these were formatted incorrectly in the API docs.
  • Loading branch information
p8 committed Nov 16, 2022
1 parent 98bbfc0 commit 482d94c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 55 deletions.
4 changes: 2 additions & 2 deletions actionview/lib/action_view/helpers/capture_helper.rb
Expand Up @@ -127,7 +127,7 @@ def capture(*args)
# <li><%= link_to 'Home', action: 'index' %></li>
# <% end %>
#
# And in another place:
# And in another place:
#
# <% content_for :navigation do %>
# <li><%= link_to 'Login', action: 'login' %></li>
Expand All @@ -143,7 +143,7 @@ def capture(*args)
# <li><%= link_to 'Home', action: 'index' %></li>
# <% end %>
#
# <%# Add some other content, or use a different template: %>
# <%# Add some other content, or use a different template: %>
#
# <% content_for :navigation, flush: true do %>
# <li><%= link_to 'Login', action: 'login' %></li>
Expand Down
93 changes: 52 additions & 41 deletions actionview/lib/action_view/helpers/date_helper.rb
Expand Up @@ -1001,22 +1001,25 @@ def build_options_and_select(type, selected, options = {})
end

# Build select option HTML from date value and options.
# build_options(15, start: 1, end: 31)
# => "<option value="1">1</option>
# <option value="2">2</option>
# <option value="3">3</option>..."
#
# If <tt>use_two_digit_numbers: true</tt> option is passed
# build_options(15, start: 1, end: 31, use_two_digit_numbers: true)
# => "<option value="1">01</option>
# <option value="2">02</option>
# <option value="3">03</option>..."
# build_options(15, start: 1, end: 31)
# => "<option value="1">1</option>
# <option value="2">2</option>
# <option value="3">3</option>..."
#
# If <tt>:step</tt> options is passed
# build_options(15, start: 1, end: 31, step: 2)
# => "<option value="1">1</option>
# <option value="3">3</option>
# <option value="5">5</option>..."
# If <tt>use_two_digit_numbers: true</tt> option is passed:
#
# build_options(15, start: 1, end: 31, use_two_digit_numbers: true)
# => "<option value="1">01</option>
# <option value="2">02</option>
# <option value="3">03</option>..."
#
# If <tt>:step</tt> options is passed:
#
# build_options(15, start: 1, end: 31, step: 2)
# => "<option value="1">1</option>
# <option value="3">3</option>
# <option value="5">5</option>..."
def build_options(selected, options = {})
options = {
leading_zeros: true, ampm: false, use_two_digit_numbers: false
Expand All @@ -1041,22 +1044,25 @@ def build_options(selected, options = {})
end

# Build select option HTML for day.
# build_day_options(2)
# => "<option value="1">1</option>
# <option value="2" selected="selected">2</option>
# <option value="3">3</option>..."
#
# build_day_options(2)
# => "<option value="1">1</option>
# <option value="2" selected="selected">2</option>
# <option value="3">3</option>..."
#
# If <tt>day_format: ->(day) { day.ordinalize }</tt> option is passed to DateTimeSelector
# build_day_options(2)
# => "<option value="1">1st</option>
# <option value="2" selected="selected">2nd</option>
# <option value="3">3rd</option>..."
#
# build_day_options(2)
# => "<option value="1">1st</option>
# <option value="2" selected="selected">2nd</option>
# <option value="3">3rd</option>..."
#
# If <tt>use_two_digit_numbers: true</tt> option is passed to DateTimeSelector
# build_day_options(2)
# => "<option value="1">01</option>
# <option value="2" selected="selected">02</option>
# <option value="3">03</option>..."
#
# build_day_options(2)
# => "<option value="1">01</option>
# <option value="2" selected="selected">02</option>
# <option value="3">03</option>..."
def build_day_options(selected)
select_options = []
(1..31).each do |value|
Expand All @@ -1070,10 +1076,11 @@ def build_day_options(selected)
end

# Build select option HTML for year.
# build_year_options(1998, start: 1998, end: 2000)
# => "<option value="1998" selected="selected">1998</option>
# <option value="1999">1999</option>
# <option value="2000">2000</option>"
#
# build_year_options(1998, start: 1998, end: 2000)
# => "<option value="1998" selected="selected">1998</option>
# <option value="1999">1999</option>
# <option value="2000">2000</option>"
def build_year_options(selected, options = {})
start = options.delete(:start)
stop = options.delete(:end)
Expand All @@ -1091,10 +1098,11 @@ def build_year_options(selected, options = {})
end

# Builds select tag from date type and HTML select options.
# build_select(:month, "<option value="1">January</option>...")
# => "<select id="post_written_on_2i" name="post[written_on(2i)]">
# <option value="1">January</option>...
# </select>"
#
# build_select(:month, "<option value="1">January</option>...")
# => "<select id="post_written_on_2i" name="post[written_on(2i)]">
# <option value="1">January</option>...
# </select>"
def build_select(type, select_options_as_html)
select_options = {
id: input_id_from_type(type),
Expand All @@ -1111,9 +1119,10 @@ def build_select(type, select_options_as_html)
(content_tag("select", select_html.html_safe, select_options) + "\n").html_safe
end

# Builds the CSS class value for the select element
# css_class_attribute(:year, 'date optional', { year: 'my-year' })
# => "date optional my-year"
# Builds the CSS class value for the select element.
#
# css_class_attribute(:year, 'date optional', { year: 'my-year' })
# => "date optional my-year"
def css_class_attribute(type, html_options_class, options) # :nodoc:
css_class = \
case options
Expand All @@ -1127,8 +1136,9 @@ def css_class_attribute(type, html_options_class, options) # :nodoc:
end

# Builds a prompt option tag with supplied options or from default options.
# prompt_option_tag(:month, prompt: 'Select month')
# => "<option value="">Select month</option>"
#
# prompt_option_tag(:month, prompt: 'Select month')
# => "<option value="">Select month</option>"
def prompt_option_tag(type, options)
prompt = \
case options
Expand All @@ -1145,8 +1155,9 @@ def prompt_option_tag(type, options)
end

# Builds hidden input tag for date part and value.
# build_hidden(:year, 2008)
# => "<input type="hidden" id="date_year" name="date[year]" value="2008" autocomplete="off" />"
#
# build_hidden(:year, 2008)
# => "<input type="hidden" id="date_year" name="date[year]" value="2008" autocomplete="off" />"
def build_hidden(type, value)
select_options = {
type: "hidden",
Expand Down
21 changes: 11 additions & 10 deletions actionview/lib/action_view/helpers/number_helper.rb
Expand Up @@ -202,7 +202,7 @@ def number_to_percentage(number, options = {})
# number_with_delimiter("123456.78",
# delimiter_pattern: /(\d+?)(?=(\d\d)+(\d)(?!\d))/) # => "1,23,456.78"
#
# number_with_delimiter("112a", raise: true) # => raise InvalidNumberError
# number_with_delimiter("112a", raise: true) # => raise InvalidNumberError
def number_with_delimiter(number, options = {})
delegate_number_helper_method(:number_to_delimited, number, options)
end
Expand Down Expand Up @@ -370,13 +370,14 @@ def number_to_human_size(number, options = {})
# out by default (set <tt>:strip_insignificant_zeros</tt> to
# +false+ to change that):
#
# number_to_human(12.00001) # => "12"
# number_to_human(12.00001, strip_insignificant_zeros: false) # => "12.0"
# number_to_human(12.00001) # => "12"
# number_to_human(12.00001, strip_insignificant_zeros: false) # => "12.0"
#
# ==== Custom Unit Quantifiers
#
# You can also use your own custom unit quantifiers:
# number_to_human(500000, units: {unit: "ml", thousand: "lt"}) # => "500 lt"
#
# number_to_human(500000, units: {unit: "ml", thousand: "lt"}) # => "500 lt"
#
# If in your I18n locale you have:
# distance:
Expand All @@ -393,12 +394,12 @@ def number_to_human_size(number, options = {})
#
# Then you could do:
#
# number_to_human(543934, units: :distance) # => "544 kilometers"
# number_to_human(54393498, units: :distance) # => "54400 kilometers"
# number_to_human(54393498000, units: :distance) # => "54.4 gazillion-distance"
# number_to_human(343, units: :distance, precision: 1) # => "300 meters"
# number_to_human(1, units: :distance) # => "1 meter"
# number_to_human(0.34, units: :distance) # => "34 centimeters"
# number_to_human(543934, units: :distance) # => "544 kilometers"
# number_to_human(54393498, units: :distance) # => "54400 kilometers"
# number_to_human(54393498000, units: :distance) # => "54.4 gazillion-distance"
# number_to_human(343, units: :distance, precision: 1) # => "300 meters"
# number_to_human(1, units: :distance) # => "1 meter"
# number_to_human(0.34, units: :distance) # => "34 centimeters"
#
def number_to_human(number, options = {})
delegate_number_helper_method(:number_to_human, number, options)
Expand Down
4 changes: 2 additions & 2 deletions actionview/lib/action_view/helpers/output_safety_helper.rb
Expand Up @@ -13,8 +13,8 @@ module OutputSafetyHelper
#
# For example:
#
# raw @user.name
# # => 'Jimmy <alert>Tables</alert>'
# raw @user.name
# # => 'Jimmy <alert>Tables</alert>'
def raw(stringish)
stringish.to_s.html_safe
end
Expand Down

0 comments on commit 482d94c

Please sign in to comment.