Module Ramaze::Helper::Formatting
In: lib/ramaze/helper/formatting.rb

Methods

Constants

FORMATTING_NUMBER_COUNTER = { 0 => 'no', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six', 7 => 'seven', 8 => 'eight', 9 => 'nine', 10 => 'ten' }
AUTO_LINK_RE = %r{ ( # leading text <\w+.*?>| # leading HTML tag, or [^=!:'"/]| # leading punctuation, or ^ # beginning of line ) ( (?:https?://)| # protocol spec, or (?:www\.) # www.* ) ( [-\w]+ # subdomain or domain (?:\.[-\w]+)* # remaining subdomains or domain (?::\d+)? # port (?:/(?:(?:[~\w\+@%-]|(?:[,.;:][^\s$])))?)* # path (?:\?[\w\+@%&=.;-]+)? # query string (?:\#[\w\-]*)? # trailing anchor ) ([[:punct:]]|\s|<|$) # trailing text }x unless defined? AUTO_LINK_RE   copied from actionpack

Public Instance methods

Turns all urls into clickable links. If a block is given, each url is yielded and the result is used as the link text.

autolink(text, opts = {})

Alias for auto_link

takes a string and optional argument for outputting compliance HTML instead of XHTML. e.g nl2br "a\nb\n\c" #=> ‘a<br />b<br />c‘

Answers with a representation of given count with correct grammar. If no items argument is given, and the count argument is not 1, then we first check whether the item argument responds to pluralize (for example if you are using Sequel). If this doesn‘t work we append ‘s’ to the item argument.

@example usage

  numeric_counter(0, 'comment') # => 'no comments'
  numeric_counter(1, 'comment') # => 'one comment'
  numeric_counter(2, 'comment') # => '2 comments'

Format a floating number nicely for display.

Usage:

  number_format(123.123)           # => '123.123'
  number_format(123456.12345)      # => '123,456.12345'
  number_format(123456.12345, '.') # => '123.456,12345'

Maybe port to ruby < 1.8.7 ?

Answer with the ordinal version of a number.

Usage:

  ordinal(1)   # => "1st"
  ordinal(2)   # => "2nd"
  ordinal(3)   # => "3rd"
  ordinal(13)  # => "13th"
  ordinal(33)  # => "33rd"
  ordinal(100) # => "100th"
  ordinal(133) # => "133rd"

Returns Hash with tags as keys and their weight as value.

Example:

    tags = %w[ruby ruby code ramaze]
    tagcloud(tags)
    # => {"code"=>0.75, "ramaze"=>0.75, "ruby"=>1.0}

The weight can be influenced by adjusting the min and max parameters, please make sure that max is larger than min to get meaningful output.

This is not thought as immediate output to your template but rather to help either implementing your own algorithm or using the result as input for your tagcloud.

Example:

    - tagcloud(tags).each do |tag, weight|
      - style = "font-size: %0.2fem" % weight
      %a{:style => style, :href => Rs(tag)}= h(tag)

[Validate]