jekyll-glossary_tooltip 0.1.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/CHANGELOG.md +14 -0
- data/README.md +18 -4
- data/img/tooltip_screenshot.png +0 -0
- data/img/tooltip_screenshot.xcf +0 -0
- data/lib/jekyll-glossary_tooltip.rb +2 -1
- data/lib/jekyll-glossary_tooltip/errors.rb +9 -0
- data/lib/jekyll-glossary_tooltip/jekyll-glossary_tooltip.css +22 -1
- data/lib/jekyll-glossary_tooltip/options_parser.rb +41 -0
- data/lib/jekyll-glossary_tooltip/tag.rb +7 -5
- data/lib/jekyll-glossary_tooltip/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc3418ab4d3f9ec90d2216634147be734c56f8f1dc0fb743ef2ae2fb32f1ab7a
|
4
|
+
data.tar.gz: 7d400181ba68bf52ace6e6dfd1c92f6e9b2fb53530e4929e7d79ad94465adc6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38abe820838fbeddd3380802102f47a5337fb1a772d6d453ba20f4112aa3c793a38e40c84fe8b2d51aa381263731df08fb9c8efe5348bfc18cfb94b283a83cf8
|
7
|
+
data.tar.gz: 47467bc867e32d924438fcce2e6047ec0b7e7683a220355616a6fcc41c9a9849d41c17424007e1b61a23fd22ab18bcec001ab0975dcc3b76b70706ac4351ca20
|
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:
|
79
|
+
Max: 25
|
77
80
|
|
78
81
|
Naming/FileName:
|
79
82
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,2 +1,16 @@
|
|
1
|
+
## [1.3.0] - 2021-08-07
|
2
|
+
- Open the souce link from a tooltip in a new tab.
|
3
|
+
|
4
|
+
## [1.2.0] - 2021-08-06
|
5
|
+
- Add bottom arrow to the tooltip.
|
6
|
+
- Restyle the glossary term bottom border style and color.
|
7
|
+
- Add tooltip hover animation from invisible to visible.
|
8
|
+
|
9
|
+
## [1.1.0] - 2021-08-06
|
10
|
+
- 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 %}`.
|
11
|
+
|
12
|
+
## [1.0.0] - 2021-08-05
|
13
|
+
- No changes from `v0.1.0` but just bumping to final first major release version!
|
14
|
+
|
1
15
|
## [0.1.0] - 2021-08-05
|
2
16
|
- First release version. The plugin is fully working but I suspect that there might be a few point releases just to nail the release process. Once this is working, there will soon be an 1.0.0 release!
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Jekyll Glossary Tooltip Tag Plugin
|
1
|
+
# Jekyll Glossary Tooltip Tag Plugin
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/jekyll-glossary_tooltip.svg)](https://badge.fury.io/rb/jekyll-glossary_tooltip)
|
3
3
|
[![Gem Downloads](https://ruby-gem-downloads-badge.herokuapp.com/jekyll-glossary_tooltip?color=brightgreen&type=total&label=gem%20downloads)](https://rubygems.org/gems/jekyll-glossary_tooltip)
|
4
4
|
[![Travis Build Status](https://img.shields.io/travis/erikw/jekyll-glossary_tooltip/main?logo=travis)](https://travis-ci.com/erikw/jekyll-glossary_tooltip)
|
@@ -7,7 +7,6 @@
|
|
7
7
|
|
8
8
|
<img src="/img/tooltip_screenshot.png" width="256" align="right" alt="Screenshot of the glossary tooltip term definition" title="Example of tooltip definition of the term 'Jekyll'.">
|
9
9
|
|
10
|
-
|
11
10
|
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.
|
12
11
|
|
13
12
|
It's also possible to provide an optional URL to further term definition or source reference. To also support mobile devices, this URL link is placed inside the tooltip pop-up itself, rather than making the term itself clickable. This is so that on mobile device, you will first tap the word to get the hover tooltip, then click the link in the tooltip if desired.
|
@@ -63,13 +62,22 @@ This could look something like:
|
|
63
62
|
On any page where you've made sure include the needed CSS styling, you can use the glossary tag simply like
|
64
63
|
|
65
64
|
```markdown
|
66
|
-
Here I'm
|
65
|
+
Here I'm talking about {% glossary term_name %} in a blog post.
|
67
66
|
|
68
|
-
The term name can contain spaces like {% glossary operating system }.
|
67
|
+
The term name can contain spaces like {% glossary operating system %}.
|
69
68
|
|
70
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 %}
|
71
77
|
```
|
72
78
|
|
79
|
+
**Note** that a term name can not contain a `,`, as this is the argument separator character.
|
80
|
+
|
73
81
|
|
74
82
|
## CSS Style Override
|
75
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()`.
|
@@ -172,3 +180,9 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/erikw/
|
|
172
180
|
|
173
181
|
# License
|
174
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=).
|
data/img/tooltip_screenshot.png
CHANGED
Binary file
|
data/img/tooltip_screenshot.xcf
CHANGED
Binary file
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "jekyll-glossary_tooltip/
|
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:
|
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,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,
|
10
|
+
def initialize(tag_name, args, tokens)
|
11
11
|
super
|
12
|
-
@
|
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
|
-
#{@
|
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
|
-
|
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)
|
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:
|
4
|
+
version: 1.3.0
|
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-
|
11
|
+
date: 2021-08-07 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
|