avatars_for_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/.gitignore +10 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +138 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.rdoc +91 -0
  6. data/Rakefile +29 -0
  7. data/app/controllers/avatars_controller.rb +109 -0
  8. data/app/models/avatar.rb +138 -0
  9. data/app/views/avatars/_errors.html.erb +6 -0
  10. data/app/views/avatars/_form.html.erb +128 -0
  11. data/app/views/avatars/_includes.html.erb +14 -0
  12. data/app/views/avatars/_list.html.erb +39 -0
  13. data/app/views/avatars/_new.html.erb +15 -0
  14. data/app/views/avatars/_precrop.html.erb +38 -0
  15. data/app/views/avatars/destroy.js.erb +2 -0
  16. data/app/views/avatars/edit.html.erb +8 -0
  17. data/app/views/avatars/index.html.erb +4 -0
  18. data/app/views/avatars/new.html.erb +1 -0
  19. data/app/views/avatars/show.html.erb +8 -0
  20. data/app/views/avatars/update.js.erb +6 -0
  21. data/avatars_for_rails.gemspec +40 -0
  22. data/config/locales/en.yml +28 -0
  23. data/config/routes.rb +6 -0
  24. data/lib/avatars_for_rails/avatars_controller_config.rb +4 -0
  25. data/lib/avatars_for_rails.rb +27 -0
  26. data/lib/generators/avatars_for_rails/install_generator.rb +28 -0
  27. data/lib/generators/avatars_for_rails/templates/initializer.rb +11 -0
  28. data/lib/generators/avatars_for_rails/templates/migration.rb +20 -0
  29. data/lib/generators/avatars_for_rails/templates/public/images/Jcrop.gif +0 -0
  30. data/lib/generators/avatars_for_rails/templates/public/images/cancel.png +0 -0
  31. data/lib/generators/avatars_for_rails/templates/public/images/pbar-ani.gif +0 -0
  32. data/lib/generators/avatars_for_rails/templates/public/images/rails.png +0 -0
  33. data/lib/generators/avatars_for_rails/templates/public/javascripts/application.js +2 -0
  34. data/lib/generators/avatars_for_rails/templates/public/javascripts/avatars.js +8 -0
  35. data/lib/generators/avatars_for_rails/templates/public/javascripts/controls.js +965 -0
  36. data/lib/generators/avatars_for_rails/templates/public/javascripts/dragdrop.js +974 -0
  37. data/lib/generators/avatars_for_rails/templates/public/javascripts/effects.js +1123 -0
  38. data/lib/generators/avatars_for_rails/templates/public/javascripts/jquery-ui.min.js +401 -0
  39. data/lib/generators/avatars_for_rails/templates/public/javascripts/jquery.Jcrop.min.js +163 -0
  40. data/lib/generators/avatars_for_rails/templates/public/javascripts/jquery.fileupload-ui.js +259 -0
  41. data/lib/generators/avatars_for_rails/templates/public/javascripts/jquery.fileupload.js +475 -0
  42. data/lib/generators/avatars_for_rails/templates/public/javascripts/jquery.form.js +815 -0
  43. data/lib/generators/avatars_for_rails/templates/public/javascripts/jquery.js +7179 -0
  44. data/lib/generators/avatars_for_rails/templates/public/javascripts/prototype.js +6001 -0
  45. data/lib/generators/avatars_for_rails/templates/public/javascripts/rails.js +158 -0
  46. data/lib/generators/avatars_for_rails/templates/public/stylesheets/.gitkeep +0 -0
  47. data/lib/generators/avatars_for_rails/templates/public/stylesheets/avatars.css +115 -0
  48. data/lib/generators/avatars_for_rails/templates/public/stylesheets/jquery.Jcrop.css +35 -0
  49. data/lib/generators/avatars_for_rails/templates/public/stylesheets/jquery.fileupload-ui.css +70 -0
  50. data/spec/avatars_for_rails_spec.rb +7 -0
  51. data/spec/dummy/Rakefile +7 -0
  52. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  53. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  54. data/spec/dummy/app/models/actor.rb +7 -0
  55. data/spec/dummy/app/views/layouts/application.html.erb +20 -0
  56. data/spec/dummy/config/application.rb +46 -0
  57. data/spec/dummy/config/boot.rb +10 -0
  58. data/spec/dummy/config/database.yml +22 -0
  59. data/spec/dummy/config/environment.rb +5 -0
  60. data/spec/dummy/config/environments/development.rb +26 -0
  61. data/spec/dummy/config/environments/production.rb +49 -0
  62. data/spec/dummy/config/environments/test.rb +35 -0
  63. data/spec/dummy/config/initializers/avatars_for_rails.rb +6 -0
  64. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  65. data/spec/dummy/config/initializers/inflections.rb +10 -0
  66. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  67. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  68. data/spec/dummy/config/initializers/session_store.rb +8 -0
  69. data/spec/dummy/config/locales/en.yml +5 -0
  70. data/spec/dummy/config/routes.rb +60 -0
  71. data/spec/dummy/config.ru +4 -0
  72. data/spec/dummy/db/migrate/20110411073237_create_actors.rb +13 -0
  73. data/spec/dummy/db/migrate/20110411073238_create_avatars.rb +21 -0
  74. data/spec/dummy/db/schema.rb +32 -0
  75. data/spec/dummy/public/404.html +26 -0
  76. data/spec/dummy/public/422.html +26 -0
  77. data/spec/dummy/public/500.html +26 -0
  78. data/spec/dummy/public/favicon.ico +0 -0
  79. data/spec/dummy/public/images/Jcrop.gif +0 -0
  80. data/spec/dummy/public/images/cancel.png +0 -0
  81. data/spec/dummy/public/images/pbar-ani.gif +0 -0
  82. data/spec/dummy/public/images/rails.png +0 -0
  83. data/spec/dummy/public/javascripts/application.js +2 -0
  84. data/spec/dummy/public/javascripts/avatars.js +8 -0
  85. data/spec/dummy/public/javascripts/controls.js +965 -0
  86. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  87. data/spec/dummy/public/javascripts/effects.js +1123 -0
  88. data/spec/dummy/public/javascripts/jquery-ui.min.js +401 -0
  89. data/spec/dummy/public/javascripts/jquery.Jcrop.min.js +163 -0
  90. data/spec/dummy/public/javascripts/jquery.fileupload-ui.js +259 -0
  91. data/spec/dummy/public/javascripts/jquery.fileupload.js +475 -0
  92. data/spec/dummy/public/javascripts/jquery.form.js +815 -0
  93. data/spec/dummy/public/javascripts/jquery.js +7179 -0
  94. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  95. data/spec/dummy/public/javascripts/rails.js +158 -0
  96. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  97. data/spec/dummy/public/stylesheets/avatars.css +115 -0
  98. data/spec/dummy/public/stylesheets/jquery.Jcrop.css +35 -0
  99. data/spec/dummy/public/stylesheets/jquery.fileupload-ui.css +70 -0
  100. data/spec/dummy/public/system/logos/1/actor/stream20110411-3539-1e9l1hn-0.jpg +0 -0
  101. data/spec/dummy/public/system/logos/1/original/stream20110411-3539-1e9l1hn-0.jpg +0 -0
  102. data/spec/dummy/public/system/logos/1/profile/stream20110411-3539-1e9l1hn-0.jpg +0 -0
  103. data/spec/dummy/public/system/logos/1/representation/stream20110411-3539-1e9l1hn-0.jpg +0 -0
  104. data/spec/dummy/public/system/logos/1/tie/stream20110411-3539-1e9l1hn-0.jpg +0 -0
  105. data/spec/dummy/public/system/logos/2/actor/stream20110411-3539-1hlzauh-0.jpeg +0 -0
  106. data/spec/dummy/public/system/logos/2/original/stream20110411-3539-1hlzauh-0.jpeg +0 -0
  107. data/spec/dummy/public/system/logos/2/profile/stream20110411-3539-1hlzauh-0.jpeg +0 -0
  108. data/spec/dummy/public/system/logos/2/representation/stream20110411-3539-1hlzauh-0.jpeg +0 -0
  109. data/spec/dummy/public/system/logos/2/tie/stream20110411-3539-1hlzauh-0.jpeg +0 -0
  110. data/spec/dummy/script/rails +6 -0
  111. data/spec/integration/navigation_spec.rb +9 -0
  112. data/spec/spec_helper.rb +33 -0
  113. metadata +333 -0
