jekyll_pre 1.3.1 → 1.4.0

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: 16aa76dad7fdc41eac063227ee8463e9bcb77dd1c9893840e05f22a67c08aef0
4
- data.tar.gz: 9e550133932e9b422a30bdccb813dd0c603870bac9bbb08489256a92be9d27ce
3
+ metadata.gz: 4cc10df37a945ecc8abddce501dd71a176084b9fafdde6e3aa6a48e18c7e4551
4
+ data.tar.gz: 73fe925e47914475d889e814cae15f8c8331ed7abf2498aaf0a207fd2e0bf7d9
5
5
  SHA512:
6
- metadata.gz: 8f87a17e7dff740d917a248323822a491559ac3bc3223ca4af7a62c261ca213be8f82f61577b7278112534b0ed5af597f01242fba0ba9adb9158a27425893ffa
7
- data.tar.gz: 1227a44360aae2c913a005223c28e0ef1f3a788e43e7acb0973f960fbc618846d587754e9944f15884f184f73b9ed2bd913eeedc1273ee186e694deef31e5fc5
6
+ metadata.gz: 76a1487e85b498708d27a2258fce364703fe2613253eff69e80475b22303f81f519a8bcedb14671fd62179d53521c80ca9c47d859e838d2bb43060ef58adc236
7
+ data.tar.gz: 59edd4611b9d6553096d76ce57d518a4e6dd670d2e7f236cfa6ae000c34b269584ecf318705db9bd68d32d9da42590ff71628a7a122107dca8d8e2057e048900
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 1.4.0
2
+ * Added `dedent` option and config setting.
3
+ * No longer dies when exec is passed an empty string, or a string with just whitespace.
4
+
5
+ ## 1.3.2
6
+ * No longer strips leading spaces from exec result lines.
7
+
1
8
  ## 1.3.1
2
9
  * Generates outer `div` with `jekyll_pre` class, like this:
