bcms_thumbnail 1.0.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.
- data/README +67 -0
- data/app/controllers/application_controller.rb +10 -0
- data/app/helpers/application_helper.rb +3 -0
- data/lib/bcms_thumbnail/bcms_thumbnail.rb +27 -0
- data/lib/bcms_thumbnail/routes.rb +7 -0
- data/lib/bcms_thumbnail.rb +2 -0
- data/lib/tasks/bcms_thumbnail.rake +7 -0
- data/public/bcms/thumbnail/README +1 -0
- data/rails/init.rb +5 -0
- metadata +83 -0
data/README
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
== browser_cms thumbnail extension
|
2
|
+
|
3
|
+
This extension adds a "thumbnail" view helper that takes a content_block with an attachment (an ImageBlock or a custom content_block) and creates a thumbnail according to the ImageMagick geometry you specify.
|
4
|
+
|
5
|
+
* Supports png, jpg, gif, and bmp formats. Thumbnails are output in jpg format.
|
6
|
+
* The default geometry is "100x100" - so no side larger than 100 pixels.
|
7
|
+
* It caches these thumbnails in the directory RAILS_ROOT/public/bcms_thumbnail_cache/. We'll create this directory automatically if needed.
|
8
|
+
* Use the "bcms_thumbnail:clear" rake task to clear the thumbnail cache.
|
9
|
+
* Thumbnails are public. They are served directly off the filesystem.
|
10
|
+
|
11
|
+
== Examples
|
12
|
+
|
13
|
+
It's pretty simple. The code below demonstrates creating a thumbnail from an image block, which (naturally) has a browser_cms attachment. This code overrides the default 100x100 geometry and creates images of no larger than 125 pixels on any side.
|
14
|
+
|
15
|
+
Add a dynamic portlet and the add this to the template:
|
16
|
+
<% image = ImageBlock.find(:first) %>
|
17
|
+
<%= image_tag(thumbnail(image,'125x125')) %>
|
18
|
+
|
19
|
+
A stupidly simple image gallery? It's easier than you think! Again, in a dynamic portlet:
|
20
|
+
|
21
|
+
<div class="gallery">
|
22
|
+
<% ImageBlock.find(:all).each do |image| %>
|
23
|
+
<div class="image"><%= link_to(image_tag(thumbnail(image,'100x100'), :alt => image.name),image.attachment.file_path) %></div>
|
24
|
+
<% end %>
|
25
|
+
</div>
|
26
|
+
|
27
|
+
The above, but only for images with a certain tag? Oh, hell yes:
|
28
|
+
|
29
|
+
<div class="gallery">
|
30
|
+
<% Tag.find_by_name('lol').taggings.find(:all, :conditions => ['taggable_type = ?', 'AbstractFileBlock']).collect{|img| img.taggable}.each do |image| %>
|
31
|
+
<div class="image"><%= link_to(image_tag(thumbnail(image,'100x100'), :alt => image.name),image.attachment.file_path) %></div>
|
32
|
+
<% end %>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
Note: The code above is yucky. But cool.
|
36
|
+
|
37
|
+
== Example geometries
|
38
|
+
|
39
|
+
ImageMagick will preserve aspect ratio with all the geometries below:
|
40
|
+
|
41
|
+
* "125" will ensure the width is no more than 125px.
|
42
|
+
* "x125" will ensure the height is no more than 125px.
|
43
|
+
* "125x125" will ensure neither side is more than 125px.
|
44
|
+
* "50%" will scale the image to half its size.
|
45
|
+
|
46
|
+
More info on ImageMagick geometry here: http://www.imagemagick.org/www/command-line-processing.html#geometry
|
47
|
+
|
48
|
+
== Todo
|
49
|
+
|
50
|
+
* Decache thumbnails when image attachments change via a monkey-patch on the bcms core attachment features.
|
51
|
+
* Hook image de-caching into the page de-caching control built into the bcms backend.
|
52
|
+
* Beef up the thumbnail helper to expose more mini_magick features.
|
53
|
+
* Better error reporting and sanity checking.
|
54
|
+
|
55
|
+
== Requires
|
56
|
+
|
57
|
+
* The mini_magick gem, version >= 1.2.5
|
58
|
+
* ImageMagick, to satisfy the above.
|
59
|
+
|
60
|
+
== Author
|
61
|
+
|
62
|
+
Dan Collis-Puro, http://collispuro.com, http://github.com/djcp/
|
63
|
+
|
64
|
+
== License
|
65
|
+
|
66
|
+
This extension is licensed under the Gnu LGPL: http://www.gnu.org/licenses/lgpl.html
|
67
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Filters added to this controller apply to all controllers in the application.
|
2
|
+
# Likewise, all the methods added will be available for all controllers.
|
3
|
+
|
4
|
+
class ApplicationController < ActionController::Base
|
5
|
+
helper :all # include all helpers, all the time
|
6
|
+
protect_from_forgery # See ActionController::RequestForgeryProtection for details
|
7
|
+
|
8
|
+
# Scrub sensitive parameters from your log
|
9
|
+
# filter_parameter_logging :password
|
10
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'mini_magick'
|
2
|
+
require 'uri'
|
3
|
+
module ActionView
|
4
|
+
module Helpers
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def thumbnail(attachment_obj,geometry = '100x100')
|
8
|
+
if ! attachment_obj.blank? && attachment_obj.respond_to?('attachment') && ['jpg','png','gif','bmp'].include?(attachment_obj.attachment.file_extension.downcase)
|
9
|
+
thumbnail_location = "/bcms_thumbnail_cache/#{attachment_obj.attachment.file_location.gsub(/[\\\/]/,'-')}-#{geometry}.jpg"
|
10
|
+
if ! File.exists?("#{RAILS_ROOT}/public#{thumbnail_location}")
|
11
|
+
if ! File.exists?("#{RAILS_ROOT}/public/bcms_thumbnail_cache/")
|
12
|
+
FileUtils.mkdir_p("#{RAILS_ROOT}/public/bcms_thumbnail_cache/")
|
13
|
+
end
|
14
|
+
image = MiniMagick::Image.from_file("#{RAILS_ROOT}/tmp/uploads/#{attachment_obj.attachment.file_location}")
|
15
|
+
image.resize geometry
|
16
|
+
image.write("#{RAILS_ROOT}/public#{thumbnail_location}")
|
17
|
+
URI::escape(thumbnail_location)
|
18
|
+
else
|
19
|
+
URI::escape(thumbnail_location)
|
20
|
+
end
|
21
|
+
else
|
22
|
+
logger.warn("bcms_thumbnail: Either the attachment object doesn't accept attachments, you passed us a blank object, or the attachment type can't be thumbnailed.")
|
23
|
+
'/image-not-found'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
namespace :bcms_thumbnail do
|
2
|
+
desc 'Clear cached thumbnails'
|
3
|
+
task(:clear => :environment) do
|
4
|
+
FileUtils.rm_rf("#{RAILS_ROOT}/public/bcms_thumbnail_cache/")
|
5
|
+
puts 'Thumbnail cache cleared. You should clear the page cache now as well, to ensure the thumbnails are regenerated properly'
|
6
|
+
end
|
7
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Use this directory to add public files that should copied from the gem into the project.
|
data/rails/init.rb
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
gem_root = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
2
|
+
Cms.add_to_rails_paths gem_root
|
3
|
+
Cms.add_generator_paths gem_root, "db/migrate/[0-9]*_*.rb"
|
4
|
+
Cms.add_generator_paths gem_root, "public/bcms/thumbnail/**/*"
|
5
|
+
Cms.add_generator_paths gem_root, "lib/tasks/*.rake"
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bcms_thumbnail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Dan Collis-Puro
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-24 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: mini_magick
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 2
|
30
|
+
- 5
|
31
|
+
version: 1.2.5
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description:
|
35
|
+
email: dan@collispuro.com
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files:
|
41
|
+
- README
|
42
|
+
files:
|
43
|
+
- app/helpers/application_helper.rb
|
44
|
+
- app/controllers/application_controller.rb
|
45
|
+
- lib/bcms_thumbnail.rb
|
46
|
+
- lib/bcms_thumbnail/routes.rb
|
47
|
+
- lib/bcms_thumbnail/bcms_thumbnail.rb
|
48
|
+
- rails/init.rb
|
49
|
+
- lib/tasks/bcms_thumbnail.rake
|
50
|
+
- public/bcms/thumbnail/README
|
51
|
+
- README
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://collispuro.com
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project: bcms_thumbnail
|
78
|
+
rubygems_version: 1.3.6
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: A thumbnailing view helper module for BrowserCMS
|
82
|
+
test_files: []
|
83
|
+
|