sutty-liquid 0.3.0 → 0.4.0

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: 01c1a35c0761f6c17219e3e9a06ddb2b949bf3b1433787700ade08620a55f49b
4
- data.tar.gz: fc671ef7716697be23407fd269647f7b8b49973c6576d6c5d2a9b0007779d014
3
+ metadata.gz: 5821ac5773831bb4da8ff820a9e37e52cbdda1eb6d4d02394806b3553521d199
4
+ data.tar.gz: 28fc6cadd2764f2c13d25a80464b2431b68c4bcb439dd8955b34fd7186943832
5
5
  SHA512:
6
- metadata.gz: 46fa3a15890cdf1dcada8d15d339b2bd42aa1d36d87fff009da40662400779ba5e31c3af853717c75a838f7ad712a9e5b8d487cc58048ee6636473d70a257884
7
- data.tar.gz: 6fdb47629110a3548141995992c7cf9392d7e4e214efb37921ba422aa72af4303f7e13f88319b115bd852e4af12f1e7e8c086ba074f89e8f53dae63a5648a940
6
+ metadata.gz: 6f03097086f1ec6790b5476d0e138aaae5719968e5967e33481d6995ac3abac78f3ed5f7ce29822f5622ae8d00e66296d52ffecfda696a9b619efebc205f6214
7
+ data.tar.gz: 6c21db3c81ace646f82c244579f5452cdd18cb88ceb16ce9676d2026b3df85c24b41b4dc1d1834eea007feccb1208d0532c071806ec38c645b8858b90fc822e4
@@ -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,54 @@
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
+ # Ignore empty or anchor items
39
+ next menu if item['href'].nil? || item['href'].empty? || item['href']&.start_with?('#')
40
+
41
+ menu[item['href']] = item['href']
42
+
43
+ item['active']&.each do |a|
44
+ menu[a] = item['href']
45
+ end
46
+
47
+ menu
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ Liquid::Template.register_filter(Jekyll::Filters::Menu)
@@ -6,9 +6,12 @@ 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'
11
12
  require_relative 'jekyll/filters/social_network'
12
13
 
13
14
  require_relative 'jekyll/filters/pry'
14
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.3.0
4
+ version: 0.4.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-10-02 00:00:00.000000000 Z
11
+ date: 2020-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -35,12 +35,14 @@ extra_rdoc_files:
35
35
  files:
36
36
  - LICENSE.txt
37
37
  - README.md
38
+ - lib/jekyll/drops/url_drop_decorator.rb
38
39
  - lib/jekyll/filters/assertion.rb
39
40
  - lib/jekyll/filters/compact.rb
40
41
  - lib/jekyll/filters/date_local.rb
41
42
  - lib/jekyll/filters/file.rb
42
43
  - lib/jekyll/filters/infinite.rb
43
44
  - lib/jekyll/filters/json.rb
45
+ - lib/jekyll/filters/menu.rb
44
46
  - lib/jekyll/filters/number.rb
45
47
  - lib/jekyll/filters/pry.rb
46
48
  - lib/jekyll/filters/sample.rb