jekyll-glossary_tooltip 1.0.0 → 1.3.1

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: '09c7f3e8d1674d97b97e0b2f61a9aec54c9f63887ef44e186bb98cb17f1e316e'
4
+ data.tar.gz: a04e4f54354a67f7133f9bbb49fa6a141464fdb1796caffe81d1e5253e781619
5
5
  SHA512:
6
- metadata.gz: a70b8ea06d041483fea246db14b00dabe1a54cdcad869982f5edb4428fa3f1b70d263df0cd8a474194bddf3e249875bc3bfb4aa518f02da36fe8e2a412cdf79e
7
- data.tar.gz: 7e41762075d3b7e346da21e54d3707b0f2e090554175a6f4a439cc7818ae8c217d73da921651f37760030b790d65c158fe0a73b9da0bf0db0bf938141caf2a4a
6
+ metadata.gz: 6c4fa0607b999dc875677218c0c12392fd699d5f647b37dfc0802ff1b0612bf06e9ccf564a9c562e5d5b5a4ece98b010864b1933693e3cf173446feef17ba9bb
7
+ data.tar.gz: 10a488c7d5dce9facceac915de46887d76142b0a59686c21c5a484bc116555dee5fe8cc90bd1fecea2cbeb29399f356bfc48e78d84faf42f91dfa8ed5e18454d
@@ -1,4 +1,5 @@
1
1
  # Reference: https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
2
+ # Validation: https://dependabot.com/docs/config-file/validator/
2
3
  version: 2
3
4
  updates:
4
5
  - package-ecosystem: "bundler"
data/.rubocop.yml CHANGED
@@ -5,6 +5,10 @@ require:
5
5
  - rubocop-rake
6
6
  - rubocop-rspec
7
7
 
8
+ inherit_mode:
9
+ merge:
10
+ - Exclude # Merge my AllCops.Excllude with default exludes from https://github.com/rubocop/rubocop/blob/master/config/default.yml
11
+
8
12
  AllCops:
9
13
  TargetRubyVersion: 3.0
10
14
  Include:
@@ -68,12 +72,14 @@ Lint/UnreachableCode:
68
72
  Lint/UselessAccessModifier:
69
73
  Enabled: false
70
74
 
75
+ Metrics/AbcSize:
76
+ Enabled: true
71
77
  Metrics/BlockLength:
72
78
  Enabled: true
73
79
  Max: 100
74
80
  Metrics/MethodLength:
75
81
  Enabled: true
76
- Max: 15
82
+ Max: 25
77
83
 
78
84
  Naming/FileName:
79
85
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.3.1] - 2021-08-18
2
+ - Fix gemspec dependency range stynax.
3
+
4
+ ## [1.3.0] - 2021-08-07
5
+ - Open the souce link from a tooltip in a new tab.
6
+
7
+ ## [1.2.0] - 2021-08-06
8
+ - Add bottom arrow to the tooltip.
9
+ - Restyle the glossary term bottom border style and color.
10
+ - Add tooltip hover animation from invisible to visible.
11
+
12
+ ## [1.1.0] - 2021-08-06
13
+ - 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 %}`.
14
+
1
15
  ## [1.0.0] - 2021-08-05
2
16
  - No changes from `v0.1.0` but just bumping to final first major release version!
3
17
 
data/Gemfile CHANGED
@@ -12,10 +12,11 @@ gemspec
12
12
  # Reference: https://github.com/rubygems/bundler/pull/7222
13
13
  # However there's an argument for using gemspec too: https://bundler.io/guides/creating_gem.html#testing-our-gem
14
14
  group :development, :test do
15
- gem "rake", "~> 13.0", require: false
16
- gem "travis", "~> 1.0", require: false
17
15
  gem "appraisal", "~> 2.4", require: false
18
16
  gem "gem-release", "~> 2.0", require: false
17
+ gem "rake", "~> 13.0", require: false
18
+ gem "solargraph", require: false
19
+ gem "travis", "~> 1.0", require: false
19
20
  end
20
21
 
21
22
  group :test do
data/README.md CHANGED
@@ -62,13 +62,22 @@ This could look something like:
62
62
  On any page where you've made sure include the needed CSS styling, you can use the glossary tag simply like
63
63
 
64
64
  ```markdown
65
- Here I'm taling about {% glossary term_name %} in a blog post.
65
+ Here I'm talking about {% glossary term_name %} in a blog post.
66
66
 
