jekyll-auto-image 1.1.2 → 1.1.3

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: cec08a8d995e0f3265c5d360c691511e7419b519
4
- data.tar.gz: 8e8215eb24e8d68009eecf9cd61ea75048be27b6
3
+ metadata.gz: 8e06d01730c1b039c6a772f4fac7d18ddfc15fe1
4
+ data.tar.gz: b28ccd64cdffe03c513158af14f462f66f046903
5
5
  SHA512:
6
- metadata.gz: f318489b1f8066a61ebe1d920a034e5b31acefe48d7db75df41be8c1584208ae16096c3c9ef24e1c09221acbb4ca2d04afee2360c9e535728f3ad46282afc02d
7
- data.tar.gz: 3d6f34afb694bfe99241c63e7a5c482bd66f2580c08a6c527372ff6e8e75f4a7ca686bc5319804f6551fb39752630726ab512efabc02e6536972f1e3968e5065
6
+ metadata.gz: 1eeb44f69a12c42a831a5451ab61fa702649392c0b99fc73eca0e77ce4c39d8f0a2ff6f6eb286eefb831335a88d9ccae98c2320c2bc5ab07cf6ac6196183ae24
7
+ data.tar.gz: c68a33a10d853faa6967e5430ecfed4a74eaa81af3ffb3d49f6187e7b4b29e8af809c8ab33b942dcdd79a445f6fbd101badb51ef3c96862e448dcc421481672f
@@ -10,7 +10,7 @@
10
10
  # distribute, sublicense, and/or sell copies of the Software, and to
11
11
  # permit persons to whom the Software is furnished to do so, subject to
12
12
  # the following conditions:
13
- #
13
+ #
14
14
  # The above copyright notice and this permission notice shall be
15
15
  # included in all copies or substantial portions of the Software.
16
16
  #
@@ -27,23 +27,23 @@ require "jekyll-auto-image/version"
27
27
  require "jekyll"
28
28
 
29
29
  module Jekyll
30
-
30
+
31
31
  #
32
32
  # Auto Image Generator
33
- #
33
+ #
34
34
  # Sets {{page.image}} variable in liquid with the following fallback:
35
- #
35
+ #
36
36
  # 1) image value in front matter
37
37
  # 2) first image in the post/pàge
38
38
  # 3) _config.yaml image default
39
39
  # 4) nothing (not set)
40
40
  #
41
- #
41
+ #
42
42
  class AutoImageGenerator < Generator
43
-
43
+
44
44
  def generate(site)
45
45
  @site = site
46
-
46
+
47
47
  site.pages.each do |page|
48
48
  img = get_image(page)
49
49
  page.data['image'] = img if img
@@ -55,21 +55,23 @@ module Jekyll
55
55
  #puts post.class
56
56
  #puts post.inspect
57
57
  #puts post.data.inspect
58
- #puts "-----"
58
+ #puts "-----"
59
59
  #puts post.output
60
60
  #puts "----"
61
61
  img = get_image(post)
62
62
  post.data['image'] = img if img
63
63
  end
64
64
  end # generate
65
-
65
+
66
+ #
67
+ # page: is either a Jekyll::Page or a Jekyll::Post in 2.x. In Jekyll 3.0 is Jekyll::Document and
68
+ # in Jekyll 3.3 is either Jekyll::Page or Jekyll::Document (fascinating!)
66
69
  #
67
- # page: is either a Jekyll::Page or a Jekyll::post
68
70
  # returns the path of the first image found in the contents
69
- # of the page/post
71
+ # of the page/post
70
72
  #
71
73
  def get_image(page)
72
-
74
+
73
75
  # debug lines
74
76
  #puts page.title
75
77
  #puts page.name
@@ -78,20 +80,25 @@ module Jekyll
78
80
  if page.data['image']
79
81
  return page.data['image']
80
82
  end
83
+
84
+ # fix for jekyll 3.3.0,
85
+ @site.config['kramdown'] = @site.config['kramdown'].dup
86
+
81
87
  # convert the contents to html, and extract the first <img src="" apearance
82
88
  # I know, it's not efficient, but rather easy to implement :)
83
-
84
- if page.class == Jekyll::Document # for jekyll 3.0 posts & collections
89
+
90
+ # Convertible for jekyll 3.0 and 3.3 posts & collections
91
+ if page.class < Jekyll::Convertible || page.class == Jekyll::Document
85
92
  htmled = Jekyll::Renderer.new(@site, page, @site.site_payload).convert(page.content)
