sutty-liquid 0.2.0 → 0.5.1

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: 0e0505b26f76af0f596d0c5b2b6763776ca28e0e83ef16207393488534ecde42
4
- data.tar.gz: fc1f956be9ae1a997989c4f67cb399bc1c4ad0fd26034913f74d65235658cac9
3
+ metadata.gz: 4c72d9f508299076408aafbf0aa0e75f128259b3f647b16951f4f0b3ec18233a
4
+ data.tar.gz: 6c3216caa9bf468ea6375badf89cc33eef090ce41e98c8f0f9b7c492a28626d3
5
5
  SHA512:
6
- metadata.gz: 2b9b2e9d866d1766922f9f69263a7ff8d9c11f01cab5a000f6d8a605048d8acd81a3d7a7319a8aa161e5f86727bf26e26b084b7b73521acb705ad4da6a3912a8
7
- data.tar.gz: 1bfaf334727887f40399d4680dab162001ec80faf513a595411fc7dc800d41591a90ec5b3987207b7a97d202373eab08a089a246c57ecfb2ad111dcb95e0070a
6
+ metadata.gz: 7215373c2ff717d19d0b6593f2e938c153c2f2c7825928b9f8a88d416e61a7624e09fbcfc55f83e62859481231ae3700f7aae7a03d184e880e037d5c0362d35a
7
+ data.tar.gz: 414606c886d9e4313d405e95664ad8e108a562bb9a60490abf1f5042edb0df32533f5e30f97b1559fbe31cc55c33aca6bbfaa92e4b2ba40a0f0366a1f41b1565
@@ -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)
@@ -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,11 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'jekyll/filters/compact.rb'
4
- require_relative 'jekyll/filters/infinite.rb'
5
- require_relative 'jekyll/filters/file.rb'
6
- require_relative 'jekyll/filters/json.rb'
7
- require_relative 'jekyll/filters/sample.rb'
8
- require_relative 'jekyll/filters/social_network.rb'
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.rb'
11
- require_relative 'jekyll/tags/pry.rb'
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.2.0
4
+ version: 0.5.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-09-27 00:00:00.000000000 Z
11
+ date: 2020-11-11 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,11 +49,14 @@ 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
@@ -77,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
94
  - !ruby/object:Gem::Version
78
95
  version: '0'
79
96
  requirements: []
80
- rubygems_version: 3.0.3
97
+ rubygems_version: 3.1.2
81
98
  signing_key:
82
99
  specification_version: 4
83
100
  summary: Liquid filters