jekyll-auto-image 1.1.0 → 1.1.1

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: f17eb0c04f0edea10bdc1501e63e1640c248340f
4
- data.tar.gz: f92a678b7163ef0283c98e2fe52e013e14c5c152
3
+ metadata.gz: f15dab8cf06765361ee12b89df02e0fb88870448
4
+ data.tar.gz: 7385a9d597ec8ed3d1c6e80bf6d66ff831cc2b24
5
5
  SHA512:
6
- metadata.gz: 0d3eeb9c6ad6d1a82b75def4638baa139f1c237eefdd4affc63f9f63cb18ee102d4949c56fb80ddcc9f462ee7f4bd3794d604e58142ff8c086a86f693a6bf54d
7
- data.tar.gz: 0056012c2c0893b2100c67292ff5af1faa2f1bec80453367a2614af2161ce7d75719630efe76939e81166daad4f96ff791228ea91949ae004d03b0845c8d1220
6
+ metadata.gz: 0dcd31f53aff84cf38b26d8507a81a0c07909cdf04b386a6786857f3b3006264c9c61bca53e43f8ee1f285c57d7e6f80eae9e9bfb84fe437dd9ea5fe817016f7
7
+ data.tar.gz: b97d07184afb2d7b225b21786646b40ae92f7dc87d702f8685058168212158678485df62d0f3eab70da1b6568d16747b19ee63872c317e3b51dbf1e6910bc514
@@ -43,12 +43,21 @@ module Jekyll
43
43
 
44
44
  def generate(site)
45
45
  @site = site
46
+
46
47
  site.pages.each do |page|
47
48
  img = get_image(page)
48
49
  page.data['image'] = img if img
49
50
  end
50
51
  # Now do the same with posts
51
- site.posts.docs do |post|
52
+ site.posts.docs.each do |post|
53
+ #puts "hola"
54
+ #puts Jekyll::VERSION
55
+ #puts post.class
56
+ #puts post.inspect
57
+ #puts post.data.inspect
58
+ #puts "-----"
59
+ #puts post.output
60
+ #puts "----"
52
61
  img = get_image(post)
53
62
  post.data['image'] = img if img
54
63
  end
@@ -65,13 +74,19 @@ module Jekyll
65
74
  #puts page.title
66
75
  #puts page.name
67
76
  #puts page.ext
68
- #puts site.converters.select { |c| c.matches(page.ext) }.sort
77
+ #puts @site.converters.select { |c| c.matches(page.ext) }.sort
69
78
  if page.data['image']
70
79
  return page.data['image']
71
80
  end
72
81
  # convert the contents to html, and extract the first <img src="" apearance
73
82
  # I know, it's not efficient, but rather easy to implement :)
