jekyll-glossary_tooltip 1.0.0 → 1.1.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: 27106561fba42677dd2324409e4cf8ad78dfdf8e0bfa598e2c8a4a5aff25583e
4
- data.tar.gz: 9aef06b73017f60dc04bebc53b38e1a06cd46d24572440a7b5b5d3a52f987aba
3
+ metadata.gz: 83377b31e4fd2496cf08adebb7cafb28291c10c26d45261dcdcfab8048d3eb18
4
+ data.tar.gz: 5ecf00d0a3d0a8b44e029af82ee3a4a4cb9c9105c286f3c1913a003cff55ff29
5
5
  SHA512:
6
- metadata.gz: a70b8ea06d041483fea246db14b00dabe1a54cdcad869982f5edb4428fa3f1b70d263df0cd8a474194bddf3e249875bc3bfb4aa518f02da36fe8e2a412cdf79e
7
- data.tar.gz: 7e41762075d3b7e346da21e54d3707b0f2e090554175a6f4a439cc7818ae8c217d73da921651f37760030b790d65c158fe0a73b9da0bf0db0bf938141caf2a4a
6
+ metadata.gz: fec53c345bbeb2e580dbeb8eef9349d189f35885f2c952b3c27c7d14899933fb9f7f75bc02831fbf1d3b708474f9c523a583618f9ff9f878a25bb21a355fd784
7
+ data.tar.gz: 338b23717e6025ef834cb7cb719b5ad9d58958472c9d67870398f7c3777935e9d6373d9c1d93d2e4f991b8a61ded6decc3445ca72802550aa8c1c043e34aa7d3
data/.rubocop.yml CHANGED
@@ -68,12 +68,15 @@ Lint/UnreachableCode:
68
68
  Lint/UselessAccessModifier:
69
69
  Enabled: false
70
70
 
71
+ Metrics/AbcSize:
72
+ Enabled: true
73
+ Max: 25
71
74
  Metrics/BlockLength:
72
75
  Enabled: true
73
76
  Max: 100
74
77
  Metrics/MethodLength:
75
78
  Enabled: true
76
- Max: 15
79
+ Max: 25
77
80
 
78
81
  Naming/FileName:
79
82
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## [1.1.0] - 2021-08-06
2
+ - Add optional `display:` argument to set a different term display name, rather than using the term name as defined in the glossary file. Usage: `{% glossary term_name, display: Different Name To Display %}`.
3
+
1
4
  ## [1.0.0] - 2021-08-05
2
5
  - No changes from `v0.1.0` but just bumping to final first major release version!
3
6
 
data/README.md CHANGED
@@ -67,7 +67,17 @@ Here I'm taling about {% glossary term_name %} in a blog post.
67
67
  The term name can contain spaces like {% glossary operating system }.
68
68
 
69
69
  Even if the term is defined in _data/glossary.yml as 'term_name', the matching is case-insensitive meaning that I can look it up using {% glossary TeRM_NaME %}. Note that the term is displayed as defined in the tag rather than the definition, here meaing 'TeRM_NaME'.
