All Projects → jgraichen → Rails Timeago

jgraichen / Rails Timeago

Licence: mit
A Rails helper for time tags that can be used with the jQuery Timeago plugin.

Programming Languages

ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to Rails Timeago

Timeasure
Transparent method-level wrapper for profiling purposes in Ruby
Stars: ✭ 192 (-8.57%)
Mutual labels:  rails
Ruby Docs Samples
Ruby samples for Google Cloud Platform products.
Stars: ✭ 198 (-5.71%)
Mutual labels:  rails
Vuejs Rails Starterkit
Vue.js + Rails Starting Kit GitHub Template to develop Hybrid Mobile Application: https://vuejs-rails-starterkit.herokuapp.com
Stars: ✭ 205 (-2.38%)
Mutual labels:  rails
Carrierwave Aliyun
阿里云 OSS Ruby 上传组件,基于 Carrierwave
Stars: ✭ 192 (-8.57%)
Mutual labels:  rails
Icare
Open Source Carpooling Platform
Stars: ✭ 196 (-6.67%)
Mutual labels:  rails
Webpacker React
Webpacker plugin to integrate React in your Rails application
Stars: ✭ 201 (-4.29%)
Mutual labels:  rails
Limestone
Boilerplate Rails 6 SaaS application with Webpack, Stimulus and Docker integration.
Stars: ✭ 191 (-9.05%)
Mutual labels:  rails
Cafetownsend Angular Rails
AngularJS and Rails port of the famous Cafe Townsend demo originally written in ActionScript
Stars: ✭ 208 (-0.95%)
Mutual labels:  rails
Ansible Rails
Ruby on Rails deployment using Ansible - with Lets Encrypt, Sidekiq, PostgreSQL, nginx & puma
Stars: ✭ 199 (-5.24%)
Mutual labels:  rails
Docker Web Framework Examples
Example apps that demonstate how to use Docker with your favorite web frameworks.
Stars: ✭ 204 (-2.86%)
Mutual labels:  rails
Browser
Do some browser detection with Ruby. Includes ActionController integration.
Stars: ✭ 2,263 (+977.62%)
Mutual labels:  rails
Todo Apps
Sample ToDo application (various languages) running on IBM Cloud
Stars: ✭ 195 (-7.14%)
Mutual labels:  rails
On ruby
💎 ♦️ Whitelabel Site for Ruby Communities
Stars: ✭ 201 (-4.29%)
Mutual labels:  rails
Action Cable Testing
Action Cable testing utils
Stars: ✭ 192 (-8.57%)
Mutual labels:  rails
Stupidedi
Ruby API for parsing and generating ASC X12 EDI transactions
Stars: ✭ 205 (-2.38%)
Mutual labels:  rails
Jsonapi Utils
Build JSON API-compliant APIs on Rails with no (or less) learning curve.
Stars: ✭ 191 (-9.05%)
Mutual labels:  rails
Rabl Rails
Rails 4.2 & 5 templating system with JSON, XML and Plist support.
Stars: ✭ 200 (-4.76%)
Mutual labels:  rails
Empirical Core
Empirical-Core is our web app for managing students, assigning activities, and viewing results. Core seamlessly incorporates 3rd party applications via the Empirical API.
Stars: ✭ 209 (-0.48%)
Mutual labels:  rails
Activerecord Turntable
ActiveRecord Sharding Plugin
Stars: ✭ 206 (-1.9%)
Mutual labels:  rails
Arctic admin
Responsive Theme for ActiveAdmin
Stars: ✭ 201 (-4.29%)
Mutual labels:  rails

rails-timeago

Gem Version Build Status

rails-timeago provides a timeago_tag helper to create time tags usable for jQuery Timeago plugin.

Installation

Add this line to your Gemfile:

gem 'rails-timeago', '~> 2.0'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rails-timeago

Use bundled JavaScript with Sprockets

Note: The bundled JavaScript can only be used with sprockets. Rails-webpacker cannot load scripts bundled with the gem. If you use rails-webpacker you need to install, load, and setup jquery-timeago on your own.

To use bundled jQuery Timeago plugin add this require statement to your application.js file:

//= require rails-timeago

This will also convert all matching time tags on page load.

Use the following to also include all available locale files:

//= require rails-timeago-all

If using a recent Rails with rails-ujs, jQuery might not be present anymore. You need to add jquery-rails to your Gemfile and load it, e.g.:

//= require jquery
//= require rails-timeago
//= require rails-timeago-all

Usage

Use the timeago_tag helper like any other regular tag helper:

<%= timeago_tag Time.zone.now limit: 10.days.ago %>

Available options:

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. (default: 4.days.ago)

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

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

title A string or block that will be used to create a title attribute for timeago tags. It set to nil or false no title attribute will be set. (default: proc { |time, options| I18n.l time, format: options[:format] })

All other options will be given as options to the time tag helper. The above options can be assigned globally as defaults using

Rails::Timeago.default_options limit: proc { 20.days.ago }

A global limit should always be given as a block that will be evaluated each time the rails timeago_tag helper is called. That avoids the limit becoming smaller the longer the application runs.

I18n

rails-timeago 2 ships with a modified version of jQuery timeago that allows to include all locale files at once and set the locale via an option or per element via the lang attribute:

<%= timeago_tag Time.zone.now, lang: :de %>

The following snippet will print a script tag that set the jQuery timeago locale according to your I18n.locale:

<%= timeago_script_tag %>

Just insert it in your application layout's html head. If you use another I18n framework for JavaScript you can also directly set jQuery.timeago.settings.lang. For example:

jQuery.timeago.settings.lang = $('html').attr('lang')

Do not forget to require the needed locale files by either require rails-timeago-all in your application.js file or require specific locale files:

//= require locales/jquery.timeago.de.js
//= require locales/jquery.timeago.ru.js

Note: English is included in jQuery timeago library, but can be easily override by include an own file that defines jQuery.timeago.settings.strings["en"]. See a locale file for more details.

rails-timeago includes locale files for the following locales taken from jQuery Timeago.

Your customized jQuery locale files must be changed to work with rails-timeago 2. Instead of defining your locale strings as jQuery.timeago.settings.strings you need to define them like this:

jQuery.timeago.settings.strings["en"] = {
    ...
}

License

MIT License

Copyright (c) 2014, Jan Graichen

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].