sutty-liquid 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll/filters/date_local.rb +58 -0
- data/lib/jekyll/filters/number.rb +20 -0
- data/lib/jekyll/filters/social_network.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e0505b26f76af0f596d0c5b2b6763776ca28e0e83ef16207393488534ecde42
|
4
|
+
data.tar.gz: fc1f956be9ae1a997989c4f67cb399bc1c4ad0fd26034913f74d65235658cac9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b9b2e9d866d1766922f9f69263a7ff8d9c11f01cab5a000f6d8a605048d8acd81a3d7a7319a8aa161e5f86727bf26e26b084b7b73521acb705ad4da6a3912a8
|
7
|
+
data.tar.gz: 1bfaf334727887f40399d4680dab162001ec80faf513a595411fc7dc800d41591a90ec5b3987207b7a97d202373eab08a089a246c57ecfb2ad111dcb95e0070a
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Filters
|
5
|
+
module DateLocal
|
6
|
+
# Translates month and day names. This requires certain values on your _data/LANG.yml
|
7
|
+
#
|
8
|
+
# @see {_data/es.yml}
|
9
|
+
# @param [String|Date]
|
10
|
+
# @param [String]
|
11
|
+
# @return [String]
|
12
|
+
def date_local(input, format)
|
13
|
+
require 'date'
|
14
|
+
|
15
|
+
input = Date.parse(input) if input.is_a? String
|
16
|
+
|
17
|
+
# Return early if we don't need to translate
|
18
|
+
return input.strftime(format) unless /%(|\^)[aAbBpP]/ =~ format
|
19
|
+
|
20
|
+
input.strftime translate_localization_format(input, format)
|
21
|
+
rescue ArgumentError
|
22
|
+
Jekyll.logger.warn "#{input} is not a valid Date"
|
23
|
+
input
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# Adapted from the i18n gem
|
29
|
+
# @see {https://github.com/ruby-i18n/i18n/blob/a8f4fdcb197e56b5a698d1bc68007dd0871c03bf/lib/i18n/backend/base.rb}
|
30
|
+
def translate_localization_format(object, format)
|
31
|
+
format.to_s.gsub(/%(|\^)[aAbBpP]/) do |match|
|
32
|
+
case match
|
33
|
+
when '%a' then i18n.dig('date', 'abbr_day_names', object.wday - 1)
|
34
|
+
when '%^a' then i18n.dig('date', 'abbr_day_names', object.wday - 1)&.upcase
|
35
|
+
when '%A' then i18n.dig('date', 'day_names', object.wday - 1)
|
36
|
+
when '%^A' then i18n.dig('date', 'day_names', object.wday - 1)&.upcase
|
37
|
+
when '%b' then i18n.dig('date', 'abbr_month_names', object.mon - 1)
|
38
|
+
when '%^b' then i18n.dig('date', 'abbr_month_names', object.mon - 1)&.upcase
|
39
|
+
when '%B' then i18n.dig('date', 'month_names', object.mon - 1)
|
40
|
+
when '%^B' then i18n.dig('date', 'month_names', object.mon - 1)&.upcase
|
41
|
+
when '%p' then i18n.dig('time', object.hour < 12 ? 'am' : 'pm')&.upcase if object.respond_to? :hour
|
42
|
+
when '%P' then i18n.dig('time', object.hour < 12 ? 'am' : 'pm')&.downcase if object.respond_to? :hour
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def site
|
48
|
+
@site ||= @context.registers[:site]
|
49
|
+
end
|
50
|
+
|
51
|
+
def i18n
|
52
|
+
@i18n ||= site.data.dig site.config['lang']
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
Liquid::Template.register_filter(Jekyll::Filters::DateLocal)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Filters
|
5
|
+
# Extracts numbers from a String, useful for converting phone
|
6
|
+
# numbers to tel: links.
|
7
|
+
#
|
8
|
+
# @param [String]
|
9
|
+
# @return [String]
|
10
|
+
module Numbers
|
11
|
+
def numbers(input)
|
12
|
+
return unless input.respond_to? :gsub
|
13
|
+
|
14
|
+
input.gsub(%r{[^0-9]}, '')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Liquid::Template.register_filter(Jekyll::Filters::Numbers)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sutty-liquid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- f
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -36,9 +36,11 @@ files:
|
|
36
36
|
- LICENSE.txt
|
37
37
|
- README.md
|
38
38
|
- lib/jekyll/filters/compact.rb
|
39
|
+
- lib/jekyll/filters/date_local.rb
|
39
40
|
- lib/jekyll/filters/file.rb
|
40
41
|
- lib/jekyll/filters/infinite.rb
|
41
42
|
- lib/jekyll/filters/json.rb
|
43
|
+
- lib/jekyll/filters/number.rb
|
42
44
|
- lib/jekyll/filters/pry.rb
|
43
45
|
- lib/jekyll/filters/sample.rb
|
44
46
|
- lib/jekyll/filters/social_network.rb
|