jekyll_icon_list 0.2.2 → 0.3.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: e8fa828ed8522d543437eef888c64b66b65f58720b7b81519c0673748e275caa
4
- data.tar.gz: 6a65cf25a931a0d9e49120dafc7212da582b5e1bf54da962263327d000d2187b
3
+ metadata.gz: c183bc2a0fb36c49830c7d5cd6a1e48c5d52a9f7228b749523281af82dceae8d
4
+ data.tar.gz: 19895ddfae466f1ae9ca7bca3b9ac2c6ab0be47f01b20ed7120d97948ecde58a
5
5
  SHA512:
6
- metadata.gz: 8b0372e48dff779e32b871d396039e8f2c3db85ec1bbb0f3ce1ca0ef95905acb658a2d64d1be6c49cac6cced8136954fa076e22f666c1b260877cbde606bf1da
7
- data.tar.gz: 21ff8a34efc37fe4082b20d357c4c935c8304d7775eabfc010dc6bac0cb12d52bba361138627fa2976aa4e74560cc930354e7d9083d5bb52f549de9fadb933b6
6
+ metadata.gz: b48fcc1b173c63e00459f66664bf7ef99c1e9605aade8d1550683e866ee03c5ce95f24effb41d24aafd2d025448fc2ff0f88600123b159a4b1b46533e25216da
7
+ data.tar.gz: bb425489af5383a626431e3ed48d2ea5b0db0a2550856050abc6b021c9ac00004cc269fbbd72aa8adec390d967d7e2425888c2a4ce1cbdcf23c6662b98f71389
@@ -12,13 +12,6 @@ Gem::Specification.new do |spec|
12
12
  spec.homepage = 'https://github.com/rbuchberger/jekyll_icon_list'
13
13
  spec.license = 'MIT'
14
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
15
  # Specify which files should be added to the gem when it is released. The
23
16
  # `git ls-files -z` loads the files in the RubyGem that have been added into
24
17
  # git.
@@ -36,4 +29,5 @@ Gem::Specification.new do |spec|
36
29
  spec.add_development_dependency 'rake', '~> 10.0'
37
30
 
38
31
  spec.add_dependency 'jekyll-inline-svg'
32
+ spec.add_dependency 'objective_elements', '~>0.2.0'
39
33
  end
@@ -1,6 +1,7 @@
1
1
  require 'jekyll_icon_list/version'
2
2
  require 'jekyll'
3
3
  require 'jekyll-inline-svg'
4
+ require 'objective_elements'
4
5
  # Title: Jekyll Icon List
5
6
  # Author: Robert Buchberger : robert@robert-buchberger.com
6
7
  # Description: Generates lists of icons + labels, useful for things like tag
@@ -20,41 +21,52 @@ module JekyllIconList
20
21
  super
21
22
  end
22
23
 
24
+ def render(context)
25
+ @context = context
26
+
27
+ site_settings = @context.registers[:site]
28
+ raise 'could not load website configuration data' unless site_settings
29
+
30
+ @icon_list_settings = site_settings.config['icon_list'] || {}
31
+
32
+ all_items_data = site_settings.data['icon_list'] || {}
33
+
34
+ parse_input
35
+
36
+ build_html(all_items_data)
37
+ end
38
+
23
39
  def parse_input
24
40
  # raw_input will look something like this:
25
41
  # 'item1 item2 item3 --ul attribute="value" --(...)'
42
+
26
43
  @attributes = @icon_list_settings['defaults'].dup || {}
44
+ # {'ul' => 'class="awesome" (...)', (...)}
27
45
 
28
46
  raw_input_array = @raw_input.split('--').map { |i| i.strip.split(' ') }
29
- # [['item1', 'item2', 'item3'], ['ul', 'attribute="value"'], (...) ]
47
+ # [['item1', 'item2', 'item3'], ['ul', 'attr="value', 'value2"'],(...)]
30
48
 
31
49
  @item_shortnames = raw_input_array.shift
50
+ # ['ul, 'attribute="value1 value2"', (...)]
32
51
 
33
52
  raw_input_array.each { |a| @attributes[a.shift] = a.join ' ' }
34
- @attributes.each_value { |v| v.prepend(' ') }
35
- @attributes.default = '' # Convenient for concatenation
53
+ # {'ul' => 'attribute="value1 value2 value3"'}
36
54
  end
37
55
 
38
- def build_image_tag(icon_filename)
39
- if icon_filename.split('.').pop.casecmp('svg') == 0
40
- Jekyll::Tags::JekyllInlineSvg.send(
41
- :new,
42
- 'svg',
43
- icon_filename + @attributes['svg'],
44
- @tokens
45
- ).render(@context)
46
- else
47
- "<img src=\"#{icon_filename}\"#{@attributes['img']}>"
48
- end
49
- end
56
+ def build_html(all_items_data)
57
+ list = DoubleTag.new 'ul', attributes: @attributes['ul']
50
58
 
