squidpress-plugins 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/squidpress-plugins/date_format.rb +93 -0
- data/lib/squidpress-plugins.rb +1 -0
- metadata +4 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: acd07f4cfb8028516eb0696af7b00226bbbba2c228b7a18153d5ddc1ad06e93d
|
|
4
|
+
data.tar.gz: ca772c2bc48dd2f762bb0b1fc356fe96a03f7505b821ad9e05111edb2a2f5f9a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 87c4f8ce74ff643320413eea30e53b2376269e4caba4f77a80e13b7014f16d1d700e5e8eacf2153b55d62d12a96ad30203fb5052e5f97a4a9cf2ad4063259339
|
|
7
|
+
data.tar.gz: 95d613cbda9099b6d3ca3fc1604cd3f9f69a967538c92cb639d4f200ec853ac66a36928127b89750e355a9d88489a4add22fc5ca3c015b6466d978a0b428561d
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Adapted from https://github.com/octopress/date-format
|
|
2
|
+
|
|
3
|
+
module Squidpress
|
|
4
|
+
class DateFormat
|
|
5
|
+
class << self
|
|
6
|
+
def date_html(date, date_format, time_format, time=true)
|
|
7
|
+
tag = "<time class='entry-date' datetime='#{ date.xmlschema }'>"
|
|
8
|
+
tag += "<span class='date'>#{format_date(date, date_format, true)}</span>"
|
|
9
|
+
if time
|
|
10
|
+
tag += " <span class='time'>#{format_time(date, time_format)}</span>" if time
|
|
11
|
+
end
|
|
12
|
+
tag += "</time>"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def date_updated_html(date, format, time=true)
|
|
16
|
+
date_html(date, format, time).sub('entry-date','updated')
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def format_date(date, format, html=false)
|
|
20
|
+
if format == 'ordinal'
|
|
21
|
+
html ? ordinalize_html(date) : ordinalize(date)
|
|
22
|
+
else
|
|
23
|
+
date.strftime(format)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def format_time(date, format, html=false)
|
|
28
|
+
date.strftime(format)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Returns an ordidinal date eg July 22 2007 -> July 22nd 2007
|
|
32
|
+
def ordinalize(date)
|
|
33
|
+
"#{date.strftime('%b %-d')}#{ordinal_suffix(date)}, #{date.strftime('%Y')}"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def ordinalize_html(date)
|
|
37
|
+
d = "<span class='date-month'>#{date.strftime('%b')}</span> "
|
|
38
|
+
d += "<span class='date-day'>#{date.strftime('%-d')}</span>"
|
|
39
|
+
d += "<span class='date-suffix'>#{ordinal_suffix(date)}</span>, "
|
|
40
|
+
d += "<span class='date-year'>#{date.strftime('%Y')}</span>"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Returns an ordinal number. 13 -> 13th, 21 -> 21st etc.
|
|
44
|
+
def ordinal_suffix(date)
|
|
45
|
+
number = date.strftime('%e').to_i
|
|
46
|
+
if (11..13).include?(number % 100)
|
|
47
|
+
"th"
|
|
48
|
+
else
|
|
49
|
+
case number % 10
|
|
50
|
+
when 1; "st"
|
|
51
|
+
when 2; "nd"
|
|
52
|
+
when 3; "rd"
|
|
53
|
+
else "th"
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def datetime(input)
|
|
59
|
+
case input
|
|
60
|
+
when Time
|
|
61
|
+
input
|
|
62
|
+
when Date
|
|
63
|
+
input
|
|
64
|
+
when String
|
|
65
|
+
Time.parse(input) rescue Time.at(input.to_i)
|
|
66
|
+
when Numeric
|
|
67
|
+
Time.at(input)
|
|
68
|
+
else
|
|
69
|
+
raise "Invalid Date:", "'#{input}' is not a valid datetime."
|
|
70
|
+
exit(1)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
module Filters
|
|
76
|
+
# Populated page.date_time_html (with time unset)
|
|
77
|
+
def date_html(date, time=true)
|
|
78
|
+
date_format = @context.registers[:site].config['date_format'] || 'ordinal'
|
|
79
|
+
time_format = @context.registers[:site].config['time_format'] || '%-I:%M %P'
|
|
80
|
+
Squidpress::DateFormat.date_html(date, date_format, time_format, time)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Populated page.date_time_updated_html (with time unset)
|
|
84
|
+
def date_updated_html(date, time=true)
|
|
85
|
+
date_format = @context.registers[:site].config['date_format'] || 'ordinal'
|
|
86
|
+
time_format = @context.registers[:site].config['time_format'] || '%-I:%M %P'
|
|
87
|
+
Squidpress::DateFormat.date_updated_html(date, date_format, time_format, time)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
Liquid::Template.register_filter(Squidpress::DateFormat::Filters)
|
data/lib/squidpress-plugins.rb
CHANGED
|
@@ -4,6 +4,7 @@ require "liquid"
|
|
|
4
4
|
require "squidpress-plugins/blockquote"
|
|
5
5
|
require "squidpress-plugins/category_generator"
|
|
6
6
|
require "squidpress-plugins/config_tag"
|
|
7
|
+
require "squidpress-plugins/date_format"
|
|
7
8
|
require "squidpress-plugins/gist_tag"
|
|
8
9
|
require "squidpress-plugins/haml"
|
|
9
10
|
require "squidpress-plugins/image_tag"
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: squidpress-plugins
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Misty De Méo
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: jekyll
|
|
@@ -72,7 +71,6 @@ dependencies:
|
|
|
72
71
|
- - "~>"
|
|
73
72
|
- !ruby/object:Gem::Version
|
|
74
73
|
version: '2.8'
|
|
75
|
-
description:
|
|
76
74
|
email:
|
|
77
75
|
- squidpress@mistydemeo.com
|
|
78
76
|
executables: []
|
|
@@ -83,6 +81,7 @@ files:
|
|
|
83
81
|
- lib/squidpress-plugins/blockquote.rb
|
|
84
82
|
- lib/squidpress-plugins/category_generator.rb
|
|
85
83
|
- lib/squidpress-plugins/config_tag.rb
|
|
84
|
+
- lib/squidpress-plugins/date_format.rb
|
|
86
85
|
- lib/squidpress-plugins/gist_tag.rb
|
|
87
86
|
- lib/squidpress-plugins/haml.rb
|
|
88
87
|
- lib/squidpress-plugins/image_tag.rb
|
|
@@ -96,7 +95,6 @@ homepage: https://codeberg.org/mistydemeo/squidpress-plugins
|
|
|
96
95
|
licenses:
|
|
97
96
|
- MIT
|
|
98
97
|
metadata: {}
|
|
99
|
-
post_install_message:
|
|
100
98
|
rdoc_options: []
|
|
101
99
|
require_paths:
|
|
102
100
|
- lib
|
|
@@ -111,8 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
111
109
|
- !ruby/object:Gem::Version
|
|
112
110
|
version: '0'
|
|
113
111
|
requirements: []
|
|
114
|
-
rubygems_version:
|
|
115
|
-
signing_key:
|
|
112
|
+
rubygems_version: 4.0.20
|
|
116
113
|
specification_version: 4
|
|
117
114
|
summary: Port of Octopress's theme to modern Jekyll.
|
|
118
115
|
test_files: []
|