74
- htmled = page.transform
83
+
84
+ if page.class == Jekyll::Document # for jekyll 3.0 posts & collections
85
+ htmled = Jekyll::Renderer.new(@site, page, @site.site_payload).run
86
+ else
87
+ htmled = page.transform # for jekyll 2.x pages
88
+ end
89
+
75
90
  img_url = htmled.match(/<img.*\ssrc=[\"\']([\S.]+)[\"\']/i)
76
91
  return img_url[1] if img_url != nil
77
92
  return @site.config['image'] if @site.config['image'] != nil
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module AutoImage
3
- VERSION = "1.1.0"
3
+ VERSION = "1.1.1"
4
4
  end
5
5
  end
@@ -10,13 +10,27 @@ class Jekyll::AutoImageTest < Minitest::Test
10
10
  setup do
11
11
 
12
12
  @default_image_path = '/assets/default_image.png'
13
-
14
- # Sites
15
- @site = Jekyll::Site.new(Jekyll::Configuration::DEFAULTS)
13
+
14
+ Jekyll.logger.log_level = :error
16
15
 
16
+ #
17
+ # Sites
18
+ #
17
19
  @config = Jekyll::Configuration::DEFAULTS.clone
18
- @config['image'] = @default_image_path
19
- @site_with_default_image = Jekyll::Site.new(@config)
20
+ @config['destination'] = File.expand_path('../tmp/', __FILE__)
21
+ @site = Jekyll::Site.new(@config)
22
+
23
+ # config with default image
24
+ @config_with_image = @config.clone
25
+ @config_with_image['image'] = @default_image_path
26
+ @site_with_default_image = Jekyll::Site.new(@config_with_image)
27
+
28
+ # posts are in test/fixtures/_posts/
29
+ @config_with_posts = @config.clone
30
+ @config_with_posts['source'] = File.expand_path('../fixtures/', __FILE__)
31
+ @site_with_posts = Jekyll::Site.new(@config_with_posts)
32
+ # now add the collection
33
+ @posts_collection = Jekyll::Collection.new(@site_with_posts, 'posts')
20
34
 
21
35
  # Pages
22
36
  @no_image_page = Jekyll::Page.new(@site, File.expand_path('../fixtures/', __FILE__), '', 'no-image.md')
@@ -24,11 +38,16 @@ class Jekyll::AutoImageTest < Minitest::Test
24
38
  @contents_image_page = Jekyll::Page.new(@site, File.expand_path('../fixtures/', __FILE__), '', 'contents-image.md')
25
39
  @contents_html_page = Jekyll::Page.new(@site, File.expand_path('../fixtures/', __FILE__), '', 'contents-html.html')
26
40
 
41
+ # Posts as collections
42
+ #@contents_html_page = Jekyll::Document.new(File.expand_path('../fixtures/_posts/contents-image.md', __FILE__), {:site =>@site,:collection =>'post'})
43
+
44
+
27
45
  @auto_image = Jekyll::AutoImageGenerator.new
28
46
  @auto_image.generate(@site)
29
47
  @auto_image_with_default_image = Jekyll::AutoImageGenerator.new
30
48
  @auto_image_with_default_image.generate(@site_with_default_image)
31
49
 
50
+
32
51
  #@page.instance_variable_set(:@content, '<div>ivan.tse1@gmail.com</div>')
33
52
  #@site.pages << @page
34
53
  #@email_link = '<div><a href="mailto:ivan.tse1@gmail.com">ivan.tse1@gmail.com</a></div>'
@@ -44,7 +63,7 @@ class Jekyll::AutoImageTest < Minitest::Test
44
63
  should 'not be defined site image by default' do
45
64
  assert_nil @site.config['image']
46
65
  end
47
-
66
+
48
67
  should 'not return image when not set in config and not included in page' do
49
68
  assert_nil @auto_image.get_image(@no_image_page)
50
69
  end
@@ -103,6 +122,29 @@ class Jekyll::AutoImageTest < Minitest::Test
103
122
  assert_nil @auto_image.get_image(@no_image_page)
104
123
  end
105
124
 
125
+ #
126
+ # Generate site with data
127
+ #
128
+ should 'generate a site with a page' do
129
+ #add page to site
130
+ @site.pages << @contents_image_page
131
+ @site.generate()
132
+ @auto_image.generate(@site)
133
+ @auto_image.get_image(@contents_html_page)
134
+ assert_equal '/assets/contents-html.png', @auto_image.get_image(@contents_html_page)
135
+ end
136
+
137
+ should 'generate a site with post as part of collection' do
138
+ #puts @posts_collection.directory
139
+ assert_equal 1, @posts_collection.entries.length
140
+ assert_equal 1, @posts_collection.filtered_entries.length
141
+ @site_with_posts.process
142
+ @auto_image.generate(@site_with_posts)
143
+ assert_equal 1, @site_with_posts.posts.docs.length
144
+ #puts @site_with_posts.collections.inspect
145
+ assert_equal '/assets/contents-image.png', @auto_image.get_image(@site_with_posts.posts.docs[0])
146
+ end
147
+
106
148
 
107
149
  end
108
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.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - merlos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-05 00:00:00.000000000 Z
11
+ date: 2015-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -96,7 +96,7 @@ files:
96
96
  - jekyll-auto-image.gemspec
97
97
  - lib/jekyll-auto-image.rb
98
98
  - lib/jekyll-auto-image/version.rb
99
- - test/fixtures/_posts/contents-image.md
99
+ - test/fixtures/_posts/2015-01-01-post-with-contents-image.md
100
100
  - test/fixtures/contents-html.html
101
101
  - test/fixtures/contents-image.md
102
102
  - test/fixtures/front-matter-image.md
@@ -128,7 +128,7 @@ signing_key:
128
128
  specification_version: 4
129
129
  summary: jekyll plugin that makes available the first image of a post in the template
130
130
  test_files:
131
- - test/fixtures/_posts/contents-image.md
131
+ - test/fixtures/_posts/2015-01-01-post-with-contents-image.md
132
132
  - test/fixtures/contents-html.html
133
133
  - test/fixtures/contents-image.md
134
134
  - test/fixtures/front-matter-image.md