jekyll_pre 1.2.3 → 1.3.0

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: bc048288e5f189d4519766b6db9a8807d6f41b4193be5fcd7ea7d39ed1af4a7b
4
+ data.tar.gz: 356f768bba6d1bbdb4abe52394a75e6aa387257b4fd1c58d7f9775324382ac6f
5
5
  SHA512:
6
- metadata.gz: 8e1f5e2a5cb3beb928cc2d8ad09fd1274aff0c5085ac1ee1f014456aaefaa78d5711c2bd9046e9418737b7bff7b53b2e4f54856e5dbbb8fcd1d4f193757db0fc
7
- data.tar.gz: 22747b92ec65bb6568a648c98a2a24417fd970daa012632ec596deca2232b0e994dffa7017792083d797c1ee6b2bc86b01b4b496d84525786ddcfd06769ade64
6
+ metadata.gz: 5e0833a721b44a3f9078d9ae76a70152d516469bb6062424366c3a7dc1171fe78a9407d6195e5ba5ae728224f78a278cff2f8fb145d94c5bc9346bf75bc44435
7
+ data.tar.gz: ff46960e6cfd7fd339e9d835e2bcaf0934d29dc7bb14bcf860208ced8bfab349f6bd680ac9b5cab7b426d4af5f0ae1dc10758181e24327e645cbeb0a323f8d63
data/.rubocop.yml CHANGED
@@ -26,7 +26,7 @@ Layout/LineLength:
26
26
  Max: 150
27
27
 
28
28
  Metrics/AbcSize:
29
- Max: 25
29
+ Max: 35
30
30
 
31
31
  Metrics/BlockLength:
32
32
  Exclude:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 1.3.0
2
+ * Updated to `jekyll_plugin_support` v0.6.0 for attribution support.
3
+
4
+ ## 1.2.5
5
+ * Empty exec commands are detected and reported.
6
+
7
+ ## 1.2.4
8
+ * The `exec` tag now evaluates environment variables in the command before execution.
9
+
1
10
  ## 1.2.3
2
11
  * Added `cd` option to `exec` tag.
3
12
 
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
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  END_OF_DESC
11
11
  spec.email = ['mslinn@mslinn.com']
12
12
  spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
13
- spec.homepage = 'https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#pre'
13
+ spec.homepage = 'https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#jekyll_pre'
14
14
  spec.license = 'MIT'
