local_time 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -5
- data/app/assets/javascripts/local_time.js.coffee +2 -1
- data/app/helpers/local_time_helper.rb +6 -2
- data/test/helpers/local_time_helper_test.rb +6 -1
- data/test/javascripts/index.js.coffee +9 -0
- data/test/javascripts/unit/local_time_test.js.coffee +3 -3
- data/test/javascripts/unit/page_events_test.js.coffee +5 -5
- data/test/javascripts/unit/strftime_test.js.coffee +1 -1
- data/test/javascripts/unit/time_ago_test.js.coffee +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2499d2a165c030164525b49b02920c90c4b4953
|
4
|
+
data.tar.gz: 41e33a6cbb60e66d98aba1a9089b82e324207314
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a03eda21f6d818690cf468931e43f832afdf5fc27a5adaac2d6af551b48b5f2fff3b0990e98d5ef2d49edd3ff361a4776c2e10a691a8598f69940844108c984f
|
7
|
+
data.tar.gz: d9843bb2c0f6a8f892a99218a1e95c25ea88f55ddef92be471ceac46ce25d352974947219c08de3e0cfe96b28fb4081cde6b7ebe09432673628db4e6e963a53f
|
data/README.md
CHANGED
@@ -4,13 +4,11 @@ Local Time is a Rails engine with helpers and JavaScript for displaying times an
|
|
4
4
|
|
5
5
|
####Example
|
6
6
|
|
7
|
-
Assuming the time zone is EST and `Time.now` is `2013-11-27 18:43:22 -0500`:
|
8
|
-
|
9
7
|
```erb
|
10
|
-
<%= local_time(
|
8
|
+
<%= local_time(comment.created_at) # comment.created_at => Wed, 27 Nov 2013 18:43:22 EST -0500 %>
|
11
9
|
```
|
12
10
|
|
13
|
-
Renders
|
11
|
+
Renders:
|
14
12
|
|
15
13
|
```html
|
16
14
|
<time data-format="%B %e, %Y %l:%M%P"
|
@@ -18,7 +16,7 @@ Renders in UTC time:
|
|
18
16
|
datetime="2013-11-27T23:43:22Z">November 27, 2013 11:43pm</time>
|
19
17
|
```
|
20
18
|
|
21
|
-
|
19
|
+
When the DOM loads, the content is immediately replaced with a local, formatted time:
|
22
20
|
|
23
21
|
```html
|
24
22
|
<time data-format="%B %e, %Y %l:%M%P"
|
@@ -67,6 +65,11 @@ The included JavaScript does not depend on any frameworks or libraries, and list
|
|
67
65
|
|
68
66
|
#### Version History
|
69
67
|
|
68
|
+
**0.2.0** (December 10, 2013)
|
69
|
+
|
70
|
+
* Prefer `textContent` over `innerText` for Firefox compatibility
|
71
|
+
* Added `options` argument to `local_time_ago` helper
|
72
|
+
|
70
73
|
**0.1.0** (November 29, 2013)
|
71
74
|
|
72
75
|
* Initial release.
|
@@ -171,6 +171,7 @@ process = (selector, callback) ->
|
|
171
171
|
|
172
172
|
document.addEventListener "DOMContentLoaded", ->
|
173
173
|
domLoaded = true
|
174
|
+
textProperty = if "textContent" of document.body then "textContent" else "innerText"
|
174
175
|
|
175
176
|
process "time[data-local]:not([data-localized])", (element) ->
|
176
177
|
datetime = element.getAttribute "datetime"
|
@@ -180,7 +181,7 @@ document.addEventListener "DOMContentLoaded", ->
|
|
180
181
|
time = new Date Date.parse datetime
|
181
182
|
return if isNaN time
|
182
183
|
|
183
|
-
element
|
184
|
+
element[textProperty] =
|
184
185
|
switch local
|
185
186
|
when "time"
|
186
187
|
element.setAttribute "data-localized", true
|
@@ -14,9 +14,13 @@ module LocalTimeHelper
|
|
14
14
|
local_time time, options
|
15
15
|
end
|
16
16
|
|
17
|
-
def local_time_ago(time)
|
17
|
+
def local_time_ago(time, options = {})
|
18
18
|
time = utc_time(time)
|
19
|
-
|
19
|
+
|
20
|
+
options[:data] ||= {}
|
21
|
+
options[:data].merge! local: 'time-ago'
|
22
|
+
|
23
|
+
time_tag time, time.strftime('%B %e, %Y %l:%M%P'), options
|
20
24
|
end
|
21
25
|
|
22
26
|
def utc_time(time_or_date)
|
@@ -4,7 +4,7 @@ require 'action_view'
|
|
4
4
|
require 'minitest/autorun'
|
5
5
|
|
6
6
|
|
7
|
-
class LocalTimeHelperTest <
|
7
|
+
class LocalTimeHelperTest < MiniTest::Unit::TestCase
|
8
8
|
include ActionView::Helpers::DateHelper, ActionView::Helpers::TagHelper
|
9
9
|
include LocalTimeHelper
|
10
10
|
|
@@ -65,4 +65,9 @@ class LocalTimeHelperTest < Minitest::Test
|
|
65
65
|
expected = %Q(<time data-local="time-ago" datetime="#{@time_js}">November 21, 2013 6:00am</time>)
|
66
66
|
assert_equal expected, local_time_ago(@time)
|
67
67
|
end
|
68
|
+
|
69
|
+
def test_local_time_ago_with_options
|
70
|
+
expected = %Q(<time class="date-time" data-local="time-ago" datetime="#{@time_js}">November 21, 2013 6:00am</time>)
|
71
|
+
assert_equal expected, local_time_ago(@time, class: "date-time")
|
72
|
+
end
|
68
73
|
end
|
@@ -12,6 +12,15 @@
|
|
12
12
|
document.body.appendChild el
|
13
13
|
el
|
14
14
|
|
15
|
+
@setText = (el, text) ->
|
16
|
+
textProperty = if "textContent" of el then "textContent" else "innerText"
|
17
|
+
el[textProperty] = text
|
18
|
+
|
19
|
+
@getText = (el) ->
|
20
|
+
# innerHTML works in all browsers so using it ensures we're
|
21
|
+
# reading the text content, not a potentially arbitrary property.
|
22
|
+
el.innerHTML
|
23
|
+
|
15
24
|
@triggerEvent = (name, el = document) ->
|
16
25
|
event = document.createEvent "Events"
|
17
26
|
event.initEvent name, true, true
|
@@ -9,9 +9,9 @@ test "date", ->
|
|
9
9
|
|
10
10
|
test "unparseable time", ->
|
11
11
|
el = addTimeEl "%Y", ":("
|
12
|
-
el
|
12
|
+
setText el, "2013"
|
13
13
|
run()
|
14
|
-
equal el
|
14
|
+
equal getText(el), "2013"
|
15
15
|
|
16
16
|
|
17
17
|
assertLocalized = (id, type = "time") ->
|
@@ -26,7 +26,7 @@ assertLocalized = (id, type = "time") ->
|
|
26
26
|
el = document.getElementById id
|
27
27
|
|
28
28
|
ok datetime = el.getAttribute "datetime"
|
29
|
-
ok local = el
|
29
|
+
ok local = getText el
|
30
30
|
|
31
31
|
datetimeParsed = moment datetime
|
32
32
|
localParsed = moment local, momentFormat
|
@@ -3,28 +3,28 @@ module "page events"
|
|
3
3
|
test "document DOMContentLoaded", ->
|
4
4
|
el = addTimeEl()
|
5
5
|
triggerEvent "DOMContentLoaded"
|
6
|
-
ok el
|
6
|
+
ok getText el
|
7
7
|
|
8
8
|
test "document time:elapse", ->
|
9
9
|
el = addTimeEl()
|
10
10
|
triggerEvent "time:elapse"
|
11
|
-
ok el
|
11
|
+
ok getText el
|
12
12
|
|
13
13
|
test "window popstate", ->
|
14
14
|
el = addTimeEl()
|
15
15
|
triggerEvent "popstate", window
|
16
|
-
ok el
|
16
|
+
ok getText el
|
17
17
|
|
18
18
|
test "document page:update with Turbolinks on", ->
|
19
19
|
el = addTimeEl()
|
20
20
|
triggerEvent "page:update"
|
21
|
-
ok not el
|
21
|
+
ok not getText el
|
22
22
|
|
23
23
|
original = window.Turbolinks
|
24
24
|
window.Turbolinks = { supported: true }
|
25
25
|
|
26
26
|
triggerEvent "DOMContentLoaded"
|
27
27
|
triggerEvent "page:update"
|
28
|
-
ok el
|
28
|
+
ok getText el
|
29
29
|
|
30
30
|
window.Turbolinks = original
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: local_time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Javan Makhmali
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11
|
12
|
+
date: 2013-12-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: coffee-rails
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rails
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
28
42
|
description:
|
29
43
|
email: javan@37signals.com
|
30
44
|
executables: []
|
@@ -67,7 +81,7 @@ rubyforge_project:
|
|
67
81
|
rubygems_version: 2.1.11
|
68
82
|
signing_key:
|
69
83
|
specification_version: 4
|
70
|
-
summary: Rails engine for
|
84
|
+
summary: Rails engine for client-side local time
|
71
85
|
test_files:
|
72
86
|
- test/helpers/local_time_helper_test.rb
|
73
87
|
- test/javascripts/config.ru
|