jekyll_plugin_template 0.1.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/jekyll_hooks.rb CHANGED
@@ -1,11 +1,9 @@
1
- # frozen_string_literal: true
2
-
3
- require "jekyll_plugin_logger"
4
- require_relative "jekyll_plugin_template/version"
5
- require_relative "dumpers"
1
+ require 'jekyll_plugin_logger'
2
+ require_relative 'jekyll_plugin_template/version'
3
+ require_relative 'dumpers'
6
4
 
7
5
  module JekyllPluginHooksName
8
- PLUGIN_NAME = "jekyll_plugin_hooks"
6
+ PLUGIN_NAME = 'jekyll_plugin_hooks'
9
7
  end
10
8
 
11
9
  # The Jekyll processing steps are described in https://jekyllrb.com/tutorials/orderofinterpretation/
@@ -38,8 +36,8 @@ module JekyllPluginHooks
38
36
  # However, this hook will not be called unless safe mode is OFF, so define loggers in the :site :after_init hook instead
39
37
  Jekyll::Hooks.register(:site, :after_reset, priority: :normal) do |site|
40
38
  @log_site ||= PluginMetaLogger.instance.new_logger(:SiteHooks, PluginMetaLogger.instance.config)
41
- @log_site.info { "Jekyll::Hooks.register(:site, :after_reset) invoked." }
42
- Dumpers.dump_site(@log_site, "Jekyll::Hooks.register(:site, :after_reset)", site)
39
+ @log_site.info { 'Jekyll::Hooks.register(:site, :after_reset) invoked.' }
40
+ Dumpers.dump_site(@log_site, 'Jekyll::Hooks.register(:site, :after_reset)', site)
43
41
  end
44
42
 
45
43
  # This hook is called just after the site initializes.
@@ -52,17 +50,17 @@ module JekyllPluginHooks
52
50
  @log_posts = PluginMetaLogger.instance.new_logger(:PostHooks, PluginMetaLogger.instance.config)
53
51
  @log_site ||= PluginMetaLogger.instance.new_logger(:SiteHooks, PluginMetaLogger.instance.config)
54
52
 
55
- @log_site.info { "Loaded #{JekyllPluginHooksName::PLUGIN_NAME} v#{JekyllPluginTemplate::VERSION} plugin." }
56
- @log_site.info { "Jekyll::Hooks.register(:site, :after_init) invoked." }
57
- Dumpers.dump_site(@log_site, "Jekyll::Hooks.register(:site, :after_init)", site)
53
+ @log_site.info { "Loaded #{JekyllPluginHooksName::PLUGIN_NAME} v#{JekyllPluginTemplateVersion::VERSION} plugin." }
54
+ @log_site.info { 'Jekyll::Hooks.register(:site, :after_init) invoked.' }
55
+ Dumpers.dump_site(@log_site, 'Jekyll::Hooks.register(:site, :after_init)', site)
58
56
  end
59
57
 
60
58
  # Called after all source files have been read and loaded from disk.
61
59
  # This is a good hook for enriching posts;
62
60
  # for example, adding links to author pages or adding posts to author pages.
63
61
  Jekyll::Hooks.register(:site, :post_read, priority: :normal) do |site|
64
- @log_site.info { "Jekyll::Hooks.register(:site, :post_read) invoked." }
65
- Dumpers.dump_site(@log_site, "Jekyll::Hooks.register(:site, :post_read)", site)
62
+ @log_site.info { 'Jekyll::Hooks.register(:site, :post_read) invoked.' }
63
+ Dumpers.dump_site(@log_site, 'Jekyll::Hooks.register(:site, :post_read)', site)
66
64
  end
67
65
 
68
66
  # Called before rendering the whole site
@@ -72,10 +70,10 @@ module JekyllPluginHooks
72
70
  # @param payload [Hash] according to the docs, payload is a hash containing the variables available during rendering; the hash can be modified here.
73
71
  # However, the debugger shows payload has type Jekyll::UnifiedPayloadDrop
74
72
  Jekyll::Hooks.register(:site, :pre_render, priority: :normal) do |site, payload|
