octopress-image-tag 1.0.0 → 1.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
  SHA1:
3
- metadata.gz: fc25280430a21b10fd0e33bcd8adf6f9a68f30ef
4
- data.tar.gz: bf9bc540e3cb1f8302736ed1498bee8f9c005960
3
+ metadata.gz: 7cac073cf84cbb03f15807142de0d18aec59add4
4
+ data.tar.gz: fb54c9e90176f04a821c565999620565209720a5
5
5
  SHA512:
6
- metadata.gz: 04f08de32fedc6cdb8fb34ef80f422c92c2f905d15bc2b83899cc7617f4b82523a8e4c40a3b2a3b8e0fd4e416dbec8399570a529d794b4291a8b199dc3cfb04f
7
- data.tar.gz: 1406408a6e9b049717c7a9a59adcee3638afd3b19623bb1ddc8f83a88052d4ad03233ab38134068a36c08d44c04c9bd15fdf8fe13f72a3e86c5a26e58041a475
6
+ metadata.gz: 50bd0c17760e7a50755ffb6efe275041f587eafcc3fe588aed03f9e5132e228493f2a9f46717ff562d7e89ba189f9d9d8f58657f2778658a11d2c4ef52040f8a
7
+ data.tar.gz: 1237ac401bc769ab34acfd189113b3044ded586df66fc54e9c16962dc590d7fea3a826678df401e08f897704013f1e2d6d73f3205d8856099350e6670fbe4670
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ### 1.1.0 (2015-01-07)
4
+ - New: Liquid can be processed in tag.
5
+
6
+ ### 1.0.0 (2015-01-07)
7
+ - Initial release
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 http://site.com/images/ninja.png 150px 150px %}
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://site.com/images/ninja.png" width="150px" height="150px" alt="Ninja in the shadows" title="Hidden Ninja">
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 )
@@ -12,38 +12,52 @@ module Octopress
12
12
  @img = nil
13
13
 
14
14
  def initialize(tag_name, markup, tokens)
15
- if markup =~ /title:['|"](.+?)['|"]/
16
- @title = $1.strip
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
- markup = markup.gsub(/title:['|"].+?['|"]/, '').strip
31
+ def image(context)
32
+ @markup = process_liquid(context)
20
33
 
21
- if markup =~ /(?<class>\S.*\s+)?(?<src>(?:https?:\/\/|\/|\S+\/)\S+)(?:\s+(?<width>\d\S+))?(?:\s+(?<height>\d\S+))?(?<alt>\s+.+)?/i
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
- @img = attributes.reduce({}) { |img, attr| img[attr] ||= $~[attr].strip if $~[attr]; img }
24
- text = @img['alt']
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
- @img['title'] = title
29
- @img['alt'] = alt
45
+ image['title'] = title
46
+ image['alt'] = alt
30
47
  else
31
48
  # Set alt text and title from text
32
- @img['alt'].gsub!(/"/, '') if @img['alt']
49
+ image['alt'].gsub!(/"/, '') if image['alt']
33
50
  end
34
51
  end
35
52
 
36
- @img['title'] ||= @title
37
- @img['alt'] ||= @title
38
- super
53
+ image['title'] ||= @title
54
+ image['alt'] ||= @title
55
+
56
+ image
39
57
  end
40
58
 
41
- def render(context)
42
- if @img
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
@@ -1,7 +1,7 @@
1
1
  module Octopress
2
2
  module Tags
3
3
  module ImageTag
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
6
6
  end
7
7
  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.0.0
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-07 00:00:00.000000000 Z
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