15
15
  spec.metadata = {
16
16
  'allowed_push_host' => 'https://rubygems.org',
@@ -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.6.0'
36
36
  end
data/lib/exec_tag.rb CHANGED
@@ -5,9 +5,16 @@ 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
16
+ raise PreError, "Command is empty on on line #{@line_number} (after front matter) of #{@page['path']}", [] if command.strip.empty?
17
+
11
18
  response = run_command(command)
12
19
  response = if @child_status.success?
13
20
  compress(response)
@@ -16,14 +23,14 @@ module ExecTag
16
23
  end
17
24
 
18
25
  <<~END_OUTPUT
19
- #{Rack::Utils.escape_html(command)}
26
+ #{Rack::Utils.escape_html(@original_command)}
20
27
  <span class='unselectable'>#{response}</span>
21
28
  END_OUTPUT
22
29
  rescue PreError => e
23
30
  raise PreError, e.message, []
24
31
  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
32
+ msg = self.class.remove_html_tags(e.message) + " from executing '#{@original_command}' on line #{@line_number} (after front matter) of #{@page['path']}"
33
+ raise PreError, msg.red, [] if @die_if_error
27
34
  end
28
35
 
29
36
  private
@@ -37,13 +44,14 @@ module ExecTag
37
44
  end
38
45
 
39
46
  def die(msg)
40
- msg_no_html = remove_html_tags(msg)
47
+ msg_no_html = self.class.remove_html_tags(msg)
41
48
  @logger.error("#{@page['path']} - #{msg_no_html}")
42
49
  raise PreError, "#{@page['path']} - #{msg_no_html.red}", []
43
50
  end
44
51
 
45
52
  def handle_error(command)
46
53
  msg0 = "Error: executing '#{command}'"
54
+ msg0 += " (expanded from #{@original_command})" if command != @original_command
47
55
  msg0 += " in directory '#{@cd}'" if @cd
48
56
  msg = <<~END_MSG
49
57
  #{msg0} on line #{@line_number} (after front matter) of #{@page['path']} returned error code #{@child_status.exitstatus}
@@ -78,12 +86,14 @@ module ExecTag
78
86
  end
79
87
  @child_status = $CHILD_STATUS
80
88
  result
89
+ rescue StandardError => e
90
+ msg = self.class.remove_html_tags(e.message) + " from executing '#{@original_command}' on line #{@line_number} (after front matter) of #{@page['path']}"
91
+ raise PreError, msg.red, [] if @die_if_error
92
+ ensure
93
+ @child_status = $CHILD_STATUS
94
+ result
81
95
  end
82
96
 
83
97
  JekyllPluginHelper.register(self, 'exec')
84
98
  end
85
-
86
- def remove_html_tags(string)
87
- string.gsub(/<[^>]*>/, '')
88
- end
89
99
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllPreVersion
2
- VERSION = '1.2.3'.freeze
2
+ VERSION = '1.3.0'.freeze
3
3
  end
data/lib/pre_tag_block.rb CHANGED
@@ -17,35 +17,6 @@ module PreTagBlock
17
17
  "#{@@prefix}'##{pre_id}'#{@@suffix}"
18
18
  end
19
19
 
20
- def self.make_pre(make_copy_button, number_lines, label, dark, highlight_pattern, css_class, style, clear, content) # rubocop:disable Metrics/ParameterLists
21
- pre_clear = label_clear = ''
22
- if clear
23
- if label.to_s.empty?
24
- pre_clear = ' clear'
25
- else
26
- label_clear = ' clear'
27
- end
28
- end
29
- css_class = css_class ? " #{css_class}" : ''
30
- style = style ? " style='#{style}'" : ''
31
- dark_label = ' darkLabel' if dark
32
- label = if label.to_s.empty?
33
- ''
34
- elsif label.to_s.downcase.strip == 'shell'
35
- "<div class='codeLabel unselectable#{dark_label}#{label_clear}' data-lt-active='false'>Shell</div>"
36
- else
37
- "<div class='codeLabel unselectable#{dark_label}#{label_clear}' data-lt-active='false'>#{label}</div>"
38
- end
39
- pre_id = "id#{SecureRandom.hex(6)}"
40
- copy_button = make_copy_button ? PreTagBlock.make_copy_button(pre_id) : ''
41
- content = PreTagBlock.highlight(content, highlight_pattern) if highlight_pattern
42
- content = PreTagBlock.number_content(content) if number_lines
43
-
44
- classes = "maxOneScreenHigh copyContainer#{dark}#{pre_clear}#{css_class}"
45
- pre_content = "#{copy_button}#{content.strip}"
46
- "#{label}<pre data-lt-active='false' class='#{classes}'#{style} id='#{pre_id}'>#{pre_content}</pre>"
47
- end
48
-
49
20
  def self.number_content(content)
50
21
  lines = content.split("\n")
51
22
  digits = lines.length.to_s.length
@@ -62,6 +33,7 @@ module PreTagBlock
62
33
 
63
34
  def render_impl(text)
64
35
  text.strip!
36
+ @helper.gem_file __FILE__ # Enables plugin attribution
65
37
 
66
38
  @clear = @helper.parameter_specified? 'clear'
67
39
  @class = @helper.parameter_specified? 'class'
@@ -76,7 +48,43 @@ module PreTagBlock
76
48
  @label ||= @helper.argv.join(' ')
77
49
 
78
50
  @logger.debug { "@make_copy_button = '#{@make_copy_button}'; @label = '#{@label}'" }
79
- self.class.make_pre(@make_copy_button, @number_lines, @label, @dark, @highlight, @class, @style, @clear, text)
51
+ make_pre(text)
52
+ end
53
+
54
+ private
55
+
56
+ def make_pre(content)
57
+ pre_clear = label_clear = ''
58
+ if @clear
59
+ if @label.to_s.empty?
60
+ pre_clear = ' clear'
61
+ else
62
+ label_clear = ' clear'
63
+ end
64
+ end
65
+ @class = @class ? " #{@class}" : ''
66
+ @style = @style ? " style='#{@style}'" : ''
67
+ dark_label = ' darkLabel' if @dark
68
+ @label = if @label.to_s.empty?
69
+ ''
70
+ elsif @label.to_s.casecmp('shell').zero?
71
+ "<div class='codeLabel unselectable#{dark_label}#{label_clear}' data-lt-active='false'>Shell</div>"
72
+ else
73
+ "<div class='codeLabel unselectable#{dark_label}#{label_clear}' data-lt-active='false'>#{@label}</div>"
74
+ end
75
+ pre_id = "id#{SecureRandom.hex(6)}"
76
+ copy_button = @make_copy_button ? PreTagBlock.make_copy_button(pre_id) : ''
77
+ content = PreTagBlock.highlight(content, @highlight) if @highlight
78
+ content = PreTagBlock.number_content(content) if @number_lines
79
+
80
+ classes = "maxOneScreenHigh copyContainer#{@dark}#{pre_clear}#{@class}"
81
+ pre_content = "#{copy_button}#{content}"
82
+ attribution = @helper.attribute if @helper.attribution
83
+ <<~END_OUTPUT
84
+ #{@label}
85
+ <pre data-lt-active='false' class='#{classes}'#{@style} id='#{pre_id}'>#{pre_content}</pre>
86
+ #{attribution}
87
+ END_OUTPUT
80
88
  end
81
89
 
82
90
  JekyllPluginHelper.register(self, 'pre')
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.3
4
+ version: 1.3.0
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-19 00:00:00.000000000 Z
11
+ date: 2023-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.5.0
33
+ version: 0.6.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.5.0
40
+ version: 0.6.0
41
41
  description: 'Jekyll tags pre and noselect, for HTML <pre/> tag, prompts and unselectable
42
42
  text. Can number lines.
43
43
 
@@ -62,14 +62,14 @@ files:
62
62
  - spec/pre_spec.rb
63
63
  - spec/spec_helper.rb
64
64
  - spec/status_persistence.txt
65
- homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#pre
65
+ homepage: https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#jekyll_pre
66
66
  licenses:
67
67
  - MIT
68
68
  metadata:
69
69
  allowed_push_host: https://rubygems.org
70
70
  bug_tracker_uri: https://github.com/mslinn/jekyll_pre/issues
71
71
  changelog_uri: https://github.com/mslinn/jekyll_pre/CHANGELOG.md
72
- homepage_uri: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#pre
72
+ homepage_uri: https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#jekyll_pre
73
73
  source_code_uri: https://github.com/mslinn/jekyll_pre
74
74
  post_install_message: |2+
75
75