jekyll_icon_list 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3f1da75e2e118c485c03c07af94262febe7aefe650715dbc72db46802a739594
4
+ data.tar.gz: 2f6185d3706196a24b561dd317e39ff45230690e2a3fb850730cc3448e632334
5
+ SHA512:
6
+ metadata.gz: 9b62e7b479c2a44e29e605d96e4121d5cd06cc8f354613123e6c83a56b50c39887d483cf443b0b8b66d50a1a7dd09084267d37af33d4553050b673397d38805c
7
+ data.tar.gz: 91991f9474658ba39c33012cfe0325f1c516e6d367e4824dcb0eb4c2852b0c9d5742cc07118df8822904b01d0ee8eaf08356a9188dd2cb969a5ad5ee6d5971ce
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in jekyll_icon_list.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Robert Buchberger
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,159 @@
1
+ # Jekyll Icon List
2
+
3
+ **This plugin works, but I haven't had time to test it very thoroughly. Use with caution, and please
4
+ report bugs if you find them.**
5
+
6
+ ## What is it?
7
+
8
+ It's a jekyll tag that lets you build unordered lists of items that follow the "Icon + label"
9
+ format.
10
+
11
+ Write a tag like this:
12
+ ```
13
+ {% icon_list rails bootstrap heroku aws %}
14
+ ```
15
+
16
+ Add some icons, configuration, and a little CSS, and you get something like this:
17
+
18
+ ![imgur screenshot]( https://i.imgur.com/9m6qCRB.png )
19
+
20
+ I use it on [my portfolio](https://robert-buchberger.com/projects.html)
21
+ ([ github ](https://github.com/rbuchberger/robert-buchberger.com)) if you want to see an example.
22
+ (Actually, currently my master branch doesn't use the gem. Yet. Check the other branches.)
23
+
24
+ You could use it to build category lists, or tag lists, or a bunch of other stuff. You can pass
25
+ element attributes in the tag itself, or set default attributes in the config. It only generates
26
+ markup; the styling is up to you.
27
+
28
+ It integrates with (and requires) [jekyll-svg-inliner](https://github.com/sdumetz/jekyll-inline-svg)
29
+ to inline your SVGs for you. If you don't use inline SVGs (even though you should), it sets your file
30
+ as an img src attribute (with alt text!).
31
+
32
+ ## Installation
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
+ ```ruby
37
+ # Gemfile
38
+
39
+ group :jekyll_plugins do
40
+ gem 'jekyll_icon_list', git: 'https://github.com/rbuchberger/jekyll_icon_list.git'
41
+ end
42
+ ```
43
+
44
+ ```yml
45
+ # _config.yml
46
+
47
+ plugins:
48
+ -jekyll_icon_list
49
+ ```
50
+
51
+ You'll also want some css. Here's an example that should get you close to the screenshot:
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
+ }
73
+
74
+ ```
75
+
76
+ ## Usage
77
+
78
+ Basic usage:
79
+
80
+ ```
81
+ {% icon_list example_shortname example2 %}
82
+ ```
83
+
84
+ By default, with no configuration:
85
+
86
+ * It will look for icons in images/icons/ with the same name as your shortname, grabbing the first result which matches (shortname).*
87
+
88
+ * It will take your shortname, swap dashes for spaces, and titleize it for the label.
89
+
90
+ So for example, if you write `{% icon_list ruby-on-rails %}`, with `ruby-on-rails.png` located in
91
+ `images/icons/`, it will generate markup like this:
92
+ ```
93
+ <ul>
94
+ <li><img src="/images/icons/ruby-on-rails.png">Ruby On Rails</li>
95
+ <ul>
96
+ ```
97
+
98
+ You can specify attributes to add with --(element) arguments:
99
+ ```
100
+ {% icon_list example example2 example3 --ul class="stumpy" --li class="mopey" %}
101
+
102
+ ```
103
+
104
+ Available arguments:
105
+ `--ul, --li, --img, --svg, --a`
106
+ These will overwrite any global defaults you have set.
107
+
108
+ in your \_config.yml there are a few optional settings you can add. Here's an example:
109
+ ```
110
+ # _config.yml
111
+
112
+ icon_list:
113
+ default_path: images/here/
114
+ defaults:
115
+ ul: class="icon-list"
116
+ li: class="icon-list-item"
117
+ svg: overflow="visible" class="icon"
118
+ img: class="wish-i-had-inline-svgs"
119
+ a: example-attribute="example-value"
120
+
121
+ svg:
122
+ optimize: true # Tells svg-inliner to clean up your SVGs.
123
+
124
+ ```
125
+
126
+ * `default_path:`- Prepended to the filenames specified in your data file.
127
+ * `defaults:` - Optional HTML attributes to include with your markup, if none are specified in the
128
+ tag.
129
+
130
+ If the default filenames and labels don't work for you, create:
131
+ `/_data/icon_list.yml`
132
+
133
+ And fill it with your icons in the following format:
134
+ ```
135
+ # /_data/icon_list.yml
136
+
137
+ example1:
138
+ icon: example_logo.svg
139
+ label: My Nicely Formatted, Long Name
140
+ url: https://example1.com
141
+ example2:
142
+ icon: sloppy.svg
143
+ label: Here's Another Label I Don't Have To Type Again
144
+ ```
145
+
146
+ The default directory setting in config.yml will be prepended to your
147
+ filenames. You'll obviously need some icons, I hear you can find them on the
148
+ internet.
149
+
150
+ If you set a url: for an item in the data file, it'll wrap the li's contents in
151
+ an anchor tag for you.
152
+
153
+ ## Contributing
154
+
155
+ Bug reports and pull requests are welcome. https://github.com/rbuchberger/jekyll_icon_list
156
+
157
+ ## License
158
+
159
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'jekyll_icon_list'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'jekyll_icon_list/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'jekyll_icon_list'
7
+ spec.version = JekyllIconList::VERSION
8
+ spec.authors = ['Robert Buchberger']
9
+ spec.email = ['robert@robert-buchberger.com']
10
+
11
+ spec.summary = 'Builds lists of Icons and labels'
12
+ spec.homepage = 'https://github.com/rbuchberger/jekyll_icon_list'
13
+ spec.license = 'MIT'
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the
16
+ # 'allowed_push_host' to allow pushing to a single host or delete this section
17
+ # to allow pushing to any host. if spec.respond_to?(:metadata)
18
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
19
+ # else raise 'RubyGems 2.0 or newer is required to protect against ' \ 'public
20
+ # gem pushes.' end
21
+
22
+ # Specify which files should be added to the gem when it is released. The
23
+ # `git ls-files -z` loads the files in the RubyGem that have been added into
24
+ # git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ end
30
+ spec.bindir = 'exe'
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ['lib']
33
+
34
+ spec.add_development_dependency 'bundler', '~> 1.16'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
36
+
37
+ spec.add_dependency 'jekyll-inline-svg'
38
+ end
@@ -0,0 +1,162 @@
1
+ require 'jekyll_icon_list/version'
2
+ require 'jekyll'
3
+ require 'jekyll-inline-svg'
4
+ # Title: Jekyll Icon List
5
+ # Author: Robert Buchberger : robert@robert-buchberger.com
6
+ # Description: Generates lists of icons + labels, useful for things like tag
7
+ # lists.
8
+
9
+ module JekyllIconList
10
+ # This tag looks for commands in the following format:
11
+ # {% icon_list item1 item2 item3 --ul class="example" --li class="example2" %}
12
+ # And renders an unordered list of icons and labels. Items are a space
13
+ # separated list of names defined in _data/icons.yml. Acceptable commands are
14
+ # --ul, --li, --svg, and --img. Their arguments are inserted into their
15
+ # respective HTML elements upon render.
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
+ def initialize(tag_name, raw_input, tokens)
23
+ @raw_input = raw_input
24
+ @tokens = tokens
25
+ super
26
+ end
27
+
28
+ def initialize_attributes
29
+ {
30
+ 'ul' => '',
31
+ 'li' => '',
32
+ 'img' => '',
33
+ 'svg' => '',
34
+ 'a' => ''
35
+ }
36
+ end
37
+
38
+ def attribute_defaults
39
+ attributes = initialize_attributes
40
+
41
+ attributes.each_key do |k|
42
+ if @li_settings['defaults'] && @li_settings['defaults'][k]
43
+ attributes[k] = @li_settings['defaults'][k].dup
44
+ end
45
+ end
46
+
47
+ attributes
48
+ end
49
+
50
+ def parse_input(raw_input)
51
+ # raw_input will look something like this:
52
+ # 'item1 item2 item3 --ul attribute="value" --(...) "'
53
+
54
+ raw_input_array = raw_input.split('--').map { |i| i.strip.split(' ') }
55
+ # [['item1', 'item2', 'item3'], ['ul', 'attribute="value"'], (...) ]
56
+
57
+ @item_shortnames = raw_input_array.shift
58
+
59
+ raw_input_array.each do |a|
60
+ key = a.shift
61
+ @attributes[key] = a.join ' '
62
+ end
63
+ end
64
+
65
+ def build_image_tag(icon_filename)
66
+ file_ext = FILE_EXT_REGEX.match(icon_filename)[1]
67
+
68
+ element = if file_ext == 'svg'
69
+ Jekyll::Tags::JekyllInlineSvg.send(
70
+ :new,
71
+ 'svg',
72
+ "#{icon_filename} #{@attributes['svg']}",
73
+ @tokens
74
+ ).render(@context)
75
+ else
76
+ "<img src=\"#{icon_filename}\" "\
77
+ "alt=\"icon for #{icon_data['label']}\" "\
78
+ "#{@attributes['img']}>"
79
+ end
80
+
81
+ element << "\n"
82
+ end
83
+
84
+ def find_icon(item_shortname, this_item_data)
85
+ # This line gave me an interesting bug: jekyll data files are apparently
86
+ # mutable and persistent between tag calls. If I had the same item
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
102
+
103
+ f.first # Returns the first matching result. May improve in the future
104
+ else
105
+ raise "No icon for #{item_shortname} specified in _data/icon_list.yml"\
106
+ 'And no default directory specified in _config.yml.'\
107
+ 'Must have one, the other, or both.'
108
+ end
109
+ end
110
+
111
+ def build_label(shortname, this_item_data)
112
+ this_item_data['label'] ||
113
+ shortname.split('-').map(&:capitalize).join(' ')
114
+ end
115
+
116
+ def build_li(this_item_data, icon_location, label)
117
+ li = " <li #{@attributes['li']}>"
118
+ if this_item_data && this_item_data['url']
119
+ li << "<a href=\"#{this_item_data['url']}\" #{@attributes['a']}>"
120
+ end
121
+ li << build_image_tag(icon_location)
122
+ li << label
123
+ li << '</a>' if this_item_data['url']
124
+ li << '</li>'
125
+ end
126
+
127
+ def build_html(all_items_data)
128
+ list = "<ul #{@attributes['ul']}>\n"
129
+
130
+ @item_shortnames.each do |n|
131
+ this_icon_data = all_items_data[n] || {}
132
+
133
+ icon_location = find_icon n, this_icon_data
134
+
135
+ label = build_label(n, this_icon_data)
136
+
137
+ list << build_li(this_icon_data, icon_location, label)
138
+ end
139
+
140
+ list << "</ul>\n"
141
+ end
142
+
143
+ def render(context)
144
+ @context = context
145
+
146
+ site_settings = @context.registers[:site]
147
+ raise 'could not load website configuration data' unless site_settings
148
+
149
+ @li_settings = site_settings.config['icon_list'] || {}
150
+
151
+ all_items_data = site_settings.data['icon_list'] || {}
152
+
153
+ @attributes = attribute_defaults
154
+
155
+ parse_input(@raw_input)
156
+
157
+ build_html(all_items_data)
158
+ end
159
+ end
160
+ end
161
+
162
+ Liquid::Template.register_tag('icon_list', JekyllIconList::IconList)
@@ -0,0 +1,3 @@
1
+ module JekyllIconList
2
+ VERSION = '0.1.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll_icon_list
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Robert Buchberger
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jekyll-inline-svg
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - robert@robert-buchberger.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - jekyll_icon_list.gemspec
70
+ - lib/jekyll_icon_list.rb
71
+ - lib/jekyll_icon_list/version.rb
72
+ homepage: https://github.com/rbuchberger/jekyll_icon_list
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.7.3
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Builds lists of Icons and labels
96
+ test_files: []