octopress-date-format 2.0.0

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: 1b6c0adba7917954ffbf5405d1078930c67033e9
4
+ data.tar.gz: d60d1df617fc1422eb1964d3949737ab08d98199
5
+ SHA512:
6
+ metadata.gz: 9dfe8fa193b06e5766cae535e01f631369b1ccfb0ab5ff534ba595bf79be4b175ceb529958cc8e68c46cecd8c5fa8349fd95b80723b185b000baf7713c5635c5
7
+ data.tar.gz: 0563a12335464f65f3c78c94141bbc29955fd71bfeafc0c7d25270695c87054ec9c07ac45cc51778eb57ccbd12c219695066c27ce72429cfcbb0e614d19e7674
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
19
+ _site
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ script: cd test && bundle exec clash
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in octopress-dateformat.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Brandon Mathis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,118 @@
1
+ # Octopress Date Format
2
+
3
+ A simple plugin which makes it easy to have nicely formatted dates on any post or page.
4
+ [![Build Status](https://travis-ci.org/octopress/date-format.svg)](https://travis-ci.org/octopress/date-format)
5
+ [![Gem Version](http://img.shields.io/gem/v/octopress-date-format.svg)](https://rubygems.org/gems/octopress-date-format)
6
+ [![License](http://img.shields.io/:license-mit-blue.svg)](http://octopress.mit-license.org)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'octopress-date-format'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install octopress-date-format
21
+
22
+ Next add it to your gems list in Jekyll's `_config.yml`
23
+
24
+ gems:
25
+ - octopress-date-format
26
+
27
+ ## Usage
28
+
29
+ Any post (or page with a date) will automatically have some new date attributes.
30
+
31
+ - `date` - The date, `2014-07-03 14:08:00 +0000`
32
+ - `date_text` - The formatted date, Jul 3rd, 2014
33
+ - `time_text` - The formatted time, 2:08 pm
34
+ - `date_xml` - The XML schema formatted date, 2014-07-03T14:08:00+00:00
35
+ - `date_html` - The formatted date in a `<time>` tag.
36
+ - `date_time_html` - The formatted date and time in a `<time>` tag.
37
+
38
+ Here's an example of what would be rendered with `{{ post.date_time_html }}`.
39
+
40
+ ```html
41
+ <time class='entry-date' datetime='2014-07-03T14:08:00+00:00'>
42
+ <span class='date'>
43
+ <span class='date-month'>Jul</span>
44
+ <span class='date-day'>3</span><span class='date-suffix'>rd</span>,
45
+ <span class='date-year'>2014</span>
46
+ </span>
47
+ <span class='time'>2:08 pm</span>
48
+ </time>
49
+ ```
50
+
51
+ If you update a post or page and want to display this in a template, add this to YAML
52
+ front-matter, `date_updated: 2014-07-03 15:03:15` and your post will have updated date
53
+ attributes as well.
54
+
55
+ - `updated` - The date, `2014-07-03 15:03:15 +0000`
56
+ - `date_updated_text` - The formatted date, Jul 3rd, 2014
57
+ - `time_updated_text` - The formatted time, 3:03 pm
58
+ - `date_updated_xml` - The XML schema formatted date, 2014-07-03T15:03:15+00:00
59
+ - `date_updated_html` - The formatted date in a `<time>` tag.
60
+ - `date_time_updated_html` - The formatted date and time in a `<time>` tag.
61
+
62
+ Of course you can use Liquid conditionals when outputting an updated date.
63
+
64
+ ```
65
+ {% if post.updated %}Updated: {{ post.date_time_updated_html }}{% endif %}
66
+ ```
67
+
68
+ ## Configuration
69
+
70
+ You may change the formatting of the dates and times in the
71
+ `_octopress.yml` configuration file. Here are the defaults:
72
+
73
+ ```
74
+ date_format: 'ordinal' # July 3rd, 2014
75
+ time_format: '%-I:%M %P' # 2:08 pm
76
+ ```
77
+
78
+ To choose a different format, use a [Ruby strftime](http://apidock.com/ruby/DateTime/strftime)
79
+ compatible string. For example:
80
+
81
+ ```
82
+ date_format: "%Y-%m-%d" # e.g. 2014-07-03
83
+ time_format: "%H:%M" # 24 hour time
84
+ ```
85
+
86
+ ## Contributing
87
+
88
+ 1. Fork it ( https://github.com/octopress/date-format/fork )
89
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
90
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
91
+ 4. Push to the branch (`git push origin my-new-feature`)
92
+ 5. Create new Pull Request
93
+
94
+
95
+ ## License
96
+
97
+ Copyright (c) 2013 Brandon Mathis
98
+
99
+ MIT License
100
+
101
+ Permission is hereby granted, free of charge, to any person obtaining
102
+ a copy of this software and associated documentation files (the
103
+ "Software"), to deal in the Software without restriction, including
104
+ without limitation the rights to use, copy, modify, merge, publish,
105
+ distribute, sublicense, and/or sell copies of the Software, and to
106
+ permit persons to whom the Software is furnished to do so, subject to
107
+ the following conditions:
108
+
109
+ The above copyright notice and this permission notice shall be
110
+ included in all copies or substantial portions of the Software.
111
+
112
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
113
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
114
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
115
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
116
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
117
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
118
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,109 @@
1
+ require 'octopress-hooks'
2
+ require 'octopress-date-format/configuration'
3
+ require 'octopress-date-format/version'
4
+
5
+ module Octopress
6
+ module PageDate
7
+ class PageHook < Hooks::Page
8
+ def post_init(page)
9
+ PageDate.hack_date(page)
10
+ end
11
+ end
12
+
13
+ class PostHook < Hooks::Post
14
+ def post_init(post)
15
+ PageDate.hack_date(post)
16
+ end
17
+ end
18
+
19
+ def self.hack_date(page)
20
+ if page.data['date'] || page.respond_to?(:date)
21
+ date = datetime(page.data['date'] || page.date)
22
+
23
+ page.data['date_xml'] = date.xmlschema
24
+ page.data['date_text'] = format_date(date)
25
+ page.data['time_text'] = format_time(date)
26
+ page.data['date_html'] = date_html(date, false)
27
+ page.data['date_time_html'] = date_html(date)
28
+ end
29
+
30
+ if page.data['date_updated']
31
+ updated = datetime(page.data['date_updated'])
32
+ page.data['date_updated_xml'] = updated.xmlschema
33
+ page.data['date_updated_text'] = format_date(updated)
34
+ page.data['time_updated_text'] = format_time(updated)
35
+ page.data['date_updated_html'] = date_updated_html(updated, false)
36
+ page.data['date_time_updated_html'] = date_updated_html(updated)
37
+ end
38
+ page
39
+ end
40
+
41
+ def self.date_html(date, time=true)
42
+ tag = "<time class='entry-date' datetime='#{ date.xmlschema }'>"
43
+ tag += "<span class='date'>#{format_date(date, true)}</span>"
44
+ tag += " <span class='time'>#{format_time(date)}</span>" if time
45
+ tag += "</time>"
46
+ end
47
+
48
+ def self.date_updated_html(date, time=true)
49
+ date_html(date, time).sub('entry-date','updated')
50
+ end
51
+
52
+ def self.format_date(date, html=false)
53
+ format = config['date_format']
54
+ if format == 'ordinal'
55
+ html ? ordinalize_html(date) : ordinalize(date)
56
+ else
57
+ date.strftime(format)
58
+ end
59
+ end
60
+
61
+ def self.format_time(date, html=false)
62
+ format = config['time_format']
63
+ date.strftime(format)
64
+ end
65
+
66
+ # Returns an ordidinal date eg July 22 2007 -> July 22nd 2007
67
+ def self.ordinalize(date)
68
+ "#{date.strftime('%b %-d')}#{ordinal_suffix(date)}, #{date.strftime('%Y')}"
69
+ end
70
+
71
+ def self.ordinalize_html(date)
72
+ d = "<span class='date-month'>#{date.strftime('%b')}</span> "
73
+ d += "<span class='date-day'>#{date.strftime('%-d')}</span>"
74
+ d += "<span class='date-suffix'>#{ordinal_suffix(date)}</span>, "
75
+ d += "<span class='date-year'>#{date.strftime('%Y')}</span>"
76
+ end
77
+
78
+ # Returns an ordinal number. 13 -> 13th, 21 -> 21st etc.
79
+ def self.ordinal_suffix(date)
80
+ number = date.strftime('%e').to_i
81
+ if (11..13).include?(number % 100)
82
+ "th"
83
+ else
84
+ case number % 10
85
+ when 1; "st"
86
+ when 2; "nd"
87
+ when 3; "rd"
88
+ else "th"
89
+ end
90
+ end
91
+ end
92
+
93
+ def self.datetime(input)
94
+ case input
95
+ when Time
96
+ input
97
+ when Date
98
+ input
99
+ when String
100
+ Time.parse(input) rescue Time.at(input.to_i)
101
+ when Numeric
102
+ Time.at(input)
103
+ else
104
+ raise "Invalid Date:", "'#{input}' is not a valid datetime."
105
+ exit(1)
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,26 @@
1
+ module Octopress
2
+ unless defined? Octopress.config
3
+ def self.config
4
+ file = '_octopress.yml'
5
+ if File.exist?(file)
6
+ SafeYAML.load_file(file) || {}
7
+ else
8
+ {}
9
+ end
10
+ end
11
+ end
12
+
13
+ module PageDate
14
+ module Configuration
15
+ DEFAULTS = {
16
+ 'date_format' => 'ordinal',
17
+ 'time_format' => '%-I:%M %P',
18
+ }
19
+ end
20
+
21
+ def self.config
22
+ @config ||= Jekyll::Utils.deep_merge_hashes(PageDate::Configuration::DEFAULTS, Octopress.config)
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,5 @@
1
+ module Octopress
2
+ class DateFormat
3
+ VERSION = "2.0.0"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'octopress-date-format/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "octopress-date-format"
8
+ gem.version = Octopress::DateFormat::VERSION
9
+ gem.authors = ["Brandon Mathis"]
10
+ gem.email = ["brandon@imathis.com"]
11
+ gem.description = %q{Adds nicely formated dates to Jekyll posts and pages. (formerly: 'jekyll-date-format')}
12
+ gem.summary = %q{Adds nicely formated dates to Jekyll posts and pages. (formerly: 'jekyll-date-format')}
13
+ gem.homepage = "https://github.com/octopress/date-format"
14
+ gem.license = "MIT"
15
+
16
+ gem.add_runtime_dependency 'octopress-hooks', '~> 2.0'
17
+ gem.add_runtime_dependency 'jekyll', '~> 2.0'
18
+
19
+ gem.add_development_dependency 'clash', '~> 1.0'
20
+
21
+ gem.files = `git ls-files`.split($/)
22
+ gem.require_paths = ["lib"]
23
+ end
@@ -0,0 +1,2 @@
1
+ build: true
2
+ compare: _expected _site
@@ -0,0 +1 @@
1
+ _site
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec :path => '/gemspec/path', :path => '../'
@@ -0,0 +1,7 @@
1
+ name: Your New Jekyll Site
2
+ markdown: redcarpet
3
+ timezone: UTC
4
+ gems:
5
+ - octopress-date-format
6
+ exclude:
7
+ - Gemfile*
@@ -0,0 +1,18 @@
1
+ ## Date
2
+ - Date: 2014-07-03 14:08:00 +0000
3
+ - Formatted Date: Jul 3rd, 2014
4
+ - Formatted Time: 2:08 pm
5
+ - Date XML: 2014-07-03T14:08:00+00:00
6
+ - Date HTML: <time class='entry-date' datetime='2014-07-03T14:08:00+00:00'><span class='date'><span class='date-month'>Jul</span> <span class='date-day'>3</span><span class='date-suffix'>rd</span>, <span class='date-year'>2014</span></span></time>
7
+ - Date Time HTML: <time class='entry-date' datetime='2014-07-03T14:08:00+00:00'><span class='date'><span class='date-month'>Jul</span> <span class='date-day'>3</span><span class='date-suffix'>rd</span>, <span class='date-year'>2014</span></span> <span class='time'>2:08 pm</span></time>
8
+
9
+
10
+ ## Updated
11
+ - Date: 2014-07-03 15:03:15 +0000
12
+ - Formatted Date: Jul 3rd, 2014
13
+ - Formatted Time: 3:03 pm
14
+ - XML: 2014-07-03T15:03:15+00:00
15
+ - HTML: <time class='updated' datetime='2014-07-03T15:03:15+00:00'><span class='date'><span class='date-month'>Jul</span> <span class='date-day'>3</span><span class='date-suffix'>rd</span>, <span class='date-year'>2014</span></span></time>
16
+ - Date Time HTML: <time class='updated' datetime='2014-07-03T15:03:15+00:00'><span class='date'><span class='date-month'>Jul</span> <span class='date-day'>3</span><span class='date-suffix'>rd</span>, <span class='date-year'>2014</span></span> <span class='time'>3:03 pm</span></time>
17
+
18
+
@@ -0,0 +1,10 @@
1
+ ## Date
2
+ - Date: 2013-08-16 14:08:15 +0000
3
+ - Formatted Date: Aug 16th, 2013
4
+ - Formatted Time: 2:08 pm
5
+ - Date XML: 2013-08-16T14:08:15+00:00
6
+ - Date HTML: <time class='entry-date' datetime='2013-08-16T14:08:15+00:00'><span class='date'><span class='date-month'>Aug</span> <span class='date-day'>16</span><span class='date-suffix'>th</span>, <span class='date-year'>2013</span></span></time>
7
+ - Date Time HTML: <time class='entry-date' datetime='2013-08-16T14:08:15+00:00'><span class='date'><span class='date-month'>Aug</span> <span class='date-day'>16</span><span class='date-suffix'>th</span>, <span class='date-year'>2013</span></span> <span class='time'>2:08 pm</span></time>
8
+
9
+
10
+
@@ -0,0 +1,17 @@
1
+ ## Date
2
+ - Date: {{ page.date }}
3
+ - Formatted Date: {{ page.date_text }}
4
+ - Formatted Time: {{ page.time_text }}
5
+ - Date XML: {{ page.date_xml }}
6
+ - Date HTML: {{ page.date_html }}
7
+ - Date Time HTML: {{ page.date_time_html }}
8
+
9
+ {% if page.date_updated %}
10
+ ## Updated
11
+ - Date: {{ page.date_updated }}
12
+ - Formatted Date: {{ page.date_updated_text }}
13
+ - Formatted Time: {{ page.time_updated_text }}
14
+ - XML: {{ page.date_updated_xml }}
15
+ - HTML: {{ page.date_updated_html }}
16
+ - Date Time HTML: {{ page.date_time_updated_html }}
17
+ {% endif %}
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: "Welcome to Jekyll!"
3
+ date: 2014-07-03 14:08:00
4
+ date_updated: 2014-07-03 15:03:15
5
+ ---
6
+
7
+ {% include test_date.html %}
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: Your New Jekyll Site
3
+ date: 2013-08-16 14:08:15
4
+ ---
5
+
6
+ {% include test_date.html %}
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: octopress-date-format
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Mathis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octopress-hooks
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jekyll
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: clash
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description: 'Adds nicely formated dates to Jekyll posts and pages. (formerly: ''jekyll-date-format'')'
56
+ email:
57
+ - brandon@imathis.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/octopress-date-format.rb
69
+ - lib/octopress-date-format/configuration.rb
70
+ - lib/octopress-date-format/version.rb
71
+ - octopress-date-format.gemspec
72
+ - test/.clash.yml
73
+ - test/.gitignore
74
+ - test/Gemfile
75
+ - test/_config.yml
76
+ - test/_expected/2014/07/03/welcome-to-jekyll.html
77
+ - test/_expected/index.html
78
+ - test/_includes/test_date.html
79
+ - test/_posts/2013-08-16-welcome-to-jekyll.html
80
+ - test/index.html
81
+ homepage: https://github.com/octopress/date-format
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.2.2
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: 'Adds nicely formated dates to Jekyll posts and pages. (formerly: ''jekyll-date-format'')'
105
+ test_files: []