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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 776b90fa868d03ca9d14c13cec83536e4f6d7602a4f41617477273f8a376a150
4
- data.tar.gz: 4a74ceebf5143fa1e0f7ca6259d29f37a5e7fab178d60d49af2872b859e90f9e
3
+ metadata.gz: a210f7cb78ffe64a2b89cb8d15f59c76ff97078827a602a5372eb1e16fa71b96
4
+ data.tar.gz: 20d71c89144d59e145201d17b7ff86575a31c256b98818db4524c0c5566d4628
5
5
  SHA512:
6
- metadata.gz: 8f104190796ef31527fdf72010350d44e50df9b03db99579eedf7c739827d5915b7a56cdbbc9e52e4e1580529fa0b0cb294bf3cec90dd703b8ccf71e5114e7c3
7
- data.tar.gz: cf4994bba1a2805bd07c1974e282f666c46c6956db138557a3e0f189736f814d230c85f1261e402a31908c35d014c0465a3c970d71ddc24b762e97625193c51d
6
+ metadata.gz: 6986384a4a6b14a34544984bd09fb59048258120a7137039b7e7f847bf01fcf579926585ed746960009e3310143338e03686f241f5a6932cce93851ddc15f941
7
+ data.tar.gz: c0f63044fb45aebb4e36da199d50a49f48c19ecb1e3543107ec0200bbbd1e842e4db6243b1f807f6b80f22632e06560c65326d2b969d243154623002a14f3403
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
- *.gem
2
1
  Gemfile.lock
3
2
  spec/dest
4
3
  .bundle
5
4
  .jekyll-metadata
6
- .DS_Store
5
+ *.gem
data/README.md CHANGED
@@ -43,21 +43,7 @@ Content
43
43
  </figure>
44
44
  ```
45
45
 
46
- If a figure contains an image (or multiple images), the surrounding `<p>` will be stripped:
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(es) for CSS styling:
61
+ You can also provide a class name(s) for CSS styling:
76
62
 
77
63
  ```
78
- {% figure caption:"A caption" | class:"classname" %}
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
- Finally, the `caption` parameter will accept liquid ouput markup:
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 post</figcaption>
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`
@@ -21,31 +21,38 @@ module Jekyll
21
21
  attributes[key] = value
22
22
  end
23
23
 
24
- @caption = attributes['caption']
25
- @class = attributes['class']
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[^>]*>/, '').chomp
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: convert markdown and remove paragraphs containing images
41
- figure_main = converter.convert(super(context)).gsub(/^<p>\s*((<img[^<]+?)+)\s*<\/p>(.*)/, '\\1').gsub!(/[\n]+/, "\n ");
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}\n"
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('figure', Jekyll::Figure::FigureTag)
64
+ Liquid::Template.register_tag("figure", Jekyll::Figure::FigureTag)
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Figure
3
- VERSION = "0.0.3"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -1,39 +1,57 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe(Jekyll) do
4
- let(:overrides) do
5
- {
6
- "source" => source_dir,
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(overrides)
13
- end
14
- let(:site) { Jekyll::Site.new(config) }
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 <p>Content<\/p>\n \n<\/figure>/
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 <img src="#" alt="Image" \/>\n \n<\/figure>/
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 <p>Content<\/p>\n \n <figcaption>A caption<\/figcaption>\n<\/figure>/
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 <p><strong>Markdown<\/strong> content<\/p>\n \n <figcaption><em>Markdown<\/em> content<\/figcaption>\n<\/figure>/
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 <p>Content<\/p>\n \n <figcaption>Page data<\/figcaption>\n<\/figure>/
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
@@ -1,12 +1,12 @@
1
- require 'jekyll'
2
- require File.expand_path('../lib/jekyll-figure', File.dirname(__FILE__))
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 = 'random'
9
+ config.order = "random"
10
10
 
11
11
  SOURCE_DIR = File.expand_path("../fixtures", __FILE__)
12
12
  DEST_DIR = File.expand_path("../dest", __FILE__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-figure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Robert Lloyd