51
- def search_path(path, item)
52
- # We have to strip the leading slash for Dir to know it's relative:
53
- search_results = Dir.glob( path[1..-1] + item + '.*')
54
- raise "No icon found at #{path + item} .*" unless search_results.any?
59
+ @item_shortnames.each do |n|
60
+ this_item_data = all_items_data[n] || {}
55
61
 
56
- # And put it back so that pages outside of the root directory keep working
57
- search_results.first.prepend '/'
62
+ icon_location = find_icon n, this_item_data
63
+
64
+ label = build_label(n, this_item_data)
65
+
66
+ list.add_content build_li(this_item_data, icon_location, label)
67
+ end
68
+
69
+ list.to_s
58
70
  end
59
71
 
60
72
  def find_icon(item_shortname, this_item_data)
@@ -69,51 +81,64 @@ module JekyllIconList
69
81
  end
70
82
  end
71
83
 
84
+ def search_path(path, item)
85
+ # We have to strip the leading slash for Dir to know it's relative:
86
+ search_results = Dir.glob(path[1..-1] + item + '.*')
87
+ raise "No icon found at #{path + item} .*" unless search_results.any?
88
+
89
+ # And put it back so that pages outside of the root directory keep working
90
+ search_results.first.prepend '/'
91
+ end
92
+
72
93
  def build_label(shortname, this_item_data)
73
94
  this_item_data['label'] ||
74
95
  shortname.split(/[-_]/).map(&:capitalize).join(' ')
75
96
  end
76
97
 
77
98
  def build_li(this_item_data, icon_location, label)
78
- li = " <li#{@attributes['li']}>"
79
- if this_item_data && this_item_data['url']
80
- li << "<a href=\"#{this_item_data['url']}\"#{@attributes['a']}>"
81
- end
82
- li << build_image_tag(icon_location)
83
- li << label
84
- li << '</a>' if this_item_data['url']
85
- li << "</li>\n"
99
+ li = DoubleTag.new(
100
+ 'li',
101
+ attributes: @attributes['li'],
102
+ content: [build_image_tag(icon_location), label],
103
+ oneline: true
104
+ )
105
+ return li unless this_item_data['url']
106
+
107
+ li.reset_content build_anchor(this_item_data['url'], li.content)
86
108
  end
87
109
 
88
- def build_html(all_items_data)
89
- list = "<ul#{@attributes['ul']}>\n"
90
-
91
- @item_shortnames.each do |n|
92
- this_icon_data = all_items_data[n] || {}
93
-
94
- icon_location = find_icon n, this_icon_data
95
-
96
- label = build_label(n, this_icon_data)
97
-
98
- list << build_li(this_icon_data, icon_location, label)
110
+ def build_image_tag(icon_filename)
111
+ if icon_filename.split('.').pop.casecmp('svg').zero?
112
+ build_svg(icon_filename)
113
+ else
114
+ build_img(icon_filename)
99
115
  end
100
-
101
- list << "</ul>\n"
102
116
  end
103
117
 
104
- def render(context)
105
- @context = context
106
-
107
- site_settings = @context.registers[:site]
108
- raise 'could not load website configuration data' unless site_settings
109
-
110
- @icon_list_settings = site_settings.config['icon_list'] || {}
111
-
112
- all_items_data = site_settings.data['icon_list'] || {}
118
+ def build_svg(icon_filename)
119
+ params = icon_filename
120
+ params << ' ' + @attributes['svg'] if @attributes['svg']
121
+ Jekyll::Tags::JekyllInlineSvg.send(
122
+ :new,
123
+ 'svg',
124
+ params,
125
+ @tokens
126
+ ).render(@context)
127
+ end
113
128
 
114
- parse_input
129
+ def build_img(icon_filename)
130
+ img = SingleTag.new 'img', attributes: { src: icon_filename }
131
+ img.add_attributes @attributes['img'] if @attributes['img']
132
+ end
115
133
 
116
- build_html(all_items_data)
134
+ def build_anchor(url, content)
135
+ a = DoubleTag.new(
136
+ 'a',
137
+ attributes: { href: url },
138
+ oneline: true,
139
+ content: content
140
+ )
141
+ a.add_attributes @attributes['a'] if @attributes['a']
117
142
  end
118
143
  end
119
144
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllIconList
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  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.2.2
4
+ version: 0.3.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-25 00:00:00.000000000 Z
11
+ date: 2018-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: objective_elements
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.2.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.2.0
69
83
  description:
70
84
  email:
71
85
  - robert@robert-buchberger.com
@@ -103,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
117
  version: '0'
104
118
  requirements: []
105
119
  rubyforge_project:
106
- rubygems_version: 2.7.6
120
+ rubygems_version: 2.7.3
107
121
  signing_key:
108
122
  specification_version: 4
109
123
  summary: Builds lists of Icons and labels