octopress-image-caption-tag 0.0.3
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 +7 -0
- data/CHANGELOG.md +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/lib/octopress-image-caption-tag.rb +138 -0
- data/lib/octopress-image-caption-tag/version.rb +7 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 580aafb32a39bc4905bc13addc574516a8185a21
|
4
|
+
data.tar.gz: bfb64275f2b77a1508ac1d9ecc21f4420adbf3f9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f17f366dd0d72b3a1fcc99b116dd120cc91c2af4a07eddba539db01142e9464d5e8d8feee1fbf059a07178dc5fd92742673b832919c2b589c6a26a66a1e8a8a1
|
7
|
+
data.tar.gz: 10f6bc1f9b6585b89c6a776144debe0772148812d617ef1cb171ce65e1d285d9af74d7f589dbf3d24953087c109329d1b0f14b2bc533ae6a02b9c934de9edd5d
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Brandon Mathis
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Octopress Image Caption Tag
|
2
|
+
|
3
|
+
A fork of [octopress/image-tag][img] that incorporates [Robert
|
4
|
+
Anderson's][zerosharp] technique, adds extended features, a block version,
|
5
|
+
and wraps it all up in a gem.
|
6
|
+
|
7
|
+
## Using the Tag version
|
8
|
+
```liquid
|
9
|
+
{% imgcap [right|left|center] url_or_path 200 200 ["Some Title Text" ["Some alt text"]] %}
|
10
|
+
```
|
11
|
+
Width and height can be either absolute or as a percentage. By default, width is
|
12
|
+
set to 33% for right and left aligned and 100% for centered images, and height
|
13
|
+
is auto-scaled.
|
14
|
+
|
15
|
+
If no alt text is specified, the title text is used. The title text will be used
|
16
|
+
for the caption.
|
17
|
+
|
18
|
+
## Using the Block version
|
19
|
+
```liquid
|
20
|
+
{% imgcaption [right|left|center] url_or_path 200 200 ["Some Title Text" ["Some alt text"]] %}
|
21
|
+
**Any** standard [Markdown][md] text can be used in captions using the block
|
22
|
+
version.
|
23
|
+
{% endimgcaption %}
|
24
|
+
```
|
25
|
+
The block version uses the same options as the tag version, but instead of using
|
26
|
+
the title text for the caption, a block is taken to allow Markdown formatting
|
27
|
+
in the caption text.
|
28
|
+
|
29
|
+
## Output
|
30
|
+
The output for either version is the same, and of the form:
|
31
|
+
```html
|
32
|
+
<figure class='caption-wrapper right|left|center' style='width:WIDTH'>
|
33
|
+
<a class='image-popup' href='IMGSRC'>
|
34
|
+
<img class='caption' src='IMGSRC' width='100%' title='TITLE' alt='ALT'>
|
35
|
+
</a>
|
36
|
+
<figcaption class='caption-text'>CAPTION</figcaption>
|
37
|
+
</figure>
|
38
|
+
```
|
39
|
+
|
40
|
+
## Styling
|
41
|
+
This gem does not include stylesheets for the image captions. [Robert
|
42
|
+
Anderson's][zerosharp] original blog post includes a nice example of how to
|
43
|
+
style them.
|
44
|
+
|
45
|
+
|
46
|
+
[md]: https://daringfireball.net/projects/markdown/
|
47
|
+
[img]: https://github.com/octopress/image-tag
|
48
|
+
[zerosharp]: http://blog.zerosharp.com/image-captions-for-octopress/
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require "octopress-image-caption-tag/version"
|
2
|
+
require "liquid"
|
3
|
+
|
4
|
+
# Title: Simple Image tag for Jekyll
|
5
|
+
# Authors: Brandon Mathis http://brandonmathis.com
|
6
|
+
# Felix Schäfer, Frederic Hemberger
|
7
|
+
#
|
8
|
+
|
9
|
+
module Octopress
|
10
|
+
module Tags
|
11
|
+
module ImageCaptionTag
|
12
|
+
class Tag < Liquid::Tag
|
13
|
+
@img = nil
|
14
|
+
@title = nil
|
15
|
+
@class = ''
|
16
|
+
@width = ''
|
17
|
+
@height = ''
|
18
|
+
|
19
|
+
def initialize(tag_name, markup, tokens)
|
20
|
+
if markup =~ /(\S.*\s+)?(https?:\/\/|\/)(\S+)(\s+\d+%?\s+\d+%?)?(\s+.+)?/i
|
21
|
+
@class = $1 || ''
|
22
|
+
@img = $2 + $3
|
23
|
+
if $5
|
24
|
+
@title = $5.strip
|
25
|
+
end
|
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
|
40
|
+
end
|
41
|
+
super
|
42
|
+
end
|
43
|
+
|
44
|
+
def render(context)
|
45
|
+
super
|
46
|
+
if @img && @width[-1] == "%" # Relative width, so width goes on outer span
|
47
|
+
"<figure class='#{('caption-wrapper ' + @class).rstrip}' style='width:#{@width};'>" +
|
48
|
+
"<a class='image-popup' href='#{@img}'>" +
|
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>"
|
53
|
+
elsif @img # Absolute width, so width goes on the img tag and text span gets sytle-width:@width-15;
|
54
|
+
"<figure class='#{('caption-wrapper ' + @class).rstrip}'>" +
|
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>"
|
60
|
+
else
|
61
|
+
"Error processing input, expected syntax: {% imgcap [class name(s)] /url/to/image [width height] [title [alt]] %}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class Block < Liquid::Block
|
67
|
+
@img = nil
|
68
|
+
@title = nil
|
69
|
+
@class = ''
|
70
|
+
@width = ''
|
71
|
+
@height = ''
|
72
|
+
|
73
|
+
def initialize(tag_name, markup, tokens)
|
74
|
+
if markup =~ /(\S.*\s+)?(https?:\/\/|\/)(\S+)(\s+\d+%?\s+\d+%?)?(\s+.+)?/i
|
75
|
+
@class = $1 || ''
|
76
|
+
@img = $2 + $3
|
77
|
+
if $5
|
78
|
+
@title = $5.strip
|
79
|
+
end
|
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
|
94
|
+
end
|
95
|
+
super
|
96
|
+
end
|
97
|
+
|
98
|
+
def render(context)
|
99
|
+
@caption = super
|
100
|
+
site = context.registers[:site]
|
101
|
+
converter = site.getConverterImpl(Jekyll::Converters::Markdown)
|
102
|
+
if @img && @width[-1] == "%" # Relative width, so width goes on outer span
|
103
|
+
"<figure class='#{('caption-wrapper ' + @class).rstrip}' style='width:#{@width};'>" +
|
104
|
+
"<a class='image-popup' href='#{@img}'>" +
|
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>"
|
109
|
+
elsif @img # Absolute width, so width goes on the img tag and text span gets sytle-width:@width-15;
|
110
|
+
"<figure class='#{('caption-wrapper ' + @class).rstrip}'>" +
|
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>"
|
116
|
+
else
|
117
|
+
"Error processing input, expected syntax: {% imgcaption [class name(s)] /url/to/image [width height] [title [alt]] %} Caption Text {% endimgcaption %}"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
Liquid::Template.register_tag('imgcap', Octopress::Tags::ImageCaptionTag::Tag)
|
127
|
+
Liquid::Template.register_tag('imgcaption', Octopress::Tags::ImageCaptionTag::Block)
|
128
|
+
|
129
|
+
if defined? Octopress::Docs
|
130
|
+
Octopress::Docs.add({
|
131
|
+
name: "Octopress Image Caption Tag",
|
132
|
+
gem: "octopress-image-caption-tag",
|
133
|
+
description: "A tag to create images with pretty captions for Jekyll and Octopress blogs",
|
134
|
+
path: File.expand_path(File.join(File.dirname(__FILE__), "../")),
|
135
|
+
source_url: "https://github.com/eToThePiIPower/octopress-image-caption-tag",
|
136
|
+
version: Octopress::Tags::ImageCaptionTag::VERSION
|
137
|
+
})
|
138
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: octopress-image-caption-tag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Charles Beynon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: clash
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
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'
|
83
|
+
description: A tag to create images with pretty captions for Jekyll and Octopress
|
84
|
+
blogs.
|
85
|
+
email:
|
86
|
+
- eToThePiIPower@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- CHANGELOG.md
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- lib/octopress-image-caption-tag.rb
|
95
|
+
- lib/octopress-image-caption-tag/version.rb
|
96
|
+
homepage: https://github.com/eToThePiIPower/octopress-image-caption-tag
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.4.8
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: A tag to create images with pretty captions for Jekyll and Octopress blogs.
|
120
|
+
test_files: []
|