sofa_gallery 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/.document +5 -0
  2. data/Gemfile +9 -0
  3. data/Gemfile.lock +106 -0
  4. data/LICENSE +20 -0
  5. data/README.md +30 -0
  6. data/Rakefile +21 -0
  7. data/VERSION +1 -0
  8. data/app/assets/images/sofa_gallery/jcrop.gif +0 -0
  9. data/app/assets/javascripts/sofa_gallery/application.js +15 -0
  10. data/app/assets/javascripts/sofa_gallery/jquery.jcrop.js +246 -0
  11. data/app/assets/javascripts/sofa_gallery/jquery.js +18 -0
  12. data/app/assets/javascripts/sofa_gallery/jquery_ui.js +248 -0
  13. data/app/assets/javascripts/sofa_gallery/rails.js +315 -0
  14. data/app/assets/stylesheets/sofa_gallery/application.css +68 -0
  15. data/app/assets/stylesheets/sofa_gallery/jquery.jcrop.css +32 -0
  16. data/app/assets/stylesheets/sofa_gallery/reset.css +1 -0
  17. data/app/controllers/application_controller.rb +6 -0
  18. data/app/controllers/gallery_admin/base_controller.rb +3 -0
  19. data/app/controllers/gallery_admin/galleries_controller.rb +59 -0
  20. data/app/controllers/gallery_admin/photos_controller.rb +76 -0
  21. data/app/helpers/sofa_gallery_helper.rb +11 -0
  22. data/app/models/sofa/gallery.rb +17 -0
  23. data/app/models/sofa/photo.rb +64 -0
  24. data/app/views/gallery_admin/_navigation.html.erb +1 -0
  25. data/app/views/gallery_admin/galleries/_form.html.erb +11 -0
  26. data/app/views/gallery_admin/galleries/edit.html.erb +5 -0
  27. data/app/views/gallery_admin/galleries/index.html.erb +28 -0
  28. data/app/views/gallery_admin/galleries/new.html.erb +5 -0
  29. data/app/views/gallery_admin/photos/_form.html.erb +13 -0
  30. data/app/views/gallery_admin/photos/crop.html.erb +32 -0
  31. data/app/views/gallery_admin/photos/edit.html.erb +5 -0
  32. data/app/views/gallery_admin/photos/index.html.erb +24 -0
  33. data/app/views/gallery_admin/photos/new.html.erb +5 -0
  34. data/app/views/layouts/gallery_admin/application.html.erb +16 -0
  35. data/config.ru +4 -0
  36. data/config/application.rb +51 -0
  37. data/config/boot.rb +13 -0
  38. data/config/database.yml +16 -0
  39. data/config/environment.rb +5 -0
  40. data/config/environments/development.rb +25 -0
  41. data/config/environments/production.rb +52 -0
  42. data/config/environments/test.rb +39 -0
  43. data/config/initializers/paperclip.rb +3 -0
  44. data/config/initializers/sofa_gallery.rb +15 -0
  45. data/config/routes.rb +12 -0
  46. data/db/migrate/01_create_sofa_gallery.rb +35 -0
  47. data/lib/generators/README +10 -0
  48. data/lib/generators/sofa_gallery_generator.rb +33 -0
  49. data/lib/paperclip_processors/cropper.rb +18 -0
  50. data/lib/sofa_gallery.rb +23 -0
  51. data/lib/sofa_gallery/configuration.rb +26 -0
  52. data/lib/sofa_gallery/engine.rb +21 -0
  53. data/lib/sofa_gallery/form_builder.rb +50 -0
  54. data/script/rails +6 -0
  55. data/sofa_gallery.gemspec +113 -0
  56. data/test/fixtures/files/default.jpg +0 -0
  57. data/test/fixtures/files/default.txt +1 -0
  58. data/test/fixtures/sofa/galleries.yml +10 -0
  59. data/test/fixtures/sofa/photos.yml +9 -0
  60. data/test/functional/galleries_controller_test.rb +87 -0
  61. data/test/functional/photos_controller_test.rb +123 -0
  62. data/test/test_helper.rb +36 -0
  63. data/test/unit/configuration_test.rb +18 -0
  64. data/test/unit/gallery_test.rb +33 -0
  65. data/test/unit/photo_test.rb +29 -0
  66. metadata +167 -0
