gallerize 0.1

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.
data/bin/gallerize ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'trollop'
4
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'gallerizer')
5
+
6
+ # Parse options
7
+ options = Trollop::options do
8
+ opt :name, "Name", :default => "gallerize"
9
+ opt :theme, "Theme", :default => "default"
10
+ opt :output, "Output path", :type => :string
11
+ end
12
+
13
+ Trollop::die :output, "is required" if options[:output].nil?
14
+
15
+ Gallerizer.new(options[:name], options[:output], options[:theme]).generate
data/lib/gallerizer.rb ADDED
@@ -0,0 +1,64 @@
1
+ require 'erb'
2
+ require 'fileutils'
3
+ require 'rubygems'
4
+ require 'rmagick'
5
+ require 'natural_sort_kernel'
6
+
7
+ class Gallerizer
8
+ include FileUtils
9
+
10
+ def initialize(name, output_path, theme)
11
+ @name = name
12
+ @output_path = output_path
13
+ @theme_path = File.join(File.dirname(__FILE__), "..", "themes", theme)
14
+ end
15
+
16
+ def resize(image, size, square = false)
17
+ thumb_file_path = File.join(@output_path, "thumbs", File.basename(image, ".jpg") << "_#{size}.jpg")
18
+
19
+ unless File.exists?(thumb_file_path)
20
+ file = Magick::Image::read(image).first
21
+
22
+ if square
23
+ file.resize_to_fill!(size, size)
24
+ else
25
+ file.resize_to_fit!(size, size)
26
+ end
27
+
28
+ file.write(thumb_file_path){ self.quality = (size <= 250 ? 70 : 95) }
29
+ end
30
+
31
+ File.basename(thumb_file_path)
32
+ end
33
+
34
+ def next_image(i)
35
+ @images.size - 1 != i ? @images[i + 1] : nil
36
+ end
37
+
38
+ def previous_image(i)
39
+ i != 0 ? @images[i - 1] : nil
40
+ end
41
+
42
+ def generate
43
+ # Create necessary output paths
44
+ mkdir_p([@output_path, File.join(@output_path, "thumbs"), File.join(@output_path, "show"), File.join(@output_path, "resources")])
45
+
46
+ # Copy resource files
47
+ cp_r(File.join(@theme_path, "resources/."), File.join(@output_path, "resources"))
48
+
49
+ # Gather images
50
+ @images = Dir["*.jpg"].natural_sort
51
+
52
+ # Load templates
53
+ index_template = ERB.new(File.open(File.join(@theme_path, "index.html.erb")) { |f| f.read })
54
+ show_template = ERB.new(File.open(File.join(@theme_path, "show.html.erb")) { |f| f.read })
55
+
56
+ # Create index page
57
+ File.open(File.join(@output_path, "index.html"), "w") { |f| f.write(index_template.result(binding)) }
58
+
59
+ # Create show pages
60
+ @images.each_with_index do |image, i|
61
+ File.open(File.join(@output_path, "show", "#{i}.html"), "w") { |f| f.write(show_template.result(binding)) }
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= @name %></title>
5
+ <meta charset="utf-8" />
6
+ <!--[if IE]>
7
+ <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
8
+ <![endif]-->
9
+ <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/combo?3.0.0/build/cssreset/reset-min.css&3.0.0/build/cssfonts/fonts-min.css&3.0.0/build/cssbase/base-context-min.css" />
10
+ <link rel="stylesheet" href="resources/screen.css" />
11
+ </head>
12
+ <body>
13
+ <div id="container">
14
+ <header>
15
+ <h1><%= @name %></h1>
16
+ </header>
17
+ <section class="yui-cssbase">
18
+ <% @images.each_with_index do |image, i| %>
19
+ <div class="item"><a href="show/<%= i %>.html"><img src="thumbs/<%= resize(image, 150, true) %>" height="150" width="150" /></a></div>
20
+ <% end %>
21
+ </section>
22
+ </div>
23
+ </body>
24
+ </html>
@@ -0,0 +1,31 @@
1
+ article, aside, dialog, figure, footer, header, hgroup, menu, nav, section {
2
+ display: block;
3
+ margin:0;
4
+ padding:0;
5
+ }
6
+
7
+ html {
8
+ background-color: #333;
9
+ }
10
+
11
+ body {
12
+ font-family: 'Helvetic Neue';
13
+ padding: 2em;
14
+ }
15
+
16
+ h1 {
17
+ color: #777;
18
+ font-size: 400%;
19
+ margin-bottom: .5em;
20
+ text-transform: uppercase;
21
+ }
22
+
23
+ .item {
24
+ float: left;
25
+ margin: 0 1.5em 1.5em 0;
26
+ }
27
+
28
+ .item img {
29
+ border: 1px solid #888;
30
+ -webkit-box-shadow: 2px 2px 6px #222;
31
+ }
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Gallerize</title>
5
+ <meta charset="utf-8" />
6
+ <!--[if IE]>
7
+ <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
8
+ <![endif]-->
9
+ <link rel="stylesheet" href="http://yui.yahooapis.com/combo?3.0.0/build/cssreset/reset-min.css&3.0.0/build/cssfonts/fonts-min.css&3.0.0/build/cssbase/base-context-min.css" />
10
+ <link rel="stylesheet" href="../resources/screen.css" />
11
+ </head>
12
+ <body>
13
+ <div id="container">
14
+ <header>
15
+ <h1><%= @name %></h1>
16
+ </header>
17
+ <section class="yui-cssbase">
18
+ <img src="../thumbs/<%= resize(image, 800) %>" />
19
+ <% if previous_image(i) %><a href="<%= i - 1 %>.html"><img src="../thumbs/<%= resize(previous_image(i), 75, true)%>" /></a><% end %>
20
+ <% if next_image(i) %><a href="<%= i + 1 %>.html"><img src="../thumbs/<%= resize(next_image(i), 75, true)%>" /></a><% end %>
21
+ </section>
22
+ </div>
23
+ </body>
24
+ </html>
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gallerize
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ version: "0.1"
9
+ platform: ruby
10
+ authors:
11
+ - Nick Chapman
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2010-04-28 00:00:00 -07:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: rmagick
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ segments:
27
+ - 2
28
+ - 13
29
+ - 1
30
+ version: 2.13.1
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: naturalsort
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 1
42
+ - 1
43
+ - 0
44
+ version: 1.1.0
45
+ type: :runtime
46
+ version_requirements: *id002
47
+ - !ruby/object:Gem::Dependency
48
+ name: trollop
49
+ prerelease: false
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 1
56
+ - 16
57
+ - 2
58
+ version: 1.16.2
59
+ type: :runtime
60
+ version_requirements: *id003
61
+ description:
62
+ email: nchapman@gmail.com
63
+ executables:
64
+ - gallerize
65
+ extensions: []
66
+
67
+ extra_rdoc_files: []
68
+
69
+ files:
70
+ - lib/gallerizer.rb
71
+ - bin/gallerize
72
+ - themes/default/index.html.erb
73
+ - themes/default/resources/screen.css
74
+ - themes/default/show.html.erb
75
+ has_rdoc: true
76
+ homepage:
77
+ licenses: []
78
+
79
+ post_install_message:
80
+ rdoc_options: []
81
+
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ requirements: []
99
+
100
+ rubyforge_project:
101
+ rubygems_version: 1.3.6
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Create an HTML photo gallery from a directory of images
105
+ test_files: []
106
+