3
10
  ```html
data/README.md CHANGED
@@ -15,6 +15,7 @@ This Jekyll plugin provides 3 new Liquid tags that work together:
15
15
  - `clear` – Line break after floating HTML elements
16
16
  - `copyButton` – Generate a copy button
17
17
  - `dark` – Dark mode
18
+ - `dedent` &ndash; Remove leading spaces common to all lines, like Ruby's <<~ squiggly heredoc (default is false)
18
19
  - `label='This is a label'` &ndash; Apply text above `pre` tag.
19
20
  The `label` parameter value can also be specified in free text.
20
21
  For example, the following produce the same results:
@@ -64,8 +65,38 @@ See [`demo/assets/css/style.css`](demo/assets/css/style.css) for the CSS declara
64
65
  between `/* Start of pre tag css */` and `/* End of pre tag css */`.
65
66
 
66
67
 
68
+ ## Configuration
69
+ Default options can be set for the `pre` tag by entries in `_config.yml`.
70
+ The following demonstrates setting a default value for every possible option:
71
+
72
+ ```yml
73
+ pre:
74
+ class: bg_yellow
75
+ clear: true
76
+ dark: true
77
+ dedent: true
78
+ highlight: 'Error:.*'
79
+ label: Shell
80
+ copyButton: true
81
+ number: true
82
+ style: 'font-face: courier'
83
+ wrapper_class: rounded shadow
84
+ wrapper_style: 'padding: 2em; border: thin green dashed;'
85
+ ```
86
+
87
+ The default values used on [`mslinn.com`](https://www.mslinn.com) are:
88
+
89
+ ```yml
90
+ pre:
91
+ dedent: true
92
+ label: Shell
93
+ copyButton: true
94
+ ```
95
+
96
+
67
97
  ## Additional Information
68
- More information is available on [my website](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#jekyll_pre).
98
+ More information is available on
99
+ [Mike Slinn&rsquo;s website](https://www.mslinn.com/jekyll_plugins/jekyll_pre.html).
69
100
 
70
101
 
71
102
  ## Installation
@@ -80,11 +111,24 @@ end
80
111
 
81
112
  And then execute:
82
113
 
83
- $ bundle install
114
+ $ bundle
84
115
 
85
116
 
86
117
  ## Usage
87
- The following examples are rendered on [my website](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#jekyll_pre).
118
+ The following examples are rendered on
119
+ [Mike Slinn&rsquo;s website](https://www.mslinn.com/jekyll_plugins/jekyll_pre.html).
120
+
121
+ ### Example 0
122
+ <pre data-lt-active="false" class="maxOneScreenHigh copyContainer" id="id110c50d624b4">{% pre dedent %}
123
+ This line was indented 4 spaces
124
+ This line was indented 6 spaces
125
+ This line was indented 4 spaces
126
+ {% endpre %}</pre>
127
+ Which renders as:
128
+
129
+ <pre data-lt-active="false" class="maxOneScreenHigh copyContainer" id="id377433c30186">This line was indented 4 spaces
130
+ This line was indented 6 spaces
131
+ This line was indented 4 spaces</pre>
88
132
 
89
133
  ### Example 1
90
134
  This example does not generate a copy button and does not demonstrate `noselect`.
data/jekyll_pre.gemspec CHANGED
@@ -1,3 +1,4 @@
1
+ require 'jekyll'
1
2
  require_relative 'lib/jekyll_pre/version'
2
3
 
3
4
  Gem::Specification.new do |spec|
@@ -33,4 +34,5 @@ Gem::Specification.new do |spec|
33
34
 
34
35
  spec.add_dependency 'jekyll', '>= 3.5.0'
35
36
  spec.add_dependency 'jekyll_plugin_support', '~> 0.6.0'
37
+ spec.add_dependency 'rack'
36
38
  end
data/lib/exec_tag.rb CHANGED
@@ -1,7 +1,16 @@
1
1
  require 'jekyll_plugin_support'
2
+ require 'rack/utils'
2
3
  require_relative 'jekyll_pre/version'
3
4
 
4
- module ExecTag
5
+ module JekyllPreModule
6
+ def self.compress(response, no_strip)
7
+ result = response.chomp
8
+ result = result.strip unless no_strip
9
+ result = result.gsub('\n\n', '<br>\n')
10
+ result = Rack::Utils.escape_html(result) unless @no_escape
11
+ result
12
+ end
13
+
5
14
  class ExecTag < JekyllSupport::JekyllTag
6
15
  include JekyllPreVersion
7
16
 
@@ -13,11 +22,18 @@ module ExecTag
13
22
  parse_args
14
23
  @original_command = @helper.remaining_markup_original
15
24
  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?
25
+ if command.strip.empty?
26
+ msg = "Command is empty on on line #{@line_number} (after front matter) of #{@page['path']}"
27
+ unless @die_if_error
28
+ @logger.warn { msg }
29
+ return ''
30
+ end
31
+ raise PreError, msg, []
32
+ end
17
33
 
18
34
  response = run_command(command)
19
35
  response = if @child_status.success?
20
- compress(response)
36
+ ExecTagModule.compress(response, @no_strip)
21
37
  else
22
38
  handle_error(command)
23
39
  end
@@ -36,14 +52,6 @@ module ExecTag
36
52
 
37
53
  private
38
54
 
39
- def compress(response)
40
- result = response.chomp
41
- result = result.strip unless @no_strip
42
- result = result.gsub('\n\n', '<br>\n')
43
- result = Rack::Utils.escape_html(result) unless @no_escape
44
- result
45
- end
46
-
47
55
  def die(msg)
48
56
  msg_no_html = self.class.remove_html_tags(msg)
49
57
  @logger.error("#{@page['path']} - #{msg_no_html}")
@@ -1,3 +1,3 @@
1
1
  module JekyllPreVersion
2
- VERSION = '1.3.1'.freeze
2
+ VERSION = '1.4.0'.freeze
3
3
  end
data/lib/jekyll_pre.rb CHANGED
@@ -8,10 +8,14 @@ require_relative './pre_tag_block'
8
8
 
9
9
  PreError = Class.new(Liquid::Error)
10
10
 
11
- module JekyllPreModule
12
- include NoSelectTag
13
- include PreTagBlock
14
- include ExecTag
11
+ class String
12
+ # Works like <<~ from Ruby 2.3.0
13
+ def dedent
14
+ # Find the margin whitespace on the first line
15
+ margin = self[/\A\s*/]
16
+ # Remove margin-sized whitespace from each line
17
+ gsub(/^\s{#{margin.size}}/, '')
18
+ end
15
19
  end
16
20
 
17
21
  PluginMetaLogger.instance.info { "Loaded #{JekyllPluginPreName::PLUGIN_NAME} v#{JekyllPreVersion::VERSION} plugin." }
data/lib/noselect_tag.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'jekyll_plugin_support'
2
2
  require_relative 'jekyll_pre/version'
3
3
 
4
- module NoSelectTag
4
+ module JekyllPreModule
5
5
  # """\\{% noselect %} or \\{% noselect this all gets copied.
6
6
  # Also, space before the closing percent is signficant %}"""
7
7
  class NoSelectTag < JekyllSupport::JekyllTagNoArgParsing
data/lib/pre_tag_block.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'jekyll_plugin_support'
2
2
  require_relative 'jekyll_pre/version'
3
3
 
4
- module PreTagBlock
4
+ module JekyllPreModule
5
5
  class PreTagBlock < JekyllSupport::JekyllBlock
6
6
  include JekyllPreVersion
7
7
 
@@ -31,20 +31,36 @@ module PreTagBlock
31
31
  result
32
32
  end
33
33
 
34
+ # remove leading blank lines and trailing whitespace
35
+ def self.remove_surrounding(text)
36
+ text.gsub(/\A(\s?\n)*/, '').rstrip
37
+ end
38
+
39
+ def option(name)
40
+ value = @helper.parameter_specified? name
41
+ return value unless value.nil?
42
+
43
+ @pre_config[name] if @pre_config
44
+ end
45
+
34
46
  def render_impl(text)
35
- text.strip!
47
+ text = PreTagBlock.remove_surrounding text
48
+
36
49
  @helper.gem_file __FILE__ # Enables plugin attribution
37
50
 
38
- @class = @helper.parameter_specified? 'class'
39
- @clear = @helper.parameter_specified? 'clear'
40
- @dark = ' dark' if @helper.parameter_specified? 'dark'
41
- @highlight = @helper.parameter_specified? 'highlight'
42
- @label = @helper.parameter_specified? 'label'
43
- @make_copy_button = @helper.parameter_specified? 'copyButton'
44
- @number_lines = @helper.parameter_specified? 'number'
45
- @style = @helper.parameter_specified? 'style'
46
- @wrapper_class = @helper.parameter_specified? 'wrapper_class'
47
- @wrapper_style = @helper.parameter_specified? 'wrapper_style'
51
+ @pre_config = @config['pre']
52
+
53
+ @class = option 'class'
54
+ @clear = option 'clear'
55
+ @dark = ' dark' if option 'dark'
56
+ @dedent = option 'dedent'
57
+ @highlight = option 'highlight'
58
+ @label = option 'label'
59
+ @make_copy_button = option 'copyButton'
60
+ @number_lines = option 'number'
61
+ @style = option 'style'
62
+ @wrapper_class = option 'wrapper_class'
63
+ @wrapper_style = option 'wrapper_style'
48
64
 
49
65
  @class = @class ? " #{@class}" : ''
50
66
  @style = @style ? " style='#{@style}'" : ''
@@ -55,6 +71,8 @@ module PreTagBlock
55
71
  @label ||= @helper.argv.join(' ')
56
72
 
57
73
  @logger.debug { "@make_copy_button = '#{@make_copy_button}'; @label = '#{@label}'" }
74
+
75
+ text = text.dedent if @dedent
58
76
  make_pre(text)
59
77
  end
60
78
 
data/spec/exec_spec.rb ADDED
@@ -0,0 +1,34 @@
1
+ require_relative '../lib/jekyll_pre'
2
+
3
+ module ExecTagSpec
4
+ RSpec.describe(JekyllPreModule) do
5
+ it 'strips properly' do
6
+ content = <<~END_CONTENT
7
+ Line 1
8
+ Line 2
9
+ Line 3
10
+ Line 4
11
+ Line 5
12
+ Line 6
13
+ Line 7
14
+ Line 8
15
+ Line 9
16
+ Line 10
17
+ END_CONTENT
18
+ actual = described_class.compress content, false
19
+ expected = <<~END_CONTENT
20
+ Line 1
21
+ Line 2
22
+ Line 3
23
+ Line 4
24
+ Line 5
25
+ Line 6
26
+ Line 7
27
+ Line 8
28
+ Line 9
29
+ Line 10
30
+ END_CONTENT
31
+ expect(expected.strip).to eq(actual)
32
+ end
33
+ end
34
+ end
data/spec/pre_spec.rb CHANGED
@@ -4,7 +4,71 @@ require 'key_value_parser'
4
4
  require 'shellwords'
5
5
  require_relative '../lib/jekyll_pre'
6
6
 
7
- RSpec.describe(PreTagBlock) do
7
+ RSpec.describe(JekyllPreModule::PreTagBlock) do
8
+ it 'dedents content lines' do
9
+ content = <<-END_CONTENT
10
+ Line 1
11
+ Line 2
12
+ Line 3
13
+ Line 4
14
+ Line 5
15
+ Line 6
16
+ Line 7
17
+ Line 8
18
+ Line 9
19
+ Line 10
20
+ END_CONTENT
21
+ expected = <<~END_CONTENT
22
+ Line 1
23
+ Line 2
24
+ Line 3
25
+ Line 4
26
+ Line 5
27
+ Line 6
28
+ Line 7
29
+ Line 8
30
+ Line 9
31
+ Line 10
32
+ END_CONTENT
33
+ actual = content.dedent
34
+ expect(actual).to eq(expected)
35
+ end
36
+
37
+ it 'removes surrounding whitespace' do
38
+ text = <<-END_CONTENT
39
+
40
+
41
+ Line 1
42
+ Line 2
43
+ Line 3
44
+ Line 4
45
+ Line 5
46
+ Line 6
47
+ Line 7
48
+ Line 8
49
+ Line 9
50
+ Line 10
51
+
52
+
53
+ END_CONTENT
54
+ actual = described_class.remove_surrounding(text)
55
+
56
+ expected = <<-END_CONTENT
57
+ Line 1
58
+ Line 2
59
+ Line 3
60
+ Line 4
61
+ Line 5
62
+ Line 6
63
+ Line 7
64
+ Line 8
65
+ Line 9
66
+ Line 10
67
+ END_CONTENT
68
+
69
+ expect(actual).to eq(expected.rstrip)
70
+ end
71
+
8
72
  it 'parses arguments' do
9
73
  argv = Shellwords.split 'number copyButton shell'
10
74
  options = KeyValueParser.new.parse(argv)
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'jekyll'
2
2
  require 'fileutils'
3
3
  require 'key_value_parser'
4
+ require 'jekyll_plugin_support'
5
+ require 'rack/utils'
4
6
  require 'shellwords'
5
7
 
6
8
  require_relative '../lib/jekyll_pre'
@@ -1,5 +1,13 @@
1
- example_id | status | run_time |
2
- ----------------------- | ------ | --------------- |
3
- ./spec/pre_spec.rb[1:1] | passed | 0.00075 seconds |
4
- ./spec/pre_spec.rb[1:2] | passed | 0.00044 seconds |
5
- ./spec/pre_spec.rb[1:3] | passed | 0.00018 seconds |
1
+ example_id | status | run_time |
2
+ --------------------------------------------------------------- | ------ | --------------- |
3
+ ./spec/exec_spec.rb[1:1] | passed | 0.00377 seconds |
4
+ ./spec/pre_spec.rb[1:1] | passed | 0.00014 seconds |
5
+ ./spec/pre_spec.rb[1:2] | passed | 0.00351 seconds |
6
+ ./spec/pre_spec.rb[1:3] | passed | 0.00016 seconds |
7
+ ./spec/pre_spec.rb[1:4] | passed | 0.00011 seconds |
8
+ /mnt/_/work/jekyll/my_plugins/jekyll_pre/spec/exec_spec.rb[1:1] | passed | 0.00457 seconds |
9
+ /mnt/_/work/jekyll/my_plugins/jekyll_pre/spec/pre_spec.rb[1:1] | passed | 0.00326 seconds |
10
+ /mnt/_/work/jekyll/my_plugins/jekyll_pre/spec/pre_spec.rb[1:2] | passed | 0.00067 seconds |
11
+ /mnt/_/work/jekyll/my_plugins/jekyll_pre/spec/pre_spec.rb[1:3] | passed | 0.00362 seconds |
12
+ /mnt/_/work/jekyll/my_plugins/jekyll_pre/spec/pre_spec.rb[1:4] | passed | 0.00033 seconds |
13
+ /mnt/_/work/jekyll/my_plugins/jekyll_pre/spec/pre_spec.rb[1:5] | passed | 0.00083 seconds |
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.3.1
4
+ version: 1.4.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-04-13 00:00:00.000000000 Z
11
+ date: 2023-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.6.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack
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'
41
55
  description: 'Jekyll tags pre and noselect, for HTML <pre/> tag, prompts and unselectable
42
56
  text. Can number lines.
43
57
 
@@ -59,6 +73,7 @@ files:
59
73
  - lib/jekyll_pre/version.rb
60
74
  - lib/noselect_tag.rb
61
75
  - lib/pre_tag_block.rb
76
+ - spec/exec_spec.rb
62
77
  - spec/pre_spec.rb
63
78
  - spec/spec_helper.rb
64
79
  - spec/status_persistence.txt
@@ -95,6 +110,7 @@ specification_version: 4
95
110
  summary: Jekyll tags pre and noselect, for HTML <pre/> tag, prompts and unselectable
96
111
  text. Can number lines.
97
112
  test_files:
113
+ - spec/exec_spec.rb
98
114
  - spec/pre_spec.rb
99
115
  - spec/spec_helper.rb
100
116
  - spec/status_persistence.txt