75
- @log_site.info { "Jekyll::Hooks.register(:site, :pre_render) invoked." }
76
- @log_site.debug { dump(":site, :pre_render payload", payload) }
77
- Dumpers.dump_site(@log_site, "Jekyll::Hooks.register(:site, :pre_render)", site)
78
- Dumpers.dump_payload(@log_site, "Jekyll::Hooks.register(:site, :pre_render)", payload)
73
+ @log_site.info { 'Jekyll::Hooks.register(:site, :pre_render) invoked.' }
74
+ @log_site.debug { dump(':site, :pre_render payload', payload) }
75
+ Dumpers.dump_site(@log_site, 'Jekyll::Hooks.register(:site, :pre_render)', site)
76
+ Dumpers.dump_payload(@log_site, 'Jekyll::Hooks.register(:site, :pre_render)', payload)
79
77
  end
80
78
 
81
79
  # Called after rendering the whole site, but before writing any files.
@@ -87,16 +85,16 @@ module JekyllPluginHooks
87
85
  # :documents and :pages, whereas the :pages and :documents hooks are called once for each page and document.
88
86
  # @param payload [Hash] contains final values of variables after rendering the entire site (useful for sitemaps, feeds, etc).
89
87
  Jekyll::Hooks.register(:site, :post_render, priority: :normal) do |site, payload|
90
- @log_site.info { "Jekyll::Hooks.register(:site, :post_render) invoked." }
91
- @log_site.debug { dump(":site, :post_render payload", payload) }
92
- Dumpers.dump_site(@log_site, "Jekyll::Hooks.register(:site, :post_render)", site)
93
- Dumpers.dump_payload(@log_site, "Jekyll::Hooks.register(:site, :post_render)", payload)
88
+ @log_site.info { 'Jekyll::Hooks.register(:site, :post_render) invoked.' }
89
+ @log_site.debug { dump(':site, :post_render payload', payload) }
90
+ Dumpers.dump_site(@log_site, 'Jekyll::Hooks.register(:site, :post_render)', site)
91
+ Dumpers.dump_payload(@log_site, 'Jekyll::Hooks.register(:site, :post_render)', payload)
94
92
  end
95
93
 
96
94
  # Called after writing all of the rendered files to disk
97
95
  Jekyll::Hooks.register(:site, :post_write, priority: :normal) do |site|
98
- @log_site.info { "Jekyll::Hooks.register(:site, :post_write) invoked." }
99
- Dumpers.dump_site(@log_site, "Jekyll::Hooks.register(:site, :post_write)", site)
96
+ @log_site.info { 'Jekyll::Hooks.register(:site, :post_write) invoked.' }
97
+ Dumpers.dump_site(@log_site, 'Jekyll::Hooks.register(:site, :post_write)', site)
100
98
  end
101
99
 
102
100
  ########## :pages hooks
@@ -105,34 +103,34 @@ module JekyllPluginHooks
105
103
 
106
104
  # Called whenever a page is initialized
107
105
  Jekyll::Hooks.register(:pages, :post_init, priority: :normal) do |page|
108
- @log_pages.info { "Jekyll::Hooks.register(:pages, :post_init) invoked." }
109
- Dumpers.dump_page(@log_pages, "Jekyll::Hooks.register(:pages, :post_init)", page)
106
+ @log_pages.info { 'Jekyll::Hooks.register(:pages, :post_init) invoked.' }
107
+ Dumpers.dump_page(@log_pages, 'Jekyll::Hooks.register(:pages, :post_init)', page)
110
108
  end
111
109
 
112
110
  # Called just before rendering a page
113
111
  Jekyll::Hooks.register(:pages, :pre_render, priority: :normal) do |page, payload|
114
- @log_pages.info { "Jekyll::Hooks.register(:pages, :pre_render) invoked." }
115
- Dumpers.dump_page(@log_pages, "Jekyll::Hooks.register(:pages, :pre_render)", page)
116
- Dumpers.dump_payload(@log_pages, ":pages, :pre_render payload", payload)
112
+ @log_pages.info { 'Jekyll::Hooks.register(:pages, :pre_render) invoked.' }
113
+ Dumpers.dump_page(@log_pages, 'Jekyll::Hooks.register(:pages, :pre_render)', page)
114
+ Dumpers.dump_payload(@log_pages, ':pages, :pre_render payload', payload)
117
115
  end
118
116
 
119
117
  # Called after converting the page content, but before rendering the page layout
120
118
  Jekyll::Hooks.register(:pages, :post_convert, priority: :normal) do |page|
