gallerize-cli 0.2.0 → 0.2.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: fc69d889c2a6a376cc872a33e4b6bd60637a49a7
4
- data.tar.gz: b3d1c67446924666c5d0bafe39e52dbadc04f08a
3
+ metadata.gz: 8e1ee1d0eda7806f452b027a8c96e4a1c6e85572
4
+ data.tar.gz: 3375075451bcf27df22dc5ab0fe88f01e82a8e56
5
5
  SHA512:
6
- metadata.gz: e9f3ee1e12f19706935e26052da9d640e479864154d6957547975c20f7d97082e3f0c847a62be699e04860ee22f141875ee73e35dd06cf53d26f2d07721efdbb
7
- data.tar.gz: 805f18c473d8c70de3c8053729581a153d9ae347d8fe33d2cde9f22f095443c5ae2452460afb6ba14b0b09fda586139b946fada42098f1f1d91b6cc9097215cf
6
+ metadata.gz: 7782b81aabc2d716baa258a2c0726798cffca3ca1d07502ee6554da43e329c7061de63ec41a405efba5929cb8f8d96a108825a46ab6751291faf9c4c8c6eef8a
7
+ data.tar.gz: 74f6c2d79f571219728a868936697a7a37bc3332342d8ce136e69936a842f4b66b4a83d315a211311a6a0fabd08480b3587a805ae1cef11ced2a7bf918b10a90
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/bin/gallerize CHANGED
@@ -1,4 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
+ require "pathname"
3
4
 
4
- require_relative '../lib/gallerize.rb'
5
+ bin_file = Pathname.new(__FILE__).realpath
6
+ $:.unshift File.expand_path("../../lib", bin_file)
7
+
8
+ require 'gallerize'
@@ -0,0 +1,44 @@
1
+ class Gallerize
2
+ class OutputDir
3
+
4
+ attr_accessor :root
5
+
6
+ def initialize(path)
7
+ self.root = path
8
+ end
9
+
10
+ def root=(value)
11
+ @root = File.join( File.expand_path('.'), (value || 'gallerize') )
12
+ end
13
+
14
+ def relative_root
15
+ @relative_root ||= root.gsub(File.expand_path('.').to_s + "/", './')
16
+ end
17
+
18
+ def html_file(name)
19
+ name = name.to_s
20
+ name = "#{name}.html" unless name =~ /\.html/
21
+ File.join(root, name)
22
+ end
23
+
24
+ def images
25
+ File.join( root, 'images' )
26
+ end
27
+
28
+ def html_files
29
+ File.join( root, '*.html')
30
+ end
31
+
32
+ def copy_from_gem_source(*folders)
33
+ folders.each do |folder|
34
+ outdir = File.join( root, folder )
35
+ unless Dir.exists?(outdir)
36
+ puts "copy ./#{folder} #{outdir}"
37
+ FileUtils.mkdir_p( File.expand_path(File.join(outdir, '..')) )
38
+ FileUtils.cp_r( File.join( ROOT, folder ), outdir )
39
+ end
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,17 @@
1
+ class Gallerize
2
+ class SourceDir
3
+
4
+ def config?
5
+ File.exists?(config)
6
+ end
7
+
8
+ def config
9
+ File.join( root, '.gallerize')
10
+ end
11
+
12
+ def root
13
+ @root ||= File.expand_path('.')
14
+ end
15
+
16
+ end
17
+ end
data/lib/gallerize.rb CHANGED
@@ -6,6 +6,10 @@ require 'mini_magick'
6
6
  require 'pry'
7
7
  require 'fileutils'
8
8
  require 'exifr'
9
+ require 'erb'
10
+
11
+ require 'gallerize/output_dir'
12
+ require 'gallerize/source_dir'
9
13
 
10
14
  ROOT = File.expand_path( File.join(__FILE__, '../../') )
11
15
 
@@ -13,7 +17,7 @@ class Gallerize
13
17
 
14
18
  attr_accessor :image_paths
15
19
 
16
- VERSION='0.2.0'
20
+ VERSION='0.2.1'
17
21
 
18
22
  def self.generate
19
23
  new.perform
@@ -42,7 +46,7 @@ class Gallerize
42
46
  # ensure output/images directory
43
47
  FileUtils.mkdir( output_dir.images ) unless File.exists?( output_dir.images )
44
48
  # copy css and js from gem to output
45
- output_dir.copy_from_gem_source( 'css', 'js' )
49
+ output_dir.copy_from_gem_source( 'assets/css', 'assets/js' )
46
50
  end
47
51
 
48
52
  def generate_images
