octopress-image-tag 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fc25280430a21b10fd0e33bcd8adf6f9a68f30ef
4
+ data.tar.gz: bf9bc540e3cb1f8302736ed1498bee8f9c005960
5
+ SHA512:
6
+ metadata.gz: 04f08de32fedc6cdb8fb34ef80f422c92c2f905d15bc2b83899cc7617f4b82523a8e4c40a3b2a3b8e0fd4e416dbec8399570a529d794b4291a8b199dc3cfb04f
7
+ data.tar.gz: 1406408a6e9b049717c7a9a59adcee3638afd3b19623bb1ddc8f83a88052d4ad03233ab38134068a36c08d44c04c9bd15fdf8fe13f72a3e86c5a26e58041a475
@@ -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.
@@ -0,0 +1,55 @@
1
+ # Octopress Image Tag
2
+
3
+ A nice image tag for Jekyll sites.
4
+
5
+ ## Installation
6
+
7
+ ### Using Bundler
8
+
9
+ Add this gem to your site's Gemfile in the `:jekyll_plugins` group:
10
+
11
+ group :jekyll_plugins do
12
+ gem 'octopress-image-tag'
13
+ end
14
+
15
+ Then install the gem with Bundler
16
+
17
+ $ bundle
18
+
19
+ ### Manual Installation
20
+
21
+ $ gem install octopress-image-tag
22
+
23
+ Then add the gem to your Jekyll configuration.
24
+
25
+ gems:
26
+ -octopress-image-tag
27
+
28
+ ## Usage
29
+
30
+ ```
31
+ {% img [class names] url [width [height]] "[alt text]" [title:""] %}
32
+ ```
33
+
34
+ Examples:
35
+ ```
36
+ {% img /images/ninja.png "Ninja Attack!" %}
37
+ {% img left half http://site.com/images/ninja.png title:"Hidden Ninja" %}
38
+ {% img http://site.com/images/ninja.png 150px 150px %}
39
+ ```
40
+
41
+ Output:
42
+ ```
43
+ <img src="/images/ninja.png" alt="Ninja Attack!" >
44
+ <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">
46
+ ```
47
+
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it ( https://github.com/[my-github-username]/image-tag/fork )
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create a new Pull Request
@@ -0,0 +1,64 @@
1
+ require "octopress-image-tag/version"
2
+
3
+ # Title: Simple Image tag for Jekyll
4
+ # Authors: Brandon Mathis http://brandonmathis.com
5
+ # Felix Schäfer, Frederic Hemberger
6
+ #
7
+
8
+ module Octopress
9
+ module Tags
10
+ module ImageTag
11
+ class Tag < Liquid::Tag
12
+ @img = nil
13
+
14
+ def initialize(tag_name, markup, tokens)
15
+ if markup =~ /title:['|"](.+?)['|"]/
16
+ @title = $1.strip
17
+ end
18
+
19
+ markup = markup.gsub(/title:['|"].+?['|"]/, '').strip
20
+
21
+ if markup =~ /(?<class>\S.*\s+)?(?<src>(?:https?:\/\/|\/|\S+\/)\S+)(?:\s+(?<width>\d\S+))?(?:\s+(?<height>\d\S+))?(?<alt>\s+.+)?/i
22
+ attributes = ['class', 'src', 'width', 'height', 'alt']
23
+ @img = attributes.reduce({}) { |img, attr| img[attr] ||= $~[attr].strip if $~[attr]; img }
24
+ text = @img['alt']
25
+
26
+ # Allow parsing "title" "alt"
27
+ if text =~ /(?:"|')(?<title>[^"']+)?(?:"|')\s+(?:"|')(?<alt>[^"']+)?(?:"|')/
28
+ @img['title'] = title
29
+ @img['alt'] = alt
30
+ else
31
+ # Set alt text and title from text
32
+ @img['alt'].gsub!(/"/, '') if @img['alt']
33
+ end
34
+ end
35
+
36
+ @img['title'] ||= @title
37
+ @img['alt'] ||= @title
38
+ super
39
+ end
40
+
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
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ Liquid::Template.register_tag('img', Octopress::Tags::ImageTag::Tag)
54
+
55
+ if defined? Octopress::Docs
56
+ Octopress::Docs.add({
57
+ name: "Octopress Image Tag",
58
+ gem: "octopress-image-tag",
59
+ description: "A nice image tag for Jekyll sites.",
60
+ path: File.expand_path(File.join(File.dirname(__FILE__), "../")),
61
+ source_url: "https://github.com/octopress/image-tag",
62
+ version: Octopress::Tags::ImageTag::VERSION
63
+ })
64
+ end
@@ -0,0 +1,7 @@
1
+ module Octopress
2
+ module Tags
3
+ module ImageTag
4
+ VERSION = "1.0.0"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: octopress-image-tag
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Mathis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-07 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 nice image tag for Jekyll sites.
84
+ email:
85
+ - brandon@imathis.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - LICENSE.txt
91
+ - README.md
92
+ - lib/octopress-image-tag.rb
93
+ - lib/octopress-image-tag/version.rb
94
+ homepage: https://github.com/octopress/image-tag
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.2.2
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: A nice image tag for Jekyll sites.
118
+ test_files: []