Permalink
Browse files

adding revised

  • Loading branch information...
1 parent fc81247 commit 7ed7e68a9d88e89fa5887b531b5cca3ac1ce60f4 @ryanb ryanb committed Dec 3, 2011
Showing with 3,543 additions and 0 deletions.
  1. +5 −0 revised/README
  2. BIN revised/batman.jpg
  3. +17 −0 revised/cropper-after/.gitignore
  4. +22 −0 revised/cropper-after/Gemfile
  5. +119 −0 revised/cropper-after/Gemfile.lock
  6. +9 −0 revised/cropper-after/README
  7. +7 −0 revised/cropper-after/Rakefile
  8. BIN revised/cropper-after/app/assets/images/rails.png
  9. +10 −0 revised/cropper-after/app/assets/javascripts/application.js
  10. +27 −0 revised/cropper-after/app/assets/javascripts/users.js.coffee
  11. +8 −0 revised/cropper-after/app/assets/stylesheets/application.css
  12. +81 −0 revised/cropper-after/app/assets/stylesheets/layout.css
  13. +3 −0 revised/cropper-after/app/assets/stylesheets/users.css.scss
  14. +3 −0 revised/cropper-after/app/controllers/application_controller.rb
  15. +49 −0 revised/cropper-after/app/controllers/users_controller.rb
  16. +2 −0 revised/cropper-after/app/helpers/application_helper.rb
  17. +2 −0 revised/cropper-after/app/helpers/users_helper.rb
  18. 0 revised/cropper-after/app/mailers/.gitkeep
  19. 0 revised/cropper-after/app/models/.gitkeep
  20. +9 −0 revised/cropper-after/app/models/user.rb
  21. +33 −0 revised/cropper-after/app/uploaders/avatar_uploader.rb
  22. +17 −0 revised/cropper-after/app/views/layouts/application.html.erb
  23. +24 −0 revised/cropper-after/app/views/users/_form.html.erb
  24. +17 −0 revised/cropper-after/app/views/users/crop.html.erb
  25. +3 −0 revised/cropper-after/app/views/users/edit.html.erb
  26. +9 −0 revised/cropper-after/app/views/users/index.html.erb
  27. +3 −0 revised/cropper-after/app/views/users/new.html.erb
  28. +12 −0 revised/cropper-after/app/views/users/show.html.erb
  29. +4 −0 revised/cropper-after/config.ru
  30. +48 −0 revised/cropper-after/config/application.rb
  31. +6 −0 revised/cropper-after/config/boot.rb
  32. +25 −0 revised/cropper-after/config/database.yml
  33. +5 −0 revised/cropper-after/config/environment.rb
  34. +30 −0 revised/cropper-after/config/environments/development.rb
  35. +60 −0 revised/cropper-after/config/environments/production.rb
  36. +39 −0 revised/cropper-after/config/environments/test.rb
  37. +7 −0 revised/cropper-after/config/initializers/backtrace_silencers.rb
  38. +10 −0 revised/cropper-after/config/initializers/inflections.rb
  39. +5 −0 revised/cropper-after/config/initializers/mime_types.rb
  40. +7 −0 revised/cropper-after/config/initializers/secret_token.rb
  41. +8 −0 revised/cropper-after/config/initializers/session_store.rb
  42. +14 −0 revised/cropper-after/config/initializers/wrap_parameters.rb
  43. +5 −0 revised/cropper-after/config/locales/en.yml
  44. +4 −0 revised/cropper-after/config/routes.rb
  45. +10 −0 revised/cropper-after/db/migrate/20111201194630_create_users.rb
  46. +23 −0 revised/cropper-after/db/schema.rb
  47. +7 −0 revised/cropper-after/db/seeds.rb
  48. +2 −0 revised/cropper-after/doc/README_FOR_APP
  49. 0 revised/cropper-after/lib/assets/.gitkeep
  50. 0 revised/cropper-after/lib/tasks/.gitkeep
  51. 0 revised/cropper-after/log/.gitkeep
  52. +26 −0 revised/cropper-after/public/404.html
  53. +26 −0 revised/cropper-after/public/422.html
  54. +26 −0 revised/cropper-after/public/500.html
  55. 0 revised/cropper-after/public/favicon.ico
  56. +5 −0 revised/cropper-after/public/robots.txt
  57. +6 −0 revised/cropper-after/script/rails
  58. 0 revised/cropper-after/test/fixtures/.gitkeep
  59. +9 −0 revised/cropper-after/test/fixtures/users.yml
  60. 0 revised/cropper-after/test/functional/.gitkeep
  61. +49 −0 revised/cropper-after/test/functional/users_controller_test.rb
  62. 0 revised/cropper-after/test/integration/.gitkeep
  63. +12 −0 revised/cropper-after/test/performance/browsing_test.rb
  64. +13 −0 revised/cropper-after/test/test_helper.rb
  65. 0 revised/cropper-after/test/unit/.gitkeep
  66. +4 −0 revised/cropper-after/test/unit/helpers/users_helper_test.rb
  67. +7 −0 revised/cropper-after/test/unit/user_test.rb
  68. BIN revised/cropper-after/vendor/assets/images/Jcrop.gif
  69. +1,600 −0 revised/cropper-after/vendor/assets/javascripts/jquery.Jcrop.js
  70. 0 revised/cropper-after/vendor/assets/stylesheets/.gitkeep
  71. +35 −0 revised/cropper-after/vendor/assets/stylesheets/jquery.Jcrop.css
  72. 0 revised/cropper-after/vendor/plugins/.gitkeep
  73. +17 −0 revised/cropper-before/.gitignore
  74. +22 −0 revised/cropper-before/Gemfile
  75. +119 −0 revised/cropper-before/Gemfile.lock
  76. +9 −0 revised/cropper-before/README
  77. +7 −0 revised/cropper-before/Rakefile
  78. BIN revised/cropper-before/app/assets/images/rails.png
  79. +9 −0 revised/cropper-before/app/assets/javascripts/application.js
  80. +3 −0 revised/cropper-before/app/assets/javascripts/users.js.coffee
  81. +7 −0 revised/cropper-before/app/assets/stylesheets/application.css
  82. +81 −0 revised/cropper-before/app/assets/stylesheets/layout.css
  83. +3 −0 revised/cropper-before/app/assets/stylesheets/users.css.scss
  84. +3 −0 revised/cropper-before/app/controllers/application_controller.rb
  85. +41 −0 revised/cropper-before/app/controllers/users_controller.rb
  86. +2 −0 revised/cropper-before/app/helpers/application_helper.rb
  87. +2 −0 revised/cropper-before/app/helpers/users_helper.rb
  88. 0 revised/cropper-before/app/mailers/.gitkeep
  89. 0 revised/cropper-before/app/models/.gitkeep
  90. +3 −0 revised/cropper-before/app/models/user.rb
  91. +17 −0 revised/cropper-before/app/uploaders/avatar_uploader.rb
  92. +17 −0 revised/cropper-before/app/views/layouts/application.html.erb
  93. +24 −0 revised/cropper-before/app/views/users/_form.html.erb
  94. +3 −0 revised/cropper-before/app/views/users/edit.html.erb
  95. +9 −0 revised/cropper-before/app/views/users/index.html.erb
  96. +3 −0 revised/cropper-before/app/views/users/new.html.erb
  97. +12 −0 revised/cropper-before/app/views/users/show.html.erb
  98. +4 −0 revised/cropper-before/config.ru
  99. +48 −0 revised/cropper-before/config/application.rb
  100. +6 −0 revised/cropper-before/config/boot.rb
  101. +25 −0 revised/cropper-before/config/database.yml
  102. +5 −0 revised/cropper-before/config/environment.rb
  103. +30 −0 revised/cropper-before/config/environments/development.rb
  104. +60 −0 revised/cropper-before/config/environments/production.rb
  105. +39 −0 revised/cropper-before/config/environments/test.rb
  106. +7 −0 revised/cropper-before/config/initializers/backtrace_silencers.rb
  107. +10 −0 revised/cropper-before/config/initializers/inflections.rb
  108. +5 −0 revised/cropper-before/config/initializers/mime_types.rb
  109. +7 −0 revised/cropper-before/config/initializers/secret_token.rb
  110. +8 −0 revised/cropper-before/config/initializers/session_store.rb
  111. +14 −0 revised/cropper-before/config/initializers/wrap_parameters.rb
  112. +5 −0 revised/cropper-before/config/locales/en.yml
  113. +4 −0 revised/cropper-before/config/routes.rb
  114. +10 −0 revised/cropper-before/db/migrate/20111201194630_create_users.rb
  115. +23 −0 revised/cropper-before/db/schema.rb
  116. +7 −0 revised/cropper-before/db/seeds.rb
  117. +2 −0 revised/cropper-before/doc/README_FOR_APP
  118. 0 revised/cropper-before/lib/assets/.gitkeep
  119. 0 revised/cropper-before/lib/tasks/.gitkeep
  120. 0 revised/cropper-before/log/.gitkeep
  121. +26 −0 revised/cropper-before/public/404.html
  122. +26 −0 revised/cropper-before/public/422.html
  123. +26 −0 revised/cropper-before/public/500.html
  124. 0 revised/cropper-before/public/favicon.ico
  125. +5 −0 revised/cropper-before/public/robots.txt
  126. +6 −0 revised/cropper-before/script/rails
  127. 0 revised/cropper-before/test/fixtures/.gitkeep
  128. +9 −0 revised/cropper-before/test/fixtures/users.yml
  129. 0 revised/cropper-before/test/functional/.gitkeep
  130. +49 −0 revised/cropper-before/test/functional/users_controller_test.rb
  131. 0 revised/cropper-before/test/integration/.gitkeep
  132. +12 −0 revised/cropper-before/test/performance/browsing_test.rb
  133. +13 −0 revised/cropper-before/test/test_helper.rb
  134. 0 revised/cropper-before/test/unit/.gitkeep
  135. +4 −0 revised/cropper-before/test/unit/helpers/users_helper_test.rb
  136. +7 −0 revised/cropper-before/test/unit/user_test.rb
  137. 0 revised/cropper-before/vendor/assets/stylesheets/.gitkeep
  138. 0 revised/cropper-before/vendor/plugins/.gitkeep
