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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80dcc3abc95fa1284a2fe605cbea560484b2d711351f60175bb3aba0cc85b2c5
4
- data.tar.gz: a2d79c43e542447a4acf8146c8f80e49a68cc78582aa6f72314da55a68decdf8
3
+ metadata.gz: 0e0505b26f76af0f596d0c5b2b6763776ca28e0e83ef16207393488534ecde42
4
+ data.tar.gz: fc1f956be9ae1a997989c4f67cb399bc1c4ad0fd26034913f74d65235658cac9
5
5
  SHA512:
6
- metadata.gz: 7a843c2327f75c56684fd34873c999657b4aafcf2bc48e38b593eb0c571d9dde655109a235c309a949e9dd7b705b968476433b423660179e7bcc3ddb2623c0d4
7
- data.tar.gz: 7686d8f2e1317a112a2d86cb479789d2b6316426e6b72eaf035fd105b9f2cc74fa1940f6693fe56184eb3fb5d466b8dea879169568e1361d91c71912ef02ca27
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)
@@ -15,6 +15,7 @@ module Jekyll
15
15
  require 'uri'
16
16
 
17
17
  uri = URI url
18
+ uri.host.sub! 'www.', ''
18
19
  name = %r{/@\w+} =~ uri.query ? 'mastodon' : uri.host.split('.', 2).first
19
20
 
20
21
  { 'host' => uri.host, 'name' => name, 'url' => url }.to_liquid
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.1.1
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-24 00:00:00.000000000 Z
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