@@ -66,17 +70,12 @@ class Gallerize
66
70
  some_images ||= []
67
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")
68
72
  navigation = (images.count > some_images.count) ? %Q{<div class="navigation">#{navigation}</div>} : ""
69
- html = %Q{
70
- #{body}
71
- #{navigation}
72
- <div id="images-container" class="images">
73
- #{some_images.join("\n")}
74
- </div>
75
- #{navigation}
76
- #{footer}
77
- }
73
+
74
+ template = ERB.new(File.read(File.join(ROOT, 'templates/layout.html.erb')))
75
+ html = template.result(binding)
76
+
78
77
  name ||= output_dir.html_file("images-#{ticker}")
79
- puts "generate #{name}"
78
+ puts "generate #{name.gsub(output_dir.root, output_dir.relative_root)}"
80
79
  File.write(name, html)
81
80
  end
82
81
 
@@ -117,77 +116,10 @@ class Gallerize
117
116
  }
118
117
  end
119
118
 
120
- def body
121
- %Q{
122
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
123
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
124
- <head>
125
- <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
126
- <meta name="robots" content="noindex">
127
- <meta name="googlebot" content="noindex">
128
-
129
- <script type="text/javascript" src="js/jquery-1.10.1.min.js"></script>
130
- <script type="text/javascript" src="js/jquery.fancybox.js"></script>
131
- <script type="text/javascript" src="js/imagesloaded.js"></script>
132
- <script type="text/javascript" src="js/jquery.masonry.js"></script>
133
-
134
- <link rel="stylesheet" type="text/css" href="css/styles.css" media="screen" />
135
- <link rel="stylesheet" type="text/css" href="css/jquery.fancybox.css" media="screen" />
136
- <meta name="viewport" content="width=device-width, user-scalable=no">
137
-
138
- <script type="text/javascript">
139
- $(document).ready(function(){
140
- $('#images-container').imagesLoaded( function() {
141
- $('.images').show();
142
-
143
- var container = document.querySelector('#images-container');
144
- var msnry = new Masonry( container, {
145
-
146
- itemSelector: '.image'
147
- });
148
-
149
- $('.fancybox').fancybox();
150
- });
151
- });
152
- </script>
153
-
154
- #{tracking_js}
155
-
156
- <title>#{title}</title>
157
- <link rel="stylesheet" href="css/styles.css" />
158
- </head>
159
- <body>
160
- <h1 class="page-title">#{title}</h1>
161
- }
162
- end
163
-
164
- def footer
165
- %Q{
166
- </body>
167
- </html>
168
- }
169
- end
170
-
171
119
  def per_page
172
120
  config.per_page
173
121
  end
174
122
 
175
- def tracking_js
176
- return if config.tracking.blank?
177
- %Q{
178
- <script>
179
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
180
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
181
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
182
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
183
-
184
- ga('create', '#{config.tracking}', 'auto');
185
- ga('send', 'pageview');
186
-
187
- </script>
188
- }
189
- end
190
-
191
123
  def generate_fullsize(source_path)
192
124
  image = extract_image_extension(source_path)
193
125
  output_path = File.join(output_dir.images, "#{image[:basename]}.#{image[:extension]}")
@@ -230,7 +162,7 @@ class Gallerize
230
162
  end
231
163
 
232
164
  def title
233
- File.basename(File.expand_path('.')).titleize
165
+ config.to_h.has_key?(:title) ? config.title : File.basename(File.expand_path('.')).titleize
234
166
  end
235
167
 
236
168
  def output_dir
@@ -249,67 +181,18 @@ class Gallerize
249
181
  global_config = File.join(ROOT,'config/global.yml')
250
182
  FileUtils.cp( "#{global_config}.example", global_config ) unless File.exists?( global_config )
251
183
  # load global_config and merge with source config
