jekyll_pre 1.2.2 → 1.2.3

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: 6097d5cc2c288233bb1bdb16683fa3116ec244edead6a25d971d0f002932d939
4
- data.tar.gz: ab7f388db1f0e9dbfc0f677ea1e830b8486f02acc6da3aa95f08654c2f7de3a4
3
+ metadata.gz: 2e01bd13d91a64bf9b1dc9802cd11ef6c759985a30532daf8b3ace4618bfe634
4
+ data.tar.gz: 6d33733cf1f1d0267ba226dafd459807254fa10f5199f2b1358648f9f94ccc01
5
5
  SHA512:
6
- metadata.gz: e3069935c7ad9b664004cb4235002ab12fb6e91911876a9cb5113e880c3f6b3a565d84c51bd5706470866fd82d1a6c168c0b26b88cbf59cf9d3adfc49ce9e392
7
- data.tar.gz: 5e14ff1c554fda49eb095538fef25297f13bf8cdf48d508747227db69e0fa32a698193f391dbb9981f19914f4a6a15656d9db4ad50240b1bf6162c01af68c77b
6
+ metadata.gz: 8e1f5e2a5cb3beb928cc2d8ad09fd1274aff0c5085ac1ee1f014456aaefaa78d5711c2bd9046e9418737b7bff7b53b2e4f54856e5dbbb8fcd1d4f193757db0fc
7
+ data.tar.gz: 22747b92ec65bb6568a648c98a2a24417fd970daa012632ec596deca2232b0e994dffa7017792083d797c1ee6b2bc86b01b4b496d84525786ddcfd06769ade64
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.2.3
2
+ * Added `cd` option to `exec` tag.
3
+
1
4
  ## 1.2.2
2
5
  * Added `exec` tag.
3
6
  * 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,33 @@ 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
41
  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
- }
42
+ ```
43
+ {% exec [Options] [shell command] %}
44
+ ```
45
+ `Options` are:
47
46
 
48
- .numbered_line,
49
- .unselectable.numbered_line,
50
- .numbered_line.unselectable {
51
- color: #5fb25f;
52
- }
47
+ - `cd="relative/or/absolute/directory"` - Change to specified directory before executing shell command.
48
+ Environment variables in the directory path will be expanded.
49
+ - `no_escape` – Do not HTML escape the result of running the shell command.
50
+ - `no_strip` – Do not remove leading and trailing whitespace from the result.
51
+ - `die_if_nonzero` – Set `false` to treat non-zero return codes as non-fatal.
52
+ Instead of terminating Jekyll with an error message,
53
+ the message will be displayed as an error by the Jekyll logger,
54
+ and a red message will appear in place of the result on the web page.
55
+ - `die_if_error` – Set `false` to treat exceptions generated by this plugin as non-fatal.
56
+ Instead of terminating Jekyll with an error message, the message will be displayed as an error by the Jekyll logger.
53
57
 
54
- .unselectable {
55
- color: #7922f9;
56
- -moz-user-select: none;
57
- -khtml-user-select: none;
58
- user-select: none;
59
- }
60
- ```
58
+
59
+ ## CSS
60
+ See [`demo/assets/css/style.css`](demo/assets/css/style.css) for the CSS declarations,
61
+ between `/* Start of pre tag css */` and `/* End of pre tag css */`.
61
62
 
62
63
 
63
64
  ## Additional Information
@@ -80,6 +81,7 @@ And then execute:
80
81
 
81
82
 
82
83
  ## Usage
84
+ The following examples are rendered on [my website](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#jekyll_pre).
83
85
 
84
86
  ### Example 1
85
87
  This example does not generate a copy button and does not demonstrate `noselect`.
@@ -151,20 +153,70 @@ Which renders as:
151
153
  ![example 4](images/usage4example.png)
152
154
 
153
155
 
154
- ### CSS
155
- Here are the CSS declarations that I defined pertaining to the `pre` and `noselect` tags that produced the above images:
156
+ ### Example 5
157
+ A regular expression can be passed to the `highlight` option.
158
+ This causes text that matches the regex pattern to be wrapped within a &lt;span class="bg_yellow">&lt;/span> tag.
159
+
160
+ The CSS stylesheet used for this page contains the following:
156
161
 
157
162
  ```css
