sutty-liquid 0.1.1 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll/drops/url_drop_decorator.rb +16 -0
- data/lib/jekyll/filters/assertion.rb +47 -0
- data/lib/jekyll/filters/compact.rb +4 -0
- data/lib/jekyll/filters/date_local.rb +63 -0
- data/lib/jekyll/filters/file.rb +5 -1
- data/lib/jekyll/filters/json.rb +2 -1
- data/lib/jekyll/filters/menu.rb +65 -0
- data/lib/jekyll/filters/number.rb +24 -0
- data/lib/jekyll/filters/pry.rb +4 -0
- data/lib/jekyll/filters/sample.rb +5 -1
- data/lib/jekyll/filters/social_network.rb +10 -0
- data/lib/jekyll/tags/pry.rb +4 -0
- data/lib/sutty-liquid.rb +14 -8
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d90e4da9fe0d1b7d177e20fd9a05f825a07d3465d99b1641d79b75879d526c00
|
4
|
+
data.tar.gz: f467555d544fca178ba15dce7f1de53eadfcbea7a263fe91f9a6066ac92664d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94b85e20c7c10e267e67534ab215d94539b482cc807ff7623f03d8f281463df12395cde294d00814b0b8db04897dfde6cbe0880d882982459050f7d8f53e28eb
|
7
|
+
data.tar.gz: 1dd71eb67a50c79a1f796ff0813968f2275e7b3fd56afe5f45234a2efc5244bb87c0da10fc90fb417547d64f72a3dbc534efa09c772dfe95eae063def69a2dd0
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'jekyll/drops/url_drop'
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module Drops
|
7
|
+
module UrlDropDecorator
|
8
|
+
# Permits to use layout as an URL placeholder
|
9
|
+
def layout
|
10
|
+
@obj.data['layout']
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Jekyll::Drops::UrlDrop.include Jekyll::Drops::UrlDropDecorator
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Filters
|
5
|
+
module Assertion
|
6
|
+
# Compares two values.
|
7
|
+
#
|
8
|
+
# Example usage:
|
9
|
+
#
|
10
|
+
# {{ item.url | equals: page.url }}
|
11
|
+
#
|
12
|
+
# @param [Any]
|
13
|
+
# @param [Any]
|
14
|
+
# @return [TrueClass|FalseClass]
|
15
|
+
def equals(input, comparison)
|
16
|
+
input == comparison
|
17
|
+
end
|
18
|
+
|
19
|
+
# Ternary operator. If the input value is truthy, return first
|
20
|
+
# argument, otherwise returns the last.
|
21
|
+
#
|
22
|
+
# Example usage:
|
23
|
+
#
|
24
|
+
# {% assign active = item.url | equals: page.url %}
|
25
|
+
# {{ active | ternary: 'active', '' }}
|
26
|
+
#
|
27
|
+
# @param [Any]
|
28
|
+
# @param [Any]
|
29
|
+
# @param [Any]
|
30
|
+
# @return [Any]
|
31
|
+
def ternary(input, value, alternative)
|
32
|
+
empty = case input
|
33
|
+
when Integer then input.zero?
|
34
|
+
when Float then input.zero?
|
35
|
+
when TrueClass then input
|
36
|
+
when FalseClass then input
|
37
|
+
when NilClass then false
|
38
|
+
else input.empty?
|
39
|
+
end
|
40
|
+
|
41
|
+
(empty || !!input) ? value : alternative
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
Liquid::Template.register_filter(Jekyll::Filters::Assertion)
|
@@ -0,0 +1,63 @@
|
|
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
|
7
|
+
# your _data/LANG.yml
|
8
|
+
#
|
9
|
+
# Example usage:
|
10
|
+
#
|
11
|
+
# {{ page.date | date_local: '%e de %B de %Y' }}
|
12
|
+
#
|
13
|
+
# @see {_data/es.yml}
|
14
|
+
# @param [String|Date]
|
15
|
+
# @param [String]
|
16
|
+
# @return [String]
|
17
|
+
def date_local(input, format)
|
18
|
+
require 'date'
|
19
|
+
|
20
|
+
input = Date.parse(input) if input.is_a? String
|
21
|
+
|
22
|
+
# Return early if we don't need to translate
|
23
|
+
return input.strftime(format) unless /%(|\^)[aAbBpP]/ =~ format
|
24
|
+
|
25
|
+
input.strftime translate_localization_format(input, format)
|
26
|
+
rescue ArgumentError
|
27
|
+
Jekyll.logger.warn "#{input} is not a valid Date"
|
28
|
+
input
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# Adapted from the i18n gem
|
34
|
+
# @see {https://github.com/ruby-i18n/i18n/blob/a8f4fdcb197e56b5a698d1bc68007dd0871c03bf/lib/i18n/backend/base.rb}
|
35
|
+
def translate_localization_format(object, format)
|
36
|
+
format.to_s.gsub(/%(|\^)[aAbBpP]/) do |match|
|
37
|
+
case match
|
38
|
+
when '%a' then i18n.dig('date', 'abbr_day_names', object.wday - 1)
|
39
|
+
when '%^a' then i18n.dig('date', 'abbr_day_names', object.wday - 1)&.upcase
|
40
|
+
when '%A' then i18n.dig('date', 'day_names', object.wday - 1)
|
41
|
+
when '%^A' then i18n.dig('date', 'day_names', object.wday - 1)&.upcase
|
42
|
+
when '%b' then i18n.dig('date', 'abbr_month_names', object.mon - 1)
|
43
|
+
when '%^b' then i18n.dig('date', 'abbr_month_names', object.mon - 1)&.upcase
|
44
|
+
when '%B' then i18n.dig('date', 'month_names', object.mon - 1)
|
45
|
+
when '%^B' then i18n.dig('date', 'month_names', object.mon - 1)&.upcase
|
46
|
+
when '%p' then i18n.dig('time', object.hour < 12 ? 'am' : 'pm')&.upcase if object.respond_to? :hour
|
47
|
+
when '%P' then i18n.dig('time', object.hour < 12 ? 'am' : 'pm')&.downcase if object.respond_to? :hour
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def site
|
53
|
+
@site ||= @context.registers[:site]
|
54
|
+
end
|
55
|
+
|
56
|
+
def i18n
|
57
|
+
@i18n ||= site.data.dig site.config['lang']
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
Liquid::Template.register_filter(Jekyll::Filters::DateLocal)
|
data/lib/jekyll/filters/file.rb
CHANGED
data/lib/jekyll/filters/json.rb
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Filters
|
5
|
+
module Menu
|
6
|
+
# Verifies if the given URL is an active item on the menu.
|
7
|
+
#
|
8
|
+
# Example usage:
|
9
|
+
#
|
10
|
+
# {% assign active_url = page.url | menu_active %}
|
11
|
+
# {% for item in site.i18n.menu.items %}
|
12
|
+
# <a
|
13
|
+
# href="{{ item.href }}"
|
14
|
+
# class="{{ page.url | menu_active | equals: item.href | ternary: 'active', '' }}">
|
15
|
+
#
|
16
|
+
# {{ item.title }}
|
17
|
+
# </a>
|
18
|
+
# {% endfor %}
|
19
|
+
#
|
20
|
+
# @param [String] The URL to be verified
|
21
|
+
# @return [String] The item URL
|
22
|
+
def menu_active_item(page_url)
|
23
|
+
site_menu&.find do |key, value|
|
24
|
+
key == page_url || page_url.start_with?(key)
|
25
|
+
end&.last
|
26
|
+
end
|
27
|
+
|
28
|
+
# The menu is defined in a data file that corresponds to the site
|
29
|
+
# language. This method converts the menu items into a map of URL
|
30
|
+
# parts and actual URLs.
|
31
|
+
#
|
32
|
+
# @see _data/es.yml
|
33
|
+
# @see {https://0xacab.org/sutty/jekyll/jekyll-locales}
|
34
|
+
# @return [Hash]
|
35
|
+
def site_menu
|
36
|
+
site = @context.registers[:site]
|
37
|
+
@site_menu ||= site.data.dig(site.config['locale'], 'menu', 'items')&.reduce({}) do |menu, item|
|
38
|
+
# If the item has a layout, we pick the first post and update
|
39
|
+
# the href. We can't do the same for all posts because we
|
40
|
+
# wouldn't be able to cache the menu.
|
41
|
+
if item['layout']
|
42
|
+
doc = site.documents.find do |doc|
|
43
|
+
doc.data['layout'] == item['layout']
|
44
|
+
end
|
45
|
+
|
46
|
+
item['href'] = doc&.url
|
47
|
+
end
|
48
|
+
|
49
|
+
# Ignore empty or anchor items
|
50
|
+
next menu if item['href'].nil? || item['href'].empty? || item['href']&.start_with?('#')
|
51
|
+
|
52
|
+
menu[item['href']] = item['href']
|
53
|
+
|
54
|
+
item['active']&.each do |a|
|
55
|
+
menu[a] = item['href']
|
56
|
+
end
|
57
|
+
|
58
|
+
menu
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
Liquid::Template.register_filter(Jekyll::Filters::Menu)
|
@@ -0,0 +1,24 @@
|
|
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
|
+
# Example usage:
|
9
|
+
#
|
10
|
+
# <a href="tel:{{ page.tel | numbers }}">{{ page.tel }}</a>
|
11
|
+
#
|
12
|
+
# @param [String]
|
13
|
+
# @return [String]
|
14
|
+
module Numbers
|
15
|
+
def numbers(input)
|
16
|
+
return unless input.respond_to? :gsub
|
17
|
+
|
18
|
+
input.gsub(%r{[^0-9]}, '')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Liquid::Template.register_filter(Jekyll::Filters::Numbers)
|
data/lib/jekyll/filters/pry.rb
CHANGED
@@ -7,6 +7,15 @@ module Jekyll
|
|
7
7
|
# want to generate social network buttons from an undetermined
|
8
8
|
# list of URLs.
|
9
9
|
#
|
10
|
+
# Example usage:
|
11
|
+
#
|
12
|
+
# {% assign mastodon = 'https://todon.nl/@sutty' | social_network %}
|
13
|
+
# <a href="{{ mastodon.url }}">
|
14
|
+
# <i class="fa-{{ mastodon.name }}"></i>
|
15
|
+
#
|
16
|
+
# {{ mastodon.name | capitalize }}
|
17
|
+
# </a>
|
18
|
+
#
|
10
19
|
# @param [String]
|
11
20
|
# @return [Hash]
|
12
21
|
def social_network(url)
|
@@ -15,6 +24,7 @@ module Jekyll
|
|
15
24
|
require 'uri'
|
16
25
|
|
17
26
|
uri = URI url
|
27
|
+
uri.host.sub! 'www.', ''
|
18
28
|
name = %r{/@\w+} =~ uri.query ? 'mastodon' : uri.host.split('.', 2).first
|
19
29
|
|
20
30
|
{ 'host' => uri.host, 'name' => name, 'url' => url }.to_liquid
|
data/lib/jekyll/tags/pry.rb
CHANGED
data/lib/sutty-liquid.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'jekyll/filters/
|
4
|
-
require_relative 'jekyll/filters/
|
5
|
-
require_relative 'jekyll/filters/
|
6
|
-
require_relative 'jekyll/filters/
|
7
|
-
require_relative 'jekyll/filters/
|
8
|
-
require_relative 'jekyll/filters/
|
3
|
+
require_relative 'jekyll/filters/assertion'
|
4
|
+
require_relative 'jekyll/filters/compact'
|
5
|
+
require_relative 'jekyll/filters/date_local'
|
6
|
+
require_relative 'jekyll/filters/infinite'
|
7
|
+
require_relative 'jekyll/filters/file'
|
8
|
+
require_relative 'jekyll/filters/json'
|
9
|
+
require_relative 'jekyll/filters/menu'
|
10
|
+
require_relative 'jekyll/filters/number'
|
11
|
+
require_relative 'jekyll/filters/sample'
|
12
|
+
require_relative 'jekyll/filters/social_network'
|
9
13
|
|
10
|
-
require_relative 'jekyll/filters/pry
|
11
|
-
require_relative 'jekyll/tags/pry
|
14
|
+
require_relative 'jekyll/filters/pry'
|
15
|
+
require_relative 'jekyll/tags/pry'
|
16
|
+
|
17
|
+
require_relative 'jekyll/drops/url_drop_decorator'
|
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.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- f
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -35,10 +35,15 @@ extra_rdoc_files:
|
|
35
35
|
files:
|
36
36
|
- LICENSE.txt
|
37
37
|
- README.md
|
38
|
+
- lib/jekyll/drops/url_drop_decorator.rb
|
39
|
+
- lib/jekyll/filters/assertion.rb
|
38
40
|
- lib/jekyll/filters/compact.rb
|
41
|
+
- lib/jekyll/filters/date_local.rb
|
39
42
|
- lib/jekyll/filters/file.rb
|
40
43
|
- lib/jekyll/filters/infinite.rb
|
41
44
|
- lib/jekyll/filters/json.rb
|
45
|
+
- lib/jekyll/filters/menu.rb
|
46
|
+
- lib/jekyll/filters/number.rb
|
42
47
|
- lib/jekyll/filters/pry.rb
|
43
48
|
- lib/jekyll/filters/sample.rb
|
44
49
|
- lib/jekyll/filters/social_network.rb
|
@@ -75,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
80
|
- !ruby/object:Gem::Version
|
76
81
|
version: '0'
|
77
82
|
requirements: []
|
78
|
-
rubygems_version: 3.
|
83
|
+
rubygems_version: 3.1.2
|
79
84
|
signing_key:
|
80
85
|
specification_version: 4
|
81
86
|
summary: Liquid filters
|