Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of git://github.com/jnicklas/carrierwave

Conflicts:
	spec/orm/activerecord_spec.rb
  • Loading branch information...
commit 769622ae6645a61d037a0330e16f9767e229a3e2 2 parents c564f2a + f30f54e
Bart Teeuwisse authored
View
1  .travis.yml
@@ -4,6 +4,5 @@ rvm:
- 1.9.3
- ruby-head
- ree
- - jruby
- rbx
- rbx-2.0
View
6 README.md
@@ -3,6 +3,8 @@
This gem provides a simple and extremely flexible way to upload files from Ruby applications.
It works well with Rack based web applications, such as Ruby on Rails.
+[![Build Status](https://secure.travis-ci.org/jnicklas/carrierwave.png)](http://travis-ci.org/jnicklas/carrierwave)
+
## Information
* RDoc documentation [available on RubyDoc.info](http://rubydoc.info/gems/carrierwave/frames)
@@ -173,7 +175,7 @@ plugins or client-side software.
## Setting the content type
-If care about the content type of your files and notice that it's not being set
+If you care about the content type of your files and notice that it's not being set
as expected, you can configure your uploaders to use `CarrierWave::MimeTypes`.
This adds a dependency on the [mime-types](http://rubygems.org/gems/mime-types) gem,
but is recommended when using fog, and fog already has a dependency on mime-types.
@@ -184,7 +186,7 @@ require 'carrierwave/processing/mime_types'
class MyUploader < CarrierWave::Uploader::Base
include CarrierWave::MimeTypes
- processor :set_content_type
+ process :set_content_type
end
```
View
3  lib/carrierwave.rb
@@ -15,7 +15,7 @@
module CarrierWave
class << self
- attr_accessor :root
+ attr_accessor :root, :base_path
def configure(&block)
CarrierWave::Uploader::Base.configure(&block)
@@ -92,6 +92,7 @@ module CarrierWave
class Railtie < Rails::Railtie
initializer "carrierwave.setup_paths" do
CarrierWave.root = Rails.root.join(Rails.public_path).to_s
+ CarrierWave.base_path = ENV['RAILS_RELATIVE_URL_ROOT']
end
initializer "carrierwave.active_record" do
View
2  lib/carrierwave/uploader/configuration.rb
@@ -8,6 +8,7 @@ module Configuration
class_attribute :_storage, :instance_writer => false
add_config :root
+ add_config :base_path
add_config :permissions
add_config :storage_engines
add_config :s3_access_policy
@@ -150,6 +151,7 @@ def reset_config
config.validate_integrity = true
config.validate_processing = true
config.root = CarrierWave.root
+ config.base_path = CarrierWave.base_path
config.enable_processing = true
config.ensure_multipart_form = true
end
View
4 lib/carrierwave/uploader/url.rb
@@ -3,6 +3,8 @@
module CarrierWave
module Uploader
module Url
+ extend ActiveSupport::Concern
+ include CarrierWave::Uploader::Configuration
##
# === Returns
@@ -13,7 +15,7 @@ def url
if file.respond_to?(:url) and not file.url.blank?
file.url
elsif current_path
- File.expand_path(current_path).gsub(File.expand_path(root), '')
+ (base_path || "") + File.expand_path(current_path).gsub(File.expand_path(root), '')
end
end
View
2  spec/orm/activerecord_spec.rb
@@ -97,7 +97,7 @@ class Event < ActiveRecord::Base; end # setup a basic AR class for testing
it "should return valid XML when to_xml is called when image is nil" do
@event[:image].should be_nil
- Hash.from_xml(@event.to_xml)["event#{$arclass}"].should == {"textfile"=>nil, "id"=>nil, "foo"=>nil}
+ Hash.from_xml(@event.to_xml)["event#{$arclass}"].except("id").should == {"textfile"=>nil, "foo"=>nil}
end
# FIXME to_xml should work like to_json
View
9 spec/uploader/url_spec.rb
@@ -51,6 +51,15 @@
@uploader.url(:thumb, :mini).should == '/uploads/tmp/20071201-1234-345-2255/thumb_mini_test.jpg'
end
+ it "should prepend the config option 'base_path', if set" do
+ @uploader_class.version(:thumb)
+ @uploader.class.configure do |config|
+ config.base_path = "/base_path"
+ end
+ @uploader.cache!(File.open(file_path('test.jpg')))
+ @uploader.url(:thumb).should == '/base_path/uploads/tmp/20071201-1234-345-2255/thumb_test.jpg'
+ end
+
it "should return file#url if available" do
@uploader.cache!(File.open(file_path('test.jpg')))
@uploader.file.stub!(:url).and_return('http://www.example.com/someurl.jpg')
Please sign in to comment.
Something went wrong with that request. Please try again.