121
- @log_pages.info { "Jekyll::Hooks.register(:pages, :post_convert) invoked." }
122
- Dumpers.dump_page(@log_pages, "Jekyll::Hooks.register(:pages, :post_convert)", page)
119
+ @log_pages.info { 'Jekyll::Hooks.register(:pages, :post_convert) invoked.' }
120
+ Dumpers.dump_page(@log_pages, 'Jekyll::Hooks.register(:pages, :post_convert)', page)
123
121
  end
124
122
 
125
123
  # Called after rendering a page, but before writing it to disk
126
124
  Jekyll::Hooks.register(:pages, :post_render, priority: :normal) do |page|
127
125
  page.site.safe = true
128
- @log_pages.info { "Jekyll::Hooks.register(:pages, :post_render) invoked." }
129
- Dumpers.dump_page(@log_pages, "Jekyll::Hooks.register(:pages, :post_render)", page)
126
+ @log_pages.info { 'Jekyll::Hooks.register(:pages, :post_render) invoked.' }
127
+ Dumpers.dump_page(@log_pages, 'Jekyll::Hooks.register(:pages, :post_render)', page)
130
128
  end
131
129
 
132
130
  # Called after writing a page to disk
133
131
  Jekyll::Hooks.register(:pages, :post_write, priority: :normal) do |page|
134
- @log_pages.info { "Jekyll::Hooks.register(:pages, :post_write) invoked." }
135
- Dumpers.dump_page(@log_pages, "Jekyll::Hooks.register(:pages, :post_write)", page)
132
+ @log_pages.info { 'Jekyll::Hooks.register(:pages, :post_write) invoked.' }
133
+ Dumpers.dump_page(@log_pages, 'Jekyll::Hooks.register(:pages, :post_write)', page)
136
134
  end
137
135
 
138
136
  ########## :documents hooks
@@ -149,9 +147,9 @@ module JekyllPluginHooks
149
147
  # excerpt and ext (file extension).
150
148
  # The collection attribute will be set properly for this hook.
151
149
  Jekyll::Hooks.register(:documents, :post_init, priority: :normal) do |document|
152
- @log_docs.info { "Jekyll::Hooks.register(:documents, :post_init) invoked." }
153
- Dumpers.dump_document(@log_docs, "Jekyll::Hooks.register(:documents, :post_init)", document)
154
- "stop"
150
+ @log_docs.info { 'Jekyll::Hooks.register(:documents, :post_init) invoked.' }
151
+ Dumpers.dump_document(@log_docs, 'Jekyll::Hooks.register(:documents, :post_init)', document)
152
+ 'stop'
155
153
  end
156
154
 
157
155
  # Called just before rendering a document.
@@ -160,30 +158,30 @@ module JekyllPluginHooks
160
158
  # If the document contains markdown (or some other markup),
161
159
  # it will not have been converted to HTML (or whatever the target format is) yet.
162
160
  Jekyll::Hooks.register(:documents, :pre_render, priority: :normal) do |document, payload|
163
- @log_docs.info { "Jekyll::Hooks.register(:documents, :pre_render) invoked." }
164
- Dumpers.dump_document(@log_docs, "Jekyll::Hooks.register(:documents, :pre_render)", document)
165
- Dumpers.dump_payload(@log_docs, ":documents, :pre_render payload", payload)
161
+ @log_docs.info { 'Jekyll::Hooks.register(:documents, :pre_render) invoked.' }
162
+ Dumpers.dump_document(@log_docs, 'Jekyll::Hooks.register(:documents, :pre_render)', document)
163
+ Dumpers.dump_payload(@log_docs, ':documents, :pre_render payload', payload)
166
164
  end
167
165
 
168
166
  # Called after converting the document content to HTML (or whatever),
169
167
  # but before rendering the document using the layout.
170
168
  Jekyll::Hooks.register(:documents, :post_convert, priority: :normal) do |document|
171
- @log_docs.info { "Jekyll::Hooks.register(:documents, :post_convert) invoked." }
172
- Dumpers.dump_document(@log_docs, "Jekyll::Hooks.register(:documents, :post_convert)", document)
169
+ @log_docs.info { 'Jekyll::Hooks.register(:documents, :post_convert) invoked.' }
170
+ Dumpers.dump_document(@log_docs, 'Jekyll::Hooks.register(:documents, :post_convert)', document)
173
171
  end
174
172
 
175
173
  # Called after rendering a document using the layout, but before writing it to disk.
176
174
  # This is your last chance to modify the content.
