gallerize-cli 0.2.1 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e1ee1d0eda7806f452b027a8c96e4a1c6e85572
4
- data.tar.gz: 3375075451bcf27df22dc5ab0fe88f01e82a8e56
3
+ metadata.gz: c575c4f467f417894f8475e42c28bf890d089d8c
4
+ data.tar.gz: 6dc46814ef69a1af69100cf828539f3661ec0b89
5
5
  SHA512:
6
- metadata.gz: 7782b81aabc2d716baa258a2c0726798cffca3ca1d07502ee6554da43e329c7061de63ec41a405efba5929cb8f8d96a108825a46ab6751291faf9c4c8c6eef8a
7
- data.tar.gz: 74f6c2d79f571219728a868936697a7a37bc3332342d8ce136e69936a842f4b66b4a83d315a211311a6a0fabd08480b3587a805ae1cef11ced2a7bf918b10a90
6
+ metadata.gz: a4be71dd19582f8899e51fa7c16028602bdcd7d90392d62628e14eb892455e066693270b243633722bf7ad5f7b4fc87ebd8f2c82c40455cffa2d465067c9a19e
7
+ data.tar.gz: 16612b0a0913f925af688472921c98ff1a1c0de1b883370cf340262fb9705b1e50f8d52ee3222dd81ed47206ae0b3a73ae026f1d9ab2ec9d15d491b4cb5f5786
@@ -6,4 +6,5 @@ image_width: 1200
6
6
  image_height: 800
7
7
  thumb_width: 400
8
8
  thumb_height: 300
9
- output_name: gallerize
9
+ output_name: gallerize
10
+ titles: false
data/lib/gallerize.rb CHANGED
@@ -14,15 +14,15 @@ require 'gallerize/source_dir'
14
14
  ROOT = File.expand_path( File.join(__FILE__, '../../') )
15
15
 
16
16
  class Gallerize
17
-
17
+
18
18
  attr_accessor :image_paths
19
-
20
- VERSION='0.2.1'
21
-
19
+
20
+ VERSION='0.2.2'
21
+
22
22
  def self.generate
23
23
  new.perform
24
24
  end
25
-
25
+
26
26
  def perform
27
27
  if image_paths.blank?
28
28
  puts "no images found in #{source_dir.root} matching #{config.image_types}"
@@ -36,8 +36,8 @@ class Gallerize
36
36
  ticker = ticker + 1
37
37
  end
38
38
  end
39
- end
40
-
39
+ end
40
+
41
41
  def prepare_output_directory
42
42
  # remove html files
43
43
  Dir.glob( output_dir.html_files ){|f| FileUtils.rm(f) }
@@ -48,7 +48,7 @@ class Gallerize
48
48
  # copy css and js from gem to output
49
49
  output_dir.copy_from_gem_source( 'assets/css', 'assets/js' )
50
50
  end
51
-
51
+
52
52
  def generate_images
53
53
  generated = []
54
54
  # generate images and skip any that fail
@@ -65,32 +65,33 @@ class Gallerize
65
65
  end
66
66
  generated
67
67
  end
68
-
68
+
69
69
  def images_to_html(some_images, ticker=0, name=nil)
70
70
  some_images ||= []
