module Rails::Timeago

Public Class Methods

default_options(opts = nil) click to toggle source

Read or write global rails-timeago default options. If no options are given the current defaults will be returned.

Available options:

:nojs

Add time ago in words as time tag content instead of absolute time. (default: false)

:date_only

Only print date as tag content instead of full time. (default: true)

:format

A time format for localize method used to format static time. (default: :default)

:limit

Set a limit for time ago tags. All dates before given limit will not be converted. Global limit should be given as a block to reevaluate limit each time timeago_tag is called. (default: proc { 4.days.ago })

:force

Force time ago tag ignoring limit option. (default: false)

:default

String that will be returned if time is nil. (default: '-')

# File lib/rails-timeago.rb, line 52
def self.default_options(opts = nil)
  @defaults ||= option_hash
  if opts
    @defaults.merge! \
      opts.extract!(*@defaults.keys.select {|k| opts.include?(k) })
  else
    @defaults
  end
end
option_hash() click to toggle source
# File lib/rails-timeago.rb, line 67
def self.option_hash
  {
    nojs: false,
    force: false,
    format: :default,
    limit: proc { 4.days.ago },
    date_only: true,
    default: '-',
    title: proc {|time, options| I18n.l time, format: options[:format] }
  }
end
reset_default_options() click to toggle source

Reset options to default values

# File lib/rails-timeago.rb, line 63
def self.reset_default_options
  @defaults = option_hash
end