jekyll-galleries 0.7.2 → 0.8.0

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +5 -0
  3. data/README.md +12 -3
  4. data/lib/jekyll/galleries.rb +94 -23
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96392eb09f6402ecf36bb1144ab3037ac4431d52
4
- data.tar.gz: 52129659e6b1e595d2493e3457823f5c6c653ae9
3
+ metadata.gz: 0489231e919c218babd6617e37e913be0dd8c72d
4
+ data.tar.gz: f22848c946b32ac8f1214b92e1ef0c0c9a5abf6d
5
5
  SHA512:
6
- metadata.gz: cf7c2944dd0d6bcc5703aa252295e457e198830b8c3f8347e3bb25f5320bc27df23b9cb42bd6c61675399d3c22aeb4658ba19a29b83bca9011970dc492753a65
7
- data.tar.gz: 1530757ee636776276f8d678130f09822bcfa3ce41986c8b3d28298ed0aa10d229fda40bc2dc8aa544d9978d3c120d28e1b524ca3642e0a351155239eb9cffda
6
+ metadata.gz: f34067a34ac82992965a482fce1feb0052eba6db5ce772f3083b9a2d0972d19f58a1d7472d0c7d0486c251d7ada79ad69564c181b297e05598d17687c6e424d5
7
+ data.tar.gz: 8a88da9bbc312697178aa02018ccc8f79defbc429e947a0765d30d4547e5f8fcd725fcb1727a1eacb1227bb001e6fdcb94c4988ec78327595390ec356131bdbb
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.8.0 [2014-03-13]
2
+
3
+ * Add `top` as an attribute, for putting an gallery on the top of index page
4
+ * Automatically generate thumbnails for galleries
5
+
1
6
  == 0.7.2 [2014-02-20]
2
7
 
3
8
  * Add full documentation
data/README.md CHANGED
@@ -4,6 +4,8 @@ By [allenlsy](mailto:cafe@allenlsy.com)
4
4
 
5
5
  __Jekyll-galleries__ is a Jekyll plugin used for generating photo galleries from image folders.
6
6
 
