jekyll_plugin_template 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll_plugin_logger"
4
+ require "key_value_parser"
5
+ require "shellwords"
6
+
7
+ module JekyllPluginTagTemplate
8
+ PLUGIN_NAME = "tag_template"
9
+ end
10
+
11
+ # This Jekyll tag plugin creates an emoji of the desired size and alignment.
12
+ #
13
+ # @example Float Smiley emoji right, sized 3em
14
+ # {% tag_template name='smile' align='right' size='5em' %}
15
+ # The above results in the following HTML:
16
+ # <span style="float: right; font-size: 5em;">&#x1F601;</span>
17
+ #
18
+ # @example Defaults
19
+ # {% tag_template name='smile' %}
20
+ # The above results in the following HTML:
21
+ # <span style="font-size: 3em;">&#x1F601;</span>
22
+ #
23
+ # The Jekyll log level defaults to :info, which means all the Jekyll.logger statements below will not generate output.
24
+ # You can control the log level when you start Jekyll.
25
+ # To set the log level to :debug, write an entery into _config.yml, like this:
26
+ # plugin_loggers:
27
+ # MyTag: debug
28
+ module JekyllTagPlugin
29
+ # This class implements the Jekyll tag functionality
30
+ class MyTag < Liquid::Tag
31
+ # Supported emojis (GitHub symbol, hex code) - see https://gist.github.com/rxaviers/7360908 and
32
+ # https://www.quackit.com/character_sets/emoji/emoji_v3.0/unicode_emoji_v3.0_characters_all.cfm
33
+ @@emojis = {
34
+ 'angry' => '&#x1F620;',
35
+ 'boom' => '&#x1F4A5;', # used when requested emoji is not recognized
36
+ 'kiss' => '&#x1F619;',
37
+ 'scream' => '&#x1F631;',
38
+ 'smiley' => '&#x1F601;', # default emoji
39
+ 'smirk' => '&#x1F60F;',
40
+ 'two_hearts' => '&#x1F495;',
41
+ }
42
+
43
+ # @param tag_name [String] is the name of the tag, which we already know.
44
+ # @param argument_string [String] the arguments from the web page.
45
+ # @param tokens [Liquid::ParseContext] tokenized command line
46
+ # @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"
68
+
69
+ # 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
74
+
75
+ @envs = liquid_context.environments.first
76
+ @layout_hash = @envs['layout']
77
+ # @layout_hash = @page['layout']
78
+
79
+ @logger.debug do
80
+ <<~HEREDOC
81
+ liquid_context.scopes=#{liquid_context.scopes}
82
+ mode="#{@mode}"
83
+ page attributes:
84
+ #{@page.sort
85
+ .reject { |k, _| REJECTED_ATTRIBUTES.include? k }
86
+ .map { |k, v| "#{k}=#{v}" }
87
+ .join("\n ")}
88
+ HEREDOC
89
+ end
90
+
91
+ assemble_emoji
92
+ end
93
+
94
+ def assemble_emoji # rubocop:disable Metrics/MethodLength
95
+ 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;"
102
+ else
103
+ @logger.error { "Invalid emoji alignment #{@emoji_align}" }
104
+ align = ""
105
+ end
106
+ # Compute the return value of this Jekyll tag
107
+ "<span style='font-size: #{@emoji_size}; #{align}'>#{@emoji_hex_code}</span>"
108
+ end
109
+ end
110
+ end
111
+
112
+ PluginMetaLogger.instance.info { "Loaded #{JekyllPluginTagTemplate::PLUGIN_NAME} v#{JekyllPluginTemplateVersion::VERSION} plugin." }
113
+ Liquid::Template.register_tag(JekyllPluginTagTemplate::PLUGIN_NAME, JekyllTagPlugin::MyTag)
@@ -0,0 +1,26 @@
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"
8
+
9
+ RSpec.describe(KeyValueParser) do
10
+ it "parses arguments" do
11
+ argv = "param0 param1=value1 param2='value2' param3=\"value3's tricky\" remainder of line".shellsplit
12
+ parser = KeyValueParser.new
13
+ options = parser.parse(argv)
14
+ # puts options.map { |k, v| "#{k} = #{v}" }.join("\n")
15
+
16
+ expect(options[:param0]).to eq(true)
17
+ expect(options[:param1]).to eq("value1")
18
+ expect(options[:param2]).to eq("value2")
19
+ expect(options[:param3]).to eq("value3's tricky")
20
+ expect(options[:unknown]).to be_nil
21
+
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")
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "nokogiri"
4
+
5
+ class NokoTest
6
+ webpage = <<~END_PAGE
7
+ <html>
8
+ <body>
9
+ <p>Marvin the Martian, from Warner Bros, was <a href="https://kidadl.com/quotes/marvin-the-martian-quotes-from-the-looney-tunes-beloved-character">often angry</a>.</p>
10
+ <p>Being disintegrated makes me very angry! Very angry indeed!</p>
11
+ <p>I’m not angry. Just terribly, terribly hurt.</p>
12
+ <p>You make me very angry, very angry.</p>
13
+ <p>Flux to blow Mars into subatomic space dust make me very angry.</p>
14
+ </body>
15
+ </html>
16
+ END_PAGE
17
+
18
+ html = Nokogiri.HTML(webpage)
19
+ html.css("p").each do |node|
20
+ # This strips any HTML tags from node.content:
21
+ node.content = node.content.gsub("angry", "happy")
22
+ end
23
+ puts "\n\nHTML:\n#{html}"
24
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class OldName
4
+ old_name = "blah"
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OldNameVersion
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class OldName
4
+ old_name = "blah"
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/old_name/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ github = "https://github.com/mslinn/old_name"
7
+ spec.name = "old_name"
8
+ spec.version = OldName::VERSION
9
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ load "bin/run_this_first"
4
+
5
+ RSpec.configure do |config|
6
+ config.add_setting :work_dir
7
+ config.work_dir = "/tmp/jekyll_plugin_template"
8
+
9
+ config.after(:suite) do
10
+ FileUtils.rm_rf(config.work_dir)
11
+ end
12
+ config.before(:suite) do
13
+ FileUtils.cp_r "spec/run_this_first_data", config.work_dir, :verbose => true
14
+ end
15
+ config.filter_run :focus
16
+ config.order = "random"
17
+ config.run_all_when_everything_filtered = true
18
+
19
+ # See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
20
+ config.example_status_persistence_file_path = "spec/first_status_persistence.txt"
21
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require_relative "run_this_first_helper"
5
+ load "bin/run_this_first"
6
+
7
+ RSpec.describe(JekyllPluginTemplateModule) do
8
+ it "rename_identifiers" do
9
+ run_this_first = JekyllPluginTemplateModule::RunThisFirst.new(RSpec.configuration.work_dir)
10
+ run_this_first.rename_identifiers("old_variable_name", "new_variable_name")
11
+
12
+ gemspec = File.read("old_name.gemspec")
13
+ expect(gemspec).to include <<~END_GEMSPEC
14
+ require_relative "lib/new_name/version"
15
+
16
+ Gem::Specification.new do |spec|
17
+ github = "https://github.com/mslinn/new_name"
18
+ spec.name = "new_name"
19
+ spec.version = NewNameVersion::VERSION
20
+ end
21
+ END_GEMSPEC
22
+
23
+ version_rb = File.read("old_name/old_name/version.rb")
24
+ expect(version_rb).to include("class NewName")
25
+
26
+ old_name_rb = File.read("old_name/old_name/old_name.rb")
27
+ expect(old_name_rb).to include("new_name")
28
+ end
29
+
30
+ it "rename_files" do
31
+ 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"
38
+ ]
39
+ end
40
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll"
4
+ require "fileutils"
5
+ require "key_value_parser"
6
+ require "shellwords"
7
+
8
+ require_relative "../lib/jekyll_plugin_template"
9
+
10
+ Jekyll.logger.log_level = :info
11
+
12
+ RSpec.configure do |config|
13
+ config.filter_run :focus
14
+ config.order = "random"
15
+ config.run_all_when_everything_filtered = true
16
+
17
+ # See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
18
+ config.example_status_persistence_file_path = "spec/status_persistence.txt"
19
+ end
@@ -0,0 +1,5 @@
1
+ example_id | status | run_time |
2
+ ------------------------------------------ | ------ | --------------- |
3
+ ./spec/jekyll_plugin_template_spec.rb[1:1] | passed | 0.02165 seconds |
4
+ ./spec/run_this_first_spec.rb[1:1] | failed | 0.00134 seconds |
5
+ ./spec/run_this_first_spec.rb[1:2] | failed | 2.84 seconds |
metadata ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll_plugin_template
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Firstname Lastname
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-01-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: jekyll_plugin_logger
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: key-value-parser
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
+ - !ruby/object:Gem::Dependency
56
+ name: git
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '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'
83
+ - !ruby/object:Gem::Dependency
84
+ name: os
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: shellwords
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: talk_like_a_pirate
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 0.2.2
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 0.2.2
125
+ - !ruby/object:Gem::Dependency
126
+ name: tty-prompt
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: 'Expand on what spec.summary says.
140
+
141
+ '
142
+ email:
143
+ - email@email.com
144
+ executables: []
145
+ extensions: []
146
+ extra_rdoc_files: []
147
+ files:
148
+ - ".rubocop.yml"
149
+ - CHANGELOG.md
150
+ - LICENSE.txt
151
+ - PLUGIN_README.md
152
+ - README.md
153
+ - Rakefile
154
+ - jekyll_plugin_template.gemspec
155
+ - lib/category_combiner.rb
156
+ - lib/category_index_generator.rb
157
+ - lib/dumpers.rb
158
+ - lib/jekyll_block_tag_plugin.rb
159
+ - lib/jekyll_filter_template.rb
160
+ - lib/jekyll_hook_examples.rb
161
+ - lib/jekyll_hooks.rb
162
+ - lib/jekyll_plugin_template.rb
163
+ - lib/jekyll_plugin_template/version.rb
164
+ - lib/jekyll_tag_plugin.rb
165
+ - spec/jekyll_plugin_template_spec.rb
166
+ - spec/nokogiri_test.rb
167
+ - spec/run_this_first_data/lib/old_name.rb
168
+ - spec/run_this_first_data/lib/old_name/old_name.rb
169
+ - spec/run_this_first_data/lib/old_name/version.rb
170
+ - spec/run_this_first_data/old_name.gemspec
171
+ - spec/run_this_first_helper.rb
172
+ - spec/run_this_first_spec.rb
173
+ - spec/spec_helper.rb
174
+ - spec/status_persistence.txt
175
+ homepage: https://www.mslinn.com/blog/2020/12/30/jekyll-plugin-template-collection.html
176
+ licenses:
177
+ - CC0-1.0
178
+ metadata:
179
+ allowed_push_host: https://rubygems.org
180
+ bug_tracker_uri: https://github.com/mslinn/jekyll_plugin_template/issues
181
+ changelog_uri: https://github.com/mslinn/jekyll_plugin_template/CHANGELOG.md
182
+ homepage_uri: https://www.mslinn.com/blog/2020/12/30/jekyll-plugin-template-collection.html
183
+ source_code_uri: https://github.com/mslinn/jekyll_plugin_template
184
+ post_install_message:
185
+ rdoc_options: []
186
+ require_paths:
187
+ - lib
188
+ required_ruby_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: 2.6.0
193
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ requirements: []
199
+ rubygems_version: 3.3.3
200
+ signing_key:
201
+ specification_version: 4
202
+ summary: Write a short summary; RubyGems requires one.
203
+ test_files: []