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.
- checksums.yaml +4 -4
- data/.rubocop.yml +80 -12
- data/CHANGELOG.md +15 -0
- data/Rakefile +3 -5
- data/jekyll_plugin_template.gemspec +25 -32
- data/lib/category_combiner.rb +0 -2
- data/lib/category_index_generator.rb +8 -10
- data/lib/dumpers.rb +1 -3
- data/lib/jekyll_block_tag_plugin.rb +27 -58
- data/lib/jekyll_filter_template.rb +4 -6
- data/lib/jekyll_hook_examples.rb +10 -12
- data/lib/jekyll_hooks.rb +55 -57
- data/lib/jekyll_plugin_template/version.rb +1 -3
- data/lib/jekyll_plugin_template.rb +10 -12
- data/lib/jekyll_tag_plugin.rb +54 -51
- data/spec/jekyll_plugin_template_spec.rb +12 -14
- data/spec/nokogiri_test.rb +3 -5
- data/spec/run_this_first_data/lib/old_name/old_name.rb +1 -3
- data/spec/run_this_first_data/lib/old_name/version.rb +1 -3
- data/spec/run_this_first_data/lib/old_name.rb +1 -3
- data/spec/run_this_first_data/old_name.gemspec +3 -5
- data/spec/run_this_first_helper.rb +5 -7
- data/spec/run_this_first_spec.rb +20 -22
- data/spec/spec_helper.rb +7 -9
- metadata +9 -38
- data/spec/status_persistence.txt +0 -5
data/lib/jekyll_hooks.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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 =
|
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 {
|
42
|
-
Dumpers.dump_site(@log_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#{
|
56
|
-
@log_site.info {
|
57
|
-
Dumpers.dump_site(@log_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 {
|
65
|
-
Dumpers.dump_site(@log_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 {
|
76
|
-
@log_site.debug { dump(
|
77
|
-
Dumpers.dump_site(@log_site,
|
78
|
-
Dumpers.dump_payload(@log_site,
|
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 {
|
91
|
-
@log_site.debug { dump(
|
92
|
-
Dumpers.dump_site(@log_site,
|
93
|
-
Dumpers.dump_payload(@log_site,
|
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 {
|
99
|
-
Dumpers.dump_site(@log_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 {
|
109
|
-
Dumpers.dump_page(@log_pages,
|
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 {
|
115
|
-
Dumpers.dump_page(@log_pages,
|
116
|
-
Dumpers.dump_payload(@log_pages,
|
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 {
|
122
|
-
Dumpers.dump_page(@log_pages,
|
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 {
|
129
|
-
Dumpers.dump_page(@log_pages,
|
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 {
|
135
|
-
Dumpers.dump_page(@log_pages,
|
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 {
|
153
|
-
Dumpers.dump_document(@log_docs,
|
154
|
-
|
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 {
|
164
|
-
Dumpers.dump_document(@log_docs,
|
165
|
-
Dumpers.dump_payload(@log_docs,
|
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 {
|
172
|
-
Dumpers.dump_document(@log_docs,
|
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 {
|
179
|
-
Dumpers.dump_document(@log_docs,
|
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 {
|
186
|
-
Dumpers.dump_document(@log_docs,
|
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 {
|
196
|
-
Dumpers.dump_document(@log_posts,
|
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 {
|
203
|
-
Dumpers.dump_document(@log_posts,
|
204
|
-
Dumpers.dump_payload(@log_posts,
|
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 {
|
217
|
-
Dumpers.dump_document(@log_posts,
|
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 {
|
224
|
-
Dumpers.dump_document(@log_posts,
|
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 {
|
230
|
-
Dumpers.dump_document(@log_posts,
|
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,15 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
10
|
-
require_relative
|
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
|
data/lib/jekyll_tag_plugin.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
|
-
|
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 =
|
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 <
|
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' => '😠',
|
35
33
|
'boom' => '💥', # used when requested emoji is not recognized
|
34
|
+
'grin' => '😀',
|
35
|
+
'horns' => '😈',
|
36
36
|
'kiss' => '😙',
|
37
|
+
'open' => '😃',
|
38
|
+
'poop' => '💩',
|
39
|
+
'sad' => '😢',
|
37
40
|
'scream' => '😱',
|
38
41
|
'smiley' => '😁', # default emoji
|
39
42
|
'smirk' => '😏',
|
40
43
|
'two_hearts' => '💕',
|
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
|
48
|
-
|
49
|
-
@
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
@
|
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
|
-
|
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
|
-
|
83
|
+
private
|
84
|
+
|
85
|
+
def assemble_emoji(emoji_name, emoji_hex_code)
|
95
86
|
case @emoji_align
|
96
|
-
when
|
97
|
-
align =
|
98
|
-
when
|
99
|
-
align =
|
100
|
-
when
|
101
|
-
align =
|
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
|
-
|
107
|
-
|
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
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
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
|
11
|
-
argv =
|
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(
|
18
|
-
expect(options[:param2]).to eq(
|
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
|
-
[
|
23
|
-
remainder_of_line = options.keys.join(
|
24
|
-
expect(remainder_of_line).to eq(
|
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
|
data/spec/nokogiri_test.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
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(
|
17
|
+
html.css('p').each do |node|
|
20
18
|
# This strips any HTML tags from node.content:
|
21
|
-
node.content = node.content.gsub(
|
19
|
+
node.content = node.content.gsub('angry', 'happy')
|
22
20
|
end
|
23
21
|
puts "\n\nHTML:\n#{html}"
|
24
22
|
end
|
@@ -1,9 +1,7 @@
|
|
1
|
-
|
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 =
|
7
|
-
spec.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
|
-
|
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 =
|
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
|
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 =
|
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 =
|
18
|
+
config.example_status_persistence_file_path = 'spec/first_status_persistence.txt'
|
21
19
|
end
|
data/spec/run_this_first_spec.rb
CHANGED
@@ -1,40 +1,38 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
6
|
+
it 'rename_identifiers' do
|
9
7
|
run_this_first = JekyllPluginTemplateModule::RunThisFirst.new(RSpec.configuration.work_dir)
|
10
|
-
run_this_first.rename_identifiers(
|
8
|
+
run_this_first.rename_identifiers('old_variable_name', 'new_variable_name')
|
11
9
|
|
12
|
-
gemspec = File.read(
|
10
|
+
gemspec = File.read('old_name.gemspec')
|
13
11
|
expect(gemspec).to include <<~END_GEMSPEC
|
14
|
-
require_relative
|
12
|
+
require_relative 'lib/new_name/version'
|
15
13
|
|
16
14
|
Gem::Specification.new do |spec|
|
17
|
-
github =
|
18
|
-
spec.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(
|
24
|
-
expect(version_rb).to include(
|
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(
|
27
|
-
expect(old_name_rb).to include(
|
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
|
28
|
+
it 'rename_files' do
|
31
29
|
run_this_first = JekyllPluginTemplateModule::RunThisFirst.new(RSpec.configuration.work_dir)
|
32
|
-
run_this_first.rename_files(
|
33
|
-
expect(Dir[
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
1
|
+
require 'jekyll'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'key_value_parser'
|
4
|
+
require 'shellwords'
|
2
5
|
|
3
|
-
|
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 =
|
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 =
|
16
|
+
config.example_status_persistence_file_path = 'spec/status_persistence.txt'
|
19
17
|
end
|