Skip to content

Commit 22e183b

Browse files
committed
Formatted README.md.
1 parent fa2aab2 commit 22e183b

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

README.md

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,37 @@ Generate a coffeescript for cropping:
3939

4040
this should give you a file in:
4141

42-
app/assets/javascripts/users.js.coffee
42+
app/assets/javascripts/users.js.coffee
4343

4444
## Usage
4545

4646
Open your model file and add the cropper:
4747

48-
class User < ActiveRecord::Base
49-
mount_uploader :avatar, AvatarUploader
50-
crop_uploaded :avatar ## Add this
51-
end
48+
class User < ActiveRecord::Base
49+
mount_uploader :avatar, AvatarUploader
50+
crop_uploaded :avatar ## Add this
51+
end
5252

5353
Render a view after creating/updating a user, add a `crop` action in your `controller.` For example:
5454

55-
def create
56-
@user = User.new(user_params)
57-
respond_to do |format|
58-
if @user.save
59-
format.html {
60-
if params[:user][:avatar].present?
61-
render :crop ## Render the view for cropping
62-
else
63-
redirect_to @user, notice: 'User was successfully created.'
64-
end
65-
}
66-
format.json { render action: 'show', status: :created, location: @user }
67-
else
68-
format.html { render action: 'new' }
69-
format.json { render json: @user.errors, status: :unprocessable_entity }
70-
end
55+
def create
56+
@user = User.new(user_params)
57+
respond_to do |format|
58+
if @user.save
59+
format.html {
60+
if params[:user][:avatar].present?
61+
render :crop ## Render the view for cropping
62+
else
63+
redirect_to @user, notice: 'User was successfully created.'
64+
end
65+
}
66+
format.json { render action: 'show', status: :created, location: @user }
67+
else
68+
format.html { render action: 'new' }
69+
format.json { render json: @user.errors, status: :unprocessable_entity }
7170
end
7271
end
72+
end
7373

7474
For `Rails 4.x`, whitelist the cropping attributes - `fieldname_crop_x`, `fieldname_crop_y`, `fieldname_crop_w`, `fieldname_crop_h`.
7575

@@ -92,7 +92,7 @@ In the carrierwave uploader, say `AvatarUploader`:
9292

9393
Call process on the version you would like to be cropped:
9494

95-
## If ONLY "thumb" version is to be cropped
95+
## If ONLY "thumb" version is to be cropped
9696
version :jumbo do
9797
resize_to_limit(600,600)
9898
end
@@ -113,60 +113,60 @@ If there are no versions, and original file is to be cropped directly then call
113113

114114
**To use `rmagick`, add it in your `Gemfile` as:**
115115

116-
gem 'rmagick', :require => 'RMagick' ## Specify appropriate version, if needed
116+
gem 'rmagick', :require => 'RMagick' ## Specify appropriate version, if needed
117117

118118
Run `bundle`
119119

120120
Include it in your CarrierWave Uploader. For example:
121121

122-
class AvatarUploader < CarrierWave::Uploader::Base
123-
include CarrierWave::RMagick
124-
...
125-
end
122+
class AvatarUploader < CarrierWave::Uploader::Base
123+
include CarrierWave::RMagick
124+
## ...
125+
end
126126

127127
**To use `mini_magick`, add it in your `Gemfile` as:**
128128

129-
gem 'mini_magick' ## Specify appropriate version, if needed
129+
gem 'mini_magick' ## Specify appropriate version, if needed
130130

131131
Run `bundle`
132132

133133
Include it in your CarrierWave Uploader. For example:
134134

135-
class AvatarUploader < CarrierWave::Uploader::Base
136-
include CarrierWave::MiniMagick
137-
...
138-
end
135+
class AvatarUploader < CarrierWave::Uploader::Base
136+
include CarrierWave::MiniMagick
137+
## ...
138+
end
139139

140140
3. Supports cropping of ONE attachment per model. Can be directly applied on original attachment if no versions exists.
141141

142-
process crop: :avatar
142+
process crop: :avatar
143143

144144
4. Supports cropping of MULTIPLE versions of one attachment per model.
145145
5. In form helpers, by default *original image* is rendered. To render a specific version for cropping pass `version` option. For example:
146146

147-
<%= f.cropbox :avatar , version: :medium %>
148-
<%= f.previewbox :avatar , version: :medium %> ## Pass the same version as specified in cropbox
147+
<%= f.cropbox :avatar , version: :medium %>
148+
<%= f.previewbox :avatar , version: :medium %> ## Pass the same version as specified in cropbox
149149

150150
6. By default `previewbox` has `100x100` dimensions and `cropbox` defaults to the target geometry for the version.
151151
`width` and `height` can be specified for these form helpers. BUT If you override ONE of width/height you MUST override both, otherwise passed option would be ignored.
152152

153-
<%= f.cropbox :avatar, width: 550, height: 600 %>
154-
<%= f.previewbox :avatar, width: 200, height: 200 %>
153+
<%= f.cropbox :avatar, width: 550, height: 600 %>
154+
<%= f.previewbox :avatar, width: 200, height: 200 %>
155155

156156
7. By default, `process crop: :avatar` will create the cropped version based on original image.
157157
To resize the image to a particular dimension before cropping, pass two more arguments `width` and `height`.
158158

159-
## If ONLY "thumb" version is to be cropped
160-
version :jumbo do
161-
resize_to_limit(600,600)
162-
end
163-
164-
version :thumb do
165-
## To crop this version based on `jumbo` version, pass width = 600 and height = 600
166-
## Specify both width and height values otherwise they would be ignored
167-
process crop: [:avatar, 600, 600]
168-
resize_to_limit(100,100)
169-
end
159+
## If ONLY "thumb" version is to be cropped
160+
version :jumbo do
161+
resize_to_limit(600,600)
162+
end
163+
164+
version :thumb do
165+
## To crop this version based on `jumbo` version, pass width = 600 and height = 600
166+
## Specify both width and height values otherwise they would be ignored
167+
process crop: [:avatar, 600, 600]
168+
resize_to_limit(100,100)
169+
end
170170

171171
### Credits and resources
172172
* [CarrierWave](https://github.com/carrierwaveuploader/carrierwave)

0 commit comments

Comments
 (0)