jekyll_pre 1.2.2 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6097d5cc2c288233bb1bdb16683fa3116ec244edead6a25d971d0f002932d939
4
- data.tar.gz: ab7f388db1f0e9dbfc0f677ea1e830b8486f02acc6da3aa95f08654c2f7de3a4
3
+ metadata.gz: 2a78213a8f26a3d6743a9b706501a5c0f87279eeb243e492956fdd557b0a1e6d
4
+ data.tar.gz: 64c8640dee1fe914ac54f9813df8bb3f365518d41d13aecd62bda8c752d0488e
5
5
  SHA512:
6
- metadata.gz: e3069935c7ad9b664004cb4235002ab12fb6e91911876a9cb5113e880c3f6b3a565d84c51bd5706470866fd82d1a6c168c0b26b88cbf59cf9d3adfc49ce9e392
7
- data.tar.gz: 5e14ff1c554fda49eb095538fef25297f13bf8cdf48d508747227db69e0fa32a698193f391dbb9981f19914f4a6a15656d9db4ad50240b1bf6162c01af68c77b
6
+ metadata.gz: e89f23e343045045c93f7fe7843a43611608f8702e934f4ce0f3c50b52bed7d71b856c79af679d4af9fbdd25921bbcf6977acbd709033a171bbfffc136ff358d
7
+ data.tar.gz: bba7c4caf281ab09415560e63a525c632bd98019bb475d53e526fade9c43ed4f77a9de7ef8395085c82308cf4fe31c4e4bbc52c58870f942cd7f6db1181e23ae
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.2.4
2
+ * The `exec` tag now evaluates environment variables in the command before execution.
3
+
4
+ ## 1.2.3
5
+ * Added `cd` option to `exec` tag.
6
+
1
7
  ## 1.2.2
2
8
  * Added `exec` tag.
3
9
  * Demarked CSS for the `exec`, `noselect`, and `pre` tags in `demo/assets/css/style.css`
data/README.md CHANGED
@@ -4,9 +4,9 @@ Jekyll_pre
4
4
 
5
5
  This Jekyll plugin provides 3 new Liquid tags that work together:
6
6
 
7
- * A `pre` block tag that can optionally display a copy button.
7
+ * A `pre` block tag that can be displayed various ways.
8
8
  ```
9
- {% pre [Options] [headline words] %}
9
+ {% pre [Options] [free text label] %}
10
10
  Contents of pre tag
11
11
  {% endpre %}
12
12
  ```
@@ -24,7 +24,7 @@ This Jekyll plugin provides 3 new Liquid tags that work together:
24
24
  - {% pre This is a label %}<br>Contents of pre tag<br>{% endpre %}
25
25
  - `number` &ndash; Number the lines
26
26
  - `shell` &ndash; Equivalent to `label='Shell'`
27
- - `style` &ndash; Apply CSS styles
27
+ - `style` &ndash; Apply inline CSS styles
28
28
 