177
175
  Jekyll::Hooks.register(:documents, :post_render, priority: :normal) do |document|
178
- @log_docs.info { "Jekyll::Hooks.register(:documents, :post_render) invoked." }
179
- Dumpers.dump_document(@log_docs, "Jekyll::Hooks.register(:documents, :post_render)", document)
176
+ @log_docs.info { 'Jekyll::Hooks.register(:documents, :post_render) invoked.' }
177
+ Dumpers.dump_document(@log_docs, 'Jekyll::Hooks.register(:documents, :post_render)', document)
180
178
  end
181
179
 
182
180
  # Called after writing a document to disk.
183
181
  # Useful for statistics regarding completed renderings.
184
182
  Jekyll::Hooks.register(:documents, :post_write, priority: :normal) do |document|
185
- @log_docs.info { "Jekyll::Hooks.register(:documents, :post_write) invoked." }
186
- Dumpers.dump_document(@log_docs, "Jekyll::Hooks.register(:documents, :post_write)", document)
183
+ @log_docs.info { 'Jekyll::Hooks.register(:documents, :post_write) invoked.' }
184
+ Dumpers.dump_document(@log_docs, 'Jekyll::Hooks.register(:documents, :post_write)', document)
187
185
  end
188
186
 
189
187
  ########## :posts hooks
@@ -192,16 +190,16 @@ module JekyllPluginHooks
192
190
 
193
191
  # Called whenever any post is initialized
194
192
  Jekyll::Hooks.register(:posts, :post_init, priority: :normal) do |post|
195
- @log_posts.info { "Jekyll::Hooks.register(:posts, :post_init) invoked." }
196
- Dumpers.dump_document(@log_posts, "Jekyll::Hooks.register(:posts, :post_init)", post)
193
+ @log_posts.info { 'Jekyll::Hooks.register(:posts, :post_init) invoked.' }
194
+ Dumpers.dump_document(@log_posts, 'Jekyll::Hooks.register(:posts, :post_init)', post)
197
195
  end
198
196
 
199
197
  # Called just before rendering a post
200
198
  Jekyll::Hooks.register(:posts, :pre_render, priority: :normal) do |post, payload|
201
199
  # post is a Jekyll::Document
202
- @log_posts.info { "Jekyll::Hooks.register(:posts, :pre_render) invoked." }
203
- Dumpers.dump_document(@log_posts, "Jekyll::Hooks.register(:posts, :pre_render)", post)
204
- Dumpers.dump_payload(@log_posts, ":posts, :pre_render payload", payload)
200
+ @log_posts.info { 'Jekyll::Hooks.register(:posts, :pre_render) invoked.' }
201
+ Dumpers.dump_document(@log_posts, 'Jekyll::Hooks.register(:posts, :pre_render)', post)
202
+ Dumpers.dump_payload(@log_posts, ':posts, :pre_render payload', payload)
205
203
  end
206
204
 
207
205
  # Called after converting the post content, but before rendering the post layout.
@@ -213,21 +211,21 @@ module JekyllPluginHooks
213
211
  # post.output.gsub!('programming PHP', 'banging rocks together')
214
212
  # end
215
213
  Jekyll::Hooks.register(:posts, :post_convert, priority: :normal) do |post|
216
- @log_posts.info { "Jekyll::Hooks.register(:posts, :post_convert) invoked." }
217
- Dumpers.dump_document(@log_posts, "Jekyll::Hooks.register(:posts, :post_convert)", post)
214
+ @log_posts.info { 'Jekyll::Hooks.register(:posts, :post_convert) invoked.' }
215
+ Dumpers.dump_document(@log_posts, 'Jekyll::Hooks.register(:posts, :post_convert)', post)
218
216
  end
219
217
 
220
218
  # Called after rendering a post, but before writing it to disk.
221
219
  # Changing `post.conent` has no effect on visible output.
222
220
  Jekyll::Hooks.register(:posts, :post_render, priority: :normal) do |post|
223
- @log_posts.info { "Jekyll::Hooks.register(:posts, :post_render) invoked." }
224
- Dumpers.dump_document(@log_posts, "Jekyll::Hooks.register(:posts, :post_render)", post)
221
+ @log_posts.info { 'Jekyll::Hooks.register(:posts, :post_render) invoked.' }
222
+ Dumpers.dump_document(@log_posts, 'Jekyll::Hooks.register(:posts, :post_render)', post)
225
223
  end
