wiser_date 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.rdoc +104 -0
- data/lib/wiser_date/view_helpers.rb +27 -16
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGE0MThiYjFiMzE2MWNlY2M4NzdmZGEzZTdjZmJlNThiMDUxZDM4MA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDJjMWFkMDk2M2M3NDRlMmU1ZTVjNzUwNWY2ZTI1OTUyYWUwNmU0Yg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2MxMDZjNGYyNzU3YzdjNDc1YWQ3YzlmNDljOTFiZjczMDNhODFmYTkxMzNm
|
10
|
+
NGJjMWYwYjEzY2FlMmU3NDk2MWJiOTk0NzJhYzkwMDQxNDIyZTQ4MGY5NjUw
|
11
|
+
ODc5MTFkYThhZmQ2ZWI3OWZkMGQ4MGE0NWMyNmVmMDFjZDMzNzg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDc4MTk3NTNhYjRlMmRmNTU3Mzg4YzljMTI5NzRiY2Q3ZGI5YWI3MmJjYWMz
|
14
|
+
MWE5Y2ZiYmEwYmI1ODczMjY2OGM0ZmZjMzM4ZWZkMDIyOTAxZTBhODk5N2Ey
|
15
|
+
YWE5YTVlYzM3MWE2MGEwN2RmZmExMTc4Zjg5YjBhZjVkOWQ3ZDI=
|
data/README.rdoc
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
= Wiser Date for Rails
|
2
|
+
|
3
|
+
WiserDate is a date formatting plugin written by Kenneth John Balgos (https://github.com/kennethjohnbalgos). Wiser Date features dynamic presentation of feed timestamps. Right now, it only displays the date statically. I'm writing the jQuery scripts to update the displayed dates in real-time and dynamic.
|
4
|
+
|
5
|
+
|
6
|
+
== Installing Gem
|
7
|
+
|
8
|
+
gem "wiser_date"
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
== Dependency
|
13
|
+
|
14
|
+
The Rails application should have jQuery to make the real-time feature work.
|
15
|
+
|
16
|
+
|
17
|
+
== Using the javascripts - Not Yet Available
|
18
|
+
|
19
|
+
Require jquery.wiser_date in your app/assets/application.js file.
|
20
|
+
|
21
|
+
//= require jquery.wiser_date
|
22
|
+
|
23
|
+
|
24
|
+
== Usage
|
25
|
+
|
26
|
+
Use the wiser_date function in your views.
|
27
|
+
|
28
|
+
<%= wiser_date @user.last_login_at %>
|
29
|
+
# Sample display within few seconds: just now
|
30
|
+
# Sample display within few minutes: about 30 minutes ago
|
31
|
+
# Sample display within the day: about 15 hours ago
|
32
|
+
# Sample display after the day: yesterday 12:21pm
|
33
|
+
# Sample display after 2 days: Sept 10, 2013 12:21pm
|
34
|
+
|
35
|
+
@user.last_login_at can be any timestamp you want to display.
|
36
|
+
|
37
|
+
Assume that the value is "Mon, 10 Sept 2012 12:21:16 UTC +00:00".
|
38
|
+
|
39
|
+
|
40
|
+
== Options & Examples
|
41
|
+
|
42
|
+
You can customize the behavior of the date display by using the following options:
|
43
|
+
|
44
|
+
* *date_format* - overrides the default date format [default: "%b %d, %Y"]
|
45
|
+
|
46
|
+
<%= wiser_date @user.last_login_at, :date_format => "%Y-%m-%d" %>
|
47
|
+
# Sample display within few seconds: just now
|
48
|
+
# Sample display within few minutes: about 30 minutes ago
|
49
|
+
# Sample display within the day: about 15 hours ago
|
50
|
+
# Sample display after the day: yesterday 12:21pm
|
51
|
+
# Sample display after 2 days: 2012-09-10 12:21pm
|
52
|
+
|
53
|
+
* *time_format* - overrides the default time format [default: "%l:%M%P"]
|
54
|
+
|
55
|
+
<%= wiser_date @user.last_login_at, :time_format => "%H:%M:%S" %>
|
56
|
+
# Sample display within few seconds: just now
|
57
|
+
# Sample display within few minutes: about 30 minutes ago
|
58
|
+
# Sample display within the day: about 15 hours ago
|
59
|
+
# Sample display after the day: yesterday 12:21:16
|
60
|
+
# Sample display after 2 days: Sept 10, 2013 12:21:16
|
61
|
+
|
62
|
+
* *humanize* - converts date to more readable string [default: true]
|
63
|
+
|
64
|
+
<%= wiser_date @user.last_login_at, :humanize => false %>
|
65
|
+
# Sample display within few seconds: Sept 10, 2013 12:21pm
|
66
|
+
# Sample display within few minutes: Sept 10, 2013 12:21pm
|
67
|
+
# Sample display within the day: Sept 10, 2013 12:21pm
|
68
|
+
# Sample display after the day: Sept 10, 2013 12:21pm
|
69
|
+
# Sample display after 2 days: Sept 10, 2013 12:21pm
|
70
|
+
|
71
|
+
* *time_first* - displays time first instead of date [default: false]
|
72
|
+
|
73
|
+
<%= wiser_date @user.last_login_at, :time_first => true %>
|
74
|
+
# Sample display within few seconds: just now
|
75
|
+
# Sample display within few minutes: about 30 minutes ago
|
76
|
+
# Sample display within the day: about 15 hours ago
|
77
|
+
# Sample display after the day: 12:21pm yesterday
|
78
|
+
# Sample display after 2 days: 12:21pm Sept 10, 2013
|
79
|
+
|
80
|
+
* *hide_same_year* - will not display the year if the it is the same with the present year [default: false]
|
81
|
+
|
82
|
+
<%= wiser_date @user.last_login_at, :hide_same_year => true %>
|
83
|
+
# Sample display within few seconds: just now
|
84
|
+
# Sample display within few minutes: about 30 minutes ago
|
85
|
+
# Sample display within the day: about 15 hours ago
|
86
|
+
# Sample display after the day: yesterday 12:21pm
|
87
|
+
# Sample display after 2 days: Sept 10, 12:21pm
|
88
|
+
|
89
|
+
* *capitalize* - capitalizes the first letter of the date displayed [default: true]
|
90
|
+
|
91
|
+
<%= wiser_date @user.last_login_at, :capitalize => true %>
|
92
|
+
# Sample display within few seconds: Just now
|
93
|
+
# Sample display within few minutes: About 30 minutes ago
|
94
|
+
# Sample display within the day: About 15 hours ago
|
95
|
+
# Sample display after the day: Yesterday 12:21pm
|
96
|
+
# Sample display after 2 days: Sept 10, 12:21pm
|
97
|
+
|
98
|
+
|
99
|
+
== Thanks
|
100
|
+
Thanks to me for writing an awesome real-time date display plugin :p
|
101
|
+
|
102
|
+
|
103
|
+
== Support
|
104
|
+
Open an issue in https://github.com/kennethjohnbalgos/wiser_date if you need further support or want to report a bug.
|
@@ -2,12 +2,12 @@ require 'date'
|
|
2
2
|
|
3
3
|
module WiserDate
|
4
4
|
module ViewHelpers
|
5
|
-
|
5
|
+
|
6
6
|
include ActionView::Helpers::JavaScriptHelper
|
7
7
|
include ActionView::Helpers::TagHelper
|
8
8
|
include ActionView::Helpers::DateHelper
|
9
9
|
include ActionView::Context
|
10
|
-
|
10
|
+
|
11
11
|
def wiser_date(timestamp, options = {})
|
12
12
|
# Options
|
13
13
|
date_format = options.has_key?(:date_format) ? options[:date_format] : "%b %d, %Y"
|
@@ -16,51 +16,62 @@ module WiserDate
|
|
16
16
|
time_first = options.has_key?(:time_first) ? options[:time_first] : false
|
17
17
|
hide_same_year = options.has_key?(:hide_same_year) ? options[:hide_same_year] : false
|
18
18
|
capitalize = options.has_key?(:capitalize) ? options[:capitalize] : true
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
time_now = Time.now
|
23
|
-
|
19
|
+
custom_class = options.has_key?(:custom_class) ? options[:custom_class] : nil
|
20
|
+
time_now = options.has_key?(:time_now) ? options[:time_now].to_datetime : Time.now
|
21
|
+
|
24
22
|
# Formats
|
25
23
|
flat_format = "%Y%m%d%H%M%S"
|
26
24
|
plain_format = "%Y-%m-%d %H:%M:%S"
|
27
25
|
custom_format = time_first ? "#{time_format} #{date_format}" : "#{date_format} #{time_format}"
|
28
|
-
|
26
|
+
|
29
27
|
# Timestamps
|
30
28
|
custom_timestamp = timestamp.strftime(custom_format)
|
31
29
|
plain_timestamp = timestamp.strftime(plain_format)
|
32
|
-
|
30
|
+
|
33
31
|
# Humanize Display
|
34
32
|
if humanize
|
35
33
|
time_diff_in_seconds = (time_now - timestamp.to_time).ceil
|
36
|
-
|
37
|
-
if time_diff_in_seconds <=
|
34
|
+
time_diff_in_days = (time_diff_in_seconds / (60*60*24))
|
35
|
+
if time_diff_in_seconds <= 30 && time_diff_in_seconds >= 0
|
38
36
|
custom_timestamp = "just now"
|
39
37
|
elsif time_now.to_date - 1.day == timestamp.to_date
|
40
38
|
date_value = "yesterday"
|
41
39
|
time_value = timestamp.strftime(time_format)
|
42
40
|
custom_timestamp = time_first ? "#{time_value} #{date_value}" : "#{date_value} #{time_value}"
|
43
|
-
elsif
|
41
|
+
elsif time_diff_in_days <= 1.0 && time_diff_in_days >= 0
|
44
42
|
custom_timestamp = "#{distance_of_time_in_words(Time.now, timestamp.to_time)} ago"
|
45
43
|
elsif hide_same_year && time_now.year == timestamp.year
|
46
44
|
custom_timestamp = custom_timestamp.gsub(", #{time_now.year.to_s}", '')
|
47
45
|
end
|
48
46
|
end
|
49
|
-
|
47
|
+
|
50
48
|
# Capitalize
|
51
49
|
if capitalize
|
52
50
|
custom_timestamp = custom_timestamp.to_s.capitalize
|
53
51
|
end
|
54
|
-
|
52
|
+
|
53
|
+
|
55
54
|
uniq_id = Digest::SHA1.hexdigest([Time.now, rand].join)
|
56
55
|
html = content_tag(:span, custom_timestamp,
|
57
56
|
"id" => uniq_id,
|
58
|
-
"class" => "wiser_date",
|
57
|
+
"class" => "wiser_date #{custom_class if custom_class.present?}",
|
59
58
|
"data-plain-timestamp" => plain_timestamp,
|
60
59
|
"data-custom-timestamp" => custom_timestamp,
|
61
60
|
"data-new-custom-timestamp" => custom_timestamp
|
62
61
|
)
|
63
|
-
|
62
|
+
|
63
|
+
meta_vars = []
|
64
|
+
meta_vars << "data-value=\"#"+uniq_id+"\""
|
65
|
+
meta_vars << "data-custom-format=\""+custom_format+"\""
|
66
|
+
meta_vars << "data-date-format=\""+date_format+"\""
|
67
|
+
meta_vars << "data-time-format=\""+time_format+"\""
|
68
|
+
meta_vars << "data-humanize=\""+humanize.to_s+"\""
|
69
|
+
meta_vars << "data-hide-same-year=\""+hide_same_year.to_s+"\""
|
70
|
+
meta_vars << "data-time-first=\""+time_first.to_s+"\""
|
71
|
+
meta_vars << "data-capitalize=\""+capitalize.to_s+"\""
|
72
|
+
meta_vars << "id=\"wiser_date\""
|
73
|
+
|
74
|
+
html += javascript_tag("jQuery(document).ready(function(){if(jQuery('body meta#wiser_date').size() == 0){$('body').prepend('<meta "+meta_vars.join(' ')+" />')}else{$('meta#wiser_date').attr('data-value',$('meta#wiser_date').attr('data-value')+', #"+uniq_id+"')}});")
|
64
75
|
html.html_safe
|
65
76
|
end
|
66
77
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wiser_date
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenneth John Balgos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2012-05-
|
11
|
+
date: 2012-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Display dates in the coolest format.
|
14
14
|
email: kennethjohnbalgos@gmail.com
|
@@ -19,6 +19,7 @@ files:
|
|
19
19
|
- lib/wiser_date/view_helpers.rb
|
20
20
|
- lib/wiser_date/railtie.rb
|
21
21
|
- lib/wiser_date.rb
|
22
|
+
- README.rdoc
|
22
23
|
homepage: https://github.com/kennethjohnbalgos/wiser_date
|
23
24
|
licenses:
|
24
25
|
- MIT
|