71
71
  navigation = (images.count / per_page.to_f).ceil.times.collect{|r| %Q{<a class="#{'active' if r == ticker}" href="images-#{r}.html">#{r}</a>} }.join("\n")
72
72
  navigation = (images.count > some_images.count) ? %Q{<div class="navigation">#{navigation}</div>} : ""
73
-
73
+
74
74
  template = ERB.new(File.read(File.join(ROOT, 'templates/layout.html.erb')))
75
75
  html = template.result(binding)
76
-
76
+
77
77
  name ||= output_dir.html_file("images-#{ticker}")
78
78
  puts "generate #{name.gsub(output_dir.root, output_dir.relative_root)}"
79
79
  File.write(name, html)
80
80
  end
81
-
81
+
82
82
  def images
83
83
  ticker = 0
84
- image_paths.collect do |f|
84
+ image_paths.collect do |f|
85
85
  image_fullsize = generate_fullsize(f)
86
86
  image_thumbnail = generate_thumbnail(f)
87
87
  even = (ticker % 2 == 0) ? 'image-even' : 'image-odd'
88
88
  third = (ticker % 3 == 0) ? 'image-third' : ''
89
89
  fourth = (ticker % 4 == 0) ? 'image-fourth' : ''
90
+ fancybox_attributes = get_fancybox_attributes(ticker)
90
91
  src = %Q{
91
92
  <div class="image #{even} #{fourth} #{third} image-#{ticker}">
92
93
  <div class="inner-image">
93
- <a href="./#{image_fullsize}" class="fancybox" rel="group" target="_blank"><img src="./#{image_thumbnail}" alt="" /></a>
94
+ <a href="./#{image_fullsize}" #{fancybox_attributes}><img src="./#{image_thumbnail}" alt="" /></a>
94
95
  </div>
95
96
  </div>
96
97
  }
@@ -98,12 +99,12 @@ class Gallerize
98
99
  src
99
100
  end
100
101
  end
101
-
102
+
102
103
  def image_paths
103
- @image_paths ||= Dir.glob("*.{#{config.image_types}}").reject{|f|
104
+ @image_paths ||= Dir.glob("*.{#{config.image_types}}").reject{|f|
104
105
  # reject thumbnails
105
106
  f =~ /thumbnail/
106
- }.reject{|f|
107
+ }.reject{|f|
107
108
  begin
108
109
  EXIFR::JPEG.new(f).date_time
109
110
  false
@@ -115,25 +116,25 @@ class Gallerize
115
116
  EXIFR::JPEG.new(f).date_time || Time.parse('3000-01-01')
116
117
  }
117
118
  end
118
-
119
+
119
120
  def per_page
120
121
  config.per_page
121
122
  end
122
-
123
+
123
124
  def generate_fullsize(source_path)
124
125
  image = extract_image_extension(source_path)
125
126
  output_path = File.join(output_dir.images, "#{image[:basename]}.#{image[:extension]}")
126
127
  # generate the thumbnail
127
128
  generate_image(source_path, output_path, config.image_width, config.image_height)
128
129
  end
129
-
130
+
130
131
  def generate_thumbnail(source_path)
131
132
  image = extract_image_extension(source_path)
132
133
  output_path = File.join(output_dir.images, "#{image[:basename]}-thumbnail.#{image[:extension]}")
133
134
  # generate the thumbnail
134
135
  generate_image(source_path, output_path, config.thumb_width, config.thumb_height)
135
136
  end
136
-
137
+
137
138
  def generate_image(source_path, output_path, width, height)
138
139
  # ensure correct types
139
140
  width, height = width.to_i, height.to_i
@@ -143,7 +144,7 @@ class Gallerize
143
144
  image = MiniMagick::Image.open(source_path)
144
145
  image.auto_orient
145
146
  # landscape?
146
- if image['width'] > image['height']
147
+ if image[:width] > image[:height]
147
148
  image.resize "#{width}x#{height}"
148
149
  else
149
150
  image.resize "#{height}x#{width.to_i * 1.25}"
@@ -153,26 +154,26 @@ class Gallerize
153
154
  # strip the output_dir.root from the path so that the returned path is relative
154
155
  output_path.gsub( output_dir.root, '' )
155
156
  end
156
-
157
+
157
158
  def extract_image_extension(image_path)
158
159
  basename = image_path.split(".")
159
160
  extension = basename.pop.downcase
160
161
  basename = basename.join('.')
161
162
  return { basename: basename, extension: extension }
162
163
  end
163
-
164
+
164
165
  def title
165
- config.to_h.has_key?(:title) ? config.title : File.basename(File.expand_path('.')).titleize
166
+ File.basename(File.expand_path('.')).titleize
166
167
  end
167
-
168
+
168
169
  def output_dir
169
170
  @output_dir ||= OutputDir.new( config.output_name )
170
171
  end
171
-
172
+
172
173
  def config
173
174
  @config ||= load_config
174
175
  end
175
-
176
+
176
177
  def load_config
177
178
  config = {}
178
179
  # load config from output directory if present
@@ -181,18 +182,29 @@ class Gallerize
181
182
  global_config = File.join(ROOT,'config/global.yml')
182
183
  FileUtils.cp( "#{global_config}.example", global_config ) unless File.exists?( global_config )
183
184
  # load global_config and merge with source config
184
- result = YAML.load(File.read(global_config)).merge(config)
185
- result['to_h'] = result
186
- # write to source_dir if not exists
187
- File.write(source_dir.config, YAML.dump(result)) unless source_dir.config?
188
- # onwards
189
- OpenStruct.new(result)
190
- end
191
-
185
+ OpenStruct.new(YAML.load(File.read(global_config)).merge(config))
186
+ end
187
+
192
188
  def source_dir
193
189
  @source_dir ||= SourceDir.new
194
190
  end
195
-
191
+
192
+ def get_fancybox_attributes(ticker)
193
+ attributes = {
194
+ class: 'fancybox',
195
+ rel: 'group',
196
+ }
197
+ attributes["title"] = "IMG_#{ticker}" if config.titles
198
+ attributes.map{|k,v| "#{k}='#{v}'"}.join(' ')
199
+ end
200
+
201
+ def fancybox_options
202
+ options = {}
203
+ if config.titles
204
+ options["helpers"] = {title: {type: 'inside',position: 'bottom'}}
205
+ end
206
+ JSON.dump(options)
207
+ end
196
208
  end
197
209
 
198
- Gallerize.generate
210
+ Gallerize.generate
@@ -4,58 +4,56 @@
4
4
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
5
5
  <meta name="robots" content="noindex">
6
6
  <meta name="googlebot" content="noindex">
7
-
7
+
8
8
  <script type="text/javascript" src="assets/js/jquery-1.10.1.min.js"></script>
9
9
  <script type="text/javascript" src="assets/js/jquery.fancybox.js"></script>
10
10
  <script type="text/javascript" src="assets/js/imagesloaded.js"></script>
11
11
  <script type="text/javascript" src="assets/js/jquery.masonry.js"></script>
12
-
12
+
13
13
  <link rel="stylesheet" type="text/css" href="assets/css/styles.css" media="screen" />
14
14
  <link rel="stylesheet" type="text/css" href="assets/css/jquery.fancybox.css" media="screen" />
15
15
  <meta name="viewport" content="width=device-width, user-scalable=no">
16
-
16
+
17
17
  <script type="text/javascript">
18
18
  $(document).ready(function(){
19
19
  $('#images-container').imagesLoaded( function() {
20
20
  $('.images').show();
21
-
21
+
22
22
  var container = document.querySelector('#images-container');
23
23
  var msnry = new Masonry( container, {
24
24
 
25
25
  itemSelector: '.image'
26
26
  });
27
27
 
28
- $('.fancybox').fancybox();
28
+ $('.fancybox').fancybox(<%= fancybox_options %>);
29
29
  });
30
30
  });
31
31
  </script>
32
-
32
+
33
33
  <% if config.tracking.present? %>
34
- <script>
35
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
36
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
37
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
38
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
34
+ <script>
35
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
36
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
37
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
38
+ })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
39
39
 
40
- ga('create', '<%= config.tracking %>', 'auto');
41
- ga('send', 'pageview');
40
+ ga('create', '<%= config.tracking %>', 'auto');
41
+ ga('send', 'pageview');
42
42
 
43
- </script>
43
+ </script>
44
44
  <% end %>
45
-
45
+
46
46
  <title><%= title %></title>
47
47
  <link rel="stylesheet" href="css/styles.css" />
48
48
  </head>
49
49
  <body>
50
- <% if title.present? %>
51
50
  <h1 class="page-title"><%= title %></h1>
52
- <% end %>
53
-
51
+
54
52
  <%= navigation %>
55
53
  <div id="images-container" class="images">
56
54
  <%= some_images.join("\n") %>
57
55
  </div>
58
56
  <%= navigation %>
59
-
57
+
60
58
  </body>
61
- </html>
59
+ </html>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gallerize-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hilscher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-06 00:00:00.000000000 Z
11
+ date: 2014-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_magick