sutty-liquid 0.4.0 → 0.6.2

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: 5821ac5773831bb4da8ff820a9e37e52cbdda1eb6d4d02394806b3553521d199
4
- data.tar.gz: 28fc6cadd2764f2c13d25a80464b2431b68c4bcb439dd8955b34fd7186943832
3
+ metadata.gz: cdc0091123dbfe9bfa0c5737ebf65f403f3d77998d6c9d6cc3843161df340b65
4
+ data.tar.gz: 9766675f543da7cc28a78b267b227f14012b54582af4359bbeb9e3b48f88a24a
5
5
  SHA512:
6
- metadata.gz: 6f03097086f1ec6790b5476d0e138aaae5719968e5967e33481d6995ac3abac78f3ed5f7ce29822f5622ae8d00e66296d52ffecfda696a9b619efebc205f6214
7
- data.tar.gz: 6c21db3c81ace646f82c244579f5452cdd18cb88ceb16ce9676d2026b3df85c24b41b4dc1d1834eea007feccb1208d0532c071806ec38c645b8858b90fc822e4
6
+ metadata.gz: 1f228b8e153d2814918326b742dfcb6810a5f6d1a2d16a472159070dae8e9f1e5b5b2083fded57b3509ad59bec8b60ac37e59b84c287c74e94582348dd1400cf
7
+ data.tar.gz: 0ec63e9e40d6bded522ca7ae8f9ae2624e72b72fc1daa3069a287fc96188f81ac12f8dd1fb3ffc05a037e784f91b4fb7f5ad636b0c9ef37420d6da24ac3eeaa2
@@ -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
- 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
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
@@ -35,6 +35,17 @@ module Jekyll
35
35
  def site_menu
36
36
  site = @context.registers[:site]
37
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
+
38
49
  # Ignore empty or anchor items
39
50
  next menu if item['href'].nil? || item['href'].empty? || item['href']&.start_with?('#')
40
51
 
@@ -12,6 +12,8 @@ module Jekyll
12
12
  require 'pry'
13
13
 
14
14
  binding.pry
15
+
16
+ input
15
17
  end
16
18
  end
17
19
  end
@@ -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)
@@ -9,6 +9,7 @@ require_relative 'jekyll/filters/json'
9
9
  require_relative 'jekyll/filters/menu'
10
10
  require_relative 'jekyll/filters/number'
11
11
  require_relative 'jekyll/filters/sample'
12
+ require_relative 'jekyll/filters/strings'
12
13
  require_relative 'jekyll/filters/social_network'
13
14
 
14
15
  require_relative 'jekyll/filters/pry'
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.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-08 00:00:00.000000000 Z
11
+ date: 2020-12-19 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
@@ -47,6 +61,7 @@ files:
47
61
  - lib/jekyll/filters/pry.rb
48
62
  - lib/jekyll/filters/sample.rb
49
63
  - lib/jekyll/filters/social_network.rb
64
+ - lib/jekyll/filters/strings.rb
50
65
  - lib/jekyll/tags/pry.rb
51
66
  - lib/sutty-liquid.rb
52
67
  homepage: https://0xacab.org/sutty/jekyll/sutty-liquid