sutty-liquid 0.2.1 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 297273ee3421e54485a3e5dcb5318f26a4c83a1be37b39b10e67d9b4d051867c
4
- data.tar.gz: 340d83e54a080233772571bc1bef3d7d46a04305a8da8a7e87e1d6b7d9389b00
3
+ metadata.gz: 208a07a3955ffd0ba332ba272d1b7ba868aacee433bb1a71cc1af72468a4d434
4
+ data.tar.gz: 5c5228f00ef585c35524310a5c0b57e71292dc35890ace25ce691c7ccb6b7f10
5
5
  SHA512:
6
- metadata.gz: 27f0b80e42f9236d74af8b88478507794ffdcd8b7c7f556719f77d6f3c1fd95f04df0200a1669cf187e20e22bab207832c17f164319d1386c1693e51df0b0f45
7
- data.tar.gz: f2d249f94e33161195357f173f154b5327f22bb8ae5b1bd34b39c95f9a77b1a34ca27b857de889cc2d28312a51402bdb2c0a77a48b62a183c47e197196157bec
6
+ metadata.gz: 41efec969df4effe3e52596b0ce4c38f93cf828b4e9f3614dc644d11b838d18d841ed4e5f2bf5a3ab05a106cafeaf8985c623defdbc8fd36679e9b89d4728e7d
7
+ data.tar.gz: dbacfff37b6598665a29290d75f106918dc47c96c9ee36c02f4e107b15e94b828814c9af045b47e440407ef696242448cef2f9a82a08949a57c6fd8a23fe6dde
@@ -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,147 @@
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
+ # 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
+
60
+ # Ternary operator. If the input value is truthy, return first
61
+ # argument, otherwise returns the last.
62
+ #
63
+ # Example usage:
64
+ #
65
+ # {% assign active = item.url | equals: page.url %}
66
+ # {{ active | ternary: 'active', '' }}
67
+ #
68
+ # @param [Any]
69
+ # @param [Any]
70
+ # @param [Any]
71
+ # @return [Any]
72
+ def ternary(input, value, alternative)
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
142
+ end
143
+ end
144
+ end
145
+ end
146
+
147
+ Liquid::Template.register_filter(Jekyll::Filters::Assertion)
@@ -5,6 +5,10 @@ module Jekyll
5
5
  module Compact
6
6
  # Removes nil values from an Array
7
7
  #
8
+ # Example usage:
9
+ #
10
+ # {{ 'tag,,tag2' | split: ',' | compact }}
11
+ #
8
12
  # @param [Array]
9
13
  # @return [Array]
10
14
  def compact(array)
@@ -3,7 +3,12 @@
3
3
  module Jekyll
4
4
  module Filters
5
5
  module DateLocal
6
- # Translates month and day names. This requires certain values on your _data/LANG.yml
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' }}
7
12
  #
8
13
  # @see {_data/es.yml}
9
14
  # @param [String|Date]
@@ -3,7 +3,11 @@
3
3
  module Jekyll
4
4
  module Filters
5
5
  module File
6
- # File extension
6
+ # File extension.
7
+ #
8
+ # Example usage:
9
+ #
10
+ # {{ page.file.path | extname }}
7
11
  #
8
12
  # @param [String]
9
13
  # @return [Nil|String]
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
-
4
3
  module Jekyll
5
4
  module Filters
6
5
  module Json
7
6
  # Converts an object to JSON
8
7
  #
8
+ # Note: Jekyll 4 has a jsonify filter now.
9
+ #
9
10
  # @param [Any]
10
11
  # @return [String]
11
12
  def json(object)
@@ -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)
@@ -5,6 +5,10 @@ module Jekyll
5
5
  # Extracts numbers from a String, useful for converting phone
6
6
  # numbers to tel: links.
7
7
  #
8
+ # Example usage:
9
+ #
10
+ # <a href="tel:{{ page.tel | numbers }}">{{ page.tel }}</a>
11
+ #
8
12
  # @param [String]
9
13
  # @return [String]
10
14
  module Numbers
@@ -4,6 +4,10 @@ module Jekyll
4
4
  module Filters
5
5
  module Pry
6
6
  # Pry into the input and args
7
+ #
8
+ # Example usage:
9
+ #
10
+ # {{ site.posts | pry }}
7
11
  def pry(input, *args)
8
12
  require 'pry'
9
13
 
@@ -3,7 +3,11 @@
3
3
  module Jekyll
4
4
  module Filters
5
5
  module Sample
6
- # Returns a random item from an Array
6
+ # Returns a random item from an Array.
7
+ #
8
+ # Example usage:
9
+ #
10
+ # {{ site.posts | sample }}
7
11
  #
8
12
  # @input [Array]
9
13
  # @return [Any]
@@ -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)
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Filters
5
+ module String
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::String)
@@ -4,6 +4,10 @@ module Jekyll
4
4
  module Tags
5
5
  class Pry < Liquid::Tag
6
6
  # Pry into the rendering context
7
+ #
8
+ # Example usage:
9
+ #
10
+ # {% pry %}
7
11
  def render(context)
8
12
  require 'pry'
9
13
 
@@ -1,13 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'jekyll/filters/assertion'
3
4
  require_relative 'jekyll/filters/compact'
4
5
  require_relative 'jekyll/filters/date_local'
5
6
  require_relative 'jekyll/filters/infinite'
6
7
  require_relative 'jekyll/filters/file'
7
8
  require_relative 'jekyll/filters/json'
9
+ require_relative 'jekyll/filters/menu'
8
10
  require_relative 'jekyll/filters/number'
9
11
  require_relative 'jekyll/filters/sample'
12
+ require_relative 'jekyll/filters/string'
10
13
  require_relative 'jekyll/filters/social_network'
11
14
 
12
15
  require_relative 'jekyll/filters/pry'
13
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.2.1
4
+ version: 0.6.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-29 00:00:00.000000000 Z
11
+ date: 2020-11-12 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,15 +49,19 @@ extra_rdoc_files:
35
49
  files:
36
50
  - LICENSE.txt
37
51
  - README.md
52
+ - lib/jekyll/drops/url_drop_decorator.rb
53
+ - lib/jekyll/filters/assertion.rb
38
54
  - lib/jekyll/filters/compact.rb
39
55
  - lib/jekyll/filters/date_local.rb
40
56
  - lib/jekyll/filters/file.rb
41
57
  - lib/jekyll/filters/infinite.rb
42
58
  - lib/jekyll/filters/json.rb
59
+ - lib/jekyll/filters/menu.rb
43
60
  - lib/jekyll/filters/number.rb
44
61
  - lib/jekyll/filters/pry.rb
45
62
  - lib/jekyll/filters/sample.rb
46
63
  - lib/jekyll/filters/social_network.rb
64
+ - lib/jekyll/filters/string.rb
47
65
  - lib/jekyll/tags/pry.rb
48
66
  - lib/sutty-liquid.rb
49
67
  homepage: https://0xacab.org/sutty/jekyll/sutty-liquid