86
- else
93
+ else
87
94
  htmled = page.transform # for jekyll 2.x pages
88
95
  end
89
-
96
+
90
97
  img_url = htmled.match(/<img.*\ssrc=[\"\']([\S.]+)[\"\']/i)
91
- return img_url[1] if img_url != nil
98
+ return img_url[1] if img_url != nil
92
99
  return @site.config['image'] if @site.config['image'] != nil
93
100
  return nil
94
101
  end
95
-
102
+
96
103
  end # class
97
104
  end # module
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module AutoImage
3
- VERSION = "1.1.2"
3
+ VERSION = "1.1.3"
4
4
  end
5
5
  end
@@ -1,100 +1,100 @@
1
1
  require 'helper'
2
2
 
3
3
  class Jekyll::AutoImageTest < Minitest::Test
4
- def set_page_image (page, image_path)
4
+ def set_page_image (page, image_path)
5
5
  page.instance_variable_set(:@content, '<img attribute="blabla" src="' + image_path + '">')
6
6
  end
7
-
7
+
8
8
  context 'AutoImage' do
9
-
9
+
10
10
  setup do
11
-
11
+
12
12
  @default_image_path = '/assets/default_image.png'
13
-
14
- Jekyll.logger.log_level = :error
15
-
13
+
14
+ Jekyll.logger.log_level = :error
15
+
16
16
  #
17
- # Sites
17
+ # Sites
18
18
  #
19
- @config = Jekyll::Configuration::DEFAULTS.clone
19
+ @config = Jekyll::Configuration::DEFAULTS.dup
20
20
  @config['destination'] = File.expand_path('../tmp/', __FILE__)
21
21
  @site = Jekyll::Site.new(@config)
22
-
22
+
23
23
  # config with default image
24
- @config_with_image = @config.clone
24
+ @config_with_image = @config.dup
25
25
  @config_with_image['image'] = @default_image_path
26
26
  @site_with_default_image = Jekyll::Site.new(@config_with_image)
27
-
27
+
28
28
  # posts are in test/fixtures/_posts/
29
- @config_with_posts = @config.clone
29
+ @config_with_posts = @config.dup
30
30
  @config_with_posts['source'] = File.expand_path('../fixtures/', __FILE__)
31
31
  @site_with_posts = Jekyll::Site.new(@config_with_posts)
32
32
  # now add the collection
33
33
  @posts_collection = Jekyll::Collection.new(@site_with_posts, 'posts')
34
-
34
+
35
35
  # Pages
36
36
  @no_image_page = Jekyll::Page.new(@site, File.expand_path('../fixtures/', __FILE__), '', 'no-image.md')
37
37
  @front_matter_image_page = Jekyll::Page.new(@site, File.expand_path('../fixtures/', __FILE__), '', 'front-matter-image.md')
38
38
  @contents_image_page = Jekyll::Page.new(@site, File.expand_path('../fixtures/', __FILE__), '', 'contents-image.md')
39
39
  @contents_html_page = Jekyll::Page.new(@site, File.expand_path('../fixtures/', __FILE__), '', 'contents-html.html')
40
-
40
+
41
41
  # Posts as collections
42
42
  #@contents_html_page = Jekyll::Document.new(File.expand_path('../fixtures/_posts/contents-image.md', __FILE__), {:site =>@site,:collection =>'post'})
43
-
44
-
43
+
44
+
45
45
  @auto_image = Jekyll::AutoImageGenerator.new
46
46
  @auto_image.generate(@site)
47
47
  @auto_image_with_default_image = Jekyll::AutoImageGenerator.new
48
48
  @auto_image_with_default_image.generate(@site_with_default_image)
49
-
50
-
49
+
50
+
51
51
  #@page.instance_variable_set(:@content, '<div>ivan.tse1@gmail.com</div>')
52
52
  #@site.pages << @page
53
53
  #@email_link = '<div><a href="mailto:ivan.tse1@gmail.com">ivan.tse1@gmail.com</a></div>'
54
54
  end
55
-
56
-
55
+
56
+
57
57
  #
58
58
  # FALLBACK LOGIC TESTS
59
59
  #
60
-
60
+
61
61
  # Tests without {{site.image}}
62
-
62
+
63
63
  should 'not be defined site image by default' do
64
- assert_nil @site.config['image']
64
+ assert_nil @site.config['image']
65
65
  end
66
-
66
+
67
67
  should 'not return image when not set in config and not included in page' do
68
68
  assert_nil @auto_image.get_image(@no_image_page)
69
69
  end
70
-
70
+
71
71
  should 'use front matter image whenever defined' do
72
72
  assert_equal @front_matter_image_page.data['image'], @auto_image.get_image(@front_matter_image_page)
73
73
  end
74
-
74
+
75
75
  should 'detect contents image on markdown' do
76
76
  assert_equal '/assets/contents-image.png', @auto_image.get_image(@contents_image_page)
77
77
  end
78
-
78
+
79
79
  should 'detect contents image in html' do
80
80
  assert_equal '/assets/contents-html.png', @auto_image.get_image(@contents_html_page)
81
81
  end
82
-
82
+
83
83
  # Tests with {{site.image}} defined
84
-
84
+
85
85
  should 'be defined site_image in config' do
86
- assert_equal @default_image_path, @site_with_default_image.config['image']
87
- end
88
-
86
+ assert_equal @default_image_path, @site_with_default_image.config['image']
87
+ end
88
+
89
89
  should 'return default image when page does not have image' do
90
90
  assert_equal @site_with_default_image.config['image'], @auto_image_with_default_image.get_image(@no_image_page)
91
- end
92
-
91
+ end
92
+
93
93
  should 'return front matter image even if default image is defined' do
94
94
  assert_equal @front_matter_image_page.data['image'], @auto_image_with_default_image.get_image(@front_matter_image_page)
95
- end
96
-
97
-
95
+ end
96
+
97
+
98
98
  #
99
99
  # Tests to check if the regexp works in some use cases
100
100
  #
@@ -103,7 +103,7 @@ class Jekyll::AutoImageTest < Minitest::Test
103
103
  set_page_image(@no_image_page,image)
104
104
  assert image, @auto_image.get_image(@no_image_page)
105
105
  end
106
-
106
+
107
107
  #
108
108
  # Tests to check if the regexp works in some use cases
109
109
  #
@@ -112,7 +112,7 @@ class Jekyll::AutoImageTest < Minitest::Test
112
112
  set_page_image(@no_image_page,image)
113
113
  assert image, @auto_image.get_image(@no_image_page)
114
114
  end
115
-
115
+
116
116
  #
117
117
  # Tests to check if the regexp works in some use cases
118
118
  #
@@ -121,7 +121,7 @@ class Jekyll::AutoImageTest < Minitest::Test
121
121
  set_page_image(@no_image_page,image)
122
122
  assert_nil @auto_image.get_image(@no_image_page)
123
123
  end
124
-
124
+
125
125
  #
126
126
  # Generate site with data
127
127
  #
@@ -133,18 +133,18 @@ class Jekyll::AutoImageTest < Minitest::Test
133
133
  @auto_image.get_image(@contents_html_page)
134
134
  assert_equal '/assets/contents-html.png', @auto_image.get_image(@contents_html_page)
135
135
  end
136
-
136
+
137
137
  should 'generate a site with post as part of collection' do
138
- #puts @posts_collection.directory
138
+ #puts @posts_collection.directory
139
139
  assert_equal 1, @posts_collection.entries.length
140
140
  assert_equal 1, @posts_collection.filtered_entries.length
141
- @site_with_posts.process
141
+ @site_with_posts.process
142
142
  @auto_image.generate(@site_with_posts)
143
143
  assert_equal 1, @site_with_posts.posts.docs.length
144
144
  #puts @site_with_posts.collections.inspect
145
145
  assert_equal '/assets/contents-image.png', @auto_image.get_image(@site_with_posts.posts.docs[0])
146
146
  end
147
-
148
-
147
+
148
+
149
149
  end
150
- end
150
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-auto-image
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - merlos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-15 00:00:00.000000000 Z
11
+ date: 2016-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.2.2
126
+ rubygems_version: 2.4.8
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: jekyll plugin that makes available the first image of a post in the template
@@ -135,4 +135,3 @@ test_files:
135
135
  - test/fixtures/no-image.md
136
136
  - test/helper.rb
137
137
  - test/test_jekyll_auto_image.rb
138
- has_rdoc: