octopress-image-caption-tag 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +2 -1
- data/lib/octopress-image-caption-tag.rb +86 -81
- data/lib/octopress-image-caption-tag/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e0e82cc1e3553a1963087be8c9884afc093561c
|
4
|
+
data.tar.gz: c1c41ecad9c622e63a3b81d987932b5b4aed5796
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe5368e095b007307479aa1723b552ee2de8e5d345925041648e1fe35880c0b35efd07e864e7b23ce964ada72b2c51f3ae2881bfc110b2fbb93689a6b6c801c8
|
7
|
+
data.tar.gz: 7e8b5adfc78a6a995b678aa7c2f5d4e2a0ac62523104cdc0e0ecaf84ad065fca0728e9fa1ec95b60edfff7b7c03a1fc20fb0d576581db206c80df07a2eb6f7d9
|
data/LICENSE.txt
CHANGED
@@ -1,15 +1,67 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'octopress-image-caption-tag/version'
|
2
|
+
require 'liquid'
|
3
3
|
|
4
4
|
# Title: Simple Image tag for Jekyll
|
5
|
-
# Authors:
|
5
|
+
# Authors: Charles Beynon https://eulerpi.io
|
6
|
+
# Brandon Mathis http://brandonmathis.com
|
6
7
|
# Felix Schäfer, Frederic Hemberger
|
7
8
|
#
|
8
9
|
|
9
10
|
module Octopress
|
10
11
|
module Tags
|
11
12
|
module ImageCaptionTag
|
13
|
+
module ImageCaptionFunctions
|
14
|
+
def parse_sizes(raw_size)
|
15
|
+
if /\s*(?<w>\d+%?)\s+(?<h>\d+%?)/ =~ raw_size
|
16
|
+
@width = w
|
17
|
+
@height = h
|
18
|
+
elsif @class.rstrip == 'right' || @class.rstrip == 'left'
|
19
|
+
@width = '33%'
|
20
|
+
else
|
21
|
+
@width = '100%'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse_title(raw_title)
|
26
|
+
if /(?:"|')(?<title>[^"']+)?(?:"|')\s+(?:"|')(?<alt>[^"']+)?(?:"|')/ =~ raw_title
|
27
|
+
@title = title
|
28
|
+
@alt = alt
|
29
|
+
else
|
30
|
+
/(?:"|')(?<titlealt>[^"']+)?(?:"|')/ =~ raw_title
|
31
|
+
@title = titlealt
|
32
|
+
@alt = titlealt
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def absolute_sized_figure
|
37
|
+
<<-EOS.gsub(/^ {10}/, '') # gsubm is to pretty up source by indenting
|
38
|
+
<figure class='caption-wrapper #{@class.rstrip}'>
|
39
|
+
<a class='image-popup' href='#{@img}'>
|
40
|
+
<img class='caption' src='#{@img}' width='#{@width}' height='#{@height}' title='#{@title}' alt='#{@alt}'>
|
41
|
+
</a>
|
42
|
+
<figcaption class='caption-text' style='width:#{@width.to_i - 10}px;'>
|
43
|
+
#{@caption}
|
44
|
+
</figcaption>
|
45
|
+
</figure>
|
46
|
+
EOS
|
47
|
+
end
|
48
|
+
|
49
|
+
def relative_sized_figure
|
50
|
+
<<-EOS.gsub(/^ {10}/, '') # gsubm is to pretty up source by indenting
|
51
|
+
<figure class='caption-wrapper #{@class.rstrip}' style='width:#{@width};'>
|
52
|
+
<a class='image-popup' href='#{@img}'>
|
53
|
+
<img class='caption' src='#{@img}' width='100%' height='100%' title='#{@title}' alt='#{@alt}'>
|
54
|
+
</a>
|
55
|
+
<figcaption class='caption-text'>
|
56
|
+
#{@caption}
|
57
|
+
</figcaption>
|
58
|
+
</figure>
|
59
|
+
EOS
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
12
63
|
class Tag < Liquid::Tag
|
64
|
+
include ImageCaptionFunctions
|
13
65
|
@img = nil
|
14
66
|
@title = nil
|
15
67
|
@class = ''
|
@@ -17,53 +69,31 @@ module Octopress
|
|
17
69
|
@height = ''
|
18
70
|
|
19
71
|
def initialize(tag_name, markup, tokens)
|
20
|
-
if
|
21
|
-
@class =
|
22
|
-
@img =
|
23
|
-
if
|
24
|
-
|
25
|
-
|
26
|
-
if $4 =~ /\s*(\d+%?)\s+(\d+%?)/
|
27
|
-
@width = $1
|
28
|
-
@height = $2
|
29
|
-
elsif @class.rstrip == "right" or @class.rstrip == "left"
|
30
|
-
@width = "33%"
|
31
|
-
else
|
32
|
-
@width = "100%"
|
33
|
-
end
|
34
|
-
if /(?:"|')(?<title>[^"']+)?(?:"|')\s+(?:"|')(?<alt>[^"']+)?(?:"|')/ =~ @title
|
35
|
-
@title = title
|
36
|
-
@alt = alt
|
37
|
-
else
|
38
|
-
@alt = @title.gsub!(/"/, '"') if @title
|
39
|
-
end
|
72
|
+
if %r{(?<classname>\S.*\s+)?(?<protocol>https?://|/)(?<url>\S+)(?<sizes>\s+\d+%?\s+\d+%?)?(?<title>\s+.+)?} =~ markup
|
73
|
+
@class = classname || 'center'
|
74
|
+
@img = "#{protocol}#{url}"
|
75
|
+
@title = title.strip if title
|
76
|
+
parse_sizes(sizes)
|
77
|
+
parse_title(@title)
|
40
78
|
end
|
41
79
|
super
|
42
80
|
end
|
43
81
|
|
44
82
|
def render(context)
|
45
83
|
super
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
"<img class='caption' src='#{@img}' width='100%' height='100%' title='#{@title}' alt='#{@alt}'>" +
|
50
|
-
"</a>" +
|
51
|
-
"<figurecaption class='caption-text'>#{@title}</figurecaption>" +
|
52
|
-
"</figure>"
|
84
|
+
@caption = @title
|
85
|
+
if @img && @width[-1] == '%' # Relative width, so width goes on outer span
|
86
|
+
relative_sized_figure
|
53
87
|
elsif @img # Absolute width, so width goes on the img tag and text span gets sytle-width:@width-15;
|
54
|
-
|
55
|
-
"<a class='image-popup' href='#{@img}'>" +
|
56
|
-
"<img class='caption' src='#{@img}' width='#{@width}px' height='#{@height}px' title='#{@title}' alt='#{@alt}'>" +
|
57
|
-
"</a>" +
|
58
|
-
"<figurecaption class='caption-text' style='width:#{@width.to_i - 10}px;'>#{@title}</figurecaption>" +
|
59
|
-
"</figure>"
|
88
|
+
absolute_sized_figure
|
60
89
|
else
|
61
|
-
|
90
|
+
'Error processing input, expected syntax: {% imgcap [class name(s)] /url/to/image [width height] [title [alt]] %}'
|
62
91
|
end
|
63
92
|
end
|
64
93
|
end
|
65
94
|
|
66
95
|
class Block < Liquid::Block
|
96
|
+
include ImageCaptionFunctions
|
67
97
|
@img = nil
|
68
98
|
@title = nil
|
69
99
|
@class = ''
|
@@ -71,54 +101,29 @@ module Octopress
|
|
71
101
|
@height = ''
|
72
102
|
|
73
103
|
def initialize(tag_name, markup, tokens)
|
74
|
-
if
|
75
|
-
@class =
|
76
|
-
@img =
|
77
|
-
if
|
78
|
-
|
79
|
-
|
80
|
-
if $4 =~ /\s*(\d+%?)\s+(\d+%?)/
|
81
|
-
@width = $1
|
82
|
-
@height = $2
|
83
|
-
elsif @class.rstrip == "right" or @class.rstrip == "left"
|
84
|
-
@width = "33%"
|
85
|
-
else
|
86
|
-
@width = "100%"
|
87
|
-
end
|
88
|
-
if /(?:"|')(?<title>[^"']+)?(?:"|')\s+(?:"|')(?<alt>[^"']+)?(?:"|')/ =~ @title
|
89
|
-
@title = title
|
90
|
-
@alt = alt
|
91
|
-
else
|
92
|
-
@alt = @title.gsub!(/"/, '"') if @title
|
93
|
-
end
|
104
|
+
if %r{(?<classname>\S.*\s+)?(?<protocol>https?://|/)(?<url>\S+)(?<sizes>\s+\d+%?\s+\d+%?)?(?<title>\s+.+)?} =~ markup
|
105
|
+
@class = classname || 'center'
|
106
|
+
@img = "#{protocol}#{url}"
|
107
|
+
@title = title.strip if title
|
108
|
+
parse_sizes(sizes)
|
109
|
+
parse_title(@title)
|
94
110
|
end
|
95
111
|
super
|
96
112
|
end
|
97
113
|
|
98
114
|
def render(context)
|
99
|
-
@caption = super
|
100
115
|
site = context.registers[:site]
|
101
|
-
converter = site.
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
"<img class='caption' src='#{@img}' width='100%' height='100%' title='#{@title}' alt='#{@alt}'>" +
|
106
|
-
"</a>" +
|
107
|
-
"<figurecaption class='caption-text'>#{@caption}</figurecaption>" +
|
108
|
-
"</figure>"
|
116
|
+
converter = site.find_converter_instance(Jekyll::Converters::Markdown)
|
117
|
+
@caption = converter.convert(super).lstrip.rstrip
|
118
|
+
if @img && @width[-1] == '%' # Relative width, so width goes on outer span
|
119
|
+
relative_sized_figure
|
109
120
|
elsif @img # Absolute width, so width goes on the img tag and text span gets sytle-width:@width-15;
|
110
|
-
|
111
|
-
"<a class='image-popup' href='#{@img}'>" +
|
112
|
-
"<img class='caption' src='#{@img}' width='#{@width}px' height='#{@height}px' title='#{@title}' alt='#{@alt}'>" +
|
113
|
-
"</a>" +
|
114
|
-
"<figurecaption class='caption-text' style='width:#{@width.to_i - 10}px;'>#{converter.convert(@caption)}</figurecaption>" +
|
115
|
-
"</figure>"
|
121
|
+
absolute_sized_figure
|
116
122
|
else
|
117
|
-
|
123
|
+
'Error processing input, expected syntax: {% imgcaption [class name(s)] /url/to/image [width height] [title [alt]] %} Caption Text {% endimgcaption %}'
|
118
124
|
end
|
119
125
|
end
|
120
126
|
end
|
121
|
-
|
122
127
|
end
|
123
128
|
end
|
124
129
|
end
|
@@ -127,12 +132,12 @@ Liquid::Template.register_tag('imgcap', Octopress::Tags::ImageCaptionTag::Tag)
|
|
127
132
|
Liquid::Template.register_tag('imgcaption', Octopress::Tags::ImageCaptionTag::Block)
|
128
133
|
|
129
134
|
if defined? Octopress::Docs
|
130
|
-
Octopress::Docs.add(
|
131
|
-
name:
|
132
|
-
gem:
|
133
|
-
description:
|
134
|
-
path: File.expand_path(File.join(File.dirname(__FILE__),
|
135
|
-
source_url:
|
135
|
+
Octopress::Docs.add(
|
136
|
+
name: 'Octopress Image Caption Tag',
|
137
|
+
gem: 'octopress-image-caption-tag',
|
138
|
+
description: 'A tag to create images with pretty captions for Jekyll and Octopress blogs',
|
139
|
+
path: File.expand_path(File.join(File.dirname(__FILE__), '../')),
|
140
|
+
source_url: 'https://github.com/eToThePiIPower/octopress-image-caption-tag',
|
136
141
|
version: Octopress::Tags::ImageCaptionTag::VERSION
|
137
|
-
|
142
|
+
)
|
138
143
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octopress-image-caption-tag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charles Beynon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: pry-byebug
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
127
|
version: '0'
|
114
128
|
requirements: []
|
115
129
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.
|
130
|
+
rubygems_version: 2.5.1
|
117
131
|
signing_key:
|
118
132
|
specification_version: 4
|
119
133
|
summary: A tag to create images with pretty captions for Jekyll and Octopress blogs.
|