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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6240daa4f916f4ff2b4eaa0a87c51e1ef7aa5830
4
- data.tar.gz: b47ac4068b4f584acb75cd37af4d817ddd67c727
3
+ metadata.gz: 6fcd8ba92bbdb8ee5ace18c2c115de584792d4cd
4
+ data.tar.gz: 29e897e16eb18f29dafc13e27d38e7c66eaaf1c3
5
5
  SHA512:
6
- metadata.gz: 3c9533e424d90f761eea0da101792b26b564783545d120b91f48ac454d0542cc6f4657d21c1025d8a4618b89972be4e23d003b1e0573632daacc47bd1d60b280
7
- data.tar.gz: 60babb26392549363cfb627a7d074c7a50f0d80997b549305745277275c4f04f3879e2536ffb46fe4c05b8bb9b47297196ba3fc98f2d388f52aa14f6f3dd763c
6
+ metadata.gz: 7acf6e34d7084c0e7572c1138c95a1301c9aac17c60c93769975d711f46c158685903aad50953d30239f9760c89739f1615419ceb8681fab492452758cf5f56f
7
+ data.tar.gz: 18f6b2f4ce4acfbd5181ccd141b1b8b573b35732c0ff536720abcb4e138e4b001afe2a11289d5f2cec998a52df390ab8a36670f498c3e891f852493f729dfa11
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ### 3.0.3 - 2015-05-12
4
+
5
+ - Support for Jekyll 3.0 and Jekyll Hooks
6
+
3
7
  ### 3.0.2 - 2015-01-06
4
8
 
5
9
  - Updated Octopress docs integration.
@@ -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
- def self.config
12
- @config
13
- end
14
-
15
- def self.config=(config)
16
- @config = DEFAULTS.merge(config)
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
- class PageHook < Hooks::Page
20
- def post_init(page)
21
- DateFormat.hack_date(page)
13
+ def config=(config)
14
+ @config = DEFAULTS.merge(config)
22
15
  end
23
- end
24
16
 
25
- class PostHook < Hooks::Post
26
- def post_init(post)
27
- DateFormat.hack_date(post)
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
- class SiteHook < Hooks::Site
32
- def pre_read(site)
33
- DateFormat.config = site.config
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
- def self.hack_date(page)
38
- if page.data['date'] || page.respond_to?(:date)
39
- date = datetime(page.data['date'] || page.date)
53
+ def date_updated_html(date, time=true)
54
+ date_html(date, time).sub('entry-date','updated')
55
+ end
40
56
 
41
- page.data['date_xml'] = date.xmlschema
42
- page.data['date_text'] = format_date(date)
43
- page.data['time_text'] = format_time(date)
44
- page.data['date_html'] = date_html(date, false)
45
- page.data['date_time_html'] = date_html(date)
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
- # Legacy support
49
- if page.data['updated']
50
- page.data['date_updated'] = page.data['updated']
66
+ def format_time(date, html=false)
67
+ format = config['time_format']
68
+ date.strftime(format)
51
69
  end
52
70
 
53
- if page.data['date_updated']
54
- updated = datetime(page.data['date_updated'])
55
- page.data['date_updated_xml'] = updated.xmlschema
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
- def self.date_html(date, time=true)
65
- tag = "<time class='entry-date' datetime='#{ date.xmlschema }'>"
66
- tag += "<span class='date'>#{format_date(date, true)}</span>"
67
- if time
68
- tag += " <span class='time'>#{format_time(date)}</span>" if time
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
- def self.date_updated_html(date, time=true)
74
- date_html(date, time).sub('entry-date','updated')
75
- end
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
- def self.format_date(date, html=false)
78
- format = config['date_format']
79
- if format == 'ordinal'
80
- html ? ordinalize_html(date) : ordinalize(date)
81
- else
82
- date.strftime(format)
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
- def self.format_time(date, html=false)
87
- format = config['time_format']
88
- date.strftime(format)
89
- end
115
+ if defined?(Jekyll::Hooks)
116
+ Jekyll::Hooks.register :site, :after_reset do |site|
117
+ DateFormat.config = site.config
118
+ end
90
119
 
91
- # Returns an ordidinal date eg July 22 2007 -> July 22nd 2007
92
- def self.ordinalize(date)
93
- "#{date.strftime('%b %-d')}#{ordinal_suffix(date)}, #{date.strftime('%Y')}"
94
- end
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
- def self.ordinalize_html(date)
97
- d = "<span class='date-month'>#{date.strftime('%b')}</span> "
98
- d += "<span class='date-day'>#{date.strftime('%-d')}</span>"
99
- d += "<span class='date-suffix'>#{ordinal_suffix(date)}</span>, "
100
- d += "<span class='date-year'>#{date.strftime('%Y')}</span>"
101
- end
126
+ class PageHook < Hooks::Page
127
+ def post_init(page)
128
+ DateFormat.hack_date(page)
129
+ end
130
+ end
102
131
 
103
- # Returns an ordinal number. 13 -> 13th, 21 -> 21st etc.
104
- def self.ordinal_suffix(date)
105
- number = date.strftime('%e').to_i
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
- def self.datetime(input)
119
- case input
120
- when Time
121
- input
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
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module DateFormat
3
- VERSION = "3.0.2"
3
+ VERSION = "3.0.3"
4
4
  end
5
5
  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.2
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-01-06 00:00:00.000000000 Z
11
+ date: 2015-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: octopress-hooks
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: jekyll
28
+ name: clash
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '2.0'
34
- type: :runtime
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: '2.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: clash
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.0'
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: '1.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
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: pry-byebug
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: 'Adds nicely formated dates to Jekyll posts and pages. (formerly: ''jekyll-date-format'')'
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.2.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'')'