Module: Rails::Timeago

Defined in:
lib/rails-timeago.rb,
lib/rails-timeago/helper.rb,
lib/rails-timeago/version.rb

Defined Under Namespace

Modules: Helper, VERSION Classes: Engine

Class Method Summary collapse

Class Method Details

.default_options(opts = nil) ⇒ Object

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: ‘-’)



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/rails-timeago/helper.rb', line 89

def self.default_options(opts = nil)
  @defaults ||= {
    :nojs      => false, 
    :force     => false, 
    :format    => :default, 
    :limit     => proc { 4.days.ago },
    :date_only => true,
    :default   => '-'
  }
  if opts
    @defaults.merge! opts.extract!(*@defaults.keys.select{|k| opts.include?(k)})
  else
    @defaults
  end
end