jekyll_icon_list 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +119 -61
- data/jekyll_icon_list.gemspec +1 -0
- data/lib/jekyll_icon_list/version.rb +1 -1
- data/lib/jekyll_icon_list.rb +41 -61
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f7ccfa6a8c94144f4a58982b651c553eb65976cf28b503f15b1f8efc9bb3bda
|
4
|
+
data.tar.gz: d4c30318fe1977bc2b5828871fe40d8faa902aa1323a9eea298111e3ac2a7932
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b78191361e1968ddac22c8d25309de2015414f7dc271b7c738ff235520400b13103096087853496378bdf61c1a83cd36092cdab77a50a9fe201f5be9b6a02fd
|
7
|
+
data.tar.gz: 34092df630e9c3dfffb019ff0439ecf6f403dce6930e46a3d8eb55634d836f628540d1f6948cfbf166eb1789832325d116836150b5652034b8dfb0dba9a7fe34
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -8,12 +8,12 @@ report bugs if you find them.**
|
|
8
8
|
It's a jekyll tag that lets you build unordered lists of items that follow the "Icon + label"
|
9
9
|
format.
|
10
10
|
|
11
|
-
Write
|
11
|
+
Write this:
|
12
12
|
```
|
13
13
|
{% icon_list rails bootstrap heroku aws %}
|
14
14
|
```
|
15
15
|
|
16
|
-
Add some icons, configuration, and a little CSS,
|
16
|
+
Add some icons, configuration, and a little CSS, get something like this:
|
17
17
|
|
18
18
|
![imgur screenshot]( https://i.imgur.com/9m6qCRB.png )
|
19
19
|
|
@@ -27,20 +27,20 @@ markup; the styling is up to you.
|
|
27
27
|
|
28
28
|
It integrates with (and requires) [jekyll-svg-inliner](https://github.com/sdumetz/jekyll-inline-svg)
|
29
29
|
to inline your SVGs for you. If you don't use inline SVGs (even though you should), it sets your file
|
30
|
-
as
|
30
|
+
as the `src=` of an `img` tag.
|
31
31
|
|
32
32
|
## Installation
|
33
33
|
|
34
|
-
(I don't have it hosted on rubygems yet. It will be once I've cleaned it up a bit further. .)
|
35
|
-
|
36
34
|
```ruby
|
37
35
|
# Gemfile
|
38
36
|
|
39
37
|
group :jekyll_plugins do
|
40
|
-
gem 'jekyll_icon_list'
|
38
|
+
gem 'jekyll_icon_list'
|
41
39
|
end
|
42
40
|
```
|
43
41
|
|
42
|
+
`bundle install`
|
43
|
+
|
44
44
|
```yml
|
45
45
|
# _config.yml
|
46
46
|
|
@@ -48,65 +48,73 @@ plugins:
|
|
48
48
|
-jekyll_icon_list
|
49
49
|
```
|
50
50
|
|
51
|
-
|
52
|
-
```css
|
53
|
-
|
54
|
-
ul.icon-list {
|
55
|
-
margin: 0;
|
56
|
-
font-size: 1.1em;
|
57
|
-
display: flex;
|
58
|
-
flex-wrap: wrap;
|
59
|
-
justify-content: center;
|
60
|
-
list-style: none;
|
61
|
-
}
|
62
|
-
|
63
|
-
ul.icon-list li {
|
64
|
-
display: flex;
|
65
|
-
align-items: center;
|
66
|
-
margin: 0 .5em;
|
67
|
-
}
|
68
|
-
|
69
|
-
.icon {
|
70
|
-
height: 1em;
|
71
|
-
margin-right: .2em;
|
72
|
-
}
|
51
|
+
## Basic Usage
|
73
52
|
|
74
53
|
```
|
75
|
-
|
76
|
-
## Usage
|
77
|
-
|
78
|
-
Basic usage:
|
79
|
-
|
80
|
-
```
|
81
|
-
{% icon_list example_shortname example2 %}
|
54
|
+
{% icon_list example example2 example3 %}
|
82
55
|
```
|
83
56
|
|
84
57
|
By default, with no configuration:
|
85
58
|
|
86
59
|
* It will look for icons in images/icons/ with the same name as your shortname, grabbing the first result which matches (shortname).*
|
87
60
|
|
88
|
-
* It will take your shortname, swap dashes for spaces, and titleize it for the label.
|
61
|
+
* It will take your shortname, swap dashes and underscores for spaces, and titleize it for the label.
|
89
62
|
|
90
|
-
|
63
|
+
Example: if you write `{% icon_list ruby-on-rails %}`, with `ruby-on-rails.png` located in
|
91
64
|
`images/icons/`, it will generate markup like this:
|
92
|
-
```
|
65
|
+
```html
|
93
66
|
<ul>
|
94
67
|
<li><img src="/images/icons/ruby-on-rails.png">Ruby On Rails</li>
|
95
68
|
<ul>
|
96
69
|
```
|
97
70
|
|
98
|
-
You can
|
71
|
+
You can add HTML attributes with --(element) arguments:
|
99
72
|
```
|
100
|
-
{% icon_list example
|
101
|
-
|
73
|
+
{% icon_list example --ul class="stumpy" --li class="mopey" data-max-volume="11" %}
|
74
|
+
```
|
75
|
+
Which will generate markup like this:
|
76
|
+
```html
|
77
|
+
<ul class="stumpy">
|
78
|
+
<li class="mopey" data-max-volume="11"><svg>(...)</svg>Example</li>
|
79
|
+
</ul>
|
102
80
|
```
|
103
81
|
|
104
82
|
Available arguments:
|
105
83
|
`--ul, --li, --img, --svg, --a`
|
106
84
|
These will overwrite any global defaults you have set.
|
107
85
|
|
108
|
-
|
86
|
+
## Less Basic Usage
|
87
|
+
If the default filenames and labels don't work for you, create:
|
88
|
+
`/_data/icon_list.yml`
|
89
|
+
|
90
|
+
And fill it with your icons in the following format:
|
91
|
+
```yml
|
92
|
+
# /_data/icon_list.yml
|
93
|
+
|
94
|
+
example1:
|
95
|
+
icon: example_logo.svg
|
96
|
+
label: My Nicely Formatted, Long Name
|
97
|
+
url: https://example1.com
|
98
|
+
example2:
|
99
|
+
icon: sloppy.svg
|
100
|
+
label: Here's Another Label I Don't Have To Type Again
|
109
101
|
```
|
102
|
+
|
103
|
+
Each key is an item shortname, and everything is optional. `icon:` is the filename of the icon you
|
104
|
+
would like to use, which will be prepended by your default_path if you set one (more on that later).
|
105
|
+
|
106
|
+
If you set a `url:`, it'll wrap the `<li>` contents in an anchor tag.
|
107
|
+
|
108
|
+
## Configuration
|
109
|
+
|
110
|
+
* All of icon_list's configuration is under the `icon_list:` key in \_config.yml
|
111
|
+
* `default_path:` - Where to find your icons
|
112
|
+
* `defaults:` - Optional HTML attributes to include with your markup. They will be ignored if
|
113
|
+
a corresponding --(element) argument is passed in the tag.
|
114
|
+
|
115
|
+
Here's an example configuration:
|
116
|
+
|
117
|
+
```yml
|
110
118
|
# _config.yml
|
111
119
|
|
112
120
|
icon_list:
|
@@ -123,36 +131,86 @@ svg:
|
|
123
131
|
|
124
132
|
```
|
125
133
|
|
126
|
-
|
127
|
-
* `defaults:` - Optional HTML attributes to include with your markup, if none are specified in the
|
128
|
-
tag.
|
134
|
+
## Notes
|
129
135
|
|
130
|
-
|
131
|
-
`/_data/icon_list.yml`
|
136
|
+
### Icon finding logic
|
132
137
|
|
133
|
-
|
138
|
+
It tries to be smart about finding your icons. Here's the decision matrix:
|
139
|
+
|
140
|
+
... | default_path set | default_path not set
|
141
|
+
------------------|---------------------|---------------------
|
142
|
+
item icon set | default_path + icon | icon
|
143
|
+
item icon not set | search default_path | search /images/icons
|
144
|
+
|
145
|
+
When it searches a path, it just spits out the first result and raises an exception if there aren't
|
146
|
+
any.
|
147
|
+
|
148
|
+
### Accessibility
|
149
|
+
Right now the only way to set individualized alt text for your icons is to use SVGs, and include a
|
150
|
+
title tag in the file. Since the label itself will likely describe your image quite nicely, I
|
151
|
+
recommend you set `alt=""` as a default attribute for image tags.
|
152
|
+
|
153
|
+
If you would like automatic alt-text generation, or the ability to specify alt text in the data
|
154
|
+
file, let me know or write it yourself and submit a pull request.
|
155
|
+
|
156
|
+
### Styling
|
157
|
+
Here's an example that should get you close to the screenshot:
|
158
|
+
|
159
|
+
```css
|
160
|
+
ul.icon-list {
|
161
|
+
margin: 0;
|
162
|
+
font-size: 1.1em;
|
163
|
+
display: flex;
|
164
|
+
flex-wrap: wrap;
|
165
|
+
justify-content: center;
|
166
|
+
list-style: none;
|
167
|
+
}
|
168
|
+
|
169
|
+
ul.icon-list li {
|
170
|
+
display: flex;
|
171
|
+
align-items: center;
|
172
|
+
margin: 0 .5em;
|
173
|
+
}
|
174
|
+
|
175
|
+
.icon {
|
176
|
+
height: 1em;
|
177
|
+
margin-right: .2em;
|
178
|
+
}
|
134
179
|
```
|
135
|
-
# /_data/icon_list.yml
|
136
180
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
181
|
+
### Using <use> To build an icon system
|
182
|
+
[CSS tricks on SVG Icon Systems (old article warning)](https://css-tricks.com/svg-sprites-use-better-icon-fonts/)
|
183
|
+
|
184
|
+
[Slightly newer article on <use>](https://css-tricks.com/svg-use-with-external-reference-take-2/)
|
185
|
+
|
186
|
+
[MDN docs](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/use)
|
187
|
+
|
188
|
+
You can do it while using this plugin, but it's not remarkably efficient; build
|
189
|
+
& inject the reference file on your own, and then write your SVG files like
|
190
|
+
this:
|
191
|
+
|
192
|
+
```html
|
193
|
+
<!-- example-name.svg -->
|
194
|
+
<svg>
|
195
|
+
<use href="#example-icon">
|
196
|
+
</svg>
|
144
197
|
```
|
145
198
|
|
146
|
-
|
147
|
-
|
148
|
-
|
199
|
+
At this point the dependency on jekyll-svg-inliner gets pretty tenuous; do we
|
200
|
+
really need a plugin and an extra file to render 3 lines of simple code? In the
|
201
|
+
future I'd like to streamline this.
|
149
202
|
|
150
|
-
|
151
|
-
|
203
|
+
### Liquid variables
|
204
|
+
|
205
|
+
You can't pass in liquid variables yet. It's on the to-do list.
|
152
206
|
|
153
207
|
## Contributing
|
154
208
|
|
155
209
|
Bug reports and pull requests are welcome. https://github.com/rbuchberger/jekyll_icon_list
|
210
|
+
Contact: robert@robert-buchberger.com
|
211
|
+
|
212
|
+
I've been using rubocop with the default settings, and would appreciate if pull requests did the
|
213
|
+
same.
|
156
214
|
|
157
215
|
## License
|
158
216
|
|
data/jekyll_icon_list.gemspec
CHANGED
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.require_paths = ['lib']
|
33
33
|
|
34
34
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
35
|
+
spec.add_development_dependency 'pry'
|
35
36
|
spec.add_development_dependency 'rake', '~> 10.0'
|
36
37
|
|
37
38
|
spec.add_dependency 'jekyll-inline-svg'
|
data/lib/jekyll_icon_list.rb
CHANGED
@@ -14,11 +14,6 @@ module JekyllIconList
|
|
14
14
|
# --ul, --li, --svg, and --img. Their arguments are inserted into their
|
15
15
|
# respective HTML elements upon render.
|
16
16
|
class IconList < Liquid::Tag
|
17
|
-
# \. - dot
|
18
|
-
# [\w]+ - One or more letters, numbers, or underscores
|
19
|
-
# $ - End of string
|
20
|
-
FILE_EXT_REGEX = /\.([\w]+)\z/
|
21
|
-
|
22
17
|
def initialize(tag_name, raw_input, tokens)
|
23
18
|
@raw_input = raw_input
|
24
19
|
@tokens = tokens
|
@@ -26,6 +21,9 @@ module JekyllIconList
|
|
26
21
|
end
|
27
22
|
|
28
23
|
def initialize_attributes
|
24
|
+
# We will be interpolating strings with these values several times, so
|
25
|
+
# initializing them with empty strings is convenient.
|
26
|
+
|
29
27
|
{
|
30
28
|
'ul' => '',
|
31
29
|
'li' => '',
|
@@ -35,82 +33,64 @@ module JekyllIconList
|
|
35
33
|
}
|
36
34
|
end
|
37
35
|
|
38
|
-
def
|
39
|
-
attributes = initialize_attributes
|
36
|
+
def set_attribute_defaults
|
37
|
+
@attributes = initialize_attributes
|
40
38
|
|
41
|
-
attributes.each_key do |k|
|
42
|
-
if @
|
43
|
-
attributes[k] = @
|
39
|
+
@attributes.each_key do |k|
|
40
|
+
if @icon_list_settings['defaults'] && @icon_list_settings['defaults'][k]
|
41
|
+
@attributes[k] = @icon_list_settings['defaults'][k].dup
|
44
42
|
end
|
45
43
|
end
|
46
|
-
|
47
|
-
attributes
|
48
44
|
end
|
49
45
|
|
50
|
-
def parse_input
|
46
|
+
def parse_input
|
51
47
|
# raw_input will look something like this:
|
52
|
-
# 'item1 item2 item3 --ul attribute="value" --(...)
|
48
|
+
# 'item1 item2 item3 --ul attribute="value" --(...)'
|
53
49
|
|
54
|
-
raw_input_array = raw_input.split('--').map { |i| i.strip.split(' ') }
|
50
|
+
raw_input_array = @raw_input.split('--').map { |i| i.strip.split(' ') }
|
55
51
|
# [['item1', 'item2', 'item3'], ['ul', 'attribute="value"'], (...) ]
|
56
52
|
|
57
53
|
@item_shortnames = raw_input_array.shift
|
58
54
|
|
59
|
-
raw_input_array.each
|
60
|
-
key = a.shift
|
61
|
-
@attributes[key] = a.join ' '
|
62
|
-
end
|
55
|
+
raw_input_array.each { |a| @attributes[a.shift] = a.join ' ' }
|
63
56
|
end
|
64
57
|
|
65
58
|
def build_image_tag(icon_filename)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
59
|
+
if icon_filename.split('.').pop.casecmp('svg')
|
60
|
+
Jekyll::Tags::JekyllInlineSvg.send(
|
61
|
+
:new,
|
62
|
+
'svg',
|
63
|
+
"#{icon_filename} #{@attributes['svg']}",
|
64
|
+
@tokens
|
65
|
+
).render(@context)
|
66
|
+
else
|
67
|
+
"<img src=\"#{icon_filename}\" #{@attributes['img']}>"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def search_path(path, item)
|
72
|
+
search_results = Dir.glob(Dir.pwd + path + item + '.*')
|
73
|
+
raise "No icon found at #{path + item} .*" unless search_results.any?
|
74
|
+
|
75
|
+
# Returns the first matching result. May improve in the future:
|
76
|
+
search_results.first
|
82
77
|
end
|
83
78
|
|
84
79
|
def find_icon(item_shortname, this_item_data)
|
85
|
-
|
86
|
-
|
87
|
-
# multiple times on a page (which is the entire point of this plugin), the
|
88
|
-
# default path would be prepended each time. .dup is very important!
|
89
|
-
icon_data_filename = this_item_data['icon'].dup
|
90
|
-
default_path = @li_settings['default_path'] || '/images/icons/'
|
91
|
-
|
92
|
-
if icon_data_filename && default_path
|
93
|
-
default_path + icon_data_filename
|
94
|
-
elsif icon_data_filename
|
95
|
-
icon_data_filename
|
96
|
-
elsif default_path
|
97
|
-
f = Dir.glob(Dir.pwd + default_path + item_shortname + '.*')
|
98
|
-
unless f.any?
|
99
|
-
raise "No icon for #{item_shortname} set in _data/icon_list.yml"\
|
100
|
-
", and default filename #{default_path + item_shortname}.* not found"
|
101
|
-
end
|
80
|
+
icon_filename = this_item_data['icon']
|
81
|
+
path = @icon_list_settings['default_path'] || ''
|
102
82
|
|
103
|
-
|
83
|
+
if icon_filename
|
84
|
+
path + icon_filename
|
104
85
|
else
|
105
|
-
|
106
|
-
|
107
|
-
'Must have one, the other, or both.'
|
86
|
+
path = '/images/icons/' if path.empty?
|
87
|
+
search_path(path, item_shortname)
|
108
88
|
end
|
109
89
|
end
|
110
90
|
|
111
91
|
def build_label(shortname, this_item_data)
|
112
92
|
this_item_data['label'] ||
|
113
|
-
shortname.split(
|
93
|
+
shortname.split(/[-_]/).map(&:capitalize).join(' ')
|
114
94
|
end
|
115
95
|
|
116
96
|
def build_li(this_item_data, icon_location, label)
|
@@ -121,7 +101,7 @@ module JekyllIconList
|
|
121
101
|
li << build_image_tag(icon_location)
|
122
102
|
li << label
|
123
103
|
li << '</a>' if this_item_data['url']
|
124
|
-
li << '</li
|
104
|
+
li << '</li>\n'
|
125
105
|
end
|
126
106
|
|
127
107
|
def build_html(all_items_data)
|
@@ -146,13 +126,13 @@ module JekyllIconList
|
|
146
126
|
site_settings = @context.registers[:site]
|
147
127
|
raise 'could not load website configuration data' unless site_settings
|
148
128
|
|
149
|
-
@
|
129
|
+
@icon_list_settings = site_settings.config['icon_list'] || {}
|
150
130
|
|
151
131
|
all_items_data = site_settings.data['icon_list'] || {}
|
152
132
|
|
153
|
-
|
133
|
+
set_attribute_defaults
|
154
134
|
|
155
|
-
parse_input
|
135
|
+
parse_input
|
156
136
|
|
157
137
|
build_html(all_items_data)
|
158
138
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll_icon_list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Buchberger
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|