7
+ A demo to this plugin is on my [personal website](http://allenlsy.com/galleries.html).
8
+
7
9
  If you have any questions or any suggestions, I'm very pleased to hear from you. I need your support and ideas to make this plugin better.
8
10
 
9
11
  ---
@@ -25,15 +27,15 @@ Here is an example on how to use this plugin.
25
27
 
26
28
  ##### 1. Setup the plugin
27
29
 
28
- Add `gem 'jekyll-galleries'` to the `Gemfile` in your jekyll project, and then run `bundle` command in shell to install it. Then add `require 'jekyll/galleries'` to `_plugins/_ext.rb`.
30
+ Add `gem 'jekyll-galleries'` to the `Gemfile` in your jekyll project, and also the depedencies `rmagick`. Then run `bundle` command in shell to install them. Next add `require 'jekyll/galleries'` to `_plugins/_ext.rb`.
29
31
 
30
- There are three attributes which are optional. All of them should be put at the root level of `_config.yml`, if needed.
32
+ There are three attributes which are optional. All of them should be put into the `_config.yml`, if needed.
31
33
 
32
34
  * `galleries` specifies the extra information of each gallery, using the YAML object format.
33
35
  * `gallery_dir` defines which folder in jekyll project stores the all the galleries. Default value is `galleries` if not defined.
34
36
  * `gallery_layout` defines the layout __Jekyll-galleries__ will use to render each single gallery. Default value is `gallery`, which uses the `_layouts/gallery.html` as the template.
35
37
 
36
- Check out the example `_config.yml` if you are still not clear.
38
+ Check out the example `_config.yml` down below if you are still not clear.
37
39
 
38
40
  ##### 2. Add galleries to jekyll project
39
41
 
@@ -64,6 +66,13 @@ Inside the optional `galleries` attribute in `_config.yml`, you can have objects
64
66
 
65
67
  Then in the template, the gallery will have the attribute `subtitle` that can be rendered.
66
68
 
69
+ Another attribute is `top`. If you set `top: true` for a gallery, then this gallery will always be put on top of the galleries index page. For example:
70
+
71
+ galleries:
72
+ - name: Sample Gallery
73
+ subtitle: This is a sample gallery
74
+ top: true
75
+
67
76
  ##### 5. Use attributes in template
68
77
 
69
78
  Now, the `site.data['galleries']` global variable contains all the gallery pages. It is an array of `GalleryPage` objects. Each `GalleryPage` object has at least three attributes: `name`, `date` and `url`. `url` is URL escaped. You can use them in your galleries index page.
@@ -1,12 +1,25 @@
1
+ require 'RMagick'
2
+ include Magick
3
+
4
+ include FileUtils
5
+
1
6
  module Jekyll
2
7
  class GalleryGenerator < Generator
3
- attr_accessor :site, :gallery_dir, :gallery_layout, :galleries
8
+ attr_accessor :site
9
+ attr_accessor :gallery_dir # directory for storing galleries. Default value is `galleries`
10
+ attr_accessor :gallery_layout # layout file for gallery. Default value is `gallery`
11
+ attr_accessor :galleries
12
+ attr_accessor :gallery_pages
13
+ attr_accessor :top_gallery_pages # GalleryPage array of topped galleries
14
+
4
15
  class << self; attr_accessor :site; end
5
16
 
6
17
  def generate(site)
7
18
  self.class.site = self.site = site
8
19
  self.gallery_dir = site.config['gallery_dir'] || 'galleries'
9
20
  self.gallery_layout = site.config['gallery_layout'] || 'gallery'
21
+ self.gallery_pages = []
22
+ self.top_gallery_pages = []
10
23
 
11
24
  # array of GalleryPage objects
12
25
  site.data['galleries'] = []
@@ -16,6 +29,17 @@ module Jekyll
16
29
  gallery_dirs.each do |dir|
17
30
  generate_gallery_page(dir)
18
31
  end
32
+
33
+ # ordering the Page generation
34
+ site.pages << self.top_gallery_pages
35
+ site.pages << self.gallery_pages
36
+ site.pages.flatten!
37
+
38
+ # ordering galleries on gallery index page
39
+ site.data['galleries'] << self.top_gallery_pages
40
+ site.data['galleries'] << self.gallery_pages.reverse!
41
+ site.data['galleries'].flatten!
42
+
19
43
  end
20
44
 
21
45
  private
@@ -24,54 +48,72 @@ module Jekyll
24
48
 
25
49
  page = GalleryPage.new(site, site.source, self.gallery_dir, gallery_dir, data)
26
50
 
27
- site.pages << page
28
-
29
- site.data['galleries'] << page
51
+ pages_queue = page.top? ? top_gallery_pages : gallery_pages # decide the queue that current page should be put into
52
+ pages_queue << page
30
53
  end
31
-
32
54
  end
33
55
 
34
56
  class GalleryPage < Page
35
57
  # Valid post name regex.
36
58
  MATCHER = /^(\d+-\d+-\d+)-(.*)$/
37
59
  CONFIG_GALLERIES_ATTR = 'galleries'
38
-
39
- attr_accessor :url, :name, :slug, :date
60
+ attr_accessor :url, :name, :slug, :date, :base
61
+ attr_accessor :gen_dir # path that this gallery will be generated into
62
+ attr_accessor :gallery_dir # the original path of the this gallery on local
63
+ attr_accessor :gallery_dir_name # the name of this gallery dir
64
+ attr_accessor :thumbs_dir # path of thumbnails dir
40
65
 
41
66
  def initialize(site, base, gen_dir, gallery_dir, data={})
67
+ # preparation
68
+ @base = base
69
+ @site = site
70
+ self.gen_dir = gen_dir
71
+ self.gallery_dir = gallery_dir
42
72
  self.content = data.delete('content') || ''
43
73
  self.data = data
74
+ self.thumbs_dir = site.config['thumbs_dir']
75
+
76
+ self.gallery_dir_name = File.basename gallery_dir
77
+ super(site, base, gen_dir, self.gallery_dir_name)
44
78
 
45
- gallery_dir_name = File.basename gallery_dir
46
- super(site, base, gen_dir, gallery_dir_name)
79
+ # ---
80
+ generate_photos
47
81
 
48
- # load photos configuration
49
- photos_config_filepath = "#{base}/#{site.config['gallery_dir']}/#{self.date}-#{self.name}.yml"
50
- photos_config = YAML.load(File.open(photos_config_filepath).read) if File.exists?(photos_config_filepath)
82
+ end
83
+
84
+ def generate_photos
85
+ photos_config_filepath = "#{@base}/#{@site.config['gallery_dir']}/#{self.date}-#{self.name}.yml"
86
+ photos_config = YAML.load(File.open(photos_config_filepath).read) if File.exists?(photos_config_filepath) # config of this gallery
51
87
 
52
88
  # generating photos
53
- self.url = "/#{gen_dir}/#{self.date}-#{self.slug}.html" # gallery page url
54
- self.data['url'] = URI.escape self.url
89
+ self.url = "/#{self.gen_dir}/#{self.gallery_dir_name}/index.html" # gallery page url
90
+ self.data['url'] = URI.escape self.url
55
91
 
56
92
  # For each photo, initial attributes are `filename` and `url`
57
- photos = Dir["#{gallery_dir}/*"].map { |e| { filename: File.basename(e), url: URI.escape("/#{gen_dir}/#{gallery_dir_name}/#{File.basename e}") } } # basic photos attributes
93
+ photos = Dir["#{self.gallery_dir}/*"].map { |e| { filename: File.basename(e), url: URI.escape("/#{self.gen_dir}/#{self.gallery_dir_name}/#{File.basename e}") } } # basic photos attributes
58
94
 
59
95
  self.data['photos'] = [] # storing an array of Photo
60
96
  photos.each do |photo|
61
97
  photo_data = {}
62
98
  photo_data = photos_config.find { |e| e['filename'] == photo[:filename] } if photos_config
63
- self.data['photos'] << Photo.new(photo[:filename], photo[:url], photo_data)
99
+
100
+ self.data['photos'] << Photo.new(@site, photo[:filename], self, photo_data)
64
101
  end
65
102
 
66
103
  # gallery page configuration
67
- if site.config[CONFIG_GALLERIES_ATTR]
68
- attr = site.config[CONFIG_GALLERIES_ATTR].find { |e| e['name'] == self.name}
104
+ if @site.config[CONFIG_GALLERIES_ATTR]
105
+ attr = @site.config[CONFIG_GALLERIES_ATTR].find { |e| e['name'] == self.name }
69
106
  if attr
70
107
  attr.each { |k, v| self.data[k] = v }
71
108
  end
72
109
  end
73
110
  end
74
111
 
112
+
113
+ def top?
114
+ self.data['top'] and self.data['top'] == true
115
+ end
116
+
75
117
  def read_yaml(*)
76
118
  end
77
119
 
@@ -93,16 +135,45 @@ module Jekyll
93
135
  end
94
136
 
95
137
  class Photo
96
- attr_accessor :filename, :url, :data
138
+ attr_accessor :filename, :url, :data, :thumbnail_url
97
139
 
98
- def initialize(filename, url, options=nil)
99
- self.filename = filename
100
- self.url = url
140
+ def initialize(site, filename, gallery, options=nil)
141
+ @site = site
142
+ @gallery = gallery
101
143
  self.data = options || {}
144
+ self.data['url'] = URI.escape("/#{gallery.gen_dir}/#{gallery.gallery_dir_name}/#{filename}")
145
+ self.data['filename'] = filename
146
+ self.filename = filename
147
+
148
+
149
+ @thumbs_dir = site.config['thumbnails_dir']
150
+ generate_thumbnails if @thumbs_dir
151
+
102
152
  end
103
153
 
104
154
  def to_liquid
105
- self.data.merge({ 'url' => self.url })
155
+ self.data
156
+ end
157
+
158
+ def generate_thumbnails
159
+ size_x = @site.config['thumbnail_x'] || 100
160
+ size_y = @site.config['thumbnail_y'] || 100
161
+
162
+ full_thumbs_path = "#{@site.dest}/#{@thumbs_dir}/#{@gallery.gallery_dir_name}"
163
+ FileUtils.mkdir_p(full_thumbs_path, :mode => 0755)
164
+ if File.file?("#{full_thumbs_path}/#{self.filename}") == false or File.mtime("#{@gallery.gallery_dir}/#{self.filename}") > File.mtime("#{full_thumbs_path}/#{self.filename}")
165
+ begin
166
+ m_image = ImageList.new("#{@gallery.gallery_dir}/#{self.filename}")
167
+ m_image.send("resize_to_fit!", size_x, size_y)
168
+ puts "Writing thumbnail to #{full_thumbs_path}/#{self.filename}"
169
+ m_image.write("#{full_thumbs_path}/#{self.filename}")
170
+ rescue
171
+ puts "error"
172
+ puts $!
173
+ end
174
+ GC.start
175
+ end
176
+ self.data['thumbnail_url'] = URI.escape("/#{@thumbs_dir}/#{@gallery.gallery_dir_name}/#{self.filename}")
106
177
  end
107
178
  end
108
179
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-galleries
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - allenlsy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-20 00:00:00.000000000 Z
11
+ date: 2014-03-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Jekyll plugin to automatically generate photo gallery (album) from image
14
14
  folder.
@@ -32,7 +32,7 @@ rdoc_options:
32
32
  - --line-numbers
33
33
  - --all
34
34
  - --title
35
- - jekyll-galleries Application documentation (v0.7.0)
35
+ - jekyll-galleries Application documentation (v0.8.0)
36
36
  - --main
37
37
  - ChangeLog
38
38
  require_paths: