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
-
.default_options(opts = nil) ⇒ Object
Read or write global rails-timeago default options.
- .option_hash ⇒ Object
-
.reset_default_options ⇒ Object
Reset options to default values.
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: ‘-’)
49 50 51 52 53 54 55 56 |
# File 'lib/rails-timeago.rb', line 49 def self.(opts = nil) @defaults ||= self.option_hash if opts @defaults.merge! opts.extract!(*@defaults.keys.select{|k| opts.include?(k)}) else @defaults end end |
.option_hash ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rails-timeago.rb', line 63 def self.option_hash { :nojs => false, :force => false, :format => :default, :limit => proc { 4.days.ago }, :date_only => true, :default => '-', :title => proc { |time, | I18n.l time, :format => [:format] } } end |
.reset_default_options ⇒ Object
Reset options to default values
59 60 61 |
# File 'lib/rails-timeago.rb', line 59 def self. @defaults = self.option_hash end |