226
224
 
227
225
  # Called after writing a post to disk
228
226
  Jekyll::Hooks.register(:posts, :post_write, priority: :normal) do |post|
229
- @log_posts.info { "Jekyll::Hooks.register(:posts, :post_write) invoked." }
230
- Dumpers.dump_document(@log_posts, "Jekyll::Hooks.register(:posts, :post_write)", post)
227
+ @log_posts.info { 'Jekyll::Hooks.register(:posts, :post_write) invoked.' }
228
+ Dumpers.dump_document(@log_posts, 'Jekyll::Hooks.register(:posts, :post_write)', post)
231
229
  end
232
230
 
233
231
  ########## :clean hooks
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module JekyllPluginTemplateVersion
4
- VERSION = "0.1.3"
2
+ VERSION = '0.3.0'.freeze
5
3
  end
@@ -1,15 +1,13 @@
1
- # frozen_string_literal: true
2
-
3
- require "jekyll"
4
- require "jekyll_plugin_logger"
5
- require_relative "jekyll_plugin_template/version"
6
- require_relative "jekyll_block_tag_plugin"
7
- require_relative "jekyll_filter_template"
8
- require_relative "jekyll_tag_plugin"
9
- require_relative "jekyll_hooks"
10
- require_relative "jekyll_hook_examples"
11
- require_relative "category_index_generator"
12
- require_relative "category_combiner"
1
+ require 'jekyll'
2
+ require 'jekyll_plugin_logger'
3
+ require_relative 'jekyll_plugin_template/version'
4
+ require_relative 'jekyll_block_tag_plugin'
5
+ require_relative 'jekyll_filter_template'
6
+ require_relative 'jekyll_tag_plugin'
7
+ require_relative 'jekyll_hooks'
8
+ require_relative 'jekyll_hook_examples'
9
+ require_relative 'category_index_generator'
10
+ require_relative 'category_combiner'
13
11
 
14
12
  module JekyllPluginTemplate
15
13
  include JekyllBlockTagPlugin
@@ -1,11 +1,7 @@
1
- # frozen_string_literal: true
2
-
3
- require "jekyll_plugin_logger"
4
- require "key_value_parser"
5
- require "shellwords"
1
+ require 'jekyll_plugin_support'
6
2
 
7
3
  module JekyllPluginTagTemplate
8
- PLUGIN_NAME = "tag_template"
4
+ PLUGIN_NAME = 'tag_template'.freeze
9
5
  end
10
6
 
11
7
  # This Jekyll tag plugin creates an emoji of the desired size and alignment.
@@ -27,58 +23,46 @@ end
27
23
  # MyTag: debug
28
24
  module JekyllTagPlugin
29
25
  # This class implements the Jekyll tag functionality
30
- class MyTag < Liquid::Tag
26
+ class MyTag < JekyllSupport::JekyllTag
27
+ include JekyllPluginTemplateVersion
28
+
31
29
  # Supported emojis (GitHub symbol, hex code) - see https://gist.github.com/rxaviers/7360908 and
32
30
  # https://www.quackit.com/character_sets/emoji/emoji_v3.0/unicode_emoji_v3.0_characters_all.cfm
33
31
  @@emojis = {
34
32
  'angry' => '&#x1F620;',
35
33
  'boom' => '&#x1F4A5;', # used when requested emoji is not recognized
34
+ 'grin' => '&#128512;',
35
+ 'horns' => '&#128520;',
36
36
  'kiss' => '&#x1F619;',
37
+ 'open' => '&#128515;',
38
+ 'poop' => '&#x1F4A9;',
39
+ 'sad' => '&#128546;',
37
40
  'scream' => '&#x1F631;',
38
41
  'smiley' => '&#x1F601;', # default emoji
39
42
  'smirk' => '&#x1F60F;',
40
43
  'two_hearts' => '&#x1F495;',
41
- }
44
+ }.sort_by { |k, _v| [k] }.to_h
42
45
 
43
46
  # @param tag_name [String] is the name of the tag, which we already know.
44
47
  # @param argument_string [String] the arguments from the web page.
45
48
  # @param tokens [Liquid::ParseContext] tokenized command line
46
49
  # @return [void]
