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

### Methods

auto_link autolink nl2br number_counter number_format obfuscate_email ordinal tagcloud time_diff

### 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:]]|<|$|) # trailing text }x unless defined? AUTO_LINK_RE

Copied from actionpack, and revised by insane-dreamer to fix a bug (original fails on some URLs)

### Public Instance methods

auto_link(text, opts = {}) {|text| ...}

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

nl2br(string, xhtml = true)

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‘

number_counter(count, item, items = nil)

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

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

number_format(n, delimiter = ',')

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'

obfuscate_email(email, text = nil)

Maybe port to ruby < 1.8.7 ?

ordinal(number)

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"

tagcloud(tags, min = 0.5, max = 1.5)

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)

time_diff(from_time, to_time = Time.now, include_seconds = false)

stolen and adapted from rails

[Validate]