Sha256: dcd8d6c4e91fc6ef3b60148a45b343ddec01c18b53252d1d87cafb3ecfd85f38

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

require "rails-timeago/version"
require "rails-timeago/helper"

module Rails
  module Timeago
    if defined?(::Rails::Engine)
      class Engine < ::Rails::Engine # :nodoc:
        initializer 'rails-timeago', group: :all do |app|
          ActiveSupport.on_load(:action_controller) do
            include Rails::Timeago::Helper
          end

          ActiveSupport.on_load(:action_view) do
            include Rails::Timeago::Helper
          end
        end
      end
    end

    # 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: '-')
    #
    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails-timeago-2.0.0.beta1 lib/rails-timeago.rb