29
29
  The generated &lt;pre>&lt;/pre> tag has an `data-lt-active="false"` attribute, so [LanguageTool](https://forum.languagetool.org/t/avoid-spell-check-on-certain-html-inputs-manually/3944) does not check the spelling or grammar of the contents.
30
30
 
@@ -32,32 +32,34 @@ This Jekyll plugin provides 3 new Liquid tags that work together:
32
32
  and generates a <code>$</code> prompt if no content is provided.
33
33
  ```
34
34
  {% pre %}
35
- {% noselect [optional text string, defaults to $]%}Contents of pre tag
35
+ {% noselect [optional text string, defaults to $]%}Command
36
+ {% noselect unselectable output goes here %}
36
37
  {% endpre %}
37
38
  ```
38
39
 
39
40
  * An `exec` tag that executes shell commands and incorporates the command and its output into the content of the `pre` tag.
40
- Output data is escaped, whitespace is condensed, and wrapped in the same `unselectable` class as does `unselectable`.
41
- ## CSS
42
- Below are the CSS declarations that I defined pertaining to the pre and noselect tags that produced the above images:
43
- ```css
44
- .maxOneScreenHigh {
45
- max-height: 500px;
46
- }
41
+ Environment variables are evaluated,
42
+ output data is escaped, whitespace is condensed, and wrapped in the same `unselectable` class as does `unselectable`.
43
+ ```
44
+ {% exec [Options] [shell command] %}
45
+ ```
46
+ `Options` are:
47
47
 
48
- .numbered_line,
49
- .unselectable.numbered_line,
50
- .numbered_line.unselectable {
51
- color: #5fb25f;
52
- }
48
+ - `cd="relative/or/absolute/directory"` - Change to specified directory before executing shell command.
49
+ Environment variables in the directory path will be expanded.
50
+ - `no_escape` – Do not HTML escape the result of running the shell command.
51
+ - `no_strip` – Do not remove leading and trailing whitespace from the result.
52
+ - `die_if_nonzero` – Set `false` to treat non-zero return codes as non-fatal.
53
+ Instead of terminating Jekyll with an error message,
54
+ the message will be displayed as an error by the Jekyll logger,
55
+ and a red message will appear in place of the result on the web page.
56
+ - `die_if_error` – Set `false` to treat exceptions generated by this plugin as non-fatal.
57
+ Instead of terminating Jekyll with an error message, the message will be displayed as an error by the Jekyll logger.
53
58
 
54
- .unselectable {
55
- color: #7922f9;
56
- -moz-user-select: none;
57
- -khtml-user-select: none;
58
- user-select: none;
59
- }
60
- ```
59
+
60
+ ## CSS
61
+ See [`demo/assets/css/style.css`](demo/assets/css/style.css) for the CSS declarations,
62
+ between `/* Start of pre tag css */` and `/* End of pre tag css */`.
61
63
 
62
64
 
63
65
  ## Additional Information
@@ -80,6 +82,7 @@ And then execute:
80
82
 
81
83
 
82
84
  ## Usage
85
+ The following examples are rendered on [my website](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#jekyll_pre).
83
86
 
84
87
  ### Example 1
85
88
  This example does not generate a copy button and does not demonstrate `noselect`.
@@ -151,20 +154,88 @@ Which renders as:
151
154
  ![example 4](images/usage4example.png)
152
155
 
153
156
 
154
- ### CSS
155
- Here are the CSS declarations that I defined pertaining to the `pre` and `noselect` tags that produced the above images:
157
+ ### Example 5
158
+ A regular expression can be passed to the `highlight` option.
159
+ This causes text that matches the regex pattern to be wrapped within a &lt;span class="bg_yellow">&lt;/span> tag.
160
+
161
+ The CSS stylesheet used for this page contains the following:
156
162
 
157
163
  ```css
158
- .maxOneScreenHigh {
159
- max-height: 500px;
164
+ .bg_yellow {
165
+ background-color: yellow;
166
+ padding: 2px;
160
167
  }
168
+ ```
161
169
 
162
- .unselectable {
163
- color: #7922f9;
164
- -moz-user-select: none;
165
- -khtml-user-select: none;
166
- user-select: none;
167
- }
170
+ This example demonstrates highlighting text that matches a regular expression. Regular expressions match against lines, which are delimited via newlines (\n).
171
+
172
+ ```
173
+ {% pre copyButton highlight="Line 2" %}
174
+ Line 1
175
+ Line 2
176
+ Line 3
177
+ Line 4
178
+ Line 5
179
+ Line 6
180
+ Line 7
181
+ {% endpre %}
182
+ ```
183
+
184
+
185
+ ### Example 6
186
+ Regular expressions match against lines, which are delimited via newlines (`\n`).
187
+ Thus to match an entire line that contains a phrase, specify the regex as `.*phrase.*`.
188
+ The following matches 3 possible phrases (`2`, `4` or `6`), then selects the entire line if matched.
189
+
190
+ ```
191
+ {% pre copyButton highlight=".*(2|4|6).*" %}
192
+ Line 1
193
+ Line 2
194
+ Line 3
195
+ Line 4
196
+ Line 5
197
+ Line 6
198
+ Line 7
199
+ {% endpre %}
200
+ ```
201
+
202
+
203
+ ### Example 7
204
+ This example floats an image to the right.
205
+ The `jekyll_pre plugin`’s `clear` option moves the generated HTML below the image.
206
+
207
+ ```
208
+ &lt;img src="jekyll.webp" style="float: right; width: 100px; height: auto;">
209
+ {% pre clear copyButton label='Clear example' %}
210
+ Using clear, copyButton and label parameters
211
+ {% endpre %}
212
+ ```
213
+
214
+ ### Example 8
215
+ The following executes `ls -alF /` and displays the output.
216
+
217
+ ```
218
+ {% pre clear copyButton label='Exec without error' %}
219
+ {% noselect %}{% exec die_if_nonzero=false ls -alF / %}
220
+ {% endpre %}
221
+ ```
222
+
223
+ ### Example 9
224
+ The following changes to the home directory (`$HOME`), then executes `pwd` and displays the output.
225
+
226
+ ```
227
+ {% pre clear copyButton label='Exec without error' %}
228
+ {% noselect %}{% exec cd="$HOME" die_if_nonzero=false pwd %}
229
+ {% endpre %}
230
+ ```
231
+
232
+ ### Example 10
233
+ The following executes `echo $USER` and displays the output.
234
+
235
+ ```
236
+ {% pre clear copyButton label='Exec display &dollar;USER' %}
237
+ {% noselect %}{% exec die_if_nonzero=false echo $USER %}
238
+ {% endpre %}
168
239
  ```
169
240
 
170
241
 
@@ -208,11 +279,7 @@ A test website is provided in the `demo` directory.
208
279
 
209
280
  ### Build and Install Locally
210
281
  To build and install this gem onto your local machine, run:
211
- ```shell
212
- $ rake install:local
213
- ```
214
282
 
215
- The following also does the same thing:
216
283
  ```shell
217
284
  $ bundle exec rake install
218
285
  ```
data/jekyll_pre.gemspec CHANGED
@@ -32,5 +32,5 @@ Gem::Specification.new do |spec|
32
32
  spec.version = JekyllPreVersion::VERSION
33
33
 
34
34
  spec.add_dependency 'jekyll', '>= 3.5.0'
35
- spec.add_dependency 'jekyll_plugin_support', '~> 0.5.0'
35
+ spec.add_dependency 'jekyll_plugin_support', '~> 0.5.0', '>= 0.5.3'
36
36
  end
data/lib/exec_tag.rb CHANGED
@@ -5,30 +5,30 @@ module ExecTag
5
5
  class ExecTag < JekyllSupport::JekyllTag
6
6
  include JekyllPreVersion
7
7
 
8
+ def self.remove_html_tags(string)
9
+ string.gsub(/<[^>]*>/, '')
10
+ end
11
+
8
12
  def render_impl
9
13
  parse_args
10
-
11
- command = @helper.remaining_markup
12
- response = `#{command}`
13
- if $CHILD_STATUS.success?
14
- response = compress response
15
- else
16
- msg = "Error: executing '#{command}' on line #{@line_number} (after front matter) of #{@page['path']} returned error code #{$CHILD_STATUS.exitstatus}"
17
- raise PreError, msg.red, [] if @die_if_nonzero
18
-
19
- @logger.error { msg }
20
- response = "<span class='error'>Error: error code #{$CHILD_STATUS.exitstatus}</span>"
21
- end
14
+ @original_command = @helper.remaining_markup_original
15
+ command = JekyllPluginHelper.expand_env(@original_command)
16
+ response = run_command(command)
17
+ response = if @child_status.success?
18
+ compress(response)
19
+ else
20
+ handle_error(command)
21
+ end
22
22
 
23
23
  <<~END_OUTPUT
24
- #{Rack::Utils.escape_html(command)}
24
+ #{Rack::Utils.escape_html(@original_command)}
25
25
  <span class='unselectable'>#{response}</span>
26
26
  END_OUTPUT
27
27
  rescue PreError => e
28
28
  raise PreError, e.message, []
29
29
  rescue StandardError => e
30
- msg = remove_html_tags(e.message) + " from executing '#{command}' on line #{@line_number} (after front matter) of #{@page['path']}"
31
- raise PreError, msg.red, [] if die_if_error
30
+ msg = self.class.remove_html_tags(e.message) + " from executing '#{@original_command}' on line #{@line_number} (after front matter) of #{@page['path']}"
31
+ raise PreError, msg.red, [] if @die_if_error
32
32
  end
33
33
 
34
34
  private
@@ -41,25 +41,57 @@ module ExecTag
41
41
  result
42
42
  end
43
43
 
44
+ def die(msg)
45
+ msg_no_html = self.class.remove_html_tags(msg)
46
+ @logger.error("#{@page['path']} - #{msg_no_html}")
47
+ raise PreError, "#{@page['path']} - #{msg_no_html.red}", []
48
+ end
49
+
50
+ def handle_error(command)
51
+ msg0 = "Error: executing '#{command}'"
52
+ msg0 += " (expanded from #{@original_command})" if command != @original_command
53
+ msg0 += " in directory '#{@cd}'" if @cd
54
+ msg = <<~END_MSG
55
+ #{msg0} on line #{@line_number} (after front matter) of #{@page['path']} returned error code #{@child_status.exitstatus}
56
+ END_MSG
57
+ raise PreError, msg.red, [] if @die_if_nonzero
58
+
59
+ @logger.error { msg }
60
+ "<span class='error'>Error code #{@child_status.exitstatus}</span>"
61
+ end
62
+
44
63
  def parse_args
64
+ @cd = @helper.parameter_specified? 'cd'
65
+ @cd = JekyllPluginHelper.expand_env(@cd) if @cd
66
+
45
67
  @no_escape = @helper.parameter_specified? 'no_escape'
46
68
  @no_strip = @helper.parameter_specified? 'no_strip'
47
69
  @die_if_nonzero = @helper.parameter_specified?('die_if_nonzero') # Implies die_if_error
48
70
  @die_if_error = @helper.parameter_specified?('die_if_error') | @die_if_nonzero
49
71
  end
50
72
 
51
- JekyllPluginHelper.register(self, 'exec')
52
- end
53
-
54
- private
55
-
56
- def die(msg)
57
- msg_no_html = remove_html_tags(msg)
58
- @logger.error("#{@page['path']} - #{msg_no_html}")
59
- raise PreError, "#{@page['path']} - #{msg_no_html.red}", []
60
- end
73
+ # References @cd
74
+ # Defines @child_status
75
+ # @return result of running command
76
+ # @param command [String] Shell command to execute
77
+ def run_command(command)
78
+ result = if @cd
79
+ Dir.chdir(@cd) do
80
+ `#{command}`
81
+ end
82
+ else
83
+ `#{command}`
84
+ end
85
+ @child_status = $CHILD_STATUS
86
+ result
87
+ rescue StandardError => e
88
+ msg = self.class.remove_html_tags(e.message) + " from executing '#{@original_command}' on line #{@line_number} (after front matter) of #{@page['path']}"
89
+ raise PreError, msg.red, [] if @die_if_error
90
+ ensure
91
+ @child_status = $CHILD_STATUS
92
+ result
93
+ end
61
94
 
62
- def remove_html_tags(string)
63
- string.gsub(/<[^>]*>/, '')
95
+ JekyllPluginHelper.register(self, 'exec')
64
96
  end
65
97
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllPreVersion
2
- VERSION = '1.2.2'.freeze
2
+ VERSION = '1.2.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_pre
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-18 00:00:00.000000000 Z
11
+ date: 2023-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -31,6 +31,9 @@ dependencies:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.5.0
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 0.5.3
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,6 +41,9 @@ dependencies:
38
41
  - - "~>"
39
42
  - !ruby/object:Gem::Version
40
43
  version: 0.5.0
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.5.3
41
47
  description: 'Jekyll tags pre and noselect, for HTML <pre/> tag, prompts and unselectable
42
48
  text. Can number lines.
43
49