sweet_portfolio 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/.document +5 -0
  2. data/.powrc +4 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +2 -0
  5. data/Gemfile +11 -0
  6. data/LICENSE +20 -0
  7. data/README.md +37 -0
  8. data/Rakefile +21 -0
  9. data/VERSION +1 -0
  10. data/app/assets/images/sweet_portfolio/blank.gif +0 -0
  11. data/app/assets/images/sweet_portfolio/border.png +0 -0
  12. data/app/assets/images/sweet_portfolio/controls.png +0 -0
  13. data/app/assets/images/sweet_portfolio/fancybox_loading.gif +0 -0
  14. data/app/assets/images/sweet_portfolio/fancybox_overlay.png +0 -0
  15. data/app/assets/images/sweet_portfolio/fancybox_sprite.png +0 -0
  16. data/app/assets/images/sweet_portfolio/jcrop.gif +0 -0
  17. data/app/assets/images/sweet_portfolio/loading.gif +0 -0
  18. data/app/assets/images/sweet_portfolio/loading_background.png +0 -0
  19. data/app/assets/images/sweet_portfolio/overlay.png +0 -0
  20. data/app/assets/javascripts/sweet_portfolio/jquery.colorbox.js +4 -0
  21. data/app/assets/javascripts/sweet_portfolio/jquery.fancybox-media.js +196 -0
  22. data/app/assets/javascripts/sweet_portfolio/jquery.fancybox-thumbs.js +162 -0
  23. data/app/assets/javascripts/sweet_portfolio/jquery.fancybox.pack.js +45 -0
  24. data/app/assets/javascripts/sweet_portfolio/jquery.jcrop.js +246 -0
  25. data/app/assets/stylesheets/sweet_portfolio/colorbox.css +61 -0
  26. data/app/assets/stylesheets/sweet_portfolio/jquery.fancybox-thumbs.css +54 -0
  27. data/app/assets/stylesheets/sweet_portfolio/jquery.fancybox.css +249 -0
  28. data/app/assets/stylesheets/sweet_portfolio/jquery.jcrop.css +32 -0
  29. data/app/controllers/admin/gallery/base_controller.rb +3 -0
  30. data/app/controllers/admin/gallery/galleries_controller.rb +72 -0
  31. data/app/controllers/admin/gallery/photos_controller.rb +90 -0
  32. data/app/controllers/application_controller.rb +7 -0
  33. data/app/helpers/gallery/application_helper.rb +12 -0
  34. data/app/models/gallery/gallery.rb +33 -0
  35. data/app/models/gallery/photo.rb +83 -0
  36. data/app/views/admin/gallery/_navigation.html.erb +1 -0
  37. data/app/views/admin/gallery/galleries/_form.html.haml +15 -0
  38. data/app/views/admin/gallery/galleries/edit.html.haml +5 -0
  39. data/app/views/admin/gallery/galleries/index.html.haml +28 -0
  40. data/app/views/admin/gallery/galleries/new.html.haml +5 -0
  41. data/app/views/admin/gallery/photos/_form.html.haml +12 -0
  42. data/app/views/admin/gallery/photos/crop.html.haml +50 -0
  43. data/app/views/admin/gallery/photos/edit.html.haml +5 -0
  44. data/app/views/admin/gallery/photos/index.html.haml +19 -0
  45. data/app/views/admin/gallery/photos/new.html.haml +5 -0
  46. data/app/views/layouts/gallery/application.html.haml +12 -0
  47. data/config.ru +4 -0
  48. data/config/application.rb +51 -0
  49. data/config/boot.rb +13 -0
  50. data/config/database.yml +16 -0
  51. data/config/environment.rb +5 -0
  52. data/config/environments/development.rb +25 -0
  53. data/config/environments/production.rb +52 -0
  54. data/config/environments/test.rb +39 -0
  55. data/config/initializers/paperclip.rb +3 -0
  56. data/config/initializers/sweet_portfolio.rb +12 -0
  57. data/config/routes.rb +3 -0
  58. data/db/migrate/01_create_sweet_portfolio.rb +37 -0
  59. data/lib/generators/sweet_portfolio/README +10 -0
  60. data/lib/generators/sweet_portfolio/sweet_portfolio.rb +37 -0
  61. data/lib/paperclip_processors/cropper.rb +31 -0
  62. data/lib/sweet_portfolio.rb +28 -0
  63. data/lib/sweet_portfolio/configuration.rb +26 -0
  64. data/lib/sweet_portfolio/engine.rb +21 -0
  65. data/lib/sweet_portfolio/form_builder.rb +50 -0
  66. data/lib/sweet_portfolio/routing.rb +21 -0
  67. data/lib/tasks/sweet_portfolio.rake +4 -0
  68. data/script/rails +6 -0
  69. data/sweet_portfolio.gemspec +134 -0
  70. data/test/fixtures/files/default.jpg +0 -0
  71. data/test/fixtures/files/default.txt +1 -0
  72. data/test/fixtures/files/default2.jpg +0 -0
  73. data/test/fixtures/gallery/galleries.yml +11 -0
  74. data/test/fixtures/gallery/photos.yml +8 -0
  75. data/test/functional/admin/gallery/galleries_controller_test.rb +107 -0
  76. data/test/functional/admin/gallery/photos_controller_test.rb +224 -0
  77. data/test/test_helper.rb +39 -0
  78. data/test/unit/configuration_test.rb +16 -0
  79. data/test/unit/gallery_test.rb +38 -0
  80. data/test/unit/photo_test.rb +40 -0
  81. metadata +228 -0