158
- .maxOneScreenHigh {
159
- max-height: 500px;
163
+ .bg_yellow {
164
+ background-color: yellow;
165
+ padding: 2px;
160
166
  }
167
+ ```
168
+
169
+ This example demonstrates highlighting text that matches a regular expression. Regular expressions match against lines, which are delimited via newlines (\n).
170
+
171
+ ```
172
+ {% pre copyButton highlight="Line 2" %}
173
+ Line 1
174
+ Line 2
175
+ Line 3
176
+ Line 4
177
+ Line 5
178
+ Line 6
179
+ Line 7
180
+ {% endpre %}
181
+ ```
182
+
183
+
184
+ ### Example 6
185
+ Regular expressions match against lines, which are delimited via newlines (`\n`).
186
+ Thus to match an entire line that contains a phrase, specify the regex as `.*phrase.*`.
187
+ The following matches 3 possible phrases (`2`, `4` or `6`), then selects the entire line if matched.
188
+
189
+ ```
190
+ {% pre copyButton highlight=".*(2|4|6).*" %}
191
+ Line 1
192
+ Line 2
193
+ Line 3
194
+ Line 4
195
+ Line 5
196
+ Line 6
197
+ Line 7
198
+ {% endpre %}
199
+ ```
200
+
201
+
202
+ ### Example 7
203
+ This example floats an image to the right.
204
+ The `jekyll_pre plugin`’s `clear` option moves the generated HTML below the image.
161
205
 
162
- .unselectable {
163
- color: #7922f9;
164
- -moz-user-select: none;
165
- -khtml-user-select: none;
166
- user-select: none;
167
- }
206
+ ```
207
+ &lt;img src="jekyll.webp" style="float: right; width: 100px; height: auto;">
208
+ {% pre clear copyButton label='Clear example' %}
209
+ Using clear, copyButton and label parameters
210
+ {% endpre %}
211
+ ```
212
+
213
+ ### Example 8
214
+ The following executes `ls -alF /` and displays the output.
215
+
216
+ ```
217
+ {% pre clear copyButton label='Exec without error' %}
218
+ {% noselect %}{% exec die_if_nonzero=false ls -alF / %}
219
+ {% endpre %}
168
220
  ```
169
221
 
170
222
 
@@ -208,11 +260,7 @@ A test website is provided in the `demo` directory.
208
260
 
209
261
  ### Build and Install Locally
210
262
  To build and install this gem onto your local machine, run:
211
- ```shell
212
- $ rake install:local
213
- ```
214
263
 
215
- The following also does the same thing:
216
264
  ```shell
217
265
  $ bundle exec rake install
218
266
  ```
data/lib/exec_tag.rb CHANGED
@@ -7,18 +7,13 @@ module ExecTag
7
7
 
8
8
  def render_impl
9
9
  parse_args
10
-
11
10
  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
11
+ response = run_command(command)
12
+ response = if @child_status.success?
13
+ compress(response)
14
+ else
15
+ handle_error(command)
16
+ end
22
17
 
23
18
  <<~END_OUTPUT
24
19
  #{Rack::Utils.escape_html(command)}
@@ -41,22 +36,51 @@ module ExecTag
41
36
  result
42
37
  end
43
38
 
39
+ def die(msg)
40
+ msg_no_html = remove_html_tags(msg)
41
+ @logger.error("#{@page['path']} - #{msg_no_html}")
42
+ raise PreError, "#{@page['path']} - #{msg_no_html.red}", []
43
+ end
44
+
45
+ def handle_error(command)
46
+ msg0 = "Error: executing '#{command}'"
47
+ msg0 += " in directory '#{@cd}'" if @cd
48
+ msg = <<~END_MSG
49
+ #{msg0} on line #{@line_number} (after front matter) of #{@page['path']} returned error code #{@child_status.exitstatus}
50
+ END_MSG
51
+ raise PreError, msg.red, [] if @die_if_nonzero
52
+
53
+ @logger.error { msg }
54
+ "<span class='error'>Error code #{@child_status.exitstatus}</span>"
55
+ end
56
+
44
57
  def parse_args
58
+ @cd = @helper.parameter_specified? 'cd'
59
+ @cd = JekyllPluginHelper.expand_env(@cd) if @cd
60
+
45
61
  @no_escape = @helper.parameter_specified? 'no_escape'
46
62
  @no_strip = @helper.parameter_specified? 'no_strip'
47
63
  @die_if_nonzero = @helper.parameter_specified?('die_if_nonzero') # Implies die_if_error
48
64
  @die_if_error = @helper.parameter_specified?('die_if_error') | @die_if_nonzero
49
65
  end
50
66
 
51
- JekyllPluginHelper.register(self, 'exec')
52
- end
53
-
54
- private
67
+ # References @cd
68
+ # Defines @child_status
69
+ # @return result of running command
70
+ # @param command [String] Shell command to execute
71
+ def run_command(command)
72
+ result = if @cd
73
+ Dir.chdir(@cd) do
74
+ `#{command}`
75
+ end
76
+ else
77
+ `#{command}`
78
+ end
79
+ @child_status = $CHILD_STATUS
80
+ result
81
+ end
55
82
 
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}", []
83
+ JekyllPluginHelper.register(self, 'exec')
60
84
  end
61
85
 
62
86
  def remove_html_tags(string)
@@ -1,3 +1,3 @@
1
1
  module JekyllPreVersion
2
- VERSION = '1.2.2'.freeze
2
+ VERSION = '1.2.3'.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.3
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