moved to rdoc instead of yard

This commit is contained in:
Jonas Nicklas 2009-03-16 23:09:16 +01:00
parent 3b90acc5f3
commit c04b961253
2 changed files with 35 additions and 29 deletions

View File

@ -1,8 +1,8 @@
# CarrierWave
= CarrierWave
This plugin for Merb and Rails provides a simple and extremely flexible way to upload files.
## Getting Started
== Getting Started
Install the latest stable release:
@ -20,7 +20,7 @@ In Rails, add it to your environment.rb:
config.gem "carrierwave"
## Quick Start
== Quick Start
Start off by generating an uploader:
@ -48,11 +48,11 @@ You can use your uploader class to store and retrieve files like this:
uploader.retrieve_from_store!('my_file.png')
CarrierWave gives you a `store` for permanent storage, and a `cache` for temporary storage. You can use different stores, at the moment a filesystem store and an Amazon S3 store are bundled.
CarrierWave gives you a +store+ for permanent storage, and a +cache+ for temporary storage. You can use different stores, at the moment a filesystem store and an Amazon S3 store are bundled.
Most of the time you are going to want to use CarrierWave together with an ORM. It is quite simple to mount uploaders on columns in your model, so you can simply assign files and get going:
### ActiveRecord
=== ActiveRecord
First require the activerecord extension:
@ -75,7 +75,7 @@ Now you can upload files!
u.avatar.url # => '/url/to/file.png'
u.avatar.current_path # => 'path/to/file.png'
### DataMapper
=== DataMapper
First require the activerecord extension:
@ -100,9 +100,9 @@ Now you can upload files!
u.avatar.url # => '/url/to/file.png'
u.avatar.current_path # => 'path/to/file.png'
## Changing the storage directory
== Changing the storage directory
In order to change where uploaded files are put, just override the `store_dir` method:
In order to change where uploaded files are put, just override the +store_dir+ method:
class MyUploader < CarrierWave::Uploader
def store_dir
@ -112,7 +112,7 @@ In order to change where uploaded files are put, just override the `store_dir` m
This works for the file storage as well as Amazon S3.
## Adding versions
== Adding versions
Often you'll want to add different versions of the same file. The classic example is image thumbnails. There is built in support for this:
@ -137,11 +137,11 @@ When this uploader is used, an uploaded image would be scaled to be no larger th
One important thing to remember is that process is called *before* versions are created. This can cut down on processing cost.
## Making uploads work across form redisplays
== Making uploads work across form redisplays
Often you'll notice that uploaded files disappear when a validation
fails. CarrierWave has a feature that makes it easy to remember the
uploaded file even in that case. Suppose your `user` model has an uploader mounted on `avatar` file, just add a hidden field called `avatar_cache`.
uploaded file even in that case. Suppose your +user+ model has an uploader mounted on +avatar+ file, just add a hidden field called +avatar_cache+.
In Rails, this would look like this:
<% form_for @user do |f| %>
@ -164,27 +164,27 @@ in the case of images, a small thumbnail would be a good indicator:
</p>
<% end %>
## What's in that uploader file?
== What's in that uploader file?
The fact that uploaders are separate classes in CarrierWave is a big advantage. What this means for you is:
#### Less magic
==== Less magic
In order to customize your uploader, all you need to do is override methods and use normal, clear and simple Ruby code. That means no `alias_method_chain`'ing to hook into the upload process, no messing around with weird extensions. The code in CarrierWave is very simple and easy because of this.
In order to customize your uploader, all you need to do is override methods and use normal, clear and simple Ruby code. That means no +alias_method_chain+'ing to hook into the upload process, no messing around with weird extensions. The code in CarrierWave is very simple and easy because of this.
#### Easier to test
==== Easier to test
How do you test file uploads? I always found this ridiculously hard. A separate class means you can test is separately, which is nicer, easier and more maintainable.
#### More Flexible
==== More Flexible
Many of the things you can do in CarrierWave are hard, or impossible to do in other file upload plugins, and have previously required you to roll your own. Now you can get all the flexibility without having to write low level stuff.
#### Easy to extend
==== Easy to extend
CarrierWave has support for a few different image manipulation libraries. These need *no* code to hook into CarrierWave, because they are simple modules. If you want to write your own manipulation library (doesn't need to be for images), you can do the same.
## Using Amazon S3
== Using Amazon S3
You'll need to configure a bucket, access id and secret key like this:
@ -192,7 +192,7 @@ You'll need to configure a bucket, access id and secret key like this:
CarrierWave.config[:s3][:secret_access_key] = 'xxxxxx'
CarrierWave.config[:s3][:bucket] = 'name_of_bucket'
Do this in an initializer in Rails, and in a `before_app_loads` block in Merb.
Do this in an initializer in Rails, and in a +before_app_loads+ block in Merb.
And then in your uploader, set the storage to :s3
@ -200,9 +200,9 @@ And then in your uploader, set the storage to :s3
storage :s3
end
That's it! You can still use the `CarrierWave::Uploader#url` method to return the url to the file on Amazon S3
That's it! You can still use the +CarrierWave::Uploader#url+ method to return the url to the file on Amazon S3
## Using RMagick
== Using RMagick
If you're uploading images, you'll probably want to manipulate them in some way, you might want to create thumbnail images for example. CarrierWave comes with a small library to make manipulating images with RMagick easier. It's not loaded by default so you'll need to require it:
@ -214,7 +214,7 @@ You'll also need to include it in your Uploader:
include CarrierWave::RMagick
end
The RMagick module gives you a few methods, like `CarrierWave::RMagick#crop_resized` which manipulate the image file in some way. You can set a `process` callback, which will call that method any time a file is uploaded.
The RMagick module gives you a few methods, like +CarrierWave::RMagick#crop_resized+ which manipulate the image file in some way. You can set a +process+ callback, which will call that method any time a file is uploaded.
class AvatarUploader < CarrierWave::Uploader
include CarrierWave::RMagick
@ -229,7 +229,7 @@ The RMagick module gives you a few methods, like `CarrierWave::RMagick#crop_resi
Check out the manipulate! method, which makes it easy for you to write your own manipulation methods.
## Using ImageScience
== Using ImageScience
ImageScience works the same way as RMagick. As with RMagick you'll need to require it:
@ -243,10 +243,10 @@ And then include it in your model:
process :crop_resized => [200, 200]
end
## Documentation
== Documentation
Full YARD documentation is [available at Rubyforge](http://carrierwave.rubyforge.org/).
Full rdoc documentation is {available at Rubyforge}[http://carrierwave.rubyforge.org/].
## Read the source
== Read the source
CarrierWave is still young, but most of it is pretty well documented. It is also extensively specced, and there are cucumber features for some common use cases. Just dig in and look at the source for more in-depth explanation of what things are doing.

View File

@ -1,7 +1,9 @@
require 'rubygems'
require 'rake/gempackagetask'
require 'rake/rdoctask'
gem 'rdoc', '>=2.4.0'
require 'rdoc'
require 'yard'
require 'spec/rake/spectask'
require 'cucumber/rake/task'
@ -38,8 +40,12 @@ Cucumber::Rake::Task.new do |t|
t.cucumber_opts = "--profile #{profile}"
end
YARD::Rake::YardocTask.new do |t|
t.files = ["README.md", "LICENSE", "TODO", 'lib/carrierwave/**/*.rb']
Rake::RDocTask.new do |rd|
rd.main = "README.rdoc"
rd.title = "CarrierWave"
rd.options << "--diagram" if ENV["DIAGRAM"]
rd.rdoc_dir = File.join(File.dirname(__FILE__), 'doc')
rd.rdoc_files.include("README.rdoc", "LICENSE", "TODO", 'lib/carrierwave/**/*.rb')
end
Rake::GemPackageTask.new(spec) do |pkg|