252
- OpenStruct.new(YAML.load(File.read(global_config)).merge(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)
253
190
  end
254
191
 
255
192
  def source_dir
256
193
  @source_dir ||= SourceDir.new
257
194
  end
258
195
 
259
- class SourceDir
260
-
261
- def config?
262
- File.exists?(config)
263
- end
264
-
265
- def config
266
- File.join( root, '.gallerize')
267
- end
268
-
269
- def root
270
- @root ||= File.expand_path('.')
271
- end
272
-
273
- end
274
-
275
- class OutputDir
276
-
277
- attr_accessor :root
278
-
279
- def initialize(path)
280
- self.root = path
281
- end
282
-
283
- def root=(value)
284
- @root = File.join( File.expand_path('.'), (value || 'gallerize') )
285
- end
286
-
287
- def html_file(name)
288
- name = name.to_s
289
- name = "#{name}.html" unless name =~ /\.html/
290
- File.join(root, name)
291
- end
292
-
293
- def images
294
- File.join( root, 'images' )
295
- end
296
-
297
- def html_files
298
- File.join( root, '*.html')
299
- end
300
-
301
- def copy_from_gem_source(*folders)
302
- folders.each do |folder|
303
- outdir = File.join( root, folder )
304
- puts "copy ./#{folder} #{outdir}"
305
- FileUtils.rm_rf( outdir )
306
- FileUtils.cp_r( File.join( ROOT, folder ), outdir )
307
- end
308
- end
309
-
310
-
311
- end
312
-
313
196
  end
314
197
 
315
198
  Gallerize.generate
@@ -0,0 +1,61 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
5
+ <meta name="robots" content="noindex">
6
+ <meta name="googlebot" content="noindex">
7
+
8
+ <script type="text/javascript" src="assets/js/jquery-1.10.1.min.js"></script>
9
+ <script type="text/javascript" src="assets/js/jquery.fancybox.js"></script>
10
+ <script type="text/javascript" src="assets/js/imagesloaded.js"></script>
11
+ <script type="text/javascript" src="assets/js/jquery.masonry.js"></script>
12
+
13
+ <link rel="stylesheet" type="text/css" href="assets/css/styles.css" media="screen" />
14
+ <link rel="stylesheet" type="text/css" href="assets/css/jquery.fancybox.css" media="screen" />
15
+ <meta name="viewport" content="width=device-width, user-scalable=no">
16
+
17
+ <script type="text/javascript">
18
+ $(document).ready(function(){
19
+ $('#images-container').imagesLoaded( function() {
20
+ $('.images').show();
21
+
22
+ var container = document.querySelector('#images-container');
23
+ var msnry = new Masonry( container, {
24
+
25
+ itemSelector: '.image'
26
+ });
27
+
28
+ $('.fancybox').fancybox();
29
+ });
30
+ });
31
+ </script>
32
+
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');
39
+
40
+ ga('create', '<%= config.tracking %>', 'auto');
41
+ ga('send', 'pageview');
42
+
43
+ </script>
44
+ <% end %>
45
+
46
+ <title><%= title %></title>
47
+ <link rel="stylesheet" href="css/styles.css" />
48
+ </head>
49
+ <body>
50
+ <% if title.present? %>
51
+ <h1 class="page-title"><%= title %></h1>
52
+ <% end %>
53
+
54
+ <%= navigation %>
55
+ <div id="images-container" class="images">
56
+ <%= some_images.join("\n") %>
57
+ </div>
58
+ <%= navigation %>
59
+
60
+ </body>
61
+ </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.0
4
+ version: 0.2.1
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-07-20 00:00:00.000000000 Z
11
+ date: 2014-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_magick
@@ -92,22 +92,25 @@ files:
92
92
  - Gemfile
93
93
  - Gemfile.lock
94
94
  - README.md
95
+ - assets/css/blank.gif
96
+ - assets/css/fancybox_loading.gif
97
+ - assets/css/fancybox_loading@2x.gif
98
+ - assets/css/fancybox_overlay.png
99
+ - assets/css/fancybox_sprite.png
100
+ - assets/css/fancybox_sprite@2x.png
101
+ - assets/css/jquery.fancybox.css
102
+ - assets/css/styles.css
103
+ - assets/js/imagesloaded.js
104
+ - assets/js/jquery-1.10.1.min.js
105
+ - assets/js/jquery.fancybox.js
106
+ - assets/js/jquery.masonry.js
95
107
  - bin/gallerize
96
108
  - config/global.yml.example
97
- - css/blank.gif
98
- - css/fancybox_loading.gif
99
- - css/fancybox_loading@2x.gif
100
- - css/fancybox_overlay.png
101
- - css/fancybox_sprite.png
102
- - css/fancybox_sprite@2x.png
103
- - css/jquery.fancybox.css
104
- - css/styles.css
105
109
  - gallerize-cli.gemspec
106
- - js/imagesloaded.js
107
- - js/jquery-1.10.1.min.js
108
- - js/jquery.fancybox.js
109
- - js/jquery.masonry.js
110
110
  - lib/gallerize.rb
111
+ - lib/gallerize/output_dir.rb
112
+ - lib/gallerize/source_dir.rb
113
+ - templates/layout.html.erb
111
114
  homepage: http://blake.hilscher.ca/
112
115
  licenses:
113
116
  - MIT