dragonfly 0.3.8 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of dragonfly might be problematic. Click here for more details.
- data/.gitignore +1 -0
- data/.yardopts +0 -1
- data/VERSION +1 -1
- data/dragonfly.gemspec +2 -3
- data/extra_docs/UsingWithRails.md +35 -55
- data/generators/dragonfly_app/USAGE +4 -3
- data/generators/dragonfly_app/dragonfly_app_generator.rb +5 -24
- data/generators/dragonfly_app/templates/initializer.erb +26 -5
- metadata +2 -3
- data/generators/dragonfly_app/templates/metal_file.erb +0 -32
data/.gitignore
CHANGED
data/.yardopts
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/dragonfly.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dragonfly}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mark Evans"]
|
12
|
-
s.date = %q{2010-01-
|
12
|
+
s.date = %q{2010-01-04}
|
13
13
|
s.email = %q{mark@new-bamboo.co.uk}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -44,7 +44,6 @@ Gem::Specification.new do |s|
|
|
44
44
|
"generators/dragonfly_app/USAGE",
|
45
45
|
"generators/dragonfly_app/dragonfly_app_generator.rb",
|
46
46
|
"generators/dragonfly_app/templates/initializer.erb",
|
47
|
-
"generators/dragonfly_app/templates/metal_file.erb",
|
48
47
|
"irbrc.rb",
|
49
48
|
"lib/dragonfly.rb",
|
50
49
|
"lib/dragonfly/active_record_extensions.rb",
|
@@ -1,11 +1,10 @@
|
|
1
1
|
Using With Rails
|
2
2
|
================
|
3
3
|
|
4
|
-
|
5
|
-
and as a Rails Metal.
|
4
|
+
The main way to use Dragonfly with Rails is as a {Dragonfly::Middleware middleware}.
|
6
5
|
|
7
|
-
|
8
|
-
|
6
|
+
The quick way
|
7
|
+
-------------
|
9
8
|
In environment.rb:
|
10
9
|
|
11
10
|
config.gem 'rmagick'
|
@@ -20,29 +19,6 @@ and registers the app so that you can use ActiveRecord accessors.
|
|
20
19
|
Because in this case it's configured to use {http://tomayko.com/src/rack-cache/ rack-cache} and {http://rmagick.rubyforge.org/ rmagick},
|
21
20
|
you should include the first two lines above.
|
22
21
|
|
23
|
-
For reference, the contents of 'dragonfly/rails/images.rb' are as follows:
|
24
|
-
|
25
|
-
require 'dragonfly'
|
26
|
-
|
27
|
-
### The dragonfly app ###
|
28
|
-
|
29
|
-
app = Dragonfly::App[:images]
|
30
|
-
app.configure_with(Dragonfly::RMagickConfiguration)
|
31
|
-
app.configure do |c|
|
32
|
-
c.log = RAILS_DEFAULT_LOGGER
|
33
|
-
c.datastore.configure do |d|
|
34
|
-
d.root_path = "#{Rails.root}/public/system/dragonfly/#{Rails.env}"
|
35
|
-
end
|
36
|
-
c.url_handler.configure do |u|
|
37
|
-
u.protect_from_dos_attacks = false
|
38
|
-
u.path_prefix = '/media'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
### Extend active record ###
|
43
|
-
ActiveRecord::Base.extend Dragonfly::ActiveRecordExtensions
|
44
|
-
ActiveRecord::Base.register_dragonfly_app(:image, app)
|
45
|
-
|
46
22
|
The line `config.middleware.use 'Dragonfly::MiddlewareWithCache', :images` configures rails to use a {Dragonfly::MiddlewareWithCache middleware} which uses the named app (named `:images`), and puts
|
47
23
|
{http://tomayko.com/src/rack-cache/ Rack::Cache} in front of it for performance.
|
48
24
|
You can pass extra arguments to this line which will go directly to configuring Rack::Cache (see its docs for how to configure it).
|
@@ -56,31 +32,37 @@ The default configuration for Rack::Cache is
|
|
56
32
|
|
57
33
|
To see what you can do with the active record accessors, see {file:ActiveRecord}.
|
58
34
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
35
|
+
The more explicit way - using an initializer
|
36
|
+
--------------------------------------------
|
37
|
+
If you want more control over the configuration, you can do what the file 'dragonfly/rails/images' does yourself,
|
38
|
+
in an initializer.
|
63
39
|
|
64
|
-
|
65
|
-
|
66
|
-
|
40
|
+
In that case in environment.rb we only need:
|
41
|
+
|
42
|
+
config.gem 'rmagick' # if used
|
43
|
+
config.gem 'rack-cache' # if used
|
44
|
+
config.gem 'dragonfly'
|
45
|
+
|
46
|
+
The easiest way to create the initializer is using the supplied generator
|
47
|
+
(which will be visible if you have the dragonfly gem installed).
|
67
48
|
|
68
49
|
./script/generate dragonfly_app images
|
69
50
|
|
70
51
|
The argument 'images' could be anything - it is an arbitrary app name.
|
71
52
|
|
72
|
-
This does
|
53
|
+
This creates an initializer 'dragonfly_images' which does the following:
|
73
54
|
|
74
|
-
1. Creates and configures
|
55
|
+
1. Creates and configures a dragonfly app
|
75
56
|
2. Registers the app for use with ActiveRecord - see {file:ActiveRecord}
|
57
|
+
3. Inserts the app into the Rails middleware stack
|
76
58
|
|
77
|
-
For reference, the contents of
|
59
|
+
For reference, the contents of an example initializer are shown below.
|
60
|
+
You could just copy and paste this yourself into an initializer if you prefer,
|
61
|
+
but make sure to change the 'secret' configuration option, so as to protect your app from Denial-of-Service attacks (see {file:GettingStarted}).
|
78
62
|
|
79
|
-
# Allow the metal piece to run in isolation
|
80
|
-
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
|
81
63
|
require 'dragonfly'
|
82
64
|
|
83
|
-
# Configuration
|
65
|
+
# Configuration
|
84
66
|
app = Dragonfly::App[:images]
|
85
67
|
app.configure_with(Dragonfly::RMagickConfiguration)
|
86
68
|
app.configure do |c|
|
@@ -89,22 +71,20 @@ For reference, the contents of the metal file is given below. You could do somet
|
|
89
71
|
d.root_path = "#{Rails.root}/public/system/dragonfly/#{Rails.env}"
|
90
72
|
end
|
91
73
|
c.url_handler.configure do |u|
|
92
|
-
u.secret = '
|
74
|
+
u.secret = 'd54d2f8f44e81e9a6c4ec5ba76bc8ba12cf95717'
|
93
75
|
u.path_prefix = '/media'
|
94
76
|
end
|
95
77
|
end
|
96
78
|
|
97
|
-
#
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
end
|
79
|
+
# Extend ActiveRecord
|
80
|
+
# This allows you to use e.g.
|
81
|
+
# image_accessor :my_attribute
|
82
|
+
# in your models.
|
83
|
+
ActiveRecord::Base.extend Dragonfly::ActiveRecordExtensions
|
84
|
+
ActiveRecord::Base.register_dragonfly_app(:image, Dragonfly::App[:images])
|
85
|
+
|
86
|
+
# Add the Dragonfly App to the middleware stack
|
87
|
+
ActionController::Dispatcher.middleware.use Dragonfly::Middleware, :images
|
88
|
+
|
89
|
+
# USE THIS INSTEAD IF YOU WANT TO CACHE REQUESTS WITH Rack::Cache (remember to add config.gem for 'rack-cache')
|
90
|
+
# ActionController::Dispatcher.middleware.use Dragonfly::MiddlewareWithCache, :images
|
@@ -4,9 +4,10 @@ Example:
|
|
4
4
|
|
5
5
|
./script/generate dragonfly_app images
|
6
6
|
|
7
|
-
This will:
|
8
|
-
- create
|
9
|
-
- add
|
7
|
+
This will create an initializer called dragonfly_images, which will:
|
8
|
+
- create and configure a dragonfly app for serving images
|
9
|
+
- add the app to the middleware stack
|
10
|
+
- extend activerecord, so you can do things like
|
10
11
|
|
11
12
|
image_accessor :preview_image
|
12
13
|
|
@@ -4,37 +4,18 @@ class DragonflyAppGenerator < Rails::Generator::NamedBase
|
|
4
4
|
|
5
5
|
def manifest
|
6
6
|
app_name = plural_name
|
7
|
-
single_name = singular_name.singularize
|
8
|
-
metal_file = "#{single_name}_server"
|
9
|
-
metal_name = metal_file.camelize
|
10
|
-
path_prefix = 'media'
|
11
7
|
|
12
8
|
record do |m|
|
13
|
-
# The initializer
|
14
|
-
initializer_path = File.join(Rails.root, 'config', 'initializers', 'dragonfly.rb')
|
15
|
-
already_initialized_code = File.read(initializer_path) if File.exists?(initializer_path)
|
16
9
|
m.template(
|
17
10
|
'initializer.erb',
|
18
|
-
'config
|
11
|
+
File.join('config', 'initializers', "dragonfly_#{app_name}.rb"),
|
19
12
|
:assigns => {
|
20
13
|
:app_name => app_name,
|
21
|
-
:accessor_prefix =>
|
22
|
-
:
|
23
|
-
},
|
24
|
-
:collision => :force
|
25
|
-
)
|
26
|
-
|
27
|
-
# The metal file
|
28
|
-
m.directory('app/metal')
|
29
|
-
m.template(
|
30
|
-
'metal_file.erb',
|
31
|
-
"app/metal/#{metal_file}.rb",
|
32
|
-
:assigns => {
|
33
|
-
:app_name => app_name,
|
34
|
-
:metal_name => metal_name,
|
35
|
-
:path_prefix => path_prefix,
|
14
|
+
:accessor_prefix => singular_name.singularize,
|
15
|
+
:path_prefix => 'media',
|
36
16
|
:random_secret => Digest::SHA1.hexdigest(Time.now.to_s)
|
37
|
-
}
|
17
|
+
},
|
18
|
+
:collision => :ask
|
38
19
|
)
|
39
20
|
|
40
21
|
end
|
@@ -1,7 +1,28 @@
|
|
1
|
-
<%- if already_initialized_code -%>
|
2
|
-
<%= already_initialized_code %>
|
3
|
-
<%- else -%>
|
4
1
|
require 'dragonfly'
|
2
|
+
|
3
|
+
# Configuration
|
4
|
+
app = Dragonfly::App[:<%= app_name %>]
|
5
|
+
app.configure_with(Dragonfly::RMagickConfiguration)
|
6
|
+
app.configure do |c|
|
7
|
+
c.log = RAILS_DEFAULT_LOGGER
|
8
|
+
c.datastore.configure do |d|
|
9
|
+
d.root_path = "#{Rails.root}/public/system/dragonfly/#{Rails.env}"
|
10
|
+
end
|
11
|
+
c.url_handler.configure do |u|
|
12
|
+
u.secret = '<%= random_secret %>'
|
13
|
+
u.path_prefix = '/<%= path_prefix %>'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Extend ActiveRecord
|
18
|
+
# This allows you to use e.g.
|
19
|
+
# <%= accessor_prefix %>_accessor :my_attribute
|
20
|
+
# in your models.
|
5
21
|
ActiveRecord::Base.extend Dragonfly::ActiveRecordExtensions
|
6
|
-
|
7
|
-
|
22
|
+
ActiveRecord::Base.register_dragonfly_app(:<%= accessor_prefix %>, Dragonfly::App[:<%= app_name %>])
|
23
|
+
|
24
|
+
# Add the Dragonfly App to the middleware stack
|
25
|
+
ActionController::Dispatcher.middleware.use Dragonfly::Middleware, :<%= app_name %>
|
26
|
+
|
27
|
+
# USE THIS INSTEAD IF YOU WANT TO CACHE REQUESTS WITH Rack::Cache (remember to add config.gem for 'rack-cache')
|
28
|
+
# ActionController::Dispatcher.middleware.use Dragonfly::MiddlewareWithCache, :<%= app_name %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dragonfly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Evans
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-04 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -60,7 +60,6 @@ files:
|
|
60
60
|
- generators/dragonfly_app/USAGE
|
61
61
|
- generators/dragonfly_app/dragonfly_app_generator.rb
|
62
62
|
- generators/dragonfly_app/templates/initializer.erb
|
63
|
-
- generators/dragonfly_app/templates/metal_file.erb
|
64
63
|
- irbrc.rb
|
65
64
|
- lib/dragonfly.rb
|
66
65
|
- lib/dragonfly/active_record_extensions.rb
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# Allow the metal piece to run in isolation
|
2
|
-
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
|
3
|
-
require 'dragonfly'
|
4
|
-
|
5
|
-
# Configuration of the Dragonfly App
|
6
|
-
app = Dragonfly::App[:<%= app_name %>]
|
7
|
-
app.configure_with(Dragonfly::RMagickConfiguration)
|
8
|
-
app.configure do |c|
|
9
|
-
c.log = RAILS_DEFAULT_LOGGER
|
10
|
-
c.datastore.configure do |d|
|
11
|
-
d.root_path = "#{Rails.root}/public/system/dragonfly/#{Rails.env}"
|
12
|
-
end
|
13
|
-
c.url_handler.configure do |u|
|
14
|
-
u.secret = '<%= random_secret %>'
|
15
|
-
u.path_prefix = '/<%= path_prefix %>'
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# The metal, for running the app
|
20
|
-
<%= metal_name %> = Rack::Builder.new do
|
21
|
-
|
22
|
-
# UNCOMMENT ME!!!
|
23
|
-
# ... if you want to use super-dooper middleware 'rack-cache'
|
24
|
-
# require 'rack/cache'
|
25
|
-
# use Rack::Cache,
|
26
|
-
# :verbose => true,
|
27
|
-
# :metastore => 'file:/var/cache/rack/meta',
|
28
|
-
# :entitystore => 'file:/var/cache/rack/body'
|
29
|
-
|
30
|
-
run app
|
31
|
-
|
32
|
-
end
|