47
- def initialize(tag_name, argument_string, tokens)
48
- super
49
- @logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
50
-
51
- argv = Shellwords.split(argument_string) # Scans name/value arguments
52
- params = KeyValueParser.new.parse(argv) # Extracts key/value pairs, default value for non-existant keys is nil
53
-
54
- @emoji_name = params[:name] || "smiley"
55
- @emoji_align = params[:align] || "inline" # Could be inline, right or left
56
- @emoji_size = params[:size] || "3em"
57
- @emoji_hex_code = @@emojis[@emoji_name] || @@emojis['boom']
58
- end
59
-
60
- # Method prescribed by the Jekyll plugin lifecycle.
61
- # Several variables are created to illustrate how they are made.
62
- # @param liquid_context [Liquid::Context]
63
- # @return [String]
64
- def render(liquid_context) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
65
- @site = liquid_context.registers[:site]
66
- @config = @site.config
67
- @mode = @config["env"]["JEKYLL_ENV"] || "development"
50
+ def render_impl
51
+ @emoji_name = @helper.parameter_specified?('name') || 'smiley' # Ignored if `list` is specified
52
+ @emoji_align = @helper.parameter_specified?('align') || 'inline' # Allowable values are: inline, right or left
53
+ @emoji_size = @helper.parameter_specified?('size') || '3em'
54
+ @emoji_and_name = @helper.parameter_specified?('emoji_and_name')
55
+ @list = @helper.parameter_specified?('list')
56
+ @emoji_hex_code = @@emojis[@emoji_name] if @emoji_name || @@emojis['boom']
68
57
 
69
58
  # variables defined in pages are stored as hash values in liquid_context
70
- _assigned_page_variable = liquid_context['assigned_page_variable']
71
-
72
- # The names of front matter variables are hash keys for @page
73
- @page = liquid_context.registers[:page] # @page is a Jekyll::Drops::DocumentDrop
59
+ # _assigned_page_variable = @liquid_context['assigned_page_variable']
74
60
 
75
- @envs = liquid_context.environments.first
76
- @layout_hash = @envs['layout']
77
- # @layout_hash = @page['layout']
61
+ @layout_hash = @page['layout']
78
62
 
79
63
  @logger.debug do
80
64
  <<~HEREDOC
81
- liquid_context.scopes=#{liquid_context.scopes}
65
+ liquid_context.scopes=#{@liquid_context.scopes}
82
66
  mode="#{@mode}"
83
67
  page attributes:
84
68
  #{@page.sort
@@ -88,26 +72,45 @@ module JekyllTagPlugin
88
72
  HEREDOC
89
73
  end
90
74
 
91
- assemble_emoji
75
+ # Return the value of this Jekyll tag
76
+ if @list
77
+ list
78
+ else
79
+ assemble_emoji(@emoji_name, @emoji_hex_code)
80
+ end
92
81
  end
93
82
 
94
- def assemble_emoji # rubocop:disable Metrics/MethodLength
83
+ private
84
+
85
+ def assemble_emoji(emoji_name, emoji_hex_code)
95
86
  case @emoji_align
96
- when "inline"
97
- align = ""
98
- when "right"
99
- align = "float: right; margin-left: 5px;"
100
- when "left"
101
- align = "float: left; margin-right: 5px;"
87
+ when 'inline'
88
+ align = ''
89
+ when 'right'
90
+ align = ' float: right; margin-left: 5px;'
91
+ when 'left'
92
+ align = ' float: left; margin-right: 5px;'
102
93
  else
103
94
  @logger.error { "Invalid emoji alignment #{@emoji_align}" }
104
- align = ""
95
+ align = ''
96
+ end
97
+
98
+ name = " <code>#{emoji_name}</code>" if @emoji_and_name
99
+
100
+ "<span style='font-size: #{@emoji_size};#{align}'>#{emoji_hex_code}</span>#{name}"
101
+ end
102
+
103
+ def list
104
+ items = @@emojis.map do |ename, hex_code|
105
+ " <li>#{assemble_emoji(ename, hex_code)}</li>"
105
106
  end
106
- # Compute the return value of this Jekyll tag
107
- "<span style='font-size: #{@emoji_size}; #{align}'>#{@emoji_hex_code}</span>"
107
+ <<~END_RESULT
108
+ <ul class='emoji_list'>
109
+ #{items.join("\n ")}
110
+ </ul>
111
+ END_RESULT
108
112
  end
113
+
114
+ JekyllPluginHelper.register(self, JekyllPluginTagTemplate::PLUGIN_NAME)
109
115
  end
110
116
  end
