jekyll-bits 0.4.1 → 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/.rubocop.yml +8 -0
- data/README.md +6 -3
- data/Rakefile +2 -12
- data/jekyll-bits.gemspec +2 -2
- data/lib/jekyll-bits/picture.rb +88 -0
- data/lib/jekyll-bits.rb +3 -44
- data/test/test_picture.rb +73 -0
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 162d0a9061d3e1902780dd3b30948da8a6498b1d
|
4
|
+
data.tar.gz: feb40e9c53871753e24f71b29fee3f25c92916b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7c5f566cb617f5db19ce11d47cb61d026f223e4c31a7ed59d48ac3033eb6b41488779e73b89bc93de46012c778c97026d6b719a6c16beb1749c243e6878359b
|
7
|
+
data.tar.gz: 425bde36082f1a9fd24526e1d08984b08361c0a1875ece7d262c0afe8f971e1852f03bd4d883583f961302194b704d86841545ed8d036e485b4de36c42731a82
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -32,9 +32,12 @@ Or with more details:
|
|
32
32
|
```yaml
|
33
33
|
---
|
34
34
|
jb_picture:
|
35
|
-
src:
|
36
|
-
alt:
|
37
|
-
href:
|
35
|
+
src: SRC attribute of <IMG> (mandatory)
|
36
|
+
alt: ALT attribute of <IMG> (optional)
|
37
|
+
href: HREF attribute of <A> (optional)
|
38
|
+
caption: text of <FIGCAPTION> (optional)
|
39
|
+
width: width in pixels (optional)
|
40
|
+
height: height in pixels (optional)
|
38
41
|
---
|
39
42
|
```
|
40
43
|
|
data/Rakefile
CHANGED
@@ -22,10 +22,9 @@
|
|
22
22
|
|
23
23
|
require 'rubygems'
|
24
24
|
require 'rake'
|
25
|
-
require 'rdoc'
|
26
25
|
require 'rake/clean'
|
27
26
|
|
28
|
-
CLEAN = FileList['coverage'
|
27
|
+
CLEAN = FileList['coverage']
|
29
28
|
|
30
29
|
def name
|
31
30
|
@name ||= File.basename(Dir['*.gemspec'].first, '.*')
|
@@ -35,7 +34,7 @@ def version
|
|
35
34
|
Gem::Specification.load(Dir['*.gemspec'].first).version
|
36
35
|
end
|
37
36
|
|
38
|
-
task default: [:clean, :test, :
|
37
|
+
task default: [:clean, :test, :rubocop]
|
39
38
|
|
40
39
|
require 'rake/testtask'
|
41
40
|
desc 'Run all unit tests'
|
@@ -45,15 +44,6 @@ Rake::TestTask.new(:test) do |test|
|
|
45
44
|
test.verbose = false
|
46
45
|
end
|
47
46
|
|
48
|
-
require 'rdoc/task'
|
49
|
-
desc 'Build RDoc documentation'
|
50
|
-
Rake::RDocTask.new do |rdoc|
|
51
|
-
rdoc.rdoc_dir = 'rdoc'
|
52
|
-
rdoc.title = "#{name} #{version}"
|
53
|
-
rdoc.rdoc_files.include('README*')
|
54
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
-
end
|
56
|
-
|
57
47
|
require 'rubocop/rake_task'
|
58
48
|
desc 'Run RuboCop on all directories'
|
59
49
|
RuboCop::RakeTask.new(:rubocop) do |task|
|
data/jekyll-bits.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.rubygems_version = '2.2.2'
|
9
9
|
s.required_ruby_version = '>= 1.9.3'
|
10
10
|
s.name = 'jekyll-bits'
|
11
|
-
s.version = '0.
|
11
|
+
s.version = '0.5'
|
12
12
|
s.license = 'MIT'
|
13
13
|
s.summary = 'Jekyll Bits'
|
14
14
|
s.description = 'Useful and very simple Jekyll plugins'
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_runtime_dependency('jekyll', '>=1.5.1')
|
23
23
|
s.add_development_dependency 'bundler', '~> 1.5'
|
24
24
|
s.add_development_dependency 'coveralls', '0.7.0'
|
25
|
-
s.add_development_dependency '
|
25
|
+
s.add_development_dependency 'test-unit', '3.0.8'
|
26
26
|
s.add_development_dependency 'rake'
|
27
27
|
s.add_development_dependency 'rdoc', '3.11'
|
28
28
|
s.add_development_dependency 'rubocop', '0.46.0'
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2016 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'liquid'
|
26
|
+
|
27
|
+
# Jekyll module
|
28
|
+
module Jekyll
|
29
|
+
# All our custom filters
|
30
|
+
module JbFilters
|
31
|
+
def jb_picture_head(page)
|
32
|
+
yaml = page['jb_picture']
|
33
|
+
return unless yaml
|
34
|
+
if yaml.is_a?(Hash)
|
35
|
+
raise "src is absent for jb_picture in #{page.url}" unless yaml['src']
|
36
|
+
src = yaml['src']
|
37
|
+
else
|
38
|
+
src = yaml
|
39
|
+
end
|
40
|
+
"<meta property='og:image' content='#{src}'/>"
|
41
|
+
end
|
42
|
+
|
43
|
+
def jb_picture_body(page)
|
44
|
+
yaml = page['jb_picture']
|
45
|
+
return unless yaml
|
46
|
+
html = "<img itemprop='image' alt='"
|
47
|
+
if yaml.is_a?(Hash) && yaml['alt']
|
48
|
+
html += CGI.escapeHTML(yaml['alt'])
|
49
|
+
else
|
50
|
+
html += 'front image'
|
51
|
+
end
|
52
|
+
html += "' src='"
|
53
|
+
if yaml.is_a?(Hash)
|
54
|
+
raise "src is absent for jb_picture in #{page.url}" unless yaml['src']
|
55
|
+
html += CGI.escapeElement(yaml['src'])
|
56
|
+
else
|
57
|
+
html += yaml
|
58
|
+
end
|
59
|
+
html += "'"
|
60
|
+
html += " width='#{yaml['width']}'" \
|
61
|
+
if yaml.is_a?(Hash) && yaml['width']
|
62
|
+
html += " height='#{yaml['height']}'" \
|
63
|
+
if yaml.is_a?(Hash) && yaml['height']
|
64
|
+
html += '/>'
|
65
|
+
html = "<a href='#{CGI.escapeHTML(yaml['href'])}'>#{html}</a>" \
|
66
|
+
if yaml.is_a?(Hash) && yaml['href']
|
67
|
+
html = "<figure class='jb_picture'>" + html
|
68
|
+
html += "<figcaption>#{CGI.escapeHTML(yaml['caption'])}</figcaption>" \
|
69
|
+
if yaml.is_a?(Hash) && yaml['caption']
|
70
|
+
html + '</figure>'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Box for testing and calling static methods.
|
75
|
+
class JbBox
|
76
|
+
include JbFilters
|
77
|
+
end
|
78
|
+
|
79
|
+
# Jekyll block
|
80
|
+
class JbPictureBlock < Liquid::Tag
|
81
|
+
def render(context)
|
82
|
+
JbBox.new.jb_picture_body(context.registers[:page])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
Liquid::Template.register_filter(Jekyll::JbFilters)
|
88
|
+
Liquid::Template.register_tag('jb_picture_body', Jekyll::JbPictureBlock)
|
data/lib/jekyll-bits.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
1
3
|
# (The MIT License)
|
2
4
|
#
|
3
5
|
# Copyright (c) 2016 Yegor Bugayenko
|
@@ -20,47 +22,4 @@
|
|
20
22
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
23
|
# SOFTWARE.
|
22
24
|
|
23
|
-
require '
|
24
|
-
|
25
|
-
puts 'jekyll-bits is alive'
|
26
|
-
|
27
|
-
# Jekyll module
|
28
|
-
module Jekyll
|
29
|
-
# All our custom filters
|
30
|
-
module JbFilters
|
31
|
-
def jb_picture_head(page)
|
32
|
-
yaml = page['jb_picture']
|
33
|
-
return unless yaml
|
34
|
-
src = if yaml.is_a?(Array)
|
35
|
-
yaml['src']
|
36
|
-
else
|
37
|
-
yaml
|
38
|
-
end
|
39
|
-
"<meta property='og:image' content='#{src}'/>"
|
40
|
-
end
|
41
|
-
|
42
|
-
def jb_picture_body(page)
|
43
|
-
yaml = page['jb_picture']
|
44
|
-
return unless yaml
|
45
|
-
if yaml.is_a?(Array)
|
46
|
-
"<figure class='jb_picture'><a \
|
47
|
-
href='#{CGI.escapeElement(yaml['href'])}'>\
|
48
|
-
<img alt='#{CGI.escapeElement(yaml['alt'])}' \
|
49
|
-
src='#{CGI.escapeElement(yaml['src'])}'/></a></figure>"
|
50
|
-
else
|
51
|
-
"<figure class='jb_picture'><img \
|
52
|
-
alt='front picture' src='#{CGI.escapeElement(yaml)}'/></figure>"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# Jekyll block
|
58
|
-
class JbPictureBlock < Liquid::Tag
|
59
|
-
def render(context)
|
60
|
-
Jekyll::JbFilters.jb_picture_body(context.registers[:page])
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
Liquid::Template.register_filter(Jekyll::JbFilters)
|
66
|
-
Liquid::Template.register_tag('jb_picture_body', Jekyll::JbPictureBlock)
|
25
|
+
require 'jekyll-bits/picture'
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2016 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'test/unit'
|
26
|
+
require_relative '../lib/jekyll-bits/picture'
|
27
|
+
|
28
|
+
# Picture test.
|
29
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
+
# Copyright:: Copyright (c) 2016 Yegor Bugayenko
|
31
|
+
# License:: MIT
|
32
|
+
module Jekyll
|
33
|
+
class TestPicture < Test::Unit::TestCase
|
34
|
+
def test_generates_html_simple_head
|
35
|
+
html = JbBox.new.jb_picture_head('jb_picture' => '/img.png')
|
36
|
+
assert_match(/meta/, html)
|
37
|
+
assert_match(/img\.png/, html)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_generates_html_complex_head
|
41
|
+
html = JbBox.new.jb_picture_head(
|
42
|
+
'jb_picture' => {
|
43
|
+
'src' => '/img2.png'
|
44
|
+
}
|
45
|
+
)
|
46
|
+
assert_match(/meta/, html)
|
47
|
+
assert_match(/img2\.png/, html)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_generates_html_simple_body
|
51
|
+
html = JbBox.new.jb_picture_body('jb_picture' => '/img1.png')
|
52
|
+
assert_match(/img/, html)
|
53
|
+
assert_match(/figure/, html)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_generates_html_complex_body
|
57
|
+
html = JbBox.new.jb_picture_body(
|
58
|
+
'jb_picture' => {
|
59
|
+
'src' => '/img1.png',
|
60
|
+
'href' => 'http://www.yegor256.com',
|
61
|
+
'caption' => 'it is <simple>',
|
62
|
+
'alt' => "nothing 'to' say",
|
63
|
+
'width' => 500
|
64
|
+
}
|
65
|
+
)
|
66
|
+
assert_match(/figcaption/, html)
|
67
|
+
assert_match(/figure/, html)
|
68
|
+
assert_match(/<figcaption>it is <simple>/, html)
|
69
|
+
assert_match(/alt='nothing 'to' say'/, html)
|
70
|
+
assert_match(/width='500'/, html)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-bits
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -53,19 +53,19 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.7.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: test-unit
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 3.0.8
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 3.0.8
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,6 +140,8 @@ files:
|
|
140
140
|
- Rakefile
|
141
141
|
- jekyll-bits.gemspec
|
142
142
|
- lib/jekyll-bits.rb
|
143
|
+
- lib/jekyll-bits/picture.rb
|
144
|
+
- test/test_picture.rb
|
143
145
|
homepage: http://github.com/yegor256/jekyll-bits
|
144
146
|
licenses:
|
145
147
|
- MIT
|
@@ -165,4 +167,5 @@ rubygems_version: 2.4.5.1
|
|
165
167
|
signing_key:
|
166
168
|
specification_version: 2
|
167
169
|
summary: Jekyll Bits
|
168
|
-
test_files:
|
170
|
+
test_files:
|
171
|
+
- test/test_picture.rb
|