jekyll-figure 0.1.0 → 0.2.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: a210f7cb78ffe64a2b89cb8d15f59c76ff97078827a602a5372eb1e16fa71b96
4
- data.tar.gz: 20d71c89144d59e145201d17b7ff86575a31c256b98818db4524c0c5566d4628
3
+ metadata.gz: d4ef02f57060db513906d950dbf708ddc1237495dd3df4ff783799fd049a908d
4
+ data.tar.gz: 46f4a6336c409de505479624196de701a22b9bd087a56939f552d24f9ffff987
5
5
  SHA512:
6
- metadata.gz: 6986384a4a6b14a34544984bd09fb59048258120a7137039b7e7f847bf01fcf579926585ed746960009e3310143338e03686f241f5a6932cce93851ddc15f941
7
- data.tar.gz: c0f63044fb45aebb4e36da199d50a49f48c19ecb1e3543107ec0200bbbd1e842e4db6243b1f807f6b80f22632e06560c65326d2b969d243154623002a14f3403
6
+ metadata.gz: 844cd1bf4a667cf4f2fc006f8fc71d4b32c25cafadacdeab072add72c31cfd71ea07fce71f0871f6075aab42ab24a8d70213fbeb32f071b61f19caff097be094
7
+ data.tar.gz: 86e3492bcc24ab601d33362da912d227ac538282951589a0b80a72de3e08a3f6c678c5e08a1acec8cd2db94b994191fa43546b53af8b3a09bcd757761a8b4f31
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "bundler"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "monthly"
@@ -0,0 +1,27 @@
1
+ name: test
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby: [2.6.6]
15
+ jekyll: [3.0, 4.0]
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - name: Set up Ruby
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby }}
22
+ env:
23
+ JEKYLL_VERSION: ${{ matrix.jekyll }}
24
+ - name: Install dependencies
25
+ run: bundle install
26
+ - name: Run tests
27
+ run: bundle exec rake spec
data/README.md CHANGED
@@ -2,26 +2,26 @@
2
2
 
3
3
  A liquid tag for Jekyll that generates `<figure>` elements.
4
4
 