111
-
112
- PluginMetaLogger.instance.info { "Loaded #{JekyllPluginTagTemplate::PLUGIN_NAME} v#{JekyllPluginTemplateVersion::VERSION} plugin." }
113
- Liquid::Template.register_tag(JekyllPluginTagTemplate::PLUGIN_NAME, JekyllTagPlugin::MyTag)
@@ -1,26 +1,24 @@
1
- # frozen_string_literal: true
2
-
3
- require "fileutils"
4
- require "jekyll"
5
- require "key_value_parser"
6
- require "shellwords"
7
- require_relative "../lib/jekyll_plugin_template"
1
+ require 'fileutils'
2
+ require 'jekyll'
3
+ require 'key_value_parser'
4
+ require 'shellwords'
5
+ require_relative '../lib/jekyll_plugin_template'
8
6
 
9
7
  RSpec.describe(KeyValueParser) do
10
- it "parses arguments" do
11
- argv = "param0 param1=value1 param2='value2' param3=\"value3's tricky\" remainder of line".shellsplit
8
+ it 'parses arguments' do
9
+ argv = 'param0 param1=value1 param2=\'value2\' param3="value3\'s tricky" remainder of line'.shellsplit
12
10
  parser = KeyValueParser.new
13
11
  options = parser.parse(argv)
14
12
  # puts options.map { |k, v| "#{k} = #{v}" }.join("\n")
15
13
 
16
14
  expect(options[:param0]).to eq(true)
17
- expect(options[:param1]).to eq("value1")
18
- expect(options[:param2]).to eq("value2")
15
+ expect(options[:param1]).to eq('value1')
16
+ expect(options[:param2]).to eq('value2')
19
17
  expect(options[:param3]).to eq("value3's tricky")
20
18
  expect(options[:unknown]).to be_nil
21
19
 
22
- [:param0, :param1, :param2, :param3].each { |key| options.delete key }
23
- remainder_of_line = options.keys.join(" ")
24
- expect(remainder_of_line).to eq("remainder of line")
20
+ %i[param0 param1 param2 param3].each { |key| options.delete key }
21
+ remainder_of_line = options.keys.join(' ')
22
+ expect(remainder_of_line).to eq('remainder of line')
25
23
  end
26
24
  end
@@ -1,6 +1,4 @@
1
- # frozen_string_literal: true
2
-
3
- require "nokogiri"
1
+ require 'nokogiri'
4
2
 
5
3
  class NokoTest
6
4
  webpage = <<~END_PAGE
@@ -16,9 +14,9 @@ class NokoTest
16
14
  END_PAGE
17
15
 
18
16
  html = Nokogiri.HTML(webpage)
19
- html.css("p").each do |node|
17
+ html.css('p').each do |node|
20
18
  # This strips any HTML tags from node.content:
21
- node.content = node.content.gsub("angry", "happy")
19
+ node.content = node.content.gsub('angry', 'happy')
22
20
  end
23
21
  puts "\n\nHTML:\n#{html}"
24
22
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  class OldName
4
- old_name = "blah"
2
+ old_name = 'blah'
5
3
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module OldNameVersion
4
- VERSION = "0.1.0"
2
+ VERSION = '0.1.0'.freeze
5
3
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  class OldName
4
- old_name = "blah"
2
+ old_name = 'blah'
5
3
  end
@@ -1,9 +1,7 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/old_name/version"
1
+ require_relative 'lib/old_name/version'
4
2
 
5
3
  Gem::Specification.new do |spec|
6
- github = "https://github.com/mslinn/old_name"
7
- spec.name = "old_name"
4
+ github = 'https://github.com/mslinn/old_name'
5
+ spec.name = 'old_name'
8
6
  spec.version = OldName::VERSION
9
7
  end
@@ -1,21 +1,19 @@
1
- # frozen_string_literal: true
2
-
3
- load "bin/run_this_first"
1
+ load 'bin/run_this_first'
4
2
 
5
3
  RSpec.configure do |config|
6
4
  config.add_setting :work_dir
7
- config.work_dir = "/tmp/jekyll_plugin_template"
5
+ config.work_dir = '/tmp/jekyll_plugin_template'
8
6
 
9
7
  config.after(:suite) do
10
8
  FileUtils.rm_rf(config.work_dir)
11
9
  end
12
10
  config.before(:suite) do
