picturama 0.0.3 → 0.0.5
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/Gemfile.lock +1 -1
- data/lib/picturama.rb +1 -1
- data/lib/picturama/album.rb +4 -0
- data/lib/picturama/picture.rb +12 -4
- data/lib/picturama/version.rb +1 -1
- data/lib/tasks/album.rake +43 -0
- data/lib/tasks/thumbnail.rake +28 -0
- data/lib/tasks/url.rake +14 -0
- data/rakefile +2 -88
- data/spec/picture_spec.rb +8 -0
- metadata +7 -4
data/Gemfile.lock
CHANGED
data/lib/picturama.rb
CHANGED
@@ -20,7 +20,7 @@ module Picturama
|
|
20
20
|
Dir["#{album_source}/*"].each { |album|
|
21
21
|
if File.directory?(album)
|
22
22
|
potential_album = Picturama::Album.new(:folder => album)
|
23
|
-
albums.push(potential_album)
|
23
|
+
albums.push(potential_album) if potential_album.valid?
|
24
24
|
end
|
25
25
|
}
|
26
26
|
albums
|
data/lib/picturama/album.rb
CHANGED
data/lib/picturama/picture.rb
CHANGED
@@ -3,13 +3,17 @@ require 'picturama'
|
|
3
3
|
module Picturama
|
4
4
|
class Picture < File
|
5
5
|
|
6
|
-
attr_accessor :thumbnail
|
6
|
+
attr_accessor :thumbnail, :resized, :metainfo
|
7
7
|
|
8
8
|
def initialize(args)
|
9
9
|
super
|
10
|
-
@thumbnail = "#{File.dirname(path)}/thumbnails/#{Picturama::config['thumbnail_prefix']}#{
|
11
|
-
@resized = "#{File.dirname(path)}/resized/resized_#{
|
12
|
-
@metainfo = "#{File.dirname(path)}/resized/resized_#{
|
10
|
+
@thumbnail = "#{File.dirname(path)}/thumbnails/#{Picturama::config['thumbnail_prefix']}#{basename}"
|
11
|
+
@resized = "#{File.dirname(path)}/resized/resized_#{basename}"
|
12
|
+
@metainfo = "#{File.dirname(path)}/resized/resized_#{basename}.info"
|
13
|
+
end
|
14
|
+
|
15
|
+
def basename
|
16
|
+
File.basename(path)
|
13
17
|
end
|
14
18
|
|
15
19
|
def info
|
@@ -29,5 +33,9 @@ module Picturama
|
|
29
33
|
File.delete(@resized) if has_resized?
|
30
34
|
end
|
31
35
|
|
36
|
+
def type
|
37
|
+
File.extname(path).split('.').last
|
38
|
+
end
|
39
|
+
|
32
40
|
end
|
33
41
|
end
|
data/lib/picturama/version.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
namespace :album do
|
2
|
+
desc "metadata handling for a given album"
|
3
|
+
namespace :metadata do
|
4
|
+
desc "generate metadata for an album in a given path"
|
5
|
+
task :generate do
|
6
|
+
puts ""
|
7
|
+
print "Type the album path: "
|
8
|
+
path = STDIN.gets.chomp
|
9
|
+
if File.directory?(path)
|
10
|
+
puts "Title:"
|
11
|
+
title = STDIN.gets.chomp
|
12
|
+
unless title.nil?
|
13
|
+
puts "Description (optional):"
|
14
|
+
description = STDIN.gets.chomp
|
15
|
+
puts "Author (optional):"
|
16
|
+
author = STDIN.gets.chomp
|
17
|
+
info = {"album" => {"title" => title, "description" => description, "author" => author}}
|
18
|
+
File.open("#{path}/.info.yml", 'w+') {|f| f.write(info.to_yaml) }
|
19
|
+
else
|
20
|
+
puts "Title cannot be empty. Run the task again"
|
21
|
+
end
|
22
|
+
else
|
23
|
+
puts "Sorry but #{path.inspect} entered is not a folder. Run the task again"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "retrieve metadata album based on path"
|
28
|
+
task :check do
|
29
|
+
puts ""
|
30
|
+
print "Type the album path: "
|
31
|
+
path = STDIN.gets.chomp
|
32
|
+
info_file = "#{path}/.info.yml"
|
33
|
+
if File.directory?(path) && File.exists?(info_file)
|
34
|
+
data = YAML.load_file(info_file)['album']
|
35
|
+
puts "Title: #{data['title']}"
|
36
|
+
puts "Description: #{data['description']}"
|
37
|
+
puts "Author: #{data['author']}"
|
38
|
+
else
|
39
|
+
puts "Sorry but #{path.inspect} entered is not a folder. Run the task again"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
namespace :thumbnail do
|
2
|
+
|
3
|
+
desc "Generate thumbnail for a given folder or just a single file"
|
4
|
+
task :generate, :source do |t, args|
|
5
|
+
if File.directory?(args[:source]) || File.exists?(args[:source])
|
6
|
+
size = Picturama::config['thumnail_default_size']
|
7
|
+
album = Picturama::Album.new(:folder => args[:source])
|
8
|
+
puts "Generating #{album.count_pictures} thumbnails for folder #{args[:source]}..."
|
9
|
+
puts "Size: #{size}"
|
10
|
+
unless album.has_broken_thumbnails?
|
11
|
+
puts "WARNING: Seems that this album has all his thumbnails properly generated. There are no broken thumbs."
|
12
|
+
end
|
13
|
+
album.init_thumbnails
|
14
|
+
album.pictures.each do |picture|
|
15
|
+
unless picture.has_thumbnail?
|
16
|
+
thumb = MiniMagick::Image.open(picture.path)
|
17
|
+
thumb.resize "#{size}"
|
18
|
+
thumb.format "jpg"
|
19
|
+
thumb.write picture.thumbnail
|
20
|
+
puts "Thumbnail generated for source #{File.basename(picture.path)}. Target destination #{File.basename(picture.thumbnail)}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
else
|
24
|
+
puts "Error => target destination #{args[:source]} does not exist"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/tasks/url.rake
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
namespace :url do
|
2
|
+
desc "Normalize album names name for URL format"
|
3
|
+
task :sluglify, :source do |t, args|
|
4
|
+
albums = Picturama::albums(args[:source])
|
5
|
+
puts "In folder #{args[:source].inspect} I'm moving..."
|
6
|
+
albums.each do |album|
|
7
|
+
target_folder = "#{args[:source]}/#{album.folder.to_url}"
|
8
|
+
unless File.directory?(target_folder)
|
9
|
+
FileUtils.mv "#{args[:source]}/#{album.folder}", "#{target_folder}"
|
10
|
+
puts "#{album.folder.inspect} to #{album.folder.to_url.inspect}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/rakefile
CHANGED
@@ -10,92 +10,6 @@ require "bundler/gem_tasks"
|
|
10
10
|
require "rake"
|
11
11
|
require "rake/testtask"
|
12
12
|
|
13
|
-
|
13
|
+
Dir.glob('lib/tasks/*.rake').each {|r| import r}
|
14
14
|
|
15
|
-
|
16
|
-
task :generate, :source do |t, args|
|
17
|
-
if File.directory?(args[:source]) || File.exists?(args[:source])
|
18
|
-
size = Picturama::config['thumnail_default_size']
|
19
|
-
album = Picturama::Album.new(:folder => args[:source])
|
20
|
-
puts "Generating #{album.count_pictures} thumbnails for folder #{args[:source]}..."
|
21
|
-
puts "Size: #{size}"
|
22
|
-
unless album.has_broken_thumbnails?
|
23
|
-
puts "WARNING: Seems that this album has all his thumbnails properly generated. There are no broken thumbs."
|
24
|
-
end
|
25
|
-
album.init_thumbnails
|
26
|
-
album.pictures.each do |picture|
|
27
|
-
unless picture.has_thumbnail?
|
28
|
-
thumb = MiniMagick::Image.open(picture.path)
|
29
|
-
thumb.resize "#{size}"
|
30
|
-
thumb.format "jpg"
|
31
|
-
thumb.write picture.thumbnail
|
32
|
-
puts "Thumbnail generated for source #{File.basename(picture.path)}. Target destination #{File.basename(picture.thumbnail)}"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
else
|
36
|
-
puts "Error => target destination #{args[:source]} does not exist"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
namespace :url do
|
43
|
-
desc "Normalize album names name for URL format"
|
44
|
-
task :sluglify, :source do |t, args|
|
45
|
-
albums = Picturama::albums(args[:source])
|
46
|
-
puts "In folder #{args[:source].inspect} I'm moving..."
|
47
|
-
albums.each do |album|
|
48
|
-
target_folder = "#{args[:source]}/#{album.folder.to_url}"
|
49
|
-
unless File.directory?(target_folder)
|
50
|
-
FileUtils.mv "#{args[:source]}/#{album.folder}", "#{target_folder}"
|
51
|
-
puts "#{album.folder.inspect} to #{album.folder.to_url.inspect}"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
namespace :album do
|
58
|
-
desc "metadata handling for a given album"
|
59
|
-
namespace :metadata do
|
60
|
-
desc "generate metadata for an album in a given path"
|
61
|
-
task :generate do
|
62
|
-
puts ""
|
63
|
-
print "Type the album path: "
|
64
|
-
path = STDIN.gets.chomp
|
65
|
-
if File.directory?(path)
|
66
|
-
puts "Title:"
|
67
|
-
title = STDIN.gets.chomp
|
68
|
-
unless title.nil?
|
69
|
-
puts "Description (optional):"
|
70
|
-
description = STDIN.gets.chomp
|
71
|
-
puts "Author (optional):"
|
72
|
-
author = STDIN.gets.chomp
|
73
|
-
info = {"album" => {"title" => title, "description" => description, "author" => author}}
|
74
|
-
File.open("#{path}/.info.yml", 'w+') {|f| f.write(info.to_yaml) }
|
75
|
-
else
|
76
|
-
puts "Title cannot be empty. Run the task again"
|
77
|
-
end
|
78
|
-
else
|
79
|
-
puts "Sorry but #{path.inspect} entered is not a folder. Run the task again"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
desc "retrieve metadata an album based on path"
|
84
|
-
task :check do
|
85
|
-
puts ""
|
86
|
-
print "Type the album path: "
|
87
|
-
path = STDIN.gets.chomp
|
88
|
-
info_file = "#{path}/.info.yml"
|
89
|
-
if File.directory?(path) && File.exists?(info_file)
|
90
|
-
data = YAML.load_file(info_file)['album']
|
91
|
-
puts "Title: #{data['title']}"
|
92
|
-
puts "Description: #{data['description']}"
|
93
|
-
puts "Author: #{data['author']}"
|
94
|
-
else
|
95
|
-
puts "Sorry but #{path.inspect} entered is not a folder. Run the task again"
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
task :default
|
15
|
+
task :default
|
data/spec/picture_spec.rb
CHANGED
@@ -22,5 +22,13 @@ describe "For a given picture in a given album" do
|
|
22
22
|
@picture.has_thumbnail?.should be_false
|
23
23
|
end
|
24
24
|
|
25
|
+
it "checks the image basename" do
|
26
|
+
@picture.basename.should == 'king.jpg'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "checks the image extension" do
|
30
|
+
@picture.type.downcase.should == 'jpg'
|
31
|
+
end
|
32
|
+
|
25
33
|
|
26
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: picturama
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mini_magick
|
@@ -80,6 +80,9 @@ files:
|
|
80
80
|
- lib/picturama/album.rb
|
81
81
|
- lib/picturama/picture.rb
|
82
82
|
- lib/picturama/version.rb
|
83
|
+
- lib/tasks/album.rake
|
84
|
+
- lib/tasks/thumbnail.rake
|
85
|
+
- lib/tasks/url.rake
|
83
86
|
- picturama.gemspec
|
84
87
|
- rakefile
|
85
88
|
- spec/album_spec.rb
|
@@ -104,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
107
|
version: '0'
|
105
108
|
segments:
|
106
109
|
- 0
|
107
|
-
hash:
|
110
|
+
hash: -319223615
|
108
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
112
|
none: false
|
110
113
|
requirements:
|
@@ -113,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
116
|
version: '0'
|
114
117
|
segments:
|
115
118
|
- 0
|
116
|
-
hash:
|
119
|
+
hash: -319223615
|
117
120
|
requirements: []
|
118
121
|
rubyforge_project:
|
119
122
|
rubygems_version: 1.8.24
|