@@ -0,0 +1,5 @@
1
+ <h1>Editing Photo</h1>
2
+
3
+ <%= gallery_form_for @photo, :url => { :action => :update }, :html => { :multipart => true } do |form| %>
4
+ <%= render :partial => form %>
5
+ <% end %>
@@ -0,0 +1,24 @@
1
+ <%= link_to 'Add new photo', new_gallery_admin_gallery_photo_path, :class => 'big button' %>
2
+
3
+ <h1>Photos in <%=@gallery.title%></h1>
4
+
5
+ <table class='formatted'>
6
+ <tbody class='sortable'>
7
+ <% @photos.each do |photo| %>
8
+ <tr id='<%= dom_id(photo) %>'>
9
+ <td>
10
+ <%= image_tag(photo.image.url(:admin_thumb), :class => 'thumb dragger') %>
11
+ </td>
12
+ <td class='main'>
13
+ <div class='title'><%= photo.title %></div>
14
+ <div class='sublabel'><%= photo.slug %></div>
15
+ </td>
16
+ <td class='action_links'>
17
+ <%= link_to 'Crop', crop_gallery_admin_gallery_photo_path(@gallery, photo) %>
18
+ <%= link_to 'Edit', edit_gallery_admin_gallery_photo_path(@gallery, photo) %>
19
+ <%= link_to 'Delete', gallery_admin_gallery_photo_path(@gallery, photo), :method => :delete, :confirm => 'Are you sure?' %>
20
+ </td>
21
+ </tr>
22
+ <% end %>
23
+ </tbody>
24
+ </table>
@@ -0,0 +1,5 @@
1
+ <h1>New Photo</h1>
2
+
3
+ <%= gallery_form_for @photo, :as => :photo, :url => {:action => :create}, :html => {:multipart => true} do |form|%>
4
+ <%= render :partial => form %>
5
+ <% end -%>
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
5
+ <title>SofaGallery</title>
6
+ <%= javascript_include_tag 'sofa_gallery/application' %>
7
+ <%= stylesheet_link_tag 'sofa_gallery/application' %>
8
+ <%= yield :head %>
9
+ </head>
10
+ <body class='c_<%= params[:controller].gsub('/', '_') %> a_<%= params[:action] %>'>
11
+ <% flash.each do |type, message| %>
12
+ <div class='flash <%= type %>'><%= message %></div>
13
+ <% end %>
14
+ <%= yield %>
15
+ </body>
16
+ </html>
data/config.ru ADDED
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run SofaGallery::Application
@@ -0,0 +1,51 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ # If you have a Gemfile, require the gems listed there, including any gems
6
+ # you've limited to :test, :development, or :production.
7
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
8
+
9
+ module SofaGallery
10
+ class Application < Rails::Application
11
+
12
+ require 'sofa_gallery'
13
+
14
+ # Settings in config/environments/* take precedence over those specified here.
15
+ # Application configuration should go into files in config/initializers
16
+ # -- all .rb files in that directory are automatically loaded.
17
+
18
+ # Custom directories with classes and modules you want to be autoloadable.
19
+ # config.autoload_paths += %W(#{config.root}/extras)
20
+
21
+ # Only load the plugins named here, in the order given (default is alphabetical).
22
+ # :all can be used as a placeholder for all plugins not explicitly named.
23
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
24
+
25
+ # Activate observers that should always be running.
26
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
27
+
28
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
29
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
30
+ # config.time_zone = 'Central Time (US & Canada)'
31
+
32
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
33
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
34
+ # config.i18n.default_locale = :de
35
+
36
+ # JavaScript files you want as :defaults (application.js is always included).
37
+
38
+ # Configure the default encoding used in templates for Ruby 1.9.
39
+ config.encoding = "utf-8"
40
+
41
+ # Configure sensitive parameters which will be filtered from the log file.
42
+ config.filter_parameters += [:password]
43
+
44
+ # Enable the asset pipeline
45
+ config.assets.enabled = true
46
+
47
+ config.session_store :cookie_store, :key => '_comfortable_mexican_sofa_session'
48
+ config.secret_token = 'e0fef4ab56c1cacd8845864fe2cb2a27f5caad72523419f87b2774785187090a654b83229bf9cef70ce475a83bfa561dbbaa2015788181ea837c456964c1e0f6'
49
+
50
+ end
51
+ end
data/config/boot.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ gemfile = File.expand_path('../../Gemfile', __FILE__)
5
+ begin
6
+ ENV['BUNDLE_GEMFILE'] = gemfile
7
+ require 'bundler'
8
+ Bundler.setup
9
+ rescue Bundler::GemNotFound => e
10
+ STDERR.puts e.message
11
+ STDERR.puts "Try running `bundle install`."
12
+ exit!
13
+ end if File.exist?(gemfile)
@@ -0,0 +1,16 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ pool: 5
7
+ timeout: 5000
8
+
9
+ # Warning: The database defined as "test" will be erased and
10
+ # re-generated from your development database when you run "rake".
11
+ # Do not set this db to the same as development or production.
12
+ test:
13
+ adapter: sqlite3
14
+ database: db/test.sqlite3
15
+ pool: 5
16
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ SofaGallery::Application.initialize!
@@ -0,0 +1,25 @@
1
+ defined?(SofaGallery::Application) && SofaGallery::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+ end
25
+
@@ -0,0 +1,52 @@
1
+ defined?(SofaGallery::Application) && SofaGallery::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+
11
+ # Disable Rails's static asset server (Apache or nginx will already do this)
12
+ config.serve_static_assets = false
13
+
14
+ # Compress both stylesheets and JavaScripts
15
+ config.assets.js_compressor = :uglifier
16
+ config.assets.css_compressor = :scss
17
+
18
+ # Specifies the header that your server uses for sending files
19
+ # (comment out if your front-end server doesn't support this)
20
+ config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx
21
+
22
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
23
+ # config.force_ssl = true
24
+
25
+ # See everything in the log (default is :info)
26
+ # config.log_level = :debug
27
+
28
+ # Use a different logger for distributed setups
29
+ # config.logger = SyslogLogger.new
30
+
31
+ # Use a different cache store in production
32
+ # config.cache_store = :mem_cache_store
33
+
34
+ # Enable serving of images, stylesheets, and javascripts from an asset server
35
+ # config.action_controller.asset_host = "http://assets.example.com"
36
+
37
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
38
+ # config.assets.precompile += %w( search.js )
39
+
40
+ # Disable delivery errors, bad email addresses will be ignored
41
+ # config.action_mailer.raise_delivery_errors = false
42
+
43
+ # Enable threaded mode
44
+ # config.threadsafe!
45
+
46
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
47
+ # the I18n.default_locale when a translation can not be found)
48
+ config.i18n.fallbacks = true
49
+
50
+ # Send deprecation notices to registered listeners
51
+ config.active_support.deprecation = :notify
52
+ end
@@ -0,0 +1,39 @@
1
+ defined?(SofaGallery::Application) && SofaGallery::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Configure static asset server for tests with Cache-Control for performance
11
+ config.serve_static_assets = true
12
+ config.static_cache_control = "public, max-age=3600"
13
+
14
+ # Log error messages when you accidentally call methods on nil
15
+ config.whiny_nils = true
16
+
17
+ # Show full error reports and disable caching
18
+ config.consider_all_requests_local = true
19
+ config.action_controller.perform_caching = false
20
+
21
+ # Raise exceptions instead of rendering exception templates
22
+ config.action_dispatch.show_exceptions = false
23
+
24
+ # Disable request forgery protection in test environment
25
+ config.action_controller.allow_forgery_protection = false
26
+
27
+ # Tell Action Mailer not to deliver emails to the real world.
28
+ # The :test delivery method accumulates sent emails in the
29
+ # ActionMailer::Base.deliveries array.
30
+ config.action_mailer.delivery_method = :test
31
+
32
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
33
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
34
+ # like if you have constraints or database-specific column types
35
+ # config.active_record.schema_format = :sql
36
+
37
+ # Print deprecation notices to the stderr
38
+ config.active_support.deprecation = :stderr
39
+ end
@@ -0,0 +1,3 @@
1
+ Paperclip.options[:command_path] = case Rails.env
2
+ when 'development', 'test' then "/usr/local/bin"
3
+ end
@@ -0,0 +1,15 @@
1
+ SofaGallery.configure do |config|
2
+
3
+ # Just like CMS, photos are uploaded through Paperclip and can support filesystem or s3 storage.
4
+ # config.upload_photo_options = { :storage => :filesystem }
5
+
6
+ # set the cms admin path if you have changed it for CMS
7
+ # config.admin_route_prefix = 'admin'
8
+
9
+ # Controller that should be used for admin area
10
+ # config.admin_controller = 'ApplicationController'
11
+
12
+ # Form builder
13
+ # config.form_builder = 'SofaGallery::FormBuilder'
14
+
15
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,12 @@
1
+ Rails.application.routes.draw do
2
+
3
+ namespace :gallery_admin, :path => SofaGallery.config.admin_route_prefix do
4
+ resources :galleries do
5
+ resources :photos do
6
+ put :reorder, :on => :collection
7
+ get :crop, :on => :member
8
+ end
9
+ end
10
+ end unless SofaGallery.config.admin_route_prefix.blank?
11
+
12
+ end
@@ -0,0 +1,35 @@
1
+ class CreateSofaGallery < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :sofa_galleries do |t|
4
+ t.string :title
5
+ t.string :slug
6
+ t.text :description
7
+ t.integer :full_width, :null => false, :default => 600
8
+ t.integer :full_height, :null => false, :default => 450
9
+ t.integer :thumb_width, :null => false, :default => 200
10
+ t.integer :thumb_height, :null => false, :default => 150
11
+ t.boolean :force_ratio, :null => false, :default => true
12
+ t.timestamps
13
+ end
14
+ add_index :sofa_galleries, :slug
15
+
16
+ create_table :sofa_photos do |t|
17
+ t.integer :gallery_id
18
+ t.string :title
19
+ t.string :slug
20
+ t.text :description
21
+ t.string :image_file_name
22
+ t.string :image_content_type
23
+ t.integer :image_file_size
24
+ t.integer :position, :null => false, :default => 0
25
+ t.timestamps
26
+ end
27
+ add_index :sofa_photos, [ :gallery_id, :position ]
28
+ add_index :sofa_photos, :slug
29
+ end
30
+
31
+ def self.down
32
+ drop_table :sofa_photos
33
+ drop_table :sofa_galleries
34
+ end
35
+ end
@@ -0,0 +1,10 @@
1
+ ____ __ ____ _ _
2
+ / ___| ___ / _| __ _ / ___| __ _| | | ___ _ __ _ _
3
+ \___ \ / _ \| |_ / _` | | _ / _` | | |/ _ \ '__| | | |
4
+ ___) | (_) | _| (_| | |_| | (_| | | | __/ | | |_| |
5
+ |____/ \___/|_| \__,_|\____|\__,_|_|_|\___|_| \__, |
6
+ |___/
7
+
8
+ Hey! Everything is almost done. Please don't forget to
9
+
10
+ * run migrations -> `rake db:migrate`
@@ -0,0 +1,33 @@
1
+ class SofaGalleryGenerator < Rails::Generators::Base
2
+
3
+ require 'rails/generators/active_record'
4
+ include Rails::Generators::Migration
5
+ include Thor::Actions
6
+
7
+ source_root File.expand_path('../../..', __FILE__)
8
+
9
+ def generate_migration
10
+ destination = File.expand_path('db/migrate/01_create_sofa_gallery.rb', self.destination_root)
11
+ migration_dir = File.dirname(destination)
12
+ destination = self.class.migration_exists?(migration_dir, 'create_sofa_gallery')
13
+
14
+ if destination
15
+ puts "\e[0m\e[31mFound existing create_cms_gallery.rb migration. Remove it if you want to regenerate.\e[0m"
16
+ else
17
+ migration_template 'db/migrate/01_create_sofa_gallery.rb', 'db/migrate/create_sofa_gallery.rb'
18
+ end
19
+ end
20
+
21
+ def generate_initialization
22
+ copy_file 'config/initializers/sofa_gallery.rb', 'config/initializers/sofa_gallery.rb'
23
+ end
24
+
25
+ def show_readme
26
+ readme 'lib/generators/README'
27
+ end
28
+
29
+ def self.next_migration_number(dirname)
30
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
31
+ end
32
+
33
+ end
@@ -0,0 +1,18 @@
1
+ module Paperclip
2
+ class Cropper < Thumbnail
3
+ def transformation_command
4
+ if crop_command
5
+ crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')
6
+ else
7
+ super
8
+ end
9
+ end
10
+
11
+ def crop_command
12
+ target = @attachment.instance
13
+ if target.cropping?
14
+ ["-crop", "#{target.crop_w}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y}"]
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ # Loading engine only if this is not a standalone installation
2
+ unless defined? SofaGallery::Application
3
+ require File.expand_path('sofa_gallery/engine', File.dirname(__FILE__))
4
+ end
5
+
6
+ require File.expand_path('sofa_gallery/configuration', File.dirname(__FILE__))
7
+ require File.expand_path('sofa_gallery/form_builder', File.dirname(__FILE__))
8
+ require File.expand_path('paperclip_processors/cropper', File.dirname(__FILE__))
9
+
10
+ module SofaGallery
11
+ class << self
12
+
13
+ def configure
14
+ yield configuration
15
+ end
16
+
17
+ def configuration
18
+ @configuration ||= Configuration.new
19
+ end
20
+ alias :config :configuration
21
+
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ module SofaGallery
2
+ class Configuration
3
+
4
+ # Paperclip upload settings for photos
5
+ attr_accessor :upload_options
6
+
7
+ # Default url to access admin area is http://yourhost/cms-admin/
8
+ # You can change 'cms-admin' to 'admin', for example.
9
+ attr_accessor :admin_route_prefix
10
+
11
+ # Controller that should be used for admin area
12
+ attr_accessor :admin_controller
13
+
14
+ # Form builder
15
+ attr_accessor :form_builder
16
+
17
+ # Configuration defaults
18
+ def initialize
19
+ @upload_photo_options = { }
20
+ @admin_route_prefix = 'admin'
21
+ @admin_controller = 'ApplicationController'
22
+ @form_builder = 'SofaGallery::FormBuilder'
23
+ end
24
+
25
+ end
26
+ end