octopress-date-format 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/octopress-date-format.rb +110 -99
- data/lib/octopress-date-format/version.rb +1 -1
- metadata +20 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fcd8ba92bbdb8ee5ace18c2c115de584792d4cd
|
4
|
+
data.tar.gz: 29e897e16eb18f29dafc13e27d38e7c66eaaf1c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7acf6e34d7084c0e7572c1138c95a1301c9aac17c60c93769975d711f46c158685903aad50953d30239f9760c89739f1615419ceb8681fab492452758cf5f56f
|
7
|
+
data.tar.gz: 18f6b2f4ce4acfbd5181ccd141b1b8b573b35732c0ff536720abcb4e138e4b001afe2a11289d5f2cec998a52df390ab8a36670f498c3e891f852493f729dfa11
|
data/CHANGELOG.md
CHANGED
@@ -1,133 +1,144 @@
|
|
1
|
-
require 'octopress-hooks'
|
2
1
|
require 'octopress-date-format/version'
|
3
2
|
|
4
3
|
module Octopress
|
5
4
|
module DateFormat
|
6
|
-
DEFAULTS = {
|
7
|
-
'date_format' => 'ordinal',
|
8
|
-
'time_format' => '%-I:%M %P'
|
9
|
-
}
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
6
|
+
class << self
|
7
|
+
DEFAULTS = {
|
8
|
+
'date_format' => 'ordinal',
|
9
|
+
'time_format' => '%-I:%M %P'
|
10
|
+
}
|
11
|
+
attr_accessor :config
|
18
12
|
|
19
|
-
|
20
|
-
|
21
|
-
DateFormat.hack_date(page)
|
13
|
+
def config=(config)
|
14
|
+
@config = DEFAULTS.merge(config)
|
22
15
|
end
|
23
|
-
end
|
24
16
|
|
25
|
-
|
26
|
-
|
27
|
-
|
17
|
+
def hack_date(page)
|
18
|
+
if page.data['date'] || page.respond_to?(:date)
|
19
|
+
date = datetime(page.data['date'] || page.date)
|
20
|
+
|
21
|
+
page.data['date_xml'] = date.xmlschema
|
22
|
+
page.data['date_text'] = format_date(date)
|
23
|
+
page.data['time_text'] = format_time(date)
|
24
|
+
page.data['date_html'] = date_html(date, false)
|
25
|
+
page.data['date_time_html'] = date_html(date)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Legacy support
|
29
|
+
if page.data['updated']
|
30
|
+
page.data['date_updated'] = page.data['updated']
|
31
|
+
end
|
32
|
+
|
33
|
+
if page.data['date_updated']
|
34
|
+
updated = datetime(page.data['date_updated'])
|
35
|
+
page.data['date_updated_xml'] = updated.xmlschema
|
36
|
+
page.data['date_updated_text'] = format_date(updated)
|
37
|
+
page.data['time_updated_text'] = format_time(updated)
|
38
|
+
page.data['date_updated_html'] = date_updated_html(updated, false)
|
39
|
+
page.data['date_time_updated_html'] = date_updated_html(updated)
|
40
|
+
end
|
41
|
+
page
|
28
42
|
end
|
29
|
-
end
|
30
43
|
|
31
|
-
|
32
|
-
|
33
|
-
|
44
|
+
def date_html(date, time=true)
|
45
|
+
tag = "<time class='entry-date' datetime='#{ date.xmlschema }'>"
|
46
|
+
tag += "<span class='date'>#{format_date(date, true)}</span>"
|
47
|
+
if time
|
48
|
+
tag += " <span class='time'>#{format_time(date)}</span>" if time
|
49
|
+
end
|
50
|
+
tag += "</time>"
|
34
51
|
end
|
35
|
-
end
|
36
52
|
|
37
|
-
|
38
|
-
|
39
|
-
|
53
|
+
def date_updated_html(date, time=true)
|
54
|
+
date_html(date, time).sub('entry-date','updated')
|
55
|
+
end
|
40
56
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
57
|
+
def format_date(date, html=false)
|
58
|
+
format = self.config['date_format']
|
59
|
+
if format == 'ordinal'
|
60
|
+
html ? ordinalize_html(date) : ordinalize(date)
|
61
|
+
else
|
62
|
+
date.strftime(format)
|
63
|
+
end
|
46
64
|
end
|
47
65
|
|
48
|
-
|
49
|
-
|
50
|
-
|
66
|
+
def format_time(date, html=false)
|
67
|
+
format = config['time_format']
|
68
|
+
date.strftime(format)
|
51
69
|
end
|
52
70
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
page.data['date_updated_text'] = format_date(updated)
|
57
|
-
page.data['time_updated_text'] = format_time(updated)
|
58
|
-
page.data['date_updated_html'] = date_updated_html(updated, false)
|
59
|
-
page.data['date_time_updated_html'] = date_updated_html(updated)
|
71
|
+
# Returns an ordidinal date eg July 22 2007 -> July 22nd 2007
|
72
|
+
def ordinalize(date)
|
73
|
+
"#{date.strftime('%b %-d')}#{ordinal_suffix(date)}, #{date.strftime('%Y')}"
|
60
74
|
end
|
61
|
-
page
|
62
|
-
end
|
63
75
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
76
|
+
def ordinalize_html(date)
|
77
|
+
d = "<span class='date-month'>#{date.strftime('%b')}</span> "
|
78
|
+
d += "<span class='date-day'>#{date.strftime('%-d')}</span>"
|
79
|
+
d += "<span class='date-suffix'>#{ordinal_suffix(date)}</span>, "
|
80
|
+
d += "<span class='date-year'>#{date.strftime('%Y')}</span>"
|
69
81
|
end
|
70
|
-
tag += "</time>"
|
71
|
-
end
|
72
82
|
|
73
|
-
|
74
|
-
|
75
|
-
|
83
|
+
# Returns an ordinal number. 13 -> 13th, 21 -> 21st etc.
|
84
|
+
def ordinal_suffix(date)
|
85
|
+
number = date.strftime('%e').to_i
|
86
|
+
if (11..13).include?(number % 100)
|
87
|
+
"th"
|
88
|
+
else
|
89
|
+
case number % 10
|
90
|
+
when 1; "st"
|
91
|
+
when 2; "nd"
|
92
|
+
when 3; "rd"
|
93
|
+
else "th"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
76
97
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
98
|
+
def datetime(input)
|
99
|
+
case input
|
100
|
+
when Time
|
101
|
+
input
|
102
|
+
when Date
|
103
|
+
input
|
104
|
+
when String
|
105
|
+
Time.parse(input) rescue Time.at(input.to_i)
|
106
|
+
when Numeric
|
107
|
+
Time.at(input)
|
108
|
+
else
|
109
|
+
raise "Invalid Date:", "'#{input}' is not a valid datetime."
|
110
|
+
exit(1)
|
111
|
+
end
|
83
112
|
end
|
84
113
|
end
|
85
114
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
115
|
+
if defined?(Jekyll::Hooks)
|
116
|
+
Jekyll::Hooks.register :site, :after_reset do |site|
|
117
|
+
DateFormat.config = site.config
|
118
|
+
end
|
90
119
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
120
|
+
Jekyll::Hooks.register [:page, :post], :post_init do |item|
|
121
|
+
DateFormat.hack_date(item)
|
122
|
+
end
|
123
|
+
else
|
124
|
+
require 'octopress-hooks'
|
95
125
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
126
|
+
class PageHook < Hooks::Page
|
127
|
+
def post_init(page)
|
128
|
+
DateFormat.hack_date(page)
|
129
|
+
end
|
130
|
+
end
|
102
131
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
if (11..13).include?(number % 100)
|
107
|
-
"th"
|
108
|
-
else
|
109
|
-
case number % 10
|
110
|
-
when 1; "st"
|
111
|
-
when 2; "nd"
|
112
|
-
when 3; "rd"
|
113
|
-
else "th"
|
132
|
+
class PostHook < Hooks::Post
|
133
|
+
def post_init(post)
|
134
|
+
DateFormat.hack_date(post)
|
114
135
|
end
|
115
136
|
end
|
116
|
-
end
|
117
137
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
when Date
|
123
|
-
input
|
124
|
-
when String
|
125
|
-
Time.parse(input) rescue Time.at(input.to_i)
|
126
|
-
when Numeric
|
127
|
-
Time.at(input)
|
128
|
-
else
|
129
|
-
raise "Invalid Date:", "'#{input}' is not a valid datetime."
|
130
|
-
exit(1)
|
138
|
+
class SiteHook < Hooks::Site
|
139
|
+
def pre_read(site)
|
140
|
+
DateFormat.config = site.config
|
141
|
+
end
|
131
142
|
end
|
132
143
|
end
|
133
144
|
end
|
metadata
CHANGED
@@ -1,59 +1,59 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octopress-date-format
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Mathis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: jekyll
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: clash
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
-
type: :
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: octopress-hooks
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: octopress-debugger
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description:
|
84
84
|
email:
|
85
85
|
- brandon@imathis.com
|
86
86
|
executables: []
|
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
version: '0'
|
113
113
|
requirements: []
|
114
114
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
115
|
+
rubygems_version: 2.4.6
|
116
116
|
signing_key:
|
117
117
|
specification_version: 4
|
118
118
|
summary: 'Adds nicely formated dates to Jekyll posts and pages. (formerly: ''jekyll-date-format'')'
|