module Lucky::TextHelpers
Overview
These helper methods will return a String.
Direct including types
Defined in:
lucky/page_helpers/text_helpers.crInstance Method Summary
- #current_cycle(name : String = "default")
 - #cycle(values : Array, name = "default") : String
 - #cycle(*values, name : String = "default") : String
 - 
        #excerpt(text : String, phrase : Regex | String, separator : String = "", radius : Int32 = 100, omission : String = "...") : String
        
          
Grab a window of longer string
 - 
        #pluralize(count : Int | String | Nil, singular : String, plural = nil) : String
        
          
It pluralizes
singularunlesscountis 1. - #reset_cycle(name : String = "default")
 - #reset_cycles
 - 
        #to_sentence(list : Enumerable, word_connector : String = ", ", two_word_connector : String = " and ", last_word_connector : String = ", and ") : String
        
          
Creates a comma-separated sentence from the provided
Enumerablelist and appends it to the view. - 
        #truncate_text(text : String, length : Int32 = 30, omission : String = "...", separator : String | Nil = nil) : String
        
          
Shorten text after a length point.
 - #word_wrap(text : String, line_width : Int32 = 80, break_sequence : String = "\n") : String
 
Instance Method Detail
Grab a window of longer string
You'll need to specify a phrase to center on, either a Regex or a String.
Optionally:
- A 
radius(default:100) which controls how many units out from thephraseon either side the excerpt will be. - A 
separator(default"") which controls what theradiuswill count. The unit by default is any character, which means the default is 100 character from thephrasein either direction. For example, an excerpt of # 10 words would use aradiusof 10 and aseparatorof" ". - An 
omissionstring (default:"..."), which prepends and appends to the excerpt. 
lyrics = "We represent the Lolly pop Guild, The Lolly pop Guild"
excerpt(text, phrase: "Guild", radius: 10)
outputs:
...Lolly pop Guild, The Loll...
        It pluralizes singular unless count is 1. You can specify the plural option
to override the chosen plural word.
Creates a comma-separated sentence from the provided Enumerable list
and appends it to the view.
Options:
The following options allow you to specify how the sentence is constructed:
- word_connector - A string used to join the elements in lists containing three or more elements (Default is ", ")
 - two_word_connector - A string used to join the elements in lists containing exactly two elements (Default is " and ")
 - last_word_connector - A string used to join the last element in lists containing three or more elements (Default is ", and ")
 
Examples:
to_sentence([] of String)            # => ""
to_sentence([1])                     # => "1"
to_sentence(["one", "two"])          # => "one and two"
to_sentence({"one", "two", "three"}) # => "one, two, and three"
to_sentence(["one", "two", "three"], word_connector: " + ")
# => one + two, and three
to_sentence(Set{"a", "z"}, two_word_connector: " to ")
# => a to z
to_sentence(1..3, last_word_connector: ", or ")
# => 1, 2, or 3
NOTE  By default #to_sentence will include a
serial comma. This can be
overridden like so:
to_sentence(["one", "two", "three"], last_word_connector: " and ")
# => one, two and three
        Shorten text after a length point.
Unlike truncate, this method can be used inside of other tags because it
returns a String. See truncate method for argument documentation.
link "#" do
  text truncate_text("Four score and seven years ago", length: 27)
end
outputs:
<a href=\"#\">Four score and se...</a>