Helpers related to formatting or manipulating text within templates.
#distance_of_time_in_words(from_time, to_time = 0, include_seconds = false, options = {}) ⇒ String
Reports the approximate distance in time between two Time or Date objects or integers as seconds. #escape_html(text) ⇒ String (also: #h, #sanitize_html)
Returns escaped text to protect against malicious content. #h!(text, blank_text = ' ') ⇒ String
Returns escaped text to protect against malicious content. #highlight(text, words, options = {}) ⇒ String
Highlights one or more words everywhere in text by inserting it into a :highlighter string. #js_escape_html(html_content) ⇒ String (also: #escape_javascript)
Used in xxxx.js.erb files to escape html so that it can be passed to javascript from Padrino. #pluralize(count, singular, plural = nil) ⇒ String
Attempts to pluralize the singular word unless count is 1. #simple_format(text, options = {}) ⇒ String
Returns text transformed into HTML using simple formatting rules. #strip_tags(html) ⇒ String
Strips all HTML tags from the html. #time_ago_in_words(from_time, include_seconds = false) ⇒ String
Like distance_of_time_in_words, but where to_time
is fixed to Time.now
. #truncate(text, options = {}) ⇒ String
Truncates a given text after a given :length if text is longer than :length (defaults to 30). #truncate_words(text, options = {}) ⇒ String
Truncates words of a given text after a given :length if number of words in text is more than :length (defaults to 30). #word_wrap(text, options = {}) ⇒ String
Wraps the text into lines no longer than line_width width. Reports the approximate distance in time between two Time or Date objects or integers as seconds. Set include_seconds
to true if you want more detailed approximations when distance < 1 min, 29 secs Distances are reported based on the following table:
0 <-> 29 secs # => less than a minute 30 secs <-> 1 min, 29 secs # => 1 minute 1 min, 30 secs <-> 44 mins, 29 secs # => [2..44] minutes 44 mins, 30 secs <-> 89 mins, 29 secs # => about 1 hour 89 mins, 29 secs <-> 23 hrs, 59 mins, 29 secs # => about [2..24] hours 23 hrs, 59 mins, 29 secs <-> 47 hrs, 59 mins, 29 secs # => 1 day 47 hrs, 59 mins, 29 secs <-> 29 days, 23 hrs, 59 mins, 29 secs # => [2..29] days 29 days, 23 hrs, 59 mins, 30 secs <-> 59 days, 23 hrs, 59 mins, 29 secs # => about 1 month 59 days, 23 hrs, 59 mins, 30 secs <-> 1 yr minus 1 sec # => [2..12] months 1 yr <-> 1 yr, 3 months # => about 1 year 1 yr, 3 months <-> 1 yr, 9 months # => over 1 year 1 yr, 9 months <-> 2 yr minus 1 sec # => almost 2 years 2 yrs <-> max time or date # => (same rules as 1 yr)
With include_seconds
= true and the difference < 1 minute 29 seconds:
0-4 secs # => less than 5 seconds 5-9 secs # => less than 10 seconds 10-19 secs # => less than 20 seconds 20-39 secs # => half a minute 40-59 secs # => less than a minute 60-89 secs # => 1 minute
Returns escaped text to protect against malicious content.
Returns escaped text to protect against malicious content.
Highlights one or more words everywhere in text by inserting it into a :highlighter string.
The highlighter can be customized by passing :highlighter
as a single-quoted string with 1 where the phrase is to be inserted.
Used in xxxx.js.erb files to escape html so that it can be passed to javascript from Padrino.
Attempts to pluralize the singular word unless count is 1. If plural is supplied, it will use that when count is > 1, otherwise it will use inflector to determine the plural form.
Returns text transformed into HTML using simple formatting rules. Two or more consecutive newlines(nn) are considered as a paragraph and wrapped in <p> or your own tags. One newline (n) is considered as a linebreak and a <br /> tag is appended. This method does not remove the newlines from the text.
Strips all HTML tags from the html.
Like distance_of_time_in_words, but where to_time
is fixed to Time.now
.
Truncates a given text after a given :length if text is longer than :length (defaults to 30). The last characters will be replaced with the :omission (defaults to “…”) for a total length not exceeding :length.
Truncates words of a given text after a given :length if number of words in text is more than :length (defaults to 30). The last words will be replaced with the :omission (defaults to “…”) for a total number of words not exceeding :length.
Wraps the text into lines no longer than line_width width. This method breaks on the first whitespace character that does not exceed line_width (which is 80 by default).
© 2010–2019 Padrino
Licensed under the MIT License.
https://www.rubydoc.info/github/padrino/padrino-framework/Padrino/Helpers/FormatHelpers