jekyll_icon_list 0.3.1 → 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: 294f5dc753151d6747ad2bcef2a8f22093778670afa2e22f79694eef6e0cf5cd
4
- data.tar.gz: 7e7581912633dcd57786f1cf8154c7b02d99ce84b72ee569d6991777dfc65de9
3
+ metadata.gz: 66af09ff271544ab5afed2a9e28e05769d75337d43dafa32747fc546d1f91f5f
4
+ data.tar.gz: 26ebee9c1b1fa4589a3587c2fa9169a5cc18304948e032d639e15cec76e132e9
5
5
  SHA512:
6
- metadata.gz: 8e79caf7c62ec1785166e32564cebac56de016d72552420b73fb44f0f4e02537efe79f7a5412b38b327d8122fa683824637c47d0301b0a6311a93ce0537342cf
7
- data.tar.gz: 755ab786b160630bf38271396d9ea0bafb8abc207b785ed62ebf81130ae71e05179de815a06da04c651d7911022dda56e2fe898f9bf8ff843fa616597de24109
6
+ metadata.gz: 1b507c5492ac70c6cd0aedd02e56e7f2efdf264733ee280315c086b9d09b734c480700b10c85f5ddb6c8d0903051260e00edc5896de608a93bebad6bf7c6575a
7
+ data.tar.gz: 38507a86625e2ec9ab637359bdeaad9ed195b7ede1c22885e5878ec1ff90a6cefa8123f325722ef61567edfc57bd2f6ed7b5085f3a5a559c9e221befec2f5d07
data/README.md CHANGED
@@ -48,6 +48,10 @@ plugins:
48
48
 
49
49
  ```
50
50
  {% icon_list example example2 example3 %}
51
+
52
+ # or:
53
+
54
+ {% icon_list {{ page.categories }} %}
51
55
  ```
52
56
 
53
57
  By default, with no configuration:
@@ -104,6 +108,30 @@ would like to use, which will be prepended by your default_path if you set one (
104
108
 
105
109
  If you set a `url:`, it'll wrap the `<li>` contents in an anchor tag.
106
110
 
111
+ ### Liquid Variables:
112
+
113
+ It will parse liquid variables, as either a yaml array or a space-separated-list. Enclose them in
114
+ double curly braces, like this: `{{ my_context.my_variable }}`. **If given multiword variables, it
115
+ will attempt to build an item for each word.**
116
+
117
+ Example:
118
+
119
+ ```
120
+ ---
121
+ category_list:
122
+ - skydiving
123
+ - spelunking
124
+ - bouldering
125
+
126
+ category_string: skydiving spelunking bouldering
127
+ ---
128
+
129
+ {% icon_list {{ page.category_list }} %}
130
+
131
+ {% icon_list {{ page.category_string }} %}
132
+ ```
133
+ (Both icon_list tags will return the same output)
134
+
107
135
  ## Configuration
108
136
 
109
137
  * All of icon_list's configuration is under the `icon_list:` key in \_config.yml
@@ -199,13 +227,9 @@ At this point the dependency on jekyll-svg-inliner gets pretty tenuous; do we
199
227
  really need a plugin and an extra file to render 3 lines of simple code? In the
200
228
  future I'd like to streamline this.
201
229
 
202
- ### Liquid variables
203
-
204
- You can't pass in liquid variables yet. It's on the to-do list.
205
-
206
230
  ## Contributing
207
231
 
208
- Bug reports and pull requests are welcome. https://github.com/rbuchberger/jekyll_icon_list
232
+ Bug reports, feature requests, and pull requests are welcome. https://github.com/rbuchberger/jekyll_icon_list
209
233
  Contact: robert@robert-buchberger.com
210
234
 
211
235
  I've been using rubocop with the default settings, and would appreciate if pull requests did the
@@ -1,7 +1,10 @@
1
1
  require 'jekyll_icon_list/version'
2
+
2
3
  require 'jekyll'
3
4
  require 'jekyll-inline-svg'
5
+ require 'jekyll/liquid_extensions'
4
6
  require 'objective_elements'
7
+
5
8
  # Title: Jekyll Icon List
6
9
  # Author: Robert Buchberger : robert@robert-buchberger.com
7
10
  # Description: Generates lists of icons + labels, useful for things like tag
@@ -15,6 +18,9 @@ module JekyllIconList
15
18
  # --ul, --li, --svg, and --img. Their arguments are inserted into their
16
19
  # respective HTML elements upon render.
17
20
  class IconList < Liquid::Tag
21
+ # Used for finding liquid variables in input
22
+ include Jekyll::LiquidExtensions
23
+
18
24
  def initialize(tag_name, raw_input, tokens)
19
25
  @raw_input = raw_input
20
26
  @tokens = tokens
@@ -37,22 +43,38 @@ module JekyllIconList
37
43
  end
38
44
 
39
45
  def build_settings
40
- # raw_input will look something like this:
41
- # 'item1 item2 item3 --ul attribute="value" --(...)'
42
-
43
46
  @attributes = @icon_list_settings['defaults'].dup || {}
44
47
  # {'ul' => 'class="awesome" (...)', (...)}
45
48
 
46
- raw_input_array = @raw_input.split('--').map { |i| i.strip.split(' ') }
49
+ # raw_input will look something like this:
50
+ # 'item1 item2 item3 --ul attribute="value" --(...)'
51
+ raw_input_array = liquid_lookup(@raw_input).split('--').map do |i|
52
+ i.strip.split(' ')
53
+ end
47
54
  # [['item1', 'item2', 'item3'], ['ul', 'attr="value', 'value2"'],(...)]
48
55
 
49
56
  @item_shortnames = raw_input_array.shift
50
- # ['ul, 'attribute="value1 value2"', (...)]
57
+ # item_shortnames = ['item1', 'item2', 'item3']
58
+ # raw_input_array = ['ul, 'attribute="value1 value2"', (...)]
51
59
 
52
60
  raw_input_array.each { |a| @attributes[a.shift] = a.join ' ' }
53
61
  # {'ul' => 'attribute="value1 value2 value3"'}
54
62
  end
55
63
 
64
+ LIQUID_REGEX = /\{\{\s*([\w]+\.?[\w]*)\s*\}\}/i
65
+ def liquid_lookup(input)
66
+ # I mostly stole this method from SVG Inliner. There may be a better way,
67
+ # but this works well enough.
68
+ input.scan LIQUID_REGEX do |match|
69
+ value = lookup_variable(@context, match.first)
70
+ value = value.join(' ') if value.is_a? Array
71
+
72
+ input = input.sub(LIQUID_REGEX, value)
73
+ end
74
+
75
+ input
76
+ end
77
+
56
78
  def build_html(all_items_data)
57
79
  list = DoubleTag.new 'ul', attributes: @attributes['ul']
58
80
 
@@ -134,13 +156,10 @@ module JekyllIconList
134
156
  end
135
157
 
136
158
  def build_anchor(url, content)
137
- a = DoubleTag.new(
138
- 'a',
139
- attributes: { href: url },
140
- oneline: true,
141
- content: content
142
- )
159
+ a = DoubleTag.new 'a', attributes: { href: url }, oneline: true
160
+ a.add_content content
143
161
  a.add_attributes @attributes['a'] if @attributes['a']
162
+ a
144
163
  end
145
164
  end
146
165
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllIconList
2
- VERSION = '0.3.1'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_icon_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Buchberger