67
- The term name can contain spaces like {% glossary operating system }.
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 text %}
70
77
  ```
71
78
 
79
+ **Note** that a term name can not contain a `,`, as this is the argument separator character.
80
+
72
81
 
73
82
  ## CSS Style Override
74
83
  Simply modify the rules [jekyll-glossary_tooltip.css](lib/jekyll-glossary_tooltip/jekyll-glossary_tooltip.css) that you copied to your project. The tooltip is based on this [tutorial](https://www.w3schools.com/css/css_tooltip.asp). View the generated HTML output to see the HTML tags that are styled, or check the [tag.rb](lib/jekyll-glossary_tooltip/tag.rb) implementation in the method `render()`.
@@ -171,3 +180,9 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/erikw/
171
180
 
172
181
  # License
173
182
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
183
+
184
+ # Acknowledgement
185
+ Thanks to [ayastreb/jekyll-maps](https://github.com/ayastreb/jekyll-maps) for inspiration on project structure and options parsing!
186
+
187
+ # More Jekyll
188
+ Check out my other Jekyll repositories [here](https://github.com/erikw?tab=repositories&q=jekyll-&type=&language=&sort=).
Binary file
Binary file
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "This plugin simplifies for your readers and you by making it easy to define terms or abbreviations that needs an explanation. Define a common dictionary of terms and their definition in a YAML file. Then inside markdown files you can use the provided glossary liquid tag to insert a tooltip for a defined word from the dictionary. The tooltip will show the term definition on mouse hover."
13
13
  spec.homepage = "https://github.com/erikw/jekyll-glossary_tooltip/"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.7", "< 4"
15
+ spec.required_ruby_version = [">= 2.7", "< 4"]
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
18
  spec.metadata["source_code_uri"] = "https://github.com/erikw/jekyll-glossary_tooltip/"
@@ -27,5 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_dependency "jekyll", ">= 3.7", "< 5.0"
30
+ spec.add_dependency "jekyll", [">= 3.7", "< 5.0"]
31
31
  end
@@ -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
@@ -2,7 +2,7 @@
2
2
  .jekyll-glossary {
3
3
  position: relative;
4
4
  display: inline-block;
5
- border-bottom: 3px dotted blue;
5
+ border-bottom: 2px dotted #0074bd;
6
6
  cursor: help;
7
7
  }
8
8
 
@@ -36,3 +36,24 @@
36
36
  .jekyll-glossary-source-link:before {
37
37
  content: "[source]"; // "(reference)", "<link>" or whatever you want.
38
38
  }
39
+
40
+ /* Arrow created with borders. */
41
+ .jekyll-glossary .jekyll-glossary-tooltip::after {
42
+ content: " ";
43
+ position: absolute;
44
+ top: 100%;
45
+ left: 50%;
46
+ margin-left: -5px;
47
+ border-width: 5px;
48
+ border-style: solid;
49
+ border-color: black transparent transparent transparent;
50
+ }
51
+
52
+ /* Animation from invisible to visible on hover. */
53
+ .jekyll-glossary .jekyll-glossary-tooltip {
54
+ opacity: 0;
55
+ transition: opacity 1s;
56
+ }
57
+ .jekyll-glossary:hover .jekyll-glossary-tooltip {
58
+ opacity: 1;
59
+ }
@@ -0,0 +1,44 @@
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
+ parse_segments(options, opt_segments)
27
+ options
28
+ end
29
+
30
+ def parse_segments(options, opt_segments)
31
+ opt_segments.each do |opt_segment|
32
+ raise Errors::OptionsBadTagArgumentFormat, options[:term_name] unless opt_segment =~ ARGS_PATTERN
33
+
34
+ arg_name = Regexp.last_match(1)
35
+ arg_value = Regexp.last_match(2)
36
+ raise Errors::OptionsUnknownTagArgument, arg_name unless ARGS_ALLOWED.include?(arg_name)
37
+
38
+ options[arg_name.to_sym] = arg_value
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ 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
@@ -29,7 +30,8 @@ module Jekyll
29
30
  def render_tooltip_url(entry)
30
31
  # The content of the anchor is set from the CSS class jekyll-glossary-source-link,
31
32
  # so that the plugin user can customize the text without touching ruby source.
32
- entry["url"] ? "<br><a class=\"jekyll-glossary-source-link\" href=\"#{entry["url"]}\"></a>" : ""
33
+ anchor = "<br><a class=\"jekyll-glossary-source-link\" href=\"#{entry["url"]}\" target=\"_blank\"></a>"
34
+ entry["url"] ? anchor : ""
33
35
  end
34
36
 
35
37
  def lookup_entry(site, term_name)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module GlossaryTooltip
5
- VERSION = "1.0.0"
5
+ VERSION = "1.3.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Westrup
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-05 00:00:00.000000000 Z
11
+ date: 2021-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -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