5
- [![Gem Version](https://img.shields.io/gem/v/jekyll-figure.svg)](https://rubygems.org/gems/jekyll-figure)
6
- [![Build Status](https://img.shields.io/travis/paulrobertlloyd/jekyll-figure/master.svg)](https://travis-ci.org/paulrobertlloyd/jekyll-figure)
5
+ [![Gem version](https://img.shields.io/gem/v/jekyll-figure.svg)](https://rubygems.org/gems/jekyll-figure)
6
+ [![Build status](https://github.com/paulrobertlloyd/jekyll-figure/workflows/test/badge.svg)](https://github.com/paulrobertlloyd/jekyll-figure/actions)
7
7
 
8
8
  ## Installation
9
9
 
10
10
  1. Add `gem 'jekyll-figure'` to your site’s Gemfile and run `bundle`
11
11
  2. Add the following to your site’s `_config.yml`:
12
12
 
13
-
14
13
  ```yaml
15
14
  plugins:
16
15
  - jekyll-figure
17
16
  ```
17
+
18
18
  Note: If you are using a Jekyll version less than 3.5.0, use the `gems` key instead of `plugins`.
19
19
 
20
20
  ## Usage
21
21
 
22
22
  This plugin provides a liquid tag that enables you to generate a `<figure>` element. It takes optional `caption` and `class` parameters.
23
23
 
24
- ```
24
+ ```liquid
25
25
  {% figure [caption:"Caption (markdown)"] [class:"class1 class2"] %}
26
26
  Figure content (markdown)
27
27
  {% endfigure %}
@@ -31,7 +31,7 @@ Figure content (markdown)
31
31
 
32
32
  In simplest usage:
33
33
 
34
- ```
34
+ ```liquid
35
35
  {% figure %}
36
36
  Content
37
37
  {% endfigure %}
@@ -45,7 +45,7 @@ Content
45
45
 
46
46
  You can provide a caption, for which any markdown will be rendered:
47
47
 
48
- ```
48
+ ```liquid
49
49
  {% figure caption:"*Markdown* caption" %}
50
50
  Content
51
51
  {% endfigure %}
@@ -60,7 +60,7 @@ Content
60
60
 
61
61
  You can also provide a class name(s) for CSS styling:
62
62
 
63
- ```
63
+ ```liquid
64
64
  {% figure caption:"A caption" class:"classname" %}
65
65
  Content
66
66
  {% endfigure %}
@@ -75,7 +75,7 @@ Content
75
75
 
76
76
  The `caption` parameter also accepts liquid markup:
77
77
 
78
- ```
78
+ ```liquid
79
79
  {% figure caption:"{{ page.title }}" %}
80
80
  Content
81
81
  {% endfigure %}
@@ -88,9 +88,30 @@ Content
88
88
  </figure>
89
89
  ```
90
90
 
91
+ You can also add labels and reference them:
92
+
93
+ ```liquid
94
+ {% figure caption:"A caption." label:example %}
95
+ An example figure that can be referenced later.
96
+ {% endfigure %}
97
+
98
+ You can see an example in {% figref example %}.
99
+ ```
100
+
101
+ ```html
102
+ <figure id="example">
103
+ <p>An example figure that can be referenced later.</p>
104
+ <figcaption><em>Figure 1:</em> A caption.</figcaption>
105
+ </figure>
106
+
107
+ <p>You can see an example in <a href="#example">figure 1</a></p>
108
+ ```
109
+
110
+ The word ‘Figure’ in the figcaption is translated according to the `lang` you set in the yaml header of your post. If your language is not supported simple set `figure` to the yaml header of your post to the value you want to use instead of ‘Figure’.
111
+
91
112
  ## Configuration
92
113
 
93
- Any markdown provided within the `{% figure %}` block is rendered using Jekyll's Markdown parser, [Kramdown](https://kramdown.gettalong.org). However, this means images and other content will be wrapped within `<p>` tags, like so:
114
+ Any markdown provided within the `{% figure %}` block is rendered using Jekylls Markdown parser, [Kramdown](https://kramdown.gettalong.org). However, this means images and other content will be wrapped within `<p>` tags, like so:
94
115
 
95
116
  ```html
96
117
  <figure>
@@ -112,8 +133,8 @@ Note however that this will remove *all* paragraph tags, even those nested withi
112
133
 
113
134
  ## Testing
114
135
 
115
- 1. `script/bootstrap`
116
- 2. `script/cibuild`
136
+ 1. `bundle install`
137
+ 2. `bundle exec rake spec`
117
138
 
118
139
  ## Contributing
119
140
 
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_development_dependency "jekyll", [">= 3.0", "< 4.0"]
22
+ spec.add_development_dependency "jekyll", [">= 3.0", "< 5.0"]
23
23
  spec.add_development_dependency "rspec", "~> 3.0"
24
- spec.add_development_dependency 'rake', '~> 0'
25
- spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency 'rake', '~> 13.0.1'
25
+ spec.add_development_dependency "bundler", "~> 2.1"
26
26
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Figure
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -0,0 +1,22 @@
1
+ require 'utils'
2
+
3
+ module Jekyll
4
+ module Figure
5
+
6
+ class FigRefTag < Liquid::Tag
7
+ include Utils
8
+
9
+ def initialize(tag_name, markup, tokens)
10
+ @label = markup
11
+ super
12
+ end
13
+
14
+ def render(context)
15
+ @context = context
16
+ print_reference(@label)
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ Liquid::Template.register_tag("figref", Jekyll::Figure::FigRefTag)
data/lib/jekyll-figure.rb CHANGED
@@ -1,7 +1,12 @@
1
+ require 'utils'
2
+ require 'jekyll-figure-ref'
3
+
1
4
  module Jekyll
2
5
  module Figure
3
6
 
4
7
  class FigureTag < Liquid::Block
8
+ include Utils
9
+
5
10
  def initialize(tag_name, markup, tokens)
6
11
  @markup = markup
7
12
  super
@@ -24,11 +29,14 @@ module Jekyll
24
29
  @settings = site.config["jekyll-figure"]
25
30
  @caption = attributes["caption"]
26
31
  @class = attributes["class"]
32
+ @label = attributes["label"]
33
+ @context = context
27
34
 
28
35
  # Caption: convert markdown and remove paragraphs
29
36
  unless @caption.nil?
30
37
  figure_caption = @caption.gsub!(/\A"|"\Z/, "")
31
38
  figure_caption = converter.convert(figure_caption).gsub(/<\/?p[^>]*>/, "").chomp
39
+ figure_caption = print_figure_counter(@label) + figure_caption unless @label.nil? || @label.empty?
32
40
  figure_caption = " <figcaption>#{figure_caption}</figcaption>\n"
33
41
  end
34
42
 
@@ -38,6 +46,8 @@ module Jekyll
38
46
  figure_class = " class\=\"#{figure_class}\""
39
47
  end
40
48
 
49
+ figure_label = @label.nil? || @label.empty? ? "" : ' id="' + @label.gsub(/A"|"\Z/, "") + '"'
50
+
41
51
  # Content
42
52
  if @settings && @settings["paragraphs"] == false
43
53
  # Strip paragraphs
@@ -51,7 +61,7 @@ module Jekyll
51
61
  markdown_escape = "\ "
52
62
 
53
63
  # Render <figure>
54
- figure_tag = "<figure#{figure_class}>"
64
+ figure_tag = "<figure#{figure_class}#{figure_label}>"
55
65
  figure_tag += "#{figure_main}"
56
66
  figure_tag += "#{figure_caption}"
57
67
  figure_tag += "</figure>"
data/lib/utils.rb ADDED
@@ -0,0 +1,47 @@
1
+ module Jekyll
2
+ module Figure
3
+ module Utils
4
+
5
+ class I18n
6
+ @figure_i18n = {'en' => "Figure",
7
+ 'de' => "Abbildung",
8
+ 'sv' => "Figur",
9
+ 'fr' => "Figure"}
10
+ def self.figure(lang)
11
+ return @figure_i18n[lang] if @figure_i18n.key?(lang)
12
+ @figure_i18n['en']
13
+ end
14
+ end
15
+
16
+ def lang
17
+ return @context.registers[:page]["lang"].to_s if @context.registers[:page].key?("lang")
18
+ "en".to_s
19
+ end
20
+
21
+ def figure
22
+ return @context.registers[:page]["figure"].to_s if @context.registers[:page].key?("figure")
23
+ I18n.figure(lang)
24
+ end
25
+
26
+ def print_figure_counter(label)
27
+ label.gsub!(/\s/, '')
28
+ @context.registers[:page]["figure_labels"] ||= {}
29
+
30
+ if @context.registers[:page]["figure_labels"].key?(label)
31
+ value = @context.registers[:page]["figure_labels"][label]
32
+ else
33
+ value = @context.registers[:page]["figure_labels"].length + 1
34
+ @context.registers[:page]["figure_labels"][label] = value
35
+ end
36
+ "<em>" + figure + " " + value.to_s + ":</em> "
37
+ end
38
+
39
+ def print_reference(label)
40
+ label.gsub!(/\s/, '')
41
+ "<a href=\"\##{label.to_s}\">" + figure.downcase + " " +
42
+ @context.registers[:page]["figure_labels"][label.to_s].to_s +
43
+ "</a>"
44
+ end
45
+ end
46
+ end
47
+ end
@@ -23,3 +23,9 @@ Content
23
23
  {% figure caption:"{{ page.test }}" %}
24
24
  Content
25
25
  {% endfigure %}
26
+
27
+ {% figure caption:"A caption" label:example %}
28
+ Content
29
+ {% endfigure %}
30
+
31
+ See {% figref example %}
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+
3
+ describe(Jekyll) do
4
+ Jekyll.logger.log_level = :error
5
+
6
+ let(:config_overrides) { {} }
7
+ let(:config) do
8
+ Jekyll.configuration(
9
+ config_overrides.merge(
10
+ "source" => source_dir,
11
+ "destination" => dest_dir,
12
+ "url" => "http://example.org",
13
+ )
14
+ )
15
+ end
16
+ let(:site) { Jekyll::Site.new(config) }
17
+ let(:contents) { File.read(dest_dir("index.html")) }
18
+ before(:each) do
19
+ site.process
20
+ end
21
+
22
+ it "creates a figref element" do
23
+ expect(contents).to match /See <a href="#example">figure 1<\/a>/
24
+ end
25
+ end
@@ -39,6 +39,10 @@ describe(Jekyll) do
39
39
  expect(contents).to match /<figure>\n<p>Content<\/p>\n <figcaption>Page data<\/figcaption>\n<\/figure>/
40
40
  end
41
41
 
42
+ it "creates a figure element with caption and label" do
43
+ expect(contents).to match /<figure id="example">\n<p>Content<\/p>\n <figcaption><em>Figure 1:<\/em> A caption<\/figcaption>\n<\/figure>/
44
+ end
45
+
42
46
  context "with paragraphs stripped" do
43
47
  let(:config_overrides) do
44
48
  {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-figure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Robert Lloyd
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-22 00:00:00.000000000 Z
11
+ date: 2023-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '3.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '4.0'
22
+ version: '5.0'
23
23
  type: :development
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '3.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '4.0'
32
+ version: '5.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rspec
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -50,57 +50,57 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
53
+ version: 13.0.1
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '0'
60
+ version: 13.0.1
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: bundler
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '1.6'
67
+ version: '2.1'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '1.6'
74
+ version: '2.1'
75
75
  description: A liquid tag for Jekyll that generates <figure> elements.
76
76
  email: me+rubygems@paulrobertlloyd.com
77
77
  executables: []
78
78
  extensions: []
79
79
  extra_rdoc_files: []
80
80
  files:
81
+ - ".github/dependabot.yml"
82
+ - ".github/workflows/test.yml"
81
83
  - ".gitignore"
82
- - ".travis.yml"
83
84
  - Gemfile
84
85
  - LICENSE
85
86
  - README.md
86
87
  - Rakefile
87
88
  - jekyll-figure.gemspec
89
+ - lib/jekyll-figure-ref.rb
88
90
  - lib/jekyll-figure.rb
89
91
  - lib/jekyll-figure/version.rb
90
- - script/bootstrap
91
- - script/cibuild
92
- - script/console
93
- - script/release
92
+ - lib/utils.rb
94
93
  - spec/fixtures/_config.yml
95
94
  - spec/fixtures/_layouts/some_default.html
96
95
  - spec/fixtures/index.html
96
+ - spec/jekyll-figure-ref_spec.rb
97
97
  - spec/jekyll-figure_spec.rb
98
98
  - spec/spec_helper.rb
99
99
  homepage: https://github.com/paulrobertlloyd/jekyll-figure
100
100
  licenses:
101
101
  - MIT
102
102
  metadata: {}
103
- post_install_message:
103
+ post_install_message:
104
104
  rdoc_options: []
105
105
  require_paths:
106
106
  - lib
@@ -115,14 +115,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  requirements: []
118
- rubyforge_project:
119
- rubygems_version: 2.7.7
120
- signing_key:
118
+ rubygems_version: 3.3.7
119
+ signing_key:
121
120
  specification_version: 4
122
121
  summary: Jekyll plugin that generates <figure> elements.
123
122
  test_files:
124
123
  - spec/fixtures/_config.yml
125
124
  - spec/fixtures/_layouts/some_default.html
126
125
  - spec/fixtures/index.html
126
+ - spec/jekyll-figure-ref_spec.rb
127
127
  - spec/jekyll-figure_spec.rb
128
128
  - spec/spec_helper.rb
data/.travis.yml DELETED
@@ -1,14 +0,0 @@
1
- language: ruby
2
- script: "script/cibuild"
3
- matrix:
4
- include:
5
- - rvm: 2.0
6
- env: ""
7
- - rvm: 2.0
8
- env: JEKYLL_VERSION=3.0.0
9
- - rvm: 2.1
10
- env: ""
11
- - rvm: 2.1
12
- env: JEKYLL_VERSION=3.0.0
13
- - rvm: 2.1
14
- env: JEKYLL_VERSION=3.7.4
data/script/bootstrap DELETED
@@ -1,3 +0,0 @@
1
- #! /bin/bash
2
-
3
- bundle install
data/script/cibuild DELETED
@@ -1,3 +0,0 @@
1
- #! /bin/bash
2
-
3
- bundle exec rspec
data/script/console DELETED
@@ -1,34 +0,0 @@
1
- #! /usr/bin/env ruby
2
-
3
- def relative_to_root(path)
4
- File.expand_path(path, File.dirname(File.dirname(__FILE__)))
5
- end
6
-
7
- require 'jekyll'
8
- require relative_to_root('lib/jekyll-figure.rb')
9
- require 'pry-debugger'
10
-
11
- SOURCE_DIR = relative_to_root('spec/fixtures')
12
- DEST_DIR = relative_to_root('spec/dest')
13
-
14
- def source_dir(*files)
15
- File.join(SOURCE_DIR, *files)
16
- end
17
-
18
- def dest_dir(*files)
19
- File.join(DEST_DIR, *files)
20
- end
21
-
22
- def config(overrides = {})
23
- Jekyll.configuration({
24
- "source" => source_dir,
25
- "destination" => dest_dir,
26
- "url" => "http://example.org"
27
- }).merge(overrides)
28
- end
29
-
30
- def site(configuration = config)
31
- Jekyll::Site.new(configuration)
32
- end
33
-
34
- binding.pry
data/script/release DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/sh
2
- # Tag and push a release.
3
-
4
- set -e
5
-
6
- script/cibuild
7
- bundle exec rake release