jekyll_pre 1.2.3 → 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: 2e01bd13d91a64bf9b1dc9802cd11ef6c759985a30532daf8b3ace4618bfe634
4
- data.tar.gz: 6d33733cf1f1d0267ba226dafd459807254fa10f5199f2b1358648f9f94ccc01
3
+ metadata.gz: 2a78213a8f26a3d6743a9b706501a5c0f87279eeb243e492956fdd557b0a1e6d
4
+ data.tar.gz: 64c8640dee1fe914ac54f9813df8bb3f365518d41d13aecd62bda8c752d0488e
5
5
  SHA512:
6
- metadata.gz: 8e1f5e2a5cb3beb928cc2d8ad09fd1274aff0c5085ac1ee1f014456aaefaa78d5711c2bd9046e9418737b7bff7b53b2e4f54856e5dbbb8fcd1d4f193757db0fc
7
- data.tar.gz: 22747b92ec65bb6568a648c98a2a24417fd970daa012632ec596deca2232b0e994dffa7017792083d797c1ee6b2bc86b01b4b496d84525786ddcfd06769ade64
6
+ metadata.gz: e89f23e343045045c93f7fe7843a43611608f8702e934f4ce0f3c50b52bed7d71b856c79af679d4af9fbdd25921bbcf6977acbd709033a171bbfffc136ff358d
7
+ data.tar.gz: bba7c4caf281ab09415560e63a525c632bd98019bb475d53e526fade9c43ed4f77a9de7ef8395085c82308cf4fe31c4e4bbc52c58870f942cd7f6db1181e23ae
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.2.4
2
+ * The `exec` tag now evaluates environment variables in the command before execution.
3
+
1
4
  ## 1.2.3
2
5
  * Added `cd` option to `exec` tag.
3
6
 
data/README.md CHANGED
@@ -38,7 +38,8 @@ This Jekyll plugin provides 3 new Liquid tags that work together:
38
38
  ```
39
39
 
40
40
  * An `exec` tag that executes shell commands and incorporates the command and its output into the content of the `pre` tag.
41
- Output data is escaped, whitespace is condensed, and wrapped in the same `unselectable` class as does `unselectable`.
41
+ Environment variables are evaluated,
42
+ output data is escaped, whitespace is condensed, and wrapped in the same `unselectable` class as does `unselectable`.
42
43
  ```
43
44
  {% exec [Options] [shell command] %}
44
45
  ```
@@ -219,6 +220,24 @@ The following executes `ls -alF /` and displays the output.
219
220
  {% endpre %}
220
221
  ```
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 $USER' %}
237
+ {% noselect %}{% exec die_if_nonzero=false echo $USER %}
238
+ {% endpre %}
239
+ ```
240
+
222
241
 
223
242
  ### Comprehensive Example
224
243
  The code I wrote to generate the above CSS was a good example of how the plugins work together with
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,9 +5,14 @@ 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
- command = @helper.remaining_markup
14
+ @original_command = @helper.remaining_markup_original
15
+ command = JekyllPluginHelper.expand_env(@original_command)
11
16
  response = run_command(command)
12
17
  response = if @child_status.success?
13
18
  compress(response)
@@ -16,14 +21,14 @@ module ExecTag
16
21
  end
17
22
 
18
23
  <<~END_OUTPUT
19
- #{Rack::Utils.escape_html(command)}
24
+ #{Rack::Utils.escape_html(@original_command)}
20
25
  <span class='unselectable'>#{response}</span>
21
26
  END_OUTPUT
22
27
  rescue PreError => e
23
28
  raise PreError, e.message, []
24
29
  rescue StandardError => e
25
- msg = remove_html_tags(e.message) + " from executing '#{command}' on line #{@line_number} (after front matter) of #{@page['path']}"
26
- 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
27
32
  end
28
33
 
29
34
  private
@@ -37,13 +42,14 @@ module ExecTag
37
42
  end
38
43
 
39
44
  def die(msg)
40
- msg_no_html = remove_html_tags(msg)
45
+ msg_no_html = self.class.remove_html_tags(msg)
41
46
  @logger.error("#{@page['path']} - #{msg_no_html}")
42
47
  raise PreError, "#{@page['path']} - #{msg_no_html.red}", []
43
48
  end
44
49
 
45
50
  def handle_error(command)
46
51
  msg0 = "Error: executing '#{command}'"
52
+ msg0 += " (expanded from #{@original_command})" if command != @original_command
47
53
  msg0 += " in directory '#{@cd}'" if @cd
48
54
  msg = <<~END_MSG
49
55
  #{msg0} on line #{@line_number} (after front matter) of #{@page['path']} returned error code #{@child_status.exitstatus}
@@ -78,12 +84,14 @@ module ExecTag
78
84
  end
79
85
  @child_status = $CHILD_STATUS
80
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
81
93
  end
82
94
 
83
95
  JekyllPluginHelper.register(self, 'exec')
84
96
  end
85
-
86
- def remove_html_tags(string)
87
- string.gsub(/<[^>]*>/, '')
88
- end
89
97
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllPreVersion
2
- VERSION = '1.2.3'.freeze
2
+ VERSION = '1.2.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_pre
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
@@ -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