sutty-liquid 0.3.0 → 0.6.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 +110 -10
- data/lib/jekyll/filters/menu.rb +65 -0
- data/lib/jekyll/filters/strings.rb +14 -0
- data/lib/sutty-liquid.rb +4 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b58c33b1e623a64bd0a19a7beed5f313f541165d0570968e5e3248c89489b3b
|
4
|
+
data.tar.gz: 127bd73962c2fb5c8beb66109821b52a0d0335904ff136f5f635ff907434c3c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fa6d9ccd19f5506fedaff884f603c4df346d0a054deba298589937695728ec6b99a89b08e608f9690bcc62fc27a18fe2bae444caa2ba236b381ea36d2678780
|
7
|
+
data.tar.gz: 86aec73c5775a064e60030e3dd291301cb474bdf6f64fb492df45172c8c2e962d56de2d47fbced270b9ae046c22a8fea36f1c9675f692fa4915371c438f5ed03
|
@@ -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
|
@@ -16,6 +16,47 @@ module Jekyll
|
|
16
16
|
input == comparison
|
17
17
|
end
|
18
18
|
|
19
|
+
# The two values must be different
|
20
|
+
def not(input, comparison)
|
21
|
+
input != comparison
|
22
|
+
end
|
23
|
+
|
24
|
+
# Greater than
|
25
|
+
#
|
26
|
+
# @param [Integer|Float]
|
27
|
+
# @param [Integer|Float]
|
28
|
+
# @return [TrueClass|FalseClass]
|
29
|
+
def gt(input, comparison)
|
30
|
+
input > comparison
|
31
|
+
end
|
32
|
+
|
33
|
+
# Less than
|
34
|
+
#
|
35
|
+
# @param [Integer|Float]
|
36
|
+
# @param [Integer|Float]
|
37
|
+
# @return [TrueClass|FalseClass]
|
38
|
+
def lt(input, comparison)
|
39
|
+
input < comparison
|
40
|
+
end
|
41
|
+
|
42
|
+
# Greater than or equal
|
43
|
+
#
|
44
|
+
# @param [Integer|Float]
|
45
|
+
# @param [Integer|Float]
|
46
|
+
# @return [TrueClass|FalseClass]
|
47
|
+
def gte(input, comparison)
|
48
|
+
input >= comparison
|
49
|
+
end
|
50
|
+
|
51
|
+
# Less than or equal
|
52
|
+
#
|
53
|
+
# @param [Integer|Float]
|
54
|
+
# @param [Integer|Float]
|
55
|
+
# @return [TrueClass|FalseClass]
|
56
|
+
def lte(input, comparison)
|
57
|
+
input <= comparison
|
58
|
+
end
|
59
|
+
|
19
60
|
# Ternary operator. If the input value is truthy, return first
|
20
61
|
# argument, otherwise returns the last.
|
21
62
|
#
|
@@ -29,16 +70,75 @@ module Jekyll
|
|
29
70
|
# @param [Any]
|
30
71
|
# @return [Any]
|
31
72
|
def ternary(input, value, alternative)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
73
|
+
if present(input) && input
|
74
|
+
value
|
75
|
+
else
|
76
|
+
alternative
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Returns the value when the input is not empty or falsey
|
81
|
+
#
|
82
|
+
# If tags have something:
|
83
|
+
#
|
84
|
+
# {{ post.tags | value_if: "some tags" }} => "some tags"
|
85
|
+
def value_if(input, value)
|
86
|
+
value if present(input) && input
|
87
|
+
end
|
88
|
+
|
89
|
+
# Returns the value when the input is empty or falsey
|
90
|
+
#
|
91
|
+
# If tags are empty:
|
92
|
+
#
|
93
|
+
# {{ post.tags | value_unless: "no tags" }} => nil
|
94
|
+
def value_unless(input, value)
|
95
|
+
value unless present(input) && input
|
96
|
+
end
|
97
|
+
|
98
|
+
# Returns the input when value is not empty and truthy
|
99
|
+
#
|
100
|
+
# {{ post.url | input_if: true }} => 'url/to/post/'
|
101
|
+
def input_if(input, value)
|
102
|
+
input if present(value) && value
|
103
|
+
end
|
104
|
+
|
105
|
+
# {{ post.url | input_unless: false }} => nil
|
106
|
+
def input_unless(input, value)
|
107
|
+
input unless present(value) && value
|
108
|
+
end
|
109
|
+
|
110
|
+
# Checks if input value is empty.
|
111
|
+
#
|
112
|
+
# {{ post.title | blank }} => false
|
113
|
+
def blank(input)
|
114
|
+
case input
|
115
|
+
when TrueClass then false
|
116
|
+
when FalseClass then true
|
117
|
+
when NilClass then true
|
118
|
+
when Integer then false
|
119
|
+
when Float then false
|
120
|
+
when Time then false
|
121
|
+
when String then
|
122
|
+
require 'fast_blank'
|
123
|
+
input.blank?
|
124
|
+
when Array then input.compact.empty?
|
125
|
+
when Hash then input.compact.empty?
|
126
|
+
else input.respond_to?(:empty?) ? input.empty? : !!input
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# The opposite of blank
|
131
|
+
#
|
132
|
+
# {{ post.title | present }} => true
|
133
|
+
def present(input)
|
134
|
+
!blank(input)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Return the input if it's not blank
|
138
|
+
#
|
139
|
+
# {{ post.title | presence }} => 'the post title'
|
140
|
+
def presence(input)
|
141
|
+
input if present input
|
42
142
|
end
|
43
143
|
end
|
44
144
|
end
|
@@ -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,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Filters
|
5
|
+
module Strings
|
6
|
+
# String#start_with?
|
7
|
+
def start_with(input, start)
|
8
|
+
input.to_s.start_with? start.to_s
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Liquid::Template.register_filter(Jekyll::Filters::Strings)
|
data/lib/sutty-liquid.rb
CHANGED
@@ -6,9 +6,13 @@ require_relative 'jekyll/filters/date_local'
|
|
6
6
|
require_relative 'jekyll/filters/infinite'
|
7
7
|
require_relative 'jekyll/filters/file'
|
8
8
|
require_relative 'jekyll/filters/json'
|
9
|
+
require_relative 'jekyll/filters/menu'
|
9
10
|
require_relative 'jekyll/filters/number'
|
10
11
|
require_relative 'jekyll/filters/sample'
|
12
|
+
require_relative 'jekyll/filters/strings'
|
11
13
|
require_relative 'jekyll/filters/social_network'
|
12
14
|
|
13
15
|
require_relative 'jekyll/filters/pry'
|
14
16
|
require_relative 'jekyll/tags/pry'
|
17
|
+
|
18
|
+
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.6.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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fast_blank
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
27
41
|
description: An assorment of Liquid filters and tags for Jekyll used in Sutty
|
28
42
|
email:
|
29
43
|
- f@sutty.nl
|
@@ -35,16 +49,19 @@ extra_rdoc_files:
|
|
35
49
|
files:
|
36
50
|
- LICENSE.txt
|
37
51
|
- README.md
|
52
|
+
- lib/jekyll/drops/url_drop_decorator.rb
|
38
53
|
- lib/jekyll/filters/assertion.rb
|
39
54
|
- lib/jekyll/filters/compact.rb
|
40
55
|
- lib/jekyll/filters/date_local.rb
|
41
56
|
- lib/jekyll/filters/file.rb
|
42
57
|
- lib/jekyll/filters/infinite.rb
|
43
58
|
- lib/jekyll/filters/json.rb
|
59
|
+
- lib/jekyll/filters/menu.rb
|
44
60
|
- lib/jekyll/filters/number.rb
|
45
61
|
- lib/jekyll/filters/pry.rb
|
46
62
|
- lib/jekyll/filters/sample.rb
|
47
63
|
- lib/jekyll/filters/social_network.rb
|
64
|
+
- lib/jekyll/filters/strings.rb
|
48
65
|
- lib/jekyll/tags/pry.rb
|
49
66
|
- lib/sutty-liquid.rb
|
50
67
|
homepage: https://0xacab.org/sutty/jekyll/sutty-liquid
|