@@ -0,0 +1,39 @@
1
+ <br class="clearfloat" />
2
+ <div class="space_center"></div>
3
+ <div class="space_center"></div>
4
+ <% unless(@avatars.empty? || (@avatars.first.present? && @avatars.first.id.blank?)) %>
5
+ <h2><%=t('avatar.text.use') %></h2>
6
+ <div class="space_center"></div>
7
+ <div class="space_center"></div>
8
+ <div class="avatars" id="all_avatars">
9
+ <% @avatars.each do |avatar| %>
10
+ <% unless avatar.id.blank? %>
11
+ <%= div_for(avatar) do %>
12
+ <div class="boxgrid captionfull">
13
+ <%= image_tag(avatar.logo.url(:profile), :class => avatar.active ? 'default' : 'non_default', :size => '94x94', :id => "avatar_img_#{avatar.id}") %>
14
+ <% if avatar.active %>
15
+ <div class="cover boxcaption">
16
+ <%= link_to "Delete avatar", avatar, :confirm => t('avatar.destroy_sure'), :method => :delete, :remote => true %>
17
+ </div>
18
+ <% else %>
19
+ <div class="cover boxcaption">
20
+ <%= link_to "Set as default", avatar, :confirm => t('avatar.set_default_sure'), :method => :put, :remote => true %>
21
+ <%= link_to "Delete avatar", avatar, :confirm => t('avatar.destroy_sure'), :method => :delete, :remote => true %>
22
+ </div>
23
+ <% end %>
24
+ </div>
25
+ <% end %>
26
+ <% end %>
27
+ <% end %>
28
+ </div>
29
+ <br />
30
+ <br class="clearfloat" />
31
+ <div class="space_center"></div>
32
+ <div class="space_center"></div>
33
+ <h2><%=t('avatar.text.new') %></h2>
34
+ <% else %>
35
+ <h2><%= t('avatar.new') %></h2>
36
+ <% end %>
37
+
38
+
39
+
@@ -0,0 +1,15 @@
1
+ <% if !@avatar.logo.errors['precrop'].blank? %>
2
+ <h2><%= t('avatar.crop_image') %></h2>
3
+ <br class="clearfloat" />
4
+ <div class="space_center"></div>
5
+ <%= render :partial => 'precrop' %>
6
+ <% elsif !@avatar.errors.blank? %>
7
+ <%= render :partial => 'errors' %>
8
+ <% else %>
9
+ <br class="clearfloat" />
10
+ <div class="space_center"></div>
11
+ <div class="space_center"></div>
12
+ <div id="content_logo">
13
+ <%= render :partial => 'form' %>
14
+ <% end %>
15
+
@@ -0,0 +1,38 @@
1
+ <% if params[:drag_name].blank? %>
2
+ <% my_file_name = File.basename(@avatar.logo.queued_for_write[:original].path.to_s) %>
3
+ <% else %>
4
+ <% my_file_name = params[:drag_name].to_s %>
5
+ <% end %>
6
+
7
+ <% if Avatar.check_image_tmp_valid(my_file_name) %>
8
+ <div class = "block">
9
+ <div id="precropPrev" >
10
+ <div class="form_row">
11
+ <%= t('avatar.preview') %>
12
+ </div>
13
+ <div id="precropPrevImg" class="logo">
14
+ <%= image_tag "tmp/#{my_file_name}",:id=>"preview" %>
15
+ </div>
16
+ </div>
17
+
18
+ <div class="form_row">
19
+ <%= t('avatar.original') %>
20
+ </div>
21
+
22
+ <div id="precropDiv" class = "block title content">
23
+ <%= image_tag "tmp/#{my_file_name}",:id=>"cropImage" %>
24
+ </div>
25
+ </div>
26
+
27
+ <%= form_for @avatar, :html => { :multipart => true } do |f| %>
28
+ <div class= "block">
29
+ <% for attribute in [:crop_x, :crop_y, :crop_w, :crop_h] %>
30
+ <%= f.hidden_field attribute, :id => attribute %>
31
+ <% end %>
32
+ <%= f.hidden_field :name, :value => my_file_name %>
33
+ <div class="form_row center">
34
+ <%= f.submit t('avatar.crop_submit'), :class => "button" %>
35
+ </div>
36
+ </div>
37
+ <% end %>
38
+ <% end %>
@@ -0,0 +1,2 @@
1
+ $("#avatar_<%= deleted_id %>").remove();
2
+
@@ -0,0 +1,8 @@
1
+ <%= render :partial => 'includes' %>
2
+
3
+ <h1>Editing logo</h1>
4
+
5
+ <%= render 'form' %>
6
+
7
+ <%= link_to 'Show', @avatar %> |
8
+ <%= link_to 'Back', avatars_path %>
@@ -0,0 +1,4 @@
1
+ <%= render :partial => 'includes' %>
2
+
3
+ <%= render :partial => 'list' %>
4
+ <%= render :partial => 'form' %>
@@ -0,0 +1 @@
1
+ <%= render :partial => 'new' %>
@@ -0,0 +1,8 @@
1
+ <%= render :partial => 'includes' %>
2
+
3
+
4
+ <p id="notice"><%= notice %></p>
5
+
6
+
7
+ <%= link_to 'Edit', edit_avatar_path(@avatar) %> |
8
+ <%= link_to 'Back', avatars_path %>
@@ -0,0 +1,6 @@
1
+ $("#avatar_img_<%= old_id %>").removeClass("default");
2
+ $("#avatar_img_<%= old_id %>").addClass("non_default");
3
+
4
+ $("#avatar_img_<%= new_id %>").removeClass("non_default");
5
+ $("#avatar_img_<%= new_id %>").addClass("default");
6
+
@@ -0,0 +1,40 @@
1
+ # Provide a simple gemspec so you can easily use your enginex
2
+ # project in your rails apps through git.
3
+ Gem::Specification.new do |s|
4
+ s.name = "avatars_for_rails"
5
+ s.version = "0.0.1"
6
+ s.authors = ["Jaime Castro Montero"]
7
+ s.summary = "Avatar manager for rails apps."
8
+ s.description = "A Rails engine that allows any model to act as avatarable, permitting it to have a complete avatar manager with a few options."
9
+ s.email = "jaime1988@gmail.com"
10
+ s.homepage = "http://github.com/ging/avatars_for_rails"
11
+ s.files = `git ls-files`.split("\n")
12
+ #s.files = Dir["{app,lib,config}/**/*"] + ["MIT-LICENSE", "Rakefile", "Gemfile", "README.rdoc"]
13
+ # Gem dependencies
14
+ #
15
+ # SQL foreign keys
16
+ s.add_runtime_dependency('foreigner', '~> 0.9.1')
17
+ s.add_runtime_dependency('paperclip', '~> 2.3.4')
18
+ s.add_runtime_dependency('rmagick','~> 2.13.1')
19
+
20
+
21
+ # Development Gem dependencies
22
+ #
23
+ s.add_development_dependency('rails', '~> 3.0.5')
24
+ # Testing database
25
+ s.add_development_dependency('sqlite3-ruby')
26
+ # Debugging
27
+ if RUBY_VERSION < '1.9'
28
+ s.add_development_dependency('ruby-debug', '~> 0.10.3')
29
+ end
30
+ # Specs
31
+ s.add_development_dependency('rspec-rails', '~> 2.5.0')
32
+ # Fixtures
33
+ s.add_development_dependency('factory_girl', '~> 1.3.2')
34
+ # Population
35
+ s.add_development_dependency('forgery', '~> 0.3.6')
36
+ # Integration testing
37
+ s.add_development_dependency('capybara', '~> 0.3.9')
38
+
39
+ end
40
+
@@ -0,0 +1,28 @@
1
+ en:
2
+ actor:
3
+ name: "Name"
4
+ avatar:
5
+ crop_image: "Crop the uploaded image"
6
+ crop_submit: "Crop image"
7
+ destroy: "Delete"
8
+ destroy_sure: "Are you sure you wan't to delete the selected avatar?"
9
+ error:
10
+ no_file: "You have to select a file"
11
+ no_image_file: "The file you uploaded isn't valid, it must be an image file"
12
+ list: "You have these avatars"
13
+ new: "Create a new avatar"
14
+ new_short: "New avatar"
15
+ no_avatars: "You haven't any avatar, plesase create a new one."
16
+ one: "Avatar"
17
+ other: "Avatars"
18
+ original: "Original image"
19
+ preview: "Preview"
20
+ profile_change: "Change your avatar"
21
+ set_default: "Set as default"
22
+ set_default_sure: "Are you sure you wan't to set this avatar as default?"
23
+ text:
24
+ new: "... or upload a new one"
25
+ use: "Use your saved avatars ..."
26
+ upload: "Upload"
27
+
28
+
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Rails.application.routes.draw do
2
+
3
+ resources :avatars
4
+
5
+
6
+ end
@@ -0,0 +1,4 @@
1
+ module AvatarsForRails::AvatarsControllerConfig
2
+
3
+
4
+ end
@@ -0,0 +1,27 @@
1
+
2
+ require 'paperclip'
3
+ #require 'ruby-debug'
4
+
5
+ module AvatarsForRails
6
+
7
+ autoload :AvatarsControllerConfig, 'avatars_for_rails/avatars_controller_config'
8
+
9
+ mattr_accessor :avatarable_model
10
+
11
+ class << self
12
+ def setup
13
+ yield self
14
+ end
15
+ end
16
+
17
+ class Engine < Rails::Engine
18
+
19
+ config.to_prepare do
20
+ AvatarsController.class_eval do
21
+ include AvatarsForRails::AvatarsControllerConfig
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,28 @@
1
+ #class AvatarsForRails::InstallGenerator < Rails::Generators::Base #:nodoc:
2
+ class AvatarsForRails::InstallGenerator < Rails::Generators::NamedBase #:nodoc:
3
+ include Rails::Generators::Migration
4
+
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+
8
+
9
+
10
+ require 'rails/generators/active_record'
11
+
12
+ def create_initializer_file
13
+ template 'initializer.rb', 'config/initializers/avatars_for_rails.rb'
14
+ end
15
+
16
+ def copy_public
17
+ directory "public"
18
+ end
19
+
20
+
21
+ def self.next_migration_number(dirname)
22
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
23
+ end
24
+
25
+ def create_migration_file
26
+ migration_template 'migration.rb', 'db/migrate/create_avatars_for_rails_' + file_name + '.rb'
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ AvatarsForRails.setup do |config|
2
+ config.avatarable_model = :<%= file_name %>
3
+ end
4
+
5
+
6
+
7
+ module AvatarsForRails::AvatarsControllerConfig
8
+ def current_avatarable_object
9
+ return current_<%= file_name %>
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ class CreateAvatarsForRails<%= file_name.camelize %> < ActiveRecord::Migration
2
+ def self.up
3
+ #Tables
4
+ create_table "avatars", :force => true do |t|
5
+ t.integer "<%= file_name %>_id"
6
+ t.string "logo_file_name"
7
+ t.string "logo_content_type"
8
+ t.integer "logo_file_size"
9
+ t.datetime "logo_updated_at"
10
+ t.boolean "active", :default => true
11
+ end
12
+
13
+ add_index "avatars", "<%= file_name %>_id"
14
+
15
+ end
16
+
17
+ def self.down
18
+ drop_table :avatars
19
+ end
20
+ end
@@ -0,0 +1,2 @@
1
+ // Place your application-specific JavaScript functions and classes here
2
+ // This file is automatically included by javascript_include_tag :defaults
@@ -0,0 +1,8 @@
1
+ $(document).ready( function() {
2
+ //Full Caption Sliding (Hidden to Visible)
3
+ $('.boxgrid.captionfull').hover( function() {
4
+ $(".cover", this).stop().animate({top:'61px'},{queue:false,duration:160});
5
+ }, function() {
6
+ $(".cover", this).stop().animate({top:'104px'},{queue:false,duration:160});
7
+ });
8
+ });