70
+
71
+ The case-styling above works as there's still a case-insensitive match. But what about when you actually want to dispaly the term differently? Maybe the term is defined as "cat" but you want to use the plural "cats"? Then you can supply an optional `display` argument. The syntax is:
72
+ {% glossary <term>, display: <diplay name> %}
73
+
74
+ This could be e.g.
75
+ {% glossary cat, display: cats%}
76
+ {% glossary some term, display: some other display%}
77
+
78
+ TODO mention that a term name can't contain comma
70
79
  ```
80
+ Not that a term name can not contain a `,`, as this is the argument separator character.
71
81
 
72
82
 
73
83
  ## CSS Style Override
@@ -171,3 +181,6 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/erikw/
171
181
 
172
182
  # License
173
183
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
184
+
185
+ # Acknowledgement
186
+ Thanks to [ayastreb/jekyll-maps](https://github.com/ayastreb/jekyll-maps) for inspiration on project structure and options parsing!
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "jekyll-glossary_tooltip/version"
3
+ require_relative "jekyll-glossary_tooltip/options_parser"
4
4
  require_relative "jekyll-glossary_tooltip/tag"
5
+ require_relative "jekyll-glossary_tooltip/version"
5
6
 
6
7
  module Jekyll
7
8
  # Module for the plugin.
@@ -13,6 +13,15 @@ module Jekyll
13
13
  def initialize(term_name); super("The term '#{term_name}' was defined multiple times in the glossary") end
14
14
  end
15
15
  class NoGlossaryFile < StandardError; def initialize; super("No data.glossary found") end end
16
+ class OptionsNoTermNameInTag < StandardError
17
+ def initialize; super("No term name argument for the glossary tag supplied") end
18
+ end
19
+ class OptionsBadTagArgumentFormat < StandardError
20
+ def initialize(term_name); super("The glossary tag for term '#{term_name}' has a bad argument format") end
21
+ end
22
+ class OptionsUnknownTagArgument < StandardError
23
+ def initialize(arg); super("An unknown tag argument #{arg} was encountered") end
24
+ end
16
25
  end
17
26
  end
18
27
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll-glossary_tooltip/errors"
4
+
5
+ module Jekyll
6
+ module GlossaryTooltip
7
+ # Stripped down & modified version of
8
+ # https://github.com/ayastreb/jekyll-maps/blob/master/lib/jekyll-maps/options_parser.rb
9
+ class OptionsParser
10
+ ARGS_PATTERN = %r{\s*(\w[-_\w]*):\s*(\w[^,\n\r]*)}
11
+ ARGS_ALLOWED = %w[
12
+ display
13
+ ].freeze
14
+
15
+ class << self
16
+ def parse(raw_options)
17
+ options = {
18
+ term_query: nil,
19
+ display: nil
20
+ }
21
+ opt_segments = raw_options.strip.split(",")
22
+ raise Errors::OptionsNoTermNameInTag unless opt_segments.length.positive?
23
+
24
+ options[:term_query] = opt_segments[0]
25
+ opt_segments.shift
26
+
27
+ opt_segments.each do |opt_segment|
28
+ raise Errors::OptionsBadTagArgumentFormat, options[:term_name] unless opt_segment =~ ARGS_PATTERN
29
+
30
+ arg_name = Regexp.last_match(1)
31
+ arg_value = Regexp.last_match(2)
32
+ raise Errors::OptionsUnknownTagArgument, arg_name unless ARGS_ALLOWED.include?(arg_name)
33
+
34
+ options[arg_name.to_sym] = arg_value
35
+ end
36
+ options
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -7,16 +7,17 @@ module Jekyll
7
7
  module GlossaryTooltip
8
8
  # Custom liquid tag implementation.
9
9
  class Tag < Liquid::Tag
10
- def initialize(tag_name, text, tokens)
10
+ def initialize(tag_name, args, tokens)
11
11
  super
12
- @term_query = text.strip
12
+ @opts = OptionsParser.parse(args)
13
13
  end
14
14
 
15
15
  def render(context)
16
- entry = lookup_entry(context.registers[:site], @term_query)
16
+ entry = lookup_entry(context.registers[:site], @opts[:term_query])
17
+ @opts[:display] ||= @opts[:term_query]
17
18
  <<~HTML
18
19
  <span class="jekyll-glossary">
19
- #{@term_query}
20
+ #{@opts[:display]}
20
21
  <span class="jekyll-glossary-tooltip">#{entry["definition"]}#{render_tooltip_url(entry)}</span>
21
22
  </span>
22
23
  HTML
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module GlossaryTooltip
5
- VERSION = "1.0.0"
5
+ VERSION = "1.1.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-glossary_tooltip
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Westrup
@@ -68,6 +68,7 @@ files:
68
68
  - lib/jekyll-glossary_tooltip.rb
69
69
  - lib/jekyll-glossary_tooltip/errors.rb
70
70
  - lib/jekyll-glossary_tooltip/jekyll-glossary_tooltip.css
71
+ - lib/jekyll-glossary_tooltip/options_parser.rb
71
72
  - lib/jekyll-glossary_tooltip/tag.rb
72
73
  - lib/jekyll-glossary_tooltip/version.rb
73
74
  - script/build