jquery-timeago 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4c78c84775b195005ff89c373515bf9bfb1a5544
4
+ data.tar.gz: 495aed5f678f93fc468ec9617da7e07e0dec625d
5
+ SHA512:
6
+ metadata.gz: c73ce86406368be63d91b3f7dff0179e9603b8a5bc44490515cebbdc58128cb0f740560153976667c21e9efb276fd8db146c9ccc643405c05f1e1daf8d7ef0dc
7
+ data.tar.gz: 3708d8f4a76f9f102d94c518a22a5b939d5c6a6a5f3d6a5808c19c99e83911efb1134d207d5bb9d1319206e4350a3303c782c261d8d4b10895f500a0525669c5
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.5
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in time_ago.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Roshan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # TimeAgo
2
+ A gem that integrates timeago.js in to a Rails application and provides a simple way to render relative timestamps in a view.
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/jquery-timeago.svg)](https://badge.fury.io/rb/jquery-timeago)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'jquery-timeago'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install jquery-timeago
21
+
22
+ ## Usage
23
+
24
+ Add the following to ```app/assets/javascripts/application.js``` :
25
+
26
+ ```
27
+ //= require jquery-timeago
28
+ ```
29
+
30
+ Tags using the ```timeago``` view helper get rendered to UI as:
31
+
32
+ ```html
33
+ <time class="timeago" datetime="2016-01-08T14:55:58Z">
34
+ 2016-01-08 14:55:58 UTC
35
+ </time>
36
+ ```
37
+ and are updated to:
38
+ ```html
39
+ <time class="timeago" datetime="2016-01-08T15:04:10Z" title="2016-01-08 15:04:10 UTC">
40
+ 20 days ago
41
+ </time>
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/roshan92/jquery-timeago. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
47
+
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ // jQuery Timeago setup for timeago helper
2
+ //
3
+ //= require jquery.timeago
4
+
5
+ $(document).on('page:change', function() {
6
+ $("time.timeago").timeago();
7
+ });
@@ -0,0 +1,10 @@
1
+ module TimeAgoHelper
2
+ def timeago(time, options = {})
3
+ options[:class] ||= "timeago"
4
+ content_tag(
5
+ :time,
6
+ time.to_s,
7
+ options.merge(datetime: time.getutc.iso8601)
8
+ ) if time
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "time_ago"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require "time_ago/version"
2
+
3
+ module TimeAgo
4
+ class Engine < ::Rails::Engine end
5
+ end
@@ -0,0 +1,3 @@
1
+ module TimeAgo
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'time_ago/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jquery-timeago"
8
+ spec.version = TimeAgo::VERSION
9
+ spec.authors = ["Roshan"]
10
+ spec.email = ["icemission@gmail.com"]
11
+
12
+ spec.summary = %q{A gem to integrate the timeago.js}
13
+ spec.description = %q{A gem to integrate the timeago.js}
14
+ spec.homepage = "https://github.com/roshan92/jquery-timeago"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "rails", ">= 3.1"
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.10"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ end
@@ -0,0 +1,231 @@
1
+ /**
2
+ * Timeago is a jQuery plugin that makes it easy to support automatically
3
+ * updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
4
+ *
5
+ * @name timeago
6
+ * @version 1.5.3
7
+ * @requires jQuery v1.2.3+
8
+ * @author Ryan McGeary
9
+ * @license MIT License - http://www.opensource.org/licenses/mit-license.php
10
+ *
11
+ * For usage and examples, visit:
12
+ * http://timeago.yarp.com/
13
+ *
14
+ * Copyright (c) 2008-2015, Ryan McGeary (ryan -[at]- mcgeary [*dot*] org)
15
+ */
16
+
17
+ (function (factory) {
18
+ if (typeof define === 'function' && define.amd) {
19
+ // AMD. Register as an anonymous module.
20
+ define(['jquery'], factory);
21
+ } else if (typeof module === 'object' && typeof module.exports === 'object') {
22
+ factory(require('jquery'));
23
+ } else {
24
+ // Browser globals
25
+ factory(jQuery);
26
+ }
27
+ }(function ($) {
28
+ $.timeago = function(timestamp) {
29
+ if (timestamp instanceof Date) {
30
+ return inWords(timestamp);
31
+ } else if (typeof timestamp === "string") {
32
+ return inWords($.timeago.parse(timestamp));
33
+ } else if (typeof timestamp === "number") {
34
+ return inWords(new Date(timestamp));
35
+ } else {
36
+ return inWords($.timeago.datetime(timestamp));
37
+ }
38
+ };
39
+ var $t = $.timeago;
40
+
41
+ $.extend($.timeago, {
42
+ settings: {
43
+ refreshMillis: 60000,
44
+ allowPast: true,
45
+ allowFuture: false,
46
+ localeTitle: false,
47
+ cutoff: 0,
48
+ autoDispose: true,
49
+ strings: {
50
+ prefixAgo: null,
51
+ prefixFromNow: null,
52
+ suffixAgo: "ago",
53
+ suffixFromNow: "from now",
54
+ inPast: 'any moment now',
55
+ seconds: "less than a minute",
56
+ minute: "about a minute",
57
+ minutes: "%d minutes",
58
+ hour: "about an hour",
59
+ hours: "about %d hours",
60
+ day: "a day",
61
+ days: "%d days",
62
+ month: "about a month",
63
+ months: "%d months",
64
+ year: "about a year",
65
+ years: "%d years",
66
+ wordSeparator: " ",
67
+ numbers: []
68
+ }
69
+ },
70
+
71
+ inWords: function(distanceMillis) {
72
+ if (!this.settings.allowPast && ! this.settings.allowFuture) {
73
+ throw 'timeago allowPast and allowFuture settings can not both be set to false.';
74
+ }
75
+
76
+ var $l = this.settings.strings;
77
+ var prefix = $l.prefixAgo;
78
+ var suffix = $l.suffixAgo;
79
+ if (this.settings.allowFuture) {
80
+ if (distanceMillis < 0) {
81
+ prefix = $l.prefixFromNow;
82
+ suffix = $l.suffixFromNow;
83
+ }
84
+ }
85
+
86
+ if (!this.settings.allowPast && distanceMillis >= 0) {
87
+ return this.settings.strings.inPast;
88
+ }
89
+
90
+ var seconds = Math.abs(distanceMillis) / 1000;
91
+ var minutes = seconds / 60;
92
+ var hours = minutes / 60;
93
+ var days = hours / 24;
94
+ var years = days / 365;
95
+
96
+ function substitute(stringOrFunction, number) {
97
+ var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction;
98
+ var value = ($l.numbers && $l.numbers[number]) || number;
99
+ return string.replace(/%d/i, value);
100
+ }
101
+
102
+ var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) ||
103
+ seconds < 90 && substitute($l.minute, 1) ||
104
+ minutes < 45 && substitute($l.minutes, Math.round(minutes)) ||
105
+ minutes < 90 && substitute($l.hour, 1) ||
106
+ hours < 24 && substitute($l.hours, Math.round(hours)) ||
107
+ hours < 42 && substitute($l.day, 1) ||
108
+ days < 30 && substitute($l.days, Math.round(days)) ||
109
+ days < 45 && substitute($l.month, 1) ||
110
+ days < 365 && substitute($l.months, Math.round(days / 30)) ||
111
+ years < 1.5 && substitute($l.year, 1) ||
112
+ substitute($l.years, Math.round(years));
113
+
114
+ var separator = $l.wordSeparator || "";
115
+ if ($l.wordSeparator === undefined) { separator = " "; }
116
+ return $.trim([prefix, words, suffix].join(separator));
117
+ },
118
+
119
+ parse: function(iso8601) {
120
+ var s = $.trim(iso8601);
121
+ s = s.replace(/\.\d+/,""); // remove milliseconds
122
+ s = s.replace(/-/,"/").replace(/-/,"/");
123
+ s = s.replace(/T/," ").replace(/Z/," UTC");
124
+ s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
125
+ s = s.replace(/([\+\-]\d\d)$/," $100"); // +09 -> +0900
126
+ return new Date(s);
127
+ },
128
+ datetime: function(elem) {
129
+ var iso8601 = $t.isTime(elem) ? $(elem).attr("datetime") : $(elem).attr("title");
130
+ return $t.parse(iso8601);
131
+ },
132
+ isTime: function(elem) {
133
+ // jQuery's `is()` doesn't play well with HTML5 in IE
134
+ return $(elem).get(0).tagName.toLowerCase() === "time"; // $(elem).is("time");
135
+ }
136
+ });
137
+
138
+ // functions that can be called via $(el).timeago('action')
139
+ // init is default when no action is given
140
+ // functions are called with context of a single element
141
+ var functions = {
142
+ init: function() {
143
+ var refresh_el = $.proxy(refresh, this);
144
+ refresh_el();
145
+ var $s = $t.settings;
146
+ if ($s.refreshMillis > 0) {
147
+ this._timeagoInterval = setInterval(refresh_el, $s.refreshMillis);
148
+ }
149
+ },
150
+ update: function(timestamp) {
151
+ var date = (timestamp instanceof Date) ? timestamp : $t.parse(timestamp);
152
+ $(this).data('timeago', { datetime: date });
153
+ if ($t.settings.localeTitle) {
154
+ $(this).attr("title", date.toLocaleString());
155
+ }
156
+ refresh.apply(this);
157
+ },
158
+ updateFromDOM: function() {
159
+ $(this).data('timeago', { datetime: $t.parse( $t.isTime(this) ? $(this).attr("datetime") : $(this).attr("title") ) });
160
+ refresh.apply(this);
161
+ },
162
+ dispose: function () {
163
+ if (this._timeagoInterval) {
164
+ window.clearInterval(this._timeagoInterval);
165
+ this._timeagoInterval = null;
166
+ }
167
+ }
168
+ };
169
+
170
+ $.fn.timeago = function(action, options) {
171
+ var fn = action ? functions[action] : functions.init;
172
+ if (!fn) {
173
+ throw new Error("Unknown function name '"+ action +"' for timeago");
174
+ }
175
+ // each over objects here and call the requested function
176
+ this.each(function() {
177
+ fn.call(this, options);
178
+ });
179
+ return this;
180
+ };
181
+
182
+ function refresh() {
183
+ var $s = $t.settings;
184
+
185
+ //check if it's still visible
186
+ if ($s.autoDispose && !$.contains(document.documentElement,this)) {
187
+ //stop if it has been removed
188
+ $(this).timeago("dispose");
189
+ return this;
190
+ }
191
+
192
+ var data = prepareData(this);
193
+
194
+ if (!isNaN(data.datetime)) {
195
+ if ( $s.cutoff === 0 || Math.abs(distance(data.datetime)) < $s.cutoff) {
196
+ $(this).text(inWords(data.datetime));
197
+ } else {
198
+ if ($(this).attr('title').length > 0) {
199
+ $(this).text($(this).attr('title'));
200
+ }
201
+ }
202
+ }
203
+ return this;
204
+ }
205
+
206
+ function prepareData(element) {
207
+ element = $(element);
208
+ if (!element.data("timeago")) {
209
+ element.data("timeago", { datetime: $t.datetime(element) });
210
+ var text = $.trim(element.text());
211
+ if ($t.settings.localeTitle) {
212
+ element.attr("title", element.data('timeago').datetime.toLocaleString());
213
+ } else if (text.length > 0 && !($t.isTime(element) && element.attr("title"))) {
214
+ element.attr("title", text);
215
+ }
216
+ }
217
+ return element.data("timeago");
218
+ }
219
+
220
+ function inWords(date) {
221
+ return $t.inWords(distance(date));
222
+ }
223
+
224
+ function distance(date) {
225
+ return (new Date().getTime() - date.getTime());
226
+ }
227
+
228
+ // fix for IE6 suckage
229
+ document.createElement("abbr");
230
+ document.createElement("time");
231
+ }));
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery-timeago
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Roshan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: A gem to integrate the timeago.js
56
+ email:
57
+ - icemission@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - app/assets/javascripts/jquery-timeago.js
70
+ - app/helpers/time_ago_helper.rb
71
+ - bin/console
72
+ - bin/setup
73
+ - lib/time_ago.rb
74
+ - lib/time_ago/version.rb
75
+ - time_ago.gemspec
76
+ - vendor/assets/javascripts/jquery.timeago.js
77
+ homepage: https://github.com/roshan92/jquery-timeago
78
+ licenses:
79
+ - MIT
80
+ metadata:
81
+ allowed_push_host: https://rubygems.org
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.5
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: A gem to integrate the timeago.js
102
+ test_files: []