jekyll-figure 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -2
- data/README.md +27 -19
- data/lib/jekyll-figure.rb +16 -9
- data/lib/jekyll-figure/version.rb +1 -1
- data/spec/jekyll-figure_spec.rb +34 -16
- data/spec/spec_helper.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a210f7cb78ffe64a2b89cb8d15f59c76ff97078827a602a5372eb1e16fa71b96
|
4
|
+
data.tar.gz: 20d71c89144d59e145201d17b7ff86575a31c256b98818db4524c0c5566d4628
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6986384a4a6b14a34544984bd09fb59048258120a7137039b7e7f847bf01fcf579926585ed746960009e3310143338e03686f241f5a6932cce93851ddc15f941
|
7
|
+
data.tar.gz: c0f63044fb45aebb4e36da199d50a49f48c19ecb1e3543107ec0200bbbd1e842e4db6243b1f807f6b80f22632e06560c65326d2b969d243154623002a14f3403
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -43,21 +43,7 @@ Content
|
|
43
43
|
</figure>
|
44
44
|
```
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
```
|
49
|
-
{% figure %}
|
50
|
-
![Image](/path/to/image.jpg)
|
51
|
-
{% endfigure %}
|
52
|
-
```
|
53
|
-
|
54
|
-
```html
|
55
|
-
<figure>
|
56
|
-
<img src="/path/to/image.jpg" alt="Image" />
|
57
|
-
</figure>
|
58
|
-
```
|
59
|
-
|
60
|
-
You can provide a caption. Any markdown will be rendered:
|
46
|
+
You can provide a caption, for which any markdown will be rendered:
|
61
47
|
|
62
48
|
```
|
63
49
|
{% figure caption:"*Markdown* caption" %}
|
@@ -72,10 +58,10 @@ Content
|
|
72
58
|
</figure>
|
73
59
|
```
|
74
60
|
|
75
|
-
You can also provide a class name(
|
61
|
+
You can also provide a class name(s) for CSS styling:
|
76
62
|
|
77
63
|
```
|
78
|
-
{% figure caption:"A caption"
|
64
|
+
{% figure caption:"A caption" class:"classname" %}
|
79
65
|
Content
|
80
66
|
{% endfigure %}
|
81
67
|
```
|
@@ -87,7 +73,7 @@ Content
|
|
87
73
|
</figure>
|
88
74
|
```
|
89
75
|
|
90
|
-
|
76
|
+
The `caption` parameter also accepts liquid markup:
|
91
77
|
|
92
78
|
```
|
93
79
|
{% figure caption:"{{ page.title }}" %}
|
@@ -98,10 +84,32 @@ Content
|
|
98
84
|
```html
|
99
85
|
<figure>
|
100
86
|
<p>Content</p>
|
101
|
-
<figcaption>The title of my
|
87
|
+
<figcaption>The title of my page</figcaption>
|
88
|
+
</figure>
|
89
|
+
```
|
90
|
+
|
91
|
+
## Configuration
|
92
|
+
|
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:
|
94
|
+
|
95
|
+
```html
|
96
|
+
<figure>
|
97
|
+
<p><img src="/path/to/image.jpg" alt="Image"></p>
|
102
98
|
</figure>
|
103
99
|
```
|
104
100
|
|
101
|
+
To disable this behaviour, in your Jekyll configuration set the `paragraphs` value for this plugin to `false`:
|
102
|
+
|
103
|
+
```yaml
|
104
|
+
plugins:
|
105
|
+
- jekyll-figure
|
106
|
+
|
107
|
+
jekyll-figure:
|
108
|
+
paragraphs: false
|
109
|
+
```
|
110
|
+
|
111
|
+
Note however that this will remove *all* paragraph tags, even those nested within other elements.
|
112
|
+
|
105
113
|
## Testing
|
106
114
|
|
107
115
|
1. `script/bootstrap`
|
data/lib/jekyll-figure.rb
CHANGED
@@ -21,31 +21,38 @@ module Jekyll
|
|
21
21
|
attributes[key] = value
|
22
22
|
end
|
23
23
|
|
24
|
-
@
|
25
|
-
@
|
24
|
+
@settings = site.config["jekyll-figure"]
|
25
|
+
@caption = attributes["caption"]
|
26
|
+
@class = attributes["class"]
|
26
27
|
|
27
28
|
# Caption: convert markdown and remove paragraphs
|
28
29
|
unless @caption.nil?
|
29
|
-
figure_caption = @caption.gsub!(/\A"|"\Z/,
|
30
|
-
figure_caption = converter.convert(figure_caption).gsub(/<\/?p[^>]*>/,
|
30
|
+
figure_caption = @caption.gsub!(/\A"|"\Z/, "")
|
31
|
+
figure_caption = converter.convert(figure_caption).gsub(/<\/?p[^>]*>/, "").chomp
|
31
32
|
figure_caption = " <figcaption>#{figure_caption}</figcaption>\n"
|
32
33
|
end
|
33
34
|
|
34
35
|
# Class name(s)
|
35
36
|
unless @class.nil?
|
36
|
-
figure_class = @class.gsub!(/\A"|"\Z/,
|
37
|
+
figure_class = @class.gsub!(/\A"|"\Z/, "")
|
37
38
|
figure_class = " class\=\"#{figure_class}\""
|
38
39
|
end
|
39
40
|
|
40
|
-
# Content
|
41
|
-
|
41
|
+
# Content
|
42
|
+
if @settings && @settings["paragraphs"] == false
|
43
|
+
# Strip paragraphs
|
44
|
+
figure_main = converter.convert(super(context)).gsub(/<\/?p[^>]*>/, "")
|
45
|
+
else
|
46
|
+
# Don't strip paragraphs
|
47
|
+
figure_main = converter.convert(super(context))
|
48
|
+
end
|
42
49
|
|
43
50
|
# Used to escape markdown parsing rendering
|
44
51
|
markdown_escape = "\ "
|
45
52
|
|
46
53
|
# Render <figure>
|
47
54
|
figure_tag = "<figure#{figure_class}>"
|
48
|
-
figure_tag += "#{figure_main}
|
55
|
+
figure_tag += "#{figure_main}"
|
49
56
|
figure_tag += "#{figure_caption}"
|
50
57
|
figure_tag += "</figure>"
|
51
58
|
end
|
@@ -54,4 +61,4 @@ module Jekyll
|
|
54
61
|
end
|
55
62
|
end
|
56
63
|
|
57
|
-
Liquid::Template.register_tag(
|
64
|
+
Liquid::Template.register_tag("figure", Jekyll::Figure::FigureTag)
|
data/spec/jekyll-figure_spec.rb
CHANGED
@@ -1,39 +1,57 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe(Jekyll) do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
"destination" => dest_dir,
|
8
|
-
"url" => "http://example.org",
|
9
|
-
}
|
10
|
-
end
|
4
|
+
Jekyll.logger.log_level = :error
|
5
|
+
|
6
|
+
let(:config_overrides) { {} }
|
11
7
|
let(:config) do
|
12
|
-
Jekyll.configuration(
|
13
|
-
|
14
|
-
|
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) }
|
15
17
|
let(:contents) { File.read(dest_dir("index.html")) }
|
16
18
|
before(:each) do
|
17
19
|
site.process
|
18
20
|
end
|
19
21
|
|
20
22
|
it "creates a figure element" do
|
21
|
-
expect(contents).to match /<figure>\n
|
23
|
+
expect(contents).to match /<figure>\n<p>Content<\/p>\n<\/figure>/
|
22
24
|
end
|
23
25
|
|
24
26
|
it "creates a figure element with image content" do
|
25
|
-
expect(contents).to match /<figure>\n
|
27
|
+
expect(contents).to match /<figure>\n<p><img src="#" alt="Image" \/><\/p>\n<\/figure>/
|
26
28
|
end
|
27
29
|
|
28
30
|
it "creates a figure element with caption" do
|
29
|
-
expect(contents).to match /<figure>\n
|
31
|
+
expect(contents).to match /<figure>\n<p>Content<\/p>\n <figcaption>A caption<\/figcaption>\n<\/figure>/
|
30
32
|
end
|
31
33
|
|
32
34
|
it "creates a figure element with caption and class name" do
|
33
|
-
expect(contents).to match /<figure>\n
|
35
|
+
expect(contents).to match /<figure>\n<p><strong>Markdown<\/strong> content<\/p>\n <figcaption><em>Markdown<\/em> content<\/figcaption>\n<\/figure>/
|
34
36
|
end
|
35
37
|
|
36
38
|
it "creates a figure element with liquid variable for caption" do
|
37
|
-
expect(contents).to match /<figure>\n
|
39
|
+
expect(contents).to match /<figure>\n<p>Content<\/p>\n <figcaption>Page data<\/figcaption>\n<\/figure>/
|
40
|
+
end
|
41
|
+
|
42
|
+
context "with paragraphs stripped" do
|
43
|
+
let(:config_overrides) do
|
44
|
+
{
|
45
|
+
"jekyll-figure" => { "paragraphs" => false },
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
it "creates a figure element" do
|
50
|
+
expect(contents).to match /<figure>\nContent\n<\/figure>/
|
51
|
+
end
|
52
|
+
|
53
|
+
it "creates a figure element with image content" do
|
54
|
+
expect(contents).to match /<figure>\n<img src="#" alt="Image" \/>\n<\/figure>/
|
55
|
+
end
|
38
56
|
end
|
39
57
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require File.expand_path(
|
1
|
+
require "jekyll"
|
2
|
+
require File.expand_path("../lib/jekyll-figure", File.dirname(__FILE__))
|
3
3
|
|
4
4
|
Jekyll.logger.log_level = :error
|
5
5
|
|
6
6
|
RSpec.configure do |config|
|
7
7
|
config.run_all_when_everything_filtered = true
|
8
8
|
config.filter_run :focus
|
9
|
-
config.order =
|
9
|
+
config.order = "random"
|
10
10
|
|
11
11
|
SOURCE_DIR = File.expand_path("../fixtures", __FILE__)
|
12
12
|
DEST_DIR = File.expand_path("../dest", __FILE__)
|