@@ -0,0 +1,5 @@
1
+ .page-header
2
+ %h2= "Editing #{@photo.title}"
3
+
4
+ = comfy_form_for @photo, :url => { :action => :update }, :html => { :multipart => true } do |form|
5
+ = render form
@@ -0,0 +1,19 @@
1
+ .page-header
2
+ = link_to 'Add new photo', new_admin_gallery_gallery_photo_path(@gallery), :class => 'btn pull-right'
3
+ %h2
4
+ Photos in #{@gallery.title}
5
+
6
+ %table.table.table-hover.table-bordered
7
+ %tbody.sortable
8
+ - @photos.each do |photo|
9
+ %tr{:id => dom_id(photo)}
10
+ %td
11
+ .dragger{:style => "cursor: move;"}
12
+ = image_tag(photo.image.url(:admin_thumb))
13
+ %td.main
14
+ .title= photo.title
15
+ %td
16
+ .btn-group
17
+ = link_to 'Crop', crop_admin_gallery_gallery_photo_path(@gallery, photo), :class => 'btn btn-small' if photo.force_aspect?
18
+ = link_to 'Edit', edit_admin_gallery_gallery_photo_path(@gallery, photo), :class => 'btn btn-small'
19
+ = link_to 'Delete', admin_gallery_gallery_photo_path(@gallery, photo), :method => :delete, :confirm => 'Are you sure?', :class => 'btn btn-small btn-danger'
@@ -0,0 +1,5 @@
1
+ .page-header
2
+ %h2= "New Photo"
3
+
4
+ = comfy_form_for @photo, :url => {:action => :create}, :html => {:multipart => true} do |form|
5
+ = render form
@@ -0,0 +1,12 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-type"}/
5
+ %title Sweet Portfolio
6
+ = javascript_include_tag 'sweet_portfolio/application.js'
7
+ = stylesheet_link_tag 'sweet_portfolio/application.css'
8
+ = yield :head
9
+ %body{:class => 'c_#{params[:controller].gsub('/', '_')} a_#{params[:action]}' }
10
+ - flash.each do |type, message|
11
+ %div{:class => "flash #{type}"}= message
12
+ = yield
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 SweetPortfolio::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 SweetPortfolio
10
+ class Application < Rails::Application
11
+
12
+ require 'sweet_portfolio'
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 => '_sweet_portfolio_session'
48
+ config.secret_token = 'e0fef4ab56c1cace8845864fe2cb2a27f5caad72521419f87b2774785187090a654b83229bf9cef70ce475a83bfa561dbbaa2015788181ea837c456964c1e0f6'
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
+ SweetPortfolio::Application.initialize!
@@ -0,0 +1,25 @@
1
+ defined?(SweetPortfolio::Application) && SweetPortfolio::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?(SweetPortfolio::Application) && SweetPortfolio::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?(SweetPortfolio::Application) && SweetPortfolio::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,12 @@
1
+ SweetPortfolio.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
+ # Controller that should be used for admin area
7
+ # config.admin_controller = 'ApplicationController'
8
+
9
+ # Form builder
10
+ # config.form_builder = 'SweetPortfolio::FormBuilder'
11
+
12
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ defined?(SweetPortfolio::Application) && SweetPortfolio::Application.routes.draw do
2
+ SweetPortfolio::Routing.admin
3
+ end
@@ -0,0 +1,37 @@
1
+ class CreateSweetPortfolio < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :gallery_galleries do |t|
4
+ t.string :title, :null => false
5
+ t.string :identifier, :null => false
6
+ t.text :description
7
+ t.text :short_description
8
+ t.integer :full_width, :null => false, :default => 640
9
+ t.integer :full_height, :null => false, :default => 480
10
+ t.boolean :force_ratio_full, :null => false, :default => false
11
+ t.integer :thumb_width, :null => false, :default => 150
12
+ t.integer :thumb_height, :null => false, :default => 150
13
+ t.boolean :force_ratio_thumb, :null => false, :default => true
14
+ t.integer :position, :null => false, :default => 0
15
+ t.timestamps
16
+ end
17
+ add_index :gallery_galleries, :identifier, :uniq => true
18
+
19
+ create_table :gallery_photos do |t|
20
+ t.integer :gallery_id, :null => false
21
+ t.string :title
22
+ t.text :description
23
+ t.string :embed_code
24
+ t.string :image_file_name
25
+ t.string :image_content_type
26
+ t.integer :image_file_size
27
+ t.integer :position, :null => false, :default => 0
28
+ t.timestamps
29
+ end
30
+ add_index :gallery_photos, [ :gallery_id, :position ]
31
+ end
32
+
33
+ def self.down
34
+ drop_table :gallery_photos
35
+ drop_table :gallery_galleries
36
+ end
37
+ 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,37 @@
1
+ module SweetPortfolio
2
+ module Generators
3
+ class PortfolioGenerator < Rails::Generators::Base
4
+
5
+ require 'rails/generators/active_record'
6
+ include Rails::Generators::Migration
7
+ include Thor::Actions
8
+
9
+ source_root File.expand_path('../../../../..', __FILE__)
10
+
11
+ def generate_migration
12
+ destination = File.expand_path('db/migrate/01_create_sweet_portfolio.rb', self.destination_root)
13
+ migration_dir = File.dirname(destination)
14
+ destination = self.class.migration_exists?(migration_dir, 'create_sweet_portfolio')
15
+
16
+ if destination
17
+ puts "\e[0m\e[31mFound existing create_sweet_portfolio.rb migration. Remove it if you want to regenerate.\e[0m"
18
+ else
19
+ migration_template 'db/migrate/01_create_sweet_portfolio.rb', 'db/migrate/create_sweet_portfolio.rb'
20
+ end
21
+ end
22
+
23
+ def generate_initialization
24
+ copy_file 'config/initializers/sweet_portfolio.rb', 'config/initializers/sweet_portfolio.rb'
25
+ end
26
+
27
+ def show_readme
28
+ readme 'lib/generators/sweet_portfolio/README'
29
+ end
30
+
31
+ def self.next_migration_number(dirname)
32
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ module Paperclip
2
+
3
+ class Cropper < Thumbnail
4
+ def transformation_command
5
+ if crop_command
6
+ crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')
7
+ else
8
+ super
9
+ end
10
+ end
11
+ end
12
+
13
+ class ThumbCropper < Cropper
14
+ def crop_command
15
+ target = @attachment.instance
16
+ if target.cropping_thumb?
17
+ ["-crop", "#{target.thumb_crop_w}x#{target.thumb_crop_h}+#{target.thumb_crop_x}+#{target.thumb_crop_y}"]
18
+ end
19
+ end
20
+ end
21
+
22
+ class FullCropper < Cropper
23
+ def crop_command
24
+ target = @attachment.instance
25
+ if target.cropping_full?
26
+ ["-crop", "#{target.full_crop_w}x#{target.full_crop_h}+#{target.full_crop_x}+#{target.full_crop_y}"]
27
+ end
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,28 @@
1
+ # Loading engine only if this is not a standalone installation
2
+ unless defined? SweetPortfolio::Application
3
+ require File.expand_path('sweet_portfolio/engine', File.dirname(__FILE__))
4
+ end
5
+
6
+ [ 'sweet_portfolio/configuration',
7
+ 'sweet_portfolio/form_builder',
8
+ 'paperclip_processors/cropper',
9
+ 'sweet_portfolio/routing',
10
+ ].each do |path|
11
+ require File.expand_path(path, File.dirname(__FILE__))
12
+ end
13
+
14
+
15
+ module SweetPortfolio
16
+ class << self
17
+
18
+ def configure
19
+ yield configuration
20
+ end
21
+
22
+ def configuration
23
+ @configuration ||= Configuration.new
24
+ end
25
+ alias :config :configuration
26
+
27
+ end
28
+ end