spree_watermark 0.50.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .project
7
+ tmp
8
+ nbproject
9
+ *.swp
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Redistribution and use in source and binary forms, with or without modification,
2
+ are permitted provided that the following conditions are met:
3
+
4
+ * Redistributions of source code must retain the above copyright notice,
5
+ this list of conditions and the following disclaimer.
6
+ * Redistributions in binary form must reproduce the above copyright notice,
7
+ this list of conditions and the following disclaimer in the documentation
8
+ and/or other materials provided with the distribution.
9
+ * Neither the name of the Rails Dog LLC nor the names of its
10
+ contributors may be used to endorse or promote products derived from this
11
+ software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ SpreeWatermark
2
+ ==============
3
+
4
+ Introduction goes here.
5
+
6
+
7
+ Example
8
+ =======
9
+
10
+ Example goes here.
11
+
12
+
13
+ Copyright (c) 2011 [name of extension creator], released under the New BSD License
data/Rakefile ADDED
@@ -0,0 +1,75 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/packagetask'
5
+ require 'rake/gempackagetask'
6
+
7
+ gemfile = File.expand_path('../spec/test_app/Gemfile', __FILE__)
8
+ if File.exists?(gemfile) && (%w(spec cucumber).include?(ARGV.first.to_s) || ARGV.size == 0)
9
+ require 'bundler'
10
+ ENV['BUNDLE_GEMFILE'] = gemfile
11
+ Bundler.setup
12
+
13
+ require 'rspec'
14
+ require 'rspec/core/rake_task'
15
+ RSpec::Core::RakeTask.new
16
+
17
+ require 'cucumber/rake/task'
18
+ Cucumber::Rake::Task.new do |t|
19
+ t.cucumber_opts = %w{--format progress}
20
+ end
21
+ end
22
+
23
+ desc "Default Task"
24
+ task :default => [:spec, :cucumber ]
25
+
26
+ spec = eval(File.read('spree_watermark.gemspec'))
27
+
28
+ Rake::GemPackageTask.new(spec) do |p|
29
+ p.gem_spec = spec
30
+ end
31
+
32
+ desc "Release to gemcutter"
33
+ task :release => :package do
34
+ require 'rake/gemcutter'
35
+ Rake::Gemcutter::Tasks.new(spec).define
36
+ Rake::Task['gem:push'].invoke
37
+ end
38
+
39
+ desc "Default Task"
40
+ task :default => [ :spec ]
41
+
42
+ desc "Regenerates a rails 3 app for testing"
43
+ task :test_app do
44
+ require '../spree/lib/generators/spree/test_app_generator'
45
+ class SpreeWatermarkTestAppGenerator < Spree::Generators::TestAppGenerator
46
+
47
+ def install_gems
48
+ inside "test_app" do
49
+ run 'rake spree_core:install'
50
+ run 'rake spree_watermark:install'
51
+ end
52
+ end
53
+
54
+ def migrate_db
55
+ run_migrations
56
+ end
57
+
58
+ protected
59
+ def full_path_for_local_gems
60
+ <<-gems
61
+ gem 'spree_core', :path => \'#{File.join(File.dirname(__FILE__), "../spree/", "core")}\'
62
+ gem 'spree_watermark', :path => \'#{File.dirname(__FILE__)}\'
63
+ gems
64
+ end
65
+
66
+ end
67
+ SpreeWatermarkTestAppGenerator.start
68
+ end
69
+
70
+ namespace :test_app do
71
+ desc 'Rebuild test and cucumber databases'
72
+ task :rebuild_dbs do
73
+ system("cd spec/test_app && rake db:drop db:migrate RAILS_ENV=test && rake db:drop db:migrate RAILS_ENV=cucumber")
74
+ end
75
+ end
@@ -0,0 +1,35 @@
1
+ Image.class_eval do
2
+ has_attached_file(
3
+ :attachment,
4
+ :processors => [:thumbnail, :watermark],
5
+ :styles => {
6
+ :mini => {
7
+ :geometry => '48x48>',
8
+ :watermark_path => "#{RAILS_ROOT}/public/images/watermarks/tiny.png",
9
+ :watermark_position => "SouthWest",
10
+ :format => :png,
11
+ },
12
+ :small => {
13
+ :geometry => '100x100>',
14
+ :watermark_path => "#{RAILS_ROOT}/public/images/watermarks/small.png",
15
+ :watermark_position => "SouthWest",
16
+ :format => :png,
17
+ },
18
+ :product => {
19
+ :geometry => '240x240>',
20
+ :watermark_path => "#{RAILS_ROOT}/public/images/watermarks/product.png",
21
+ :watermark_position => "SouthWest",
22
+ :format => :png,
23
+ },
24
+ :large => {
25
+ :geometry => '600x600>',
26
+ :watermark_path => "#{RAILS_ROOT}/public/images/watermarks/large.png",
27
+ :watermark_position => "SouthWest",
28
+ :format => :png,
29
+ },
30
+ },
31
+ :default_style => :product,
32
+ :url => "/assets/products/:id/:style/:basename.:extension",
33
+ :path => ":rails_root/public/assets/products/:id/:style/:basename.:extension"
34
+ )
35
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ # Add your extension routes here
3
+ end
@@ -0,0 +1,51 @@
1
+ # Based on
2
+ # https://github.com/ng/paperclip-watermarking-app/blob/master/lib/paperclip_processors/watermark.rb
3
+ # Modified by Laurynas Butkus
4
+ # Copied from https://gist.github.com/708077 into rtw_theme by Christopher Maujean
5
+
6
+ module Paperclip
7
+ class Watermark < Processor
8
+ # Handles watermarking of images that are uploaded.
9
+ attr_accessor :format, :whiny, :watermark_path, :position
10
+
11
+ def initialize file, options = {}, attachment = nil
12
+ super
13
+ @file = file
14
+ @whiny = options[:whiny].nil? ? true : options[:whiny]
15
+ @format = options[:format]
16
+ @watermark_path = options[:watermark_path]
17
+ @position = options[:watermark_position].nil? ? "SouthEast" : options[:watermark_position]
18
+
19
+ @current_format = File.extname(@file.path)
20
+ @basename = File.basename(@file.path, @current_format)
21
+ end
22
+
23
+ # Performs the conversion of the +file+ into a watermark. Returns the Tempfile
24
+ # that contains the new image.
25
+ def make
26
+ return @file unless watermark_path
27
+
28
+ dst = Tempfile.new([@basename, @format].compact.join("."))
29
+ dst.binmode
30
+
31
+ command = "composite"
32
+ params = "-gravity #{@position} #{watermark_path} #{fromfile} #{tofile(dst)}"
33
+
34
+ begin
35
+ success = Paperclip.run(command, params)
36
+ rescue PaperclipCommandLineError
37
+ raise PaperclipError, "There was an error processing the watermark for #{@basename}" if @whiny
38
+ end
39
+
40
+ dst
41
+ end
42
+
43
+ def fromfile
44
+ "\"#{ File.expand_path(@file.path) }[0]\""
45
+ end
46
+
47
+ def tofile(destination)
48
+ "\"#{ File.expand_path(destination.path) }[0]\""
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,18 @@
1
+ require 'spree_core'
2
+ require 'spree_watermark_hooks'
3
+ require "paperclip_processors/watermark.rb"
4
+
5
+ module SpreeWatermark
6
+ class Engine < Rails::Engine
7
+
8
+ config.autoload_paths += %W(#{config.root}/lib)
9
+
10
+ def self.activate
11
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
12
+ Rails.env.production? ? require(c) : load(c)
13
+ end
14
+ end
15
+
16
+ config.to_prepare &method(:activate).to_proc
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ class SpreeWatermarkHooks < Spree::ThemeSupport::HookListener
2
+ # custom hooks go here
3
+ end
@@ -0,0 +1,25 @@
1
+ namespace :spree_watermark do
2
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
3
+ task :install do
4
+ Rake::Task['spree_watermark:install:migrations'].invoke
5
+ Rake::Task['spree_watermark:install:assets'].invoke
6
+ end
7
+
8
+ namespace :install do
9
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
10
+ task :migrations do
11
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
12
+ destination = File.join(Rails.root, 'db')
13
+ Spree::FileUtilz.mirror_files(source, destination)
14
+ end
15
+
16
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
17
+ task :assets do
18
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
19
+ destination = File.join(Rails.root, 'public')
20
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
21
+ Spree::FileUtilz.mirror_files(source, destination)
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1 @@
1
+ # add custom rake tasks here
@@ -0,0 +1,30 @@
1
+ # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2
+ # from the project root directory.
3
+ ENV["RAILS_ENV"] ||= 'test'
4
+ require File.expand_path("../test_app/config/environment", __FILE__)
5
+ require 'rspec/rails'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+ # == Mock Framework
13
+ #
14
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
15
+ #
16
+ # config.mock_with :mocha
17
+ # config.mock_with :flexmock
18
+ # config.mock_with :rr
19
+ config.mock_with :rspec
20
+
21
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
22
+
23
+ #config.include Devise::TestHelpers, :type => :controller
24
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
25
+ # examples within a transaction, comment the following line or assign false
26
+ # instead of true.
27
+ config.use_transactional_fixtures = true
28
+ end
29
+
30
+ @configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.platform = Gem::Platform::RUBY
3
+ s.name = 'spree_watermark'
4
+ s.version = '0.50.0'
5
+ s.summary = 'adds watermarking to incoming images'
6
+ s.description = 'Adds watermarking to incoming images'
7
+ s.required_ruby_version = '>= 1.9.2'
8
+ s.author = 'Christopher Maujean'
9
+ s.email = 'christopher@azimuthonline.com'
10
+
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.require_path = 'lib'
15
+ s.requirements << 'none'
16
+
17
+ s.has_rdoc = true
18
+
19
+ s.add_dependency('spree_core', '>= 0.50.0')
20
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_watermark
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.50.0
6
+ platform: ruby
7
+ authors:
8
+ - Christopher Maujean
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-27 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: spree_core
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.50.0
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description: Adds watermarking to incoming images
28
+ email: christopher@azimuthonline.com
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.md
39
+ - Rakefile
40
+ - app/models/image_decorator.rb
41
+ - config/routes.rb
42
+ - lib/paperclip_processors/watermark.rb
43
+ - lib/spree_watermark.rb
44
+ - lib/spree_watermark_hooks.rb
45
+ - lib/tasks/install.rake
46
+ - lib/tasks/spree_watermark.rake
47
+ - spec/spec_helper.rb
48
+ - spree_watermark.gemspec
49
+ has_rdoc: true
50
+ homepage:
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options: []
55
+
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 1.9.2
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ requirements:
71
+ - none
72
+ rubyforge_project:
73
+ rubygems_version: 1.6.2
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: adds watermarking to incoming images
77
+ test_files:
78
+ - spec/spec_helper.rb