View
@@ -0,0 +1,5 @@
+RailsCasts Episode #182: Cropping Images (revised)
+
+http://railscasts.com/episodes/182-cropping-images-revised
+
+Requires Ruby 1.9.2 or higher.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,17 @@
+# See http://help.github.com/ignore-files/ for more about ignoring files.
+#
+# If you find yourself ignoring temporary files generated by your text editor
+# or operating system, you probably want to add a global ignore instead:
+# git config --global core.excludesfile ~/.gitignore_global
+
+# Ignore bundler config
+/.bundle
+
+# Ignore the default SQLite database.
+/db/*.sqlite3
+
+# Ignore all logfiles and tempfiles.
+/log/*.log
+/tmp
+
+/public/uploads/**/*
@@ -0,0 +1,22 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.1.3'
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'sqlite3'
+
+
+# Gems used only for assets and not required
+# in production environments by default.
+group :assets do
+ gem 'sass-rails', '~> 3.1.5'
+ gem 'coffee-rails', '~> 3.1.1'
+ gem 'uglifier', '>= 1.0.3'
+end
+
+gem 'jquery-rails'
+
+gem 'rmagick'
+gem 'carrierwave'
@@ -0,0 +1,119 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.1.3)
+ actionpack (= 3.1.3)
+ mail (~> 2.3.0)
+ actionpack (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ i18n (~> 0.6)
+ rack (~> 1.3.5)
+ rack-cache (~> 1.1)
+ rack-mount (~> 0.8.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.0.3)
+ activemodel (3.1.3)
+ activesupport (= 3.1.3)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activerecord (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ arel (~> 2.2.1)
+ tzinfo (~> 0.3.29)
+ activeresource (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ activesupport (3.1.3)
+ multi_json (~> 1.0)
+ arel (2.2.1)
+ builder (3.0.0)
+ carrierwave (0.5.8)
+ activesupport (~> 3.0)
+ coffee-rails (3.1.1)
+ coffee-script (>= 2.2.0)
+ railties (~> 3.1.0)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.1.3)
+ erubis (2.7.0)
+ execjs (1.2.9)
+ multi_json (~> 1.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ jquery-rails (1.0.19)
+ railties (~> 3.0)
+ thor (~> 0.14)
+ json (1.6.3)
+ mail (2.3.0)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.17.2)
+ multi_json (1.0.4)
+ polyglot (0.3.3)
+ rack (1.3.5)
+ rack-cache (1.1)
+ rack (>= 0.4)
+ rack-mount (0.8.3)
+ rack (>= 1.0.0)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.1.3)
+ actionmailer (= 3.1.3)
+ actionpack (= 3.1.3)
+ activerecord (= 3.1.3)
+ activeresource (= 3.1.3)
+ activesupport (= 3.1.3)
+ bundler (~> 1.0)
+ railties (= 3.1.3)
+ railties (3.1.3)
+ actionpack (= 3.1.3)
+ activesupport (= 3.1.3)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rdoc (3.11)
+ json (~> 1.4)
+ rmagick (2.13.1)
+ sass (3.1.11)
+ sass-rails (3.1.5)
+ actionpack (~> 3.1.0)
+ railties (~> 3.1.0)
+ sass (~> 3.1.10)
+ tilt (~> 1.3.2)
+ sprockets (2.0.3)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.4)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.31)
+ uglifier (1.1.0)
+ execjs (>= 0.3.0)
+ multi_json (>= 1.0.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ carrierwave
+ coffee-rails (~> 3.1.1)
+ jquery-rails
+ rails (= 3.1.3)
+ rmagick
+ sass-rails (~> 3.1.5)
+ sqlite3
+ uglifier (>= 1.0.3)
@@ -0,0 +1,9 @@
+= RailsCasts Example Application
+
+Run these commands to try it out.
+
+ bundle
+ rake db:setup
+ rails s
+
+Requires Ruby 1.9.2 or higher.
@@ -0,0 +1,7 @@
+#!/usr/bin/env rake
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+
+Cropper::Application.load_tasks
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,10 @@
+// This is a manifest file that'll be compiled into including all the files listed below.
+// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
+// be included in the compiled file accessible from http://example.com/assets/application.js
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
+//
+//= require jquery
+//= require jquery_ujs
+//= require jquery.Jcrop
+//= require_tree .
@@ -0,0 +1,27 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
+jQuery ->
+ new AvatarCropper()
+
+class AvatarCropper
+ constructor: ->
+ $('#cropbox').Jcrop
+ aspectRatio: 1
+ setSelect: [0, 0, 600, 600]
+ onSelect: @update
+ onChange: @update
+
+ update: (coords) =>
+ $('#user_crop_x').val(coords.x)
+ $('#user_crop_y').val(coords.y)
+ $('#user_crop_w').val(coords.w)
+ $('#user_crop_h').val(coords.h)
+ @updatePreview(coords)
+
+ updatePreview: (coords) =>
+ $('#preview').css
+ width: Math.round(100/coords.w * $('#cropbox').width()) + 'px'
+ height: Math.round(100/coords.h * $('#cropbox').height()) + 'px'
+ marginLeft: '-' + Math.round(100/coords.w * coords.x) + 'px'
+ marginTop: '-' + Math.round(100/coords.h * coords.y) + 'px'
@@ -0,0 +1,8 @@
+/*
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
+ *= require jquery.Jcrop
+ *= require_self
+ *= require_tree .
+*/
@@ -0,0 +1,81 @@
+body {
+ background-color: #4B7399;
+ font-family: Verdana, Helvetica, Arial;
+ font-size: 14px;
+}
+
+a img {
+ border: none;
+}
+
+a {
+ color: #0000FF;
+}
+
+.clear {
+ clear: both;
+ height: 0;
+ overflow: hidden;
+}
+
+#container {
+ width: 75%;
+ margin: 0 auto;
+ background-color: #FFF;
+ padding: 20px 40px;
+ border: solid 1px black;
+ margin-top: 20px;
+ position: relative;
+}
+
+#flash_notice, #flash_error, #flash_alert {
+ padding: 5px 8px;
+ margin: 10px 0;
+ margin-right: 150px;
+}
+
+#flash_notice {
+ background-color: #CFC;
+ border: solid 1px #6C6;
+}
+
+#flash_error, #flash_alert {
+ background-color: #FCC;
+ border: solid 1px #C66;
+}
+
+.field_with_errors {
+ display: inline;
+}
+
+.error_messages {
+ width: 400px;
+ border: 2px solid #CF0000;
+ padding: 0px;
+ padding-bottom: 12px;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ font-size: 12px;
+}
+
+.error_messages h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 10px;
+ font-size: 12px;
+ margin: 0;
+ background-color: #c00;
+ color: #fff;
+}
+
+.error_messages p {
+ margin: 8px 10px;
+}
+
+form .field, form .actions {
+ margin: 12px 0;
+}
+
+h4 {
+ margin-bottom: 5px;
+}
@@ -0,0 +1,3 @@
+// Place all the styles related to the users controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
@@ -0,0 +1,49 @@
+class UsersController < ApplicationController
+ def index
+ @users = User.all
+ end
+
+ def show
+ @user = User.find(params[:id])
+ end
+
+ def new
+ @user = User.new
+ end
+
+ def create
+ @user = User.new(params[:user])
+ if @user.save
+ if params[:user][:avatar].present?
+ render :crop
+ else
+ redirect_to @user, notice: "Successfully created user."
+ end
+ else
+ render :new
+ end
+ end
+
+ def edit
+ @user = User.find(params[:id])
+ end
+
+ def update
+ @user = User.find(params[:id])
+ if @user.update_attributes(params[:user])
+ if params[:user][:avatar].present?
+ render :crop
+ else
+ redirect_to @user, notice: "Successfully updated user."
+ end
+ else
+ render :new
+ end
+ end
+
+ def destroy
+ @user = User.find(params[:id])
+ @user.destroy
+ redirect_to users_url, notice: "Successfully destroyed user."
+ end
+end
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
@@ -0,0 +1,2 @@
+module UsersHelper
+end
No changes.
No changes.
@@ -0,0 +1,9 @@
+class User < ActiveRecord::Base
+ mount_uploader :avatar, AvatarUploader
+ attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
+ after_update :crop_avatar
+
+ def crop_avatar
+ avatar.recreate_versions! if crop_x.present?
+ end
+end
Oops, something went wrong.

0 comments on commit 7ed7e68

Please sign in to comment.