13
- FileUtils.cp_r "spec/run_this_first_data", config.work_dir, :verbose => true
11
+ FileUtils.cp_r 'spec/run_this_first_data', config.work_dir, :verbose => true
14
12
  end
15
13
  config.filter_run :focus
16
- config.order = "random"
14
+ config.order = 'random'
17
15
  config.run_all_when_everything_filtered = true
18
16
 
19
17
  # See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
20
- config.example_status_persistence_file_path = "spec/first_status_persistence.txt"
18
+ config.example_status_persistence_file_path = 'spec/first_status_persistence.txt'
21
19
  end
@@ -1,40 +1,38 @@
1
- # frozen_string_literal: true
2
-
3
- require "fileutils"
4
- require_relative "run_this_first_helper"
5
- load "bin/run_this_first"
1
+ require 'fileutils'
2
+ require_relative 'run_this_first_helper'
3
+ load 'bin/run_this_first'
6
4
 
7
5
  RSpec.describe(JekyllPluginTemplateModule) do
8
- it "rename_identifiers" do
6
+ it 'rename_identifiers' do
9
7
  run_this_first = JekyllPluginTemplateModule::RunThisFirst.new(RSpec.configuration.work_dir)
10
- run_this_first.rename_identifiers("old_variable_name", "new_variable_name")
8
+ run_this_first.rename_identifiers('old_variable_name', 'new_variable_name')
11
9
 
12
- gemspec = File.read("old_name.gemspec")
10
+ gemspec = File.read('old_name.gemspec')
13
11
  expect(gemspec).to include <<~END_GEMSPEC
14
- require_relative "lib/new_name/version"
12
+ require_relative 'lib/new_name/version'
15
13
 
16
14
  Gem::Specification.new do |spec|
17
- github = "https://github.com/mslinn/new_name"
18
- spec.name = "new_name"
15
+ github = 'https://github.com/mslinn/new_name'
16
+ spec.name = 'new_name'
19
17
  spec.version = NewNameVersion::VERSION
20
18
  end
21
19
  END_GEMSPEC
22
20
 
23
- version_rb = File.read("old_name/old_name/version.rb")
24
- expect(version_rb).to include("class NewName")
21
+ version_rb = File.read('old_name/old_name/version.rb')
22
+ expect(version_rb).to include('class NewName')
25
23
 
26
- old_name_rb = File.read("old_name/old_name/old_name.rb")
27
- expect(old_name_rb).to include("new_name")
24
+ old_name_rb = File.read('old_name/old_name/old_name.rb')
25
+ expect(old_name_rb).to include('new_name')
28
26
  end
29
27
 
30
- it "rename_files" do
28
+ it 'rename_files' do
31
29
  run_this_first = JekyllPluginTemplateModule::RunThisFirst.new(RSpec.configuration.work_dir)
32
- run_this_first.rename_files("old_name", "new_name")
33
- expect(Dir["."]).to match_array[
34
- "new_name.gemspec",
35
- "lib/new_name.rb",
36
- "lib/new_name/new_name.rb",
37
- "lib/new_name/version.rb"
30
+ run_this_first.rename_files('old_name', 'new_name')
31
+ expect(Dir['.']).to match_array[
32
+ 'new_name.gemspec',
33
+ 'lib/new_name.rb',
34
+ 'lib/new_name/new_name.rb',
35
+ 'lib/new_name/version.rb'
38
36
  ]
39
37
  end
40
38
  end
data/spec/spec_helper.rb CHANGED
@@ -1,19 +1,17 @@
1
- # frozen_string_literal: true
1
+ require 'jekyll'
2
+ require 'fileutils'
3
+ require 'key_value_parser'
4
+ require 'shellwords'
2
5
 
3
- require "jekyll"
4
- require "fileutils"
5
- require "key_value_parser"
6
- require "shellwords"
7
-
8
- require_relative "../lib/jekyll_plugin_template"
6
+ require_relative '../lib/jekyll_plugin_template'
9
7
 
10
8
  Jekyll.logger.log_level = :info
11
9
 
12
10
  RSpec.configure do |config|
13
11
  config.filter_run :focus
14
- config.order = "random"
12
+ config.order = 'random'
15
13
  config.run_all_when_everything_filtered = true
16
14
 
17
15
  # See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
18
- config.example_status_persistence_file_path = "spec/status_persistence.txt"
16
+ config.example_status_persistence_file_path = 'spec/status_persistence.txt'
19
17
  end