octopress-image-tag 1.0.0 → 1.1.0
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/CHANGELOG.md +7 -0
- data/README.md +4 -3
- data/lib/octopress-image-tag.rb +32 -18
- data/lib/octopress-image-tag/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cac073cf84cbb03f15807142de0d18aec59add4
|
4
|
+
data.tar.gz: fb54c9e90176f04a821c565999620565209720a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50bd0c17760e7a50755ffb6efe275041f587eafcc3fe588aed03f9e5132e228493f2a9f46717ff562d7e89ba189f9d9d8f58657f2778658a11d2c4ef52040f8a
|
7
|
+
data.tar.gz: 1237ac401bc769ab34acfd189113b3044ded586df66fc54e9c16962dc590d7fea3a826678df401e08f897704013f1e2d6d73f3205d8856099350e6670fbe4670
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -32,20 +32,21 @@ Then add the gem to your Jekyll configuration.
|
|
32
32
|
```
|
33
33
|
|
34
34
|
Examples:
|
35
|
+
|
35
36
|
```
|
36
37
|
{% img /images/ninja.png "Ninja Attack!" %}
|
37
38
|
{% img left half http://site.com/images/ninja.png title:"Hidden Ninja" %}
|
38
|
-
{% img
|
39
|
+
{% img {{ site.cdn }}/images/ninja.png 150px 150px %}
|
39
40
|
```
|
40
41
|
|
41
42
|
Output:
|
43
|
+
|
42
44
|
```
|
43
45
|
<img src="/images/ninja.png" alt="Ninja Attack!" >
|
44
46
|
<img class="left half" src="http://site.com/images/ninja.png" alt="Hidden Ninja" title="Hidden Ninja" >
|
45
|
-
<img src="http://
|
47
|
+
<img src="http://some.cdn.io/images/ninja.png" width="150px" height="150px" alt="Ninja in the shadows" title="Hidden Ninja">
|
46
48
|
```
|
47
49
|
|
48
|
-
|
49
50
|
## Contributing
|
50
51
|
|
51
52
|
1. Fork it ( https://github.com/[my-github-username]/image-tag/fork )
|
data/lib/octopress-image-tag.rb
CHANGED
@@ -12,38 +12,52 @@ module Octopress
|
|
12
12
|
@img = nil
|
13
13
|
|
14
14
|
def initialize(tag_name, markup, tokens)
|
15
|
-
|
16
|
-
|
15
|
+
@markup = markup
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def render(context)
|
20
|
+
begin
|
21
|
+
attributes = image(context).collect do |k,v|
|
22
|
+
"#{k}=\"#{v}\"" if v
|
23
|
+
end.join(" ")
|
24
|
+
|
25
|
+
"<img #{attributes}>"
|
26
|
+
rescue
|
27
|
+
raise "Error processing input, expected syntax: {% img [class name(s)] [http[s]:/]/path/to/image [width [height]] [title text | \"title text\" [\"alt text\"]] %}"
|
17
28
|
end
|
29
|
+
end
|
18
30
|
|
19
|
-
|
31
|
+
def image(context)
|
32
|
+
@markup = process_liquid(context)
|
20
33
|
|
21
|
-
|
34
|
+
title = /title:['|"](.+?)['|"]/
|
35
|
+
@title = @markup.scan(title).flatten.compact.last
|
36
|
+
@markup.gsub!(title, '')
|
37
|
+
|
38
|
+
if @markup =~ /(?<class>\S.*\s+)?(?<src>(?:https?:\/\/|\/|\S+\/)\S+)(?:\s+(?<width>\d\S+))?(?:\s+(?<height>\d\S+))?(?<alt>\s+.+)?/i
|
22
39
|
attributes = ['class', 'src', 'width', 'height', 'alt']
|
23
|
-
|
24
|
-
text =
|
40
|
+
image = attributes.reduce({}) { |img, attr| img[attr] ||= $~[attr].strip if $~[attr]; img }
|
41
|
+
text = image['alt']
|
25
42
|
|
26
43
|
# Allow parsing "title" "alt"
|
27
44
|
if text =~ /(?:"|')(?<title>[^"']+)?(?:"|')\s+(?:"|')(?<alt>[^"']+)?(?:"|')/
|
28
|
-
|
29
|
-
|
45
|
+
image['title'] = title
|
46
|
+
image['alt'] = alt
|
30
47
|
else
|
31
48
|
# Set alt text and title from text
|
32
|
-
|
49
|
+
image['alt'].gsub!(/"/, '') if image['alt']
|
33
50
|
end
|
34
51
|
end
|
35
52
|
|
36
|
-
|
37
|
-
|
38
|
-
|
53
|
+
image['title'] ||= @title
|
54
|
+
image['alt'] ||= @title
|
55
|
+
|
56
|
+
image
|
39
57
|
end
|
40
58
|
|
41
|
-
def
|
42
|
-
|
43
|
-
"<img #{@img.collect {|k,v| "#{k}=\"#{v}\"" if v}.join(" ")}>"
|
44
|
-
else
|
45
|
-
"Error processing input, expected syntax: {% img [class name(s)] [http[s]:/]/path/to/image [width [height]] [title text | \"title text\" [\"alt text\"]] %}"
|
46
|
-
end
|
59
|
+
def process_liquid(context)
|
60
|
+
Liquid::Template.parse(@markup).render!(context.environments.first)
|
47
61
|
end
|
48
62
|
end
|
49
63
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octopress-image-tag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Mathis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -87,6 +87,7 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
+
- CHANGELOG.md
|
90
91
|
- LICENSE.txt
|
91
92
|
- README.md
|
92
93
|
- lib/octopress-image-tag.rb
|