sofa_gallery 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,21 @@
1
+ require 'sofa_gallery'
2
+ require 'rails'
3
+ require 'paperclip'
4
+
5
+ module CmsGallery
6
+ class Engine < Rails::Engine
7
+ initializer 'sofa_gallery.helper' do |app|
8
+ if defined?(ComfortableMexicanSofa)
9
+ # applying configuraion
10
+ SofaGallery.configure do |conf|
11
+ conf.admin_route_prefix = ComfortableMexicanSofa.config.admin_route_prefix
12
+ conf.upload_options = ComfortableMexicanSofa.config.upload_file_options
13
+ conf.admin_controller = 'CmsAdmin::BaseController'
14
+ conf.form_builder = 'ComfortableMexicanSofa::FormBuilder'
15
+ end
16
+ # applying nav elements
17
+ ComfortableMexicanSofa::ViewHooks.add(:navigation, '/gallery_admin/navigation')
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,50 @@
1
+ class SofaGallery::FormBuilder < ActionView::Helpers::FormBuilder
2
+
3
+ helpers = field_helpers -
4
+ %w(hidden_field fields_for) +
5
+ %w(select)
6
+
7
+ helpers.each do |name|
8
+ class_eval %Q^
9
+ def #{name}(field, *args)
10
+ options = args.extract_options!
11
+ args << options
12
+ return super if options.delete(:disable_builder)
13
+ default_field('#{name}', field, options){ super }
14
+ end
15
+ ^
16
+ end
17
+
18
+ def default_field(type, field, options = {}, &block)
19
+ errors = if object.respond_to?(:errors) && object.errors[field].present?
20
+ "<div class='errors'>#{[object.errors[field]].flatten.first}</div>"
21
+ end
22
+ if desc = options.delete(:desc)
23
+ desc = "<div class='desc'>#{desc}</div>"
24
+ end
25
+ %(
26
+ <div class='form_element #{type}_element #{'errors' if errors}'>
27
+ <div class='label'>#{label_for(field, options)}</div>
28
+ <div class='value'>#{yield}</div>
29
+ #{desc}
30
+ #{errors}
31
+ </div>
32
+ ).html_safe
33
+ end
34
+
35
+ def label_for(field, options)
36
+ label = options.delete(:label) || field.to_s.titleize.capitalize
37
+ "<label for=\"#{object_name}_#{field}\">#{label}</label>".html_safe
38
+ end
39
+
40
+ def simple_field(label = nil, content = nil, options = {}, &block)
41
+ content ||= @template.capture(&block) if block_given?
42
+ %(
43
+ <div class='form_element #{options.delete(:class)}'>
44
+ <div class='label'>#{label}</div>
45
+ <div class='value'>#{content}</div>
46
+ </div>
47
+ ).html_safe
48
+ end
49
+
50
+ end
data/script/rails ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,113 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{sofa_gallery}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Oleg Khabarov", "Stephen McLeod", "The Working Group Inc."]
12
+ s.date = %q{2011-06-16}
13
+ s.description = %q{}
14
+ s.email = %q{stephen@theworkinggroup.ca}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "app/assets/images/sofa_gallery/jcrop.gif",
28
+ "app/assets/javascripts/sofa_gallery/application.js",
29
+ "app/assets/javascripts/sofa_gallery/jquery.jcrop.js",
30
+ "app/assets/javascripts/sofa_gallery/jquery.js",
31
+ "app/assets/javascripts/sofa_gallery/jquery_ui.js",
32
+ "app/assets/javascripts/sofa_gallery/rails.js",
33
+ "app/assets/stylesheets/sofa_gallery/application.css",
34
+ "app/assets/stylesheets/sofa_gallery/jquery.jcrop.css",
35
+ "app/assets/stylesheets/sofa_gallery/reset.css",
36
+ "app/controllers/application_controller.rb",
37
+ "app/controllers/gallery_admin/base_controller.rb",
38
+ "app/controllers/gallery_admin/galleries_controller.rb",
39
+ "app/controllers/gallery_admin/photos_controller.rb",
40
+ "app/helpers/sofa_gallery_helper.rb",
41
+ "app/models/sofa/gallery.rb",
42
+ "app/models/sofa/photo.rb",
43
+ "app/views/gallery_admin/_navigation.html.erb",
44
+ "app/views/gallery_admin/galleries/_form.html.erb",
45
+ "app/views/gallery_admin/galleries/edit.html.erb",
46
+ "app/views/gallery_admin/galleries/index.html.erb",
47
+ "app/views/gallery_admin/galleries/new.html.erb",
48
+ "app/views/gallery_admin/photos/_form.html.erb",
49
+ "app/views/gallery_admin/photos/crop.html.erb",
50
+ "app/views/gallery_admin/photos/edit.html.erb",
51
+ "app/views/gallery_admin/photos/index.html.erb",
52
+ "app/views/gallery_admin/photos/new.html.erb",
53
+ "app/views/layouts/gallery_admin/application.html.erb",
54
+ "config.ru",
55
+ "config/application.rb",
56
+ "config/boot.rb",
57
+ "config/database.yml",
58
+ "config/environment.rb",
59
+ "config/environments/development.rb",
60
+ "config/environments/production.rb",
61
+ "config/environments/test.rb",
62
+ "config/initializers/paperclip.rb",
63
+ "config/initializers/sofa_gallery.rb",
64
+ "config/routes.rb",
65
+ "db/migrate/01_create_sofa_gallery.rb",
66
+ "lib/generators/README",
67
+ "lib/generators/sofa_gallery_generator.rb",
68
+ "lib/paperclip_processors/cropper.rb",
69
+ "lib/sofa_gallery.rb",
70
+ "lib/sofa_gallery/configuration.rb",
71
+ "lib/sofa_gallery/engine.rb",
72
+ "lib/sofa_gallery/form_builder.rb",
73
+ "script/rails",
74
+ "sofa_gallery.gemspec",
75
+ "test/fixtures/files/default.jpg",
76
+ "test/fixtures/files/default.txt",
77
+ "test/fixtures/sofa/galleries.yml",
78
+ "test/fixtures/sofa/photos.yml",
79
+ "test/functional/galleries_controller_test.rb",
80
+ "test/functional/photos_controller_test.rb",
81
+ "test/test_helper.rb",
82
+ "test/unit/configuration_test.rb",
83
+ "test/unit/gallery_test.rb",
84
+ "test/unit/photo_test.rb"
85
+ ]
86
+ s.homepage = %q{http://github.com/twg/sofa-gallery}
87
+ s.licenses = ["MIT"]
88
+ s.require_paths = ["lib"]
89
+ s.rubygems_version = %q{1.7.2}
90
+ s.summary = %q{SofaGallery is an image gallery engine for Rails 3.1 apps (and ComfortableMexicanSofa)}
91
+
92
+ if s.respond_to? :specification_version then
93
+ s.specification_version = 3
94
+
95
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
96
+ s.add_runtime_dependency(%q<rails>, [">= 3.1.0.rc4"])
97
+ s.add_runtime_dependency(%q<paperclip>, [">= 0"])
98
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
99
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
100
+ else
101
+ s.add_dependency(%q<rails>, [">= 3.1.0.rc4"])
102
+ s.add_dependency(%q<paperclip>, [">= 0"])
103
+ s.add_dependency(%q<sqlite3>, [">= 0"])
104
+ s.add_dependency(%q<jeweler>, [">= 0"])
105
+ end
106
+ else
107
+ s.add_dependency(%q<rails>, [">= 3.1.0.rc4"])
108
+ s.add_dependency(%q<paperclip>, [">= 0"])
109
+ s.add_dependency(%q<sqlite3>, [">= 0"])
110
+ s.add_dependency(%q<jeweler>, [">= 0"])
111
+ end
112
+ end
113
+
Binary file
@@ -0,0 +1 @@
1
+ text file
@@ -0,0 +1,10 @@
1
+ default:
2
+ title: Default Gallery
3
+ slug: default-gallery
4
+ description: Gallery Description
5
+ full_width: 800
6
+ full_height: 600
7
+ thumb_width: 200
8
+ thumb_height: 150
9
+ force_ratio: true
10
+
@@ -0,0 +1,9 @@
1
+ default:
2
+ gallery: default
3
+ title: Default Photo
4
+ slug: default-photo
5
+ description: Photo Description
6
+ position: 0
7
+ image_file_name: default.jpg
8
+ image_content_type: image/jpeg
9
+ image_file_size: 9999
@@ -0,0 +1,87 @@
1
+ require File.expand_path('../test_helper', File.dirname(__FILE__))
2
+
3
+ class GalleryAdmin::GalleriesControllerTest < ActionController::TestCase
4
+
5
+ def test_get_index
6
+ get :index
7
+ assert_response :success
8
+ assert_template 'index'
9
+ end
10
+
11
+ def test_get_new
12
+ get :new
13
+ assert_response :success
14
+ assert_template 'new'
15
+ assert assigns(:gallery)
16
+ assert_select "form[action='/cms-admin/galleries']"
17
+ end
18
+
19
+ def test_creation
20
+ assert_difference 'Sofa::Gallery.count', 1 do
21
+ post :create, :gallery => {
22
+ :title => 'Test Gallery',
23
+ :slug => 'test-gallery',
24
+ :description => 'Test Description'
25
+ }
26
+ end
27
+ assert_equal 'Gallery created', flash[:notice]
28
+ assert_redirected_to :action => :index
29
+ end
30
+
31
+ def test_creation_failure
32
+ assert_no_difference 'Sofa::Gallery.count' do
33
+ post :create, :gallery => { }
34
+ end
35
+ assert_response :success
36
+ assert_template 'new'
37
+ assert_equal 'Failed to create Gallery', flash[:error]
38
+ end
39
+
40
+ def test_get_edit
41
+ gallery = sofa_galleries(:default)
42
+ get :edit, :id => gallery
43
+ assert_response :success
44
+ assert_template 'edit'
45
+ assert assigns(:gallery)
46
+ assert_select "form[action='/cms-admin/galleries/#{gallery.id}']"
47
+ end
48
+
49
+ def test_get_edit_failure
50
+ get :edit, :id => 'invalid'
51
+ assert_response :redirect
52
+ assert_redirected_to :action => :index
53
+ assert_equal 'Gallery not found', flash[:error]
54
+ end
55
+
56
+ def test_update
57
+ gallery = sofa_galleries(:default)
58
+ put :update, :id => gallery, :gallery => {
59
+ :title => 'New Title'
60
+ }
61
+ gallery.reload
62
+ assert_equal 'New Title', gallery.title
63
+ assert_equal 'Gallery updated', flash[:notice]
64
+ assert_redirected_to :action => :index
65
+ end
66
+
67
+ def test_update_failure
68
+ gallery = sofa_galleries(:default)
69
+ put :update, :id => gallery, :gallery => {
70
+ :title => ''
71
+ }
72
+ assert_response :success
73
+ assert_template 'edit'
74
+ assert_equal 'Failed to update Gallery', flash[:error]
75
+ gallery.reload
76
+ assert_not_equal '', gallery.title
77
+ end
78
+
79
+ def test_destroy
80
+ assert_difference 'Sofa::Gallery.count', -1 do
81
+ delete :destroy, :id => sofa_galleries(:default)
82
+ end
83
+ assert_equal 'Gallery deleted', flash[:notice]
84
+ assert_redirected_to :action => :index
85
+ end
86
+
87
+ end
@@ -0,0 +1,123 @@
1
+ require File.expand_path('../test_helper', File.dirname(__FILE__))
2
+
3
+ class GalleryAdmin::PhotosControllerTest < ActionController::TestCase
4
+
5
+ def test_get_index
6
+ get :index, :gallery_id => sofa_galleries(:default)
7
+ assert_response :success
8
+ assert_template 'index'
9
+ assert assigns(:photos)
10
+ end
11
+
12
+ def test_get_index_failure
13
+ get :index, :gallery_id => 'invalid'
14
+ assert_response :redirect
15
+ assert_redirected_to gallery_admin_galleries_path
16
+ assert_equal 'Gallery not found', flash[:error]
17
+ end
18
+
19
+ def test_new
20
+ gallery = sofa_galleries(:default)
21
+ get :new, :gallery_id => gallery
22
+ assert_response :success
23
+ assert_template 'new'
24
+ assert assigns(:photo)
25
+ assert_select "form[action='/cms-admin/galleries/#{gallery.id}/photos']"
26
+ end
27
+
28
+ def test_creation
29
+ assert_difference 'Sofa::Photo.count' do
30
+ post :create, :gallery_id => sofa_galleries(:default), :photo => {
31
+ :title => 'Test Photo',
32
+ :slug => 'test-photo',
33
+ :image => fixture_file_upload('/files/default.jpg', 'image/jpeg')
34
+ }
35
+ assert_response :redirect
36
+ assert_redirected_to :action => :index
37
+ assert_equal 'Photo created', flash[:notice]
38
+ end
39
+ end
40
+
41
+ def test_creation_fail
42
+ assert_no_difference 'Sofa::Photo.count' do
43
+ post :create, :gallery_id => sofa_galleries(:default), :photo => { }
44
+ assert_response :success
45
+ assert_template 'new'
46
+ assert_equal 'Failed to create Photo', flash[:error]
47
+ end
48
+ end
49
+
50
+ def test_get_edit
51
+ photo = sofa_photos(:default)
52
+ get :edit, :gallery_id => photo.gallery, :id => photo
53
+ assert_response :success
54
+ assert_template 'edit'
55
+ assert_select "form[action='/cms-admin/galleries/#{photo.gallery.id}/photos/#{photo.id}']"
56
+ end
57
+
58
+ def test_get_edit_failure
59
+ get :edit, :gallery_id => sofa_galleries(:default), :id => 'invalid'
60
+ assert_response :redirect
61
+ assert_redirected_to :action => :index
62
+ assert_equal 'Photo not found', flash[:error]
63
+ end
64
+
65
+ def test_update
66
+ photo = sofa_photos(:default)
67
+ put :update, :gallery_id => photo.gallery, :id => photo, :photo => {
68
+ :title => 'Updated Title'
69
+ }
70
+ assert_response :redirect
71
+ assert_redirected_to :action => :index
72
+ assert_equal 'Photo updated', flash[:notice]
73
+
74
+ photo.reload
75
+ assert_equal 'Updated Title', photo.title
76
+ end
77
+
78
+ def test_update_failure
79
+ photo = sofa_photos(:default)
80
+ put :update, :gallery_id => photo.gallery, :id => photo, :photo => {
81
+ :title => 'Updated Title',
82
+ :image => fixture_file_upload('/files/default.txt', 'text/plain')
83
+ }
84
+ assert_response :success
85
+ assert_template :edit
86
+ assert_equal 'Failed to updated Photo', flash[:error]
87
+
88
+ photo.reload
89
+ assert_not_equal 'Updated Title', photo.description
90
+ end
91
+
92
+ def test_destroy
93
+ photo = sofa_photos(:default)
94
+ assert_difference 'Sofa::Photo.count', -1 do
95
+ delete :destroy, :gallery_id => photo.gallery, :id => photo
96
+ assert_response :redirect
97
+ assert_redirected_to :action => :index
98
+ assert_equal 'Photo deleted', flash[:notice]
99
+ end
100
+ end
101
+
102
+ def test_reorder
103
+ photo = sofa_photos(:default)
104
+ assert_equal 0, photo.position
105
+ xhr :post, :reorder, :gallery_id => photo.gallery, :sofa_photo => ['dummy', photo.id]
106
+ assert_response :success
107
+
108
+ photo.reload
109
+ assert_equal 1, photo.position
110
+ end
111
+
112
+ def test_get_crop
113
+ photo = sofa_photos(:default)
114
+ photo.image = fixture_file_upload('/files/default.jpg', 'image/jpeg')
115
+ photo.save!
116
+
117
+ get :crop, :gallery_id => photo.gallery, :id => photo
118
+ assert_response :success
119
+ assert_template 'crop'
120
+ assert assigns(:photo)
121
+ end
122
+
123
+ end
@@ -0,0 +1,36 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+
7
+ fixtures :all
8
+ include ActionDispatch::TestProcess
9
+
10
+ def setup
11
+ reset_config
12
+ end
13
+
14
+ # resetting default configuration
15
+ def reset_config
16
+ SofaGallery.configure do |config|
17
+ config.admin_route_prefix = 'cms-admin'
18
+ end
19
+ end
20
+
21
+ # Example usage:
22
+ # assert_has_errors_on( @record, [:field_1, :field_2] )
23
+ # assert_has_errors_on( @record, {:field_1 => 'Message1', :field_2 => 'Message 2'} )
24
+ def assert_has_errors_on(record, fields)
25
+ fields = [fields].flatten unless fields.is_a?(Hash)
26
+ fields.each do |field, message|
27
+ assert record.errors.to_hash.has_key?(field.to_sym), "#{record.class.name} should error on invalid #{field}"
28
+ if message && record.errors[field].is_a?(Array) && !message.is_a?(Array)
29
+ assert_not_nil record.errors[field].index(message)
30
+ elsif message
31
+ assert_equal message, record.errors[field]
32
+ end
33
+ end
34
+ end
35
+
36
+ end