adminpanel 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.travis.yml +0 -1
  2. data/README.md +9 -6
  3. data/Rakefile +1 -1
  4. data/app/helpers/adminpanel/application_helper.rb +2 -2
  5. data/app/helpers/adminpanel/custom_form_builder.rb +45 -9
  6. data/app/helpers/adminpanel/shared_pages_helper.rb +10 -3
  7. data/app/models/adminpanel/gallery.rb +6 -0
  8. data/app/models/adminpanel/image.rb +3 -8
  9. data/app/models/adminpanel/section.rb +16 -6
  10. data/app/uploaders/adminpanel/image_uploader.rb +2 -2
  11. data/app/views/adminpanel/categories/_categories_table.html.erb +1 -1
  12. data/app/views/adminpanel/categories/index.html.erb +9 -8
  13. data/app/views/adminpanel/galleries/edit.html.erb +3 -10
  14. data/app/views/adminpanel/galleries/index.html.erb +2 -2
  15. data/app/views/adminpanel/galleries/new.html.erb +3 -3
  16. data/app/views/adminpanel/sections/edit.html.erb +11 -15
  17. data/app/views/shared/_form_fields.html.erb +16 -9
  18. data/app/views/shared/_image_fields.html.erb +2 -23
  19. data/app/views/shared/_init_editor.html.erb +12 -12
  20. data/app/views/shared/show.html.erb +4 -3
  21. data/config/locales/es.yml +3 -0
  22. data/lib/adminpanel.rb +1 -1
  23. data/lib/adminpanel/active_record/adminpanel_extension.rb +142 -0
  24. data/lib/adminpanel/version.rb +1 -1
  25. data/lib/generators/adminpanel/gallery/gallery_generator.rb +41 -0
  26. data/lib/generators/adminpanel/gallery/templates/gallery_migration.rb +11 -0
  27. data/lib/generators/adminpanel/gallery/templates/gallery_template.rb +8 -0
  28. data/lib/generators/adminpanel/gallery/templates/uploader.rb +86 -0
  29. data/lib/generators/adminpanel/initialize/initialize_generator.rb +22 -12
  30. data/lib/generators/adminpanel/initialize/templates/create_adminpanel_categories_table.rb +1 -1
  31. data/lib/generators/adminpanel/initialize/templates/create_adminpanel_tables.rb +3 -4
  32. data/lib/generators/adminpanel/initialize/templates/section_uploader.rb +86 -0
  33. data/lib/generators/adminpanel/resource/resource_generator.rb +72 -22
  34. data/lib/tasks/adminpanel/adminpanel.rake +1 -1
  35. data/spec/dummy/.gitignore +2 -1
  36. data/spec/dummy/app/controllers/adminpanel/categories_controller.rb +2 -2
  37. data/spec/dummy/app/controllers/adminpanel/products_controller.rb +3 -3
  38. data/spec/dummy/app/models/adminpanel/categorization.rb +17 -17
  39. data/spec/dummy/app/models/adminpanel/photo.rb +8 -0
  40. data/spec/dummy/app/models/adminpanel/product.rb +49 -26
  41. data/spec/dummy/app/uploader/adminpanel/photo_uploader.rb +86 -0
  42. data/spec/dummy/app/uploader/adminpanel/section_uploader.rb +86 -0
  43. data/spec/features/section_pages_spec.rb +4 -4
  44. data/spec/features/shared_pages_spec.rb +15 -15
  45. data/spec/generators/gallery_generator_spec.rb +53 -0
  46. data/spec/generators/initialize_generator_spec.rb +19 -12
  47. data/spec/generators/resource_generator_spec.rb +44 -37
  48. data/spec/support/define_factory_models.rb +3 -5
  49. data/spec/support/test_database.rb +8 -3
  50. data/spec/tasks/adminpanel_rake_spec.rb +5 -5
  51. metadata +18 -7
  52. data/app/helpers/adminpanel/class_definitions_helper.rb +0 -10
  53. data/app/views/adminpanel/sections/_image_fields.html.erb +0 -24
  54. data/lib/adminpanel/active_record_extension.rb +0 -123
@@ -0,0 +1,86 @@
1
+ module Adminpanel
2
+ class SectionUploader < CarrierWave::Uploader::Base
3
+ include CarrierWave::RMagick
4
+
5
+ storage :file
6
+
7
+ def root
8
+ Rails.root.join 'public/'
9
+ end
10
+
11
+ def store_dir
12
+ "uploads/image/#{mounted_as}/#{model.id}"
13
+ end
14
+
15
+ # Process files as they are uploaded:
16
+ # process :resize_to_fill => [1366, 768]
17
+
18
+ # THE THUMB VERSION IS NECESSARY!!!!
19
+ version :thumb do
20
+ process :resize_to_limit => [220, 220]
21
+ end
22
+
23
+ # however, you can create your own versions:
24
+ # version :awesome do
25
+ # process :reside_and_pad => [120, 900]
26
+ # end
27
+
28
+ # resize_and_pad(width, height, background=:transparent, gravity=::Magick::CenterGravity)
29
+ #
30
+ # Resize the image to fit within the specified dimensions while retaining
31
+ # the original aspect ratio. If necessary, will pad the remaining area with
32
+ # the given color, which defaults to transparent (for gif and png, white for jpeg).
33
+ #
34
+ # width (Integer)
35
+ # the width to scale the image to
36
+ # height (Integer)
37
+ # the height to scale the image to
38
+ # background (String, :transparent)
39
+ # the color of the background as a hexcode, like “ff45de“
40
+ # gravity (Magick::GravityType)
41
+ # how to position the image
42
+
43
+ # resize_to_fill(width, height)
44
+ #
45
+ # From the RMagick documentation: “Resize the image to fit within the
46
+ # specified dimensions while retaining the aspect ratio of the original image.
47
+ # If necessary, crop the image in the larger dimension.“
48
+ #
49
+ # See even www.imagemagick.org/RMagick/doc/image3.html#resize_to_fill
50
+ #
51
+ # width (Integer)
52
+ # the width to scale the image to
53
+ # height (Integer)
54
+ # the height to scale the image to
55
+
56
+ # resize_to_fit(width, height)
57
+ #
58
+ # From the RMagick documentation: “Resize the image to fit within the
59
+ # specified dimensions while retaining the original aspect ratio. The image
60
+ # may be shorter or narrower than specified in the smaller dimension but
61
+ # will not be larger than the specified values.“
62
+ #
63
+ # See even www.imagemagick.org/RMagick/doc/image3.html#resize_to_fit
64
+ #
65
+ # width (Integer)
66
+ # the width to scale the image to
67
+ # height (Integer)
68
+ # the height to scale the image to
69
+
70
+ # resize_to_limit(width, height)
71
+ #
72
+ # Resize the image to fit within the specified dimensions while retaining
73
+ # the original aspect ratio. Will only resize the image if it is larger than
74
+ # the specified dimensions. The resulting image may be shorter or narrower
75
+ # than specified in the smaller dimension but will not be larger than the
76
+ # specified values.
77
+ #
78
+ # width (Integer)
79
+ # the width to scale the image to
80
+ # height (Integer)
81
+ # the height to scale the image to
82
+ def extension_white_list
83
+ %w(jpg jpeg png)
84
+ end
85
+ end
86
+ end
@@ -4,11 +4,11 @@ describe "Section pages" do
4
4
  subject {page}
5
5
 
6
6
  let(:user) { Factory(:user) }
7
- before do
7
+ before do
8
8
  visit adminpanel.signin_path
9
9
  valid_signin(user)
10
10
  end
11
-
11
+
12
12
  describe "index" do
13
13
  let(:section) { Factory(:section_with_gallery) }
14
14
  before do
@@ -22,7 +22,7 @@ describe "Section pages" do
22
22
  describe "show" do
23
23
  describe "with gallery" do
24
24
  let(:section) { Factory(:section_with_gallery) }
25
- let(:image) { Factory(:image_section, :foreign_key => section.id) }
25
+ let(:image) { Factory(:image_section, :section_id => section.id) }
26
26
  # let(:image2) { Factory(:image_section, :foreign_key => section.id) }
27
27
  # let(:image3) { Factory(:image_section, :foreign_key => section.id) }
28
28
 
@@ -35,4 +35,4 @@ describe "Section pages" do
35
35
  it { should have_link("i", adminpanel.edit_section_path(section)) }
36
36
  end
37
37
  end
38
- end
38
+ end
@@ -1,29 +1,29 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- describe "shared pages" do
3
+ describe 'shared pages' do
4
4
  subject {page}
5
5
 
6
6
  let(:user) { Factory(:user) }
7
- before do
7
+ before do
8
8
  visit adminpanel.signin_path
9
9
  valid_signin(user)
10
10
  end
11
-
12
- context "when visiting" do
13
- describe "index" do
11
+
12
+ context 'when visiting' do
13
+ describe 'index' do
14
14
  let(:product) { Factory(:product) }
15
15
  before do
16
16
  visit adminpanel.products_path
17
17
  end
18
18
 
19
19
  it { should have_link(Adminpanel::Product.display_name, adminpanel.new_product_path)}
20
- it { should have_link("i", adminpanel.product_path(product)) }
21
- it { should have_link("i", adminpanel.edit_product_path(product)) }
20
+ it { should have_link('i', adminpanel.product_path(product)) }
21
+ it { should have_link('i', adminpanel.edit_product_path(product)) }
22
22
  end
23
23
 
24
- describe "new" do
24
+ describe 'new' do
25
25
  let(:category){ Factory(:category) }
26
- before do
26
+ before do
27
27
  category.id = 1 #to force instantiation and id.
28
28
  visit adminpanel.new_product_path
29
29
  end
@@ -55,7 +55,7 @@ describe "shared pages" do
55
55
  let(:category){ Factory(:category) }
56
56
  let(:product){ Factory(:product) }
57
57
 
58
- before do
58
+ before do
59
59
  category.id = 1 #to force instantiation and id.
60
60
  product.category_ids = ["1"]
61
61
  visit adminpanel.edit_product_path(product)
@@ -64,7 +64,7 @@ describe "shared pages" do
64
64
  it { should have_title(I18n.t("action.update") + " " + Adminpanel::Product.display_name) }
65
65
 
66
66
  describe "with invalid information" do
67
- before do
67
+ before do
68
68
  fill_in "product_name", :with => ""
69
69
  fill_in "product_price", :with => ""
70
70
  find("form#edit_resource").submit_form!
@@ -97,10 +97,10 @@ describe "shared pages" do
97
97
 
98
98
  describe "show" do
99
99
  let(:product) { Factory(:product) }
100
- let(:image) { Factory(:image_resource) }
100
+ let(:photo) { Factory(:photo) }
101
101
 
102
102
  before do
103
- image.foreign_key = product.id
103
+ photo.product_id = product.id
104
104
  visit adminpanel.product_path(product)
105
105
  end
106
106
 
@@ -111,4 +111,4 @@ describe "shared pages" do
111
111
  it { should have_link("i", adminpanel.edit_product_path(product)) }
112
112
  end
113
113
  end
114
- end
114
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe "adminpanel:gallery" do
4
+
5
+ with_args :Product do
6
+ it 'should generate the model' do
7
+ subject.should generate('app/models/adminpanel/productfile.rb'){ |content|
8
+ content.should =~ /attr_accessible :product_id, :file/ &&
9
+ content.should =~ /mount_uploader :file, ProductfileUploader/
10
+ }
11
+ end
12
+
13
+ it 'should generate the uploader' do
14
+ subject.should generate('app/uploader/adminpanel/productfile_uploader.rb')
15
+ end
16
+
17
+ # it 'should generate the migration' do
18
+ # subject.should generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_adminpanel_productfields_table.rb"){|content|
19
+ # content.should =~ /t.integer :product_id/
20
+ # }
21
+ #
22
+ # end
23
+ #
24
+ # it "should generate the default category model" do
25
+ # subject.should generate("app/models/adminpanel/category.rb")
26
+ # end
27
+ #
28
+ # it 'should generate the categories migration' do
29
+ # subject.should generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_adminpanel_categories_table.rb")
30
+ # end
31
+ # end
32
+ #
33
+ # with_args :'-c', :false do
34
+ # it "shouldn't generate the default category model" do
35
+ # subject.should_not generate("app/models/adminpanel/category.rb")
36
+ # end
37
+ #
38
+ # it "shouldn't generate the categories migration" do
39
+ # subject.should_not generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_adminpanel_categories_table.rb")
40
+ # end
41
+ #
42
+ # it "should generate the initialization migration" do
43
+ # subject.should generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_adminpanel_tables.rb")
44
+ # end
45
+ #
46
+ # end
47
+ #
48
+ # it 'should generate the configuration initializer' do
49
+ # subject.should generate('config/initializers/adminpanel_setup.rb'){ |content|
50
+ # content.should =~ /Adminpanel.setup do |config|/
51
+ # }
52
+ end
53
+ end
@@ -1,34 +1,41 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "adminpanel:initialize" do
4
+
4
5
  context "with no arguments or options" do
5
- it "should generate a migration" do
6
- subject.should generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_adminpanel_tables.rb")
6
+ it "should generate the initialization migration" do
7
+ subject.should generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S").to_i + 1}_create_adminpanel_tables.rb")
7
8
  end
8
9
 
9
- it "should generate the default category and migration" do
10
+ it "should generate the default category model" do
10
11
  subject.should generate("app/models/adminpanel/category.rb")
11
12
  end
12
13
 
13
14
  it 'should generate the categories migration' do
14
- subject.should generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_adminpanel_categories_tables.rb")
15
+ subject.should generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_adminpanel_categories_table.rb")
16
+ end
17
+
18
+ it 'should generate the configuration initializer' do
19
+ subject.should generate('config/initializers/adminpanel_setup.rb'){ |content|
20
+ content.should =~ /Adminpanel.setup do |config|/
21
+ }
15
22
  end
16
23
  end
17
24
 
18
- with_args :'-c', :false do
19
- it "shouldn't generate the default category and migration" do
25
+ with_args :'-c', :true, :'-u', :true, :'-m', :true do
26
+
27
+ it "shouldn't generate the default category model" do
20
28
  subject.should_not generate("app/models/adminpanel/category.rb")
21
29
  end
22
30
 
23
31
  it "shouldn't generate the categories migration" do
24
- subject.should_not generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_adminpanel_categories_tables.rb")
32
+ subject.should_not generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_adminpanel_categories_table.rb")
25
33
  end
26
34
 
27
- end
35
+ it "shouldn't generate the initialization migration" do
36
+ subject.should_not generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S").to_i + 1}_create_adminpanel_tables.rb")
37
+ end
28
38
 
29
- it 'should generate the configuration initializer' do
30
- subject.should generate('config/initializers/adminpanel_setup.rb'){ |content|
31
- content.should =~ /Adminpanel.setup do |config|/
32
- }
33
39
  end
40
+
34
41
  end
@@ -1,39 +1,39 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
+
3
+ describe 'adminpanel:resource' do
2
4
 
3
- describe "adminpanel:resource" do
4
-
5
5
  with_args :category do
6
- it "should generate categories migration" do
6
+ it 'should generate categories migration' do
7
7
  subject.should generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_categories_table.rb")
8
8
  end
9
- it "should generate categories controller" do
10
- subject.should generate("app/controllers/adminpanel/categories_controller.rb")
9
+ it 'should generate categories controller' do
10
+ subject.should generate('app/controllers/adminpanel/categories_controller.rb')
11
11
  end
12
- it "should generate category model" do
13
- subject.should generate("app/models/adminpanel/category.rb")
12
+ it 'should generate category model' do
13
+ subject.should generate('app/models/adminpanel/category.rb')
14
14
  end
15
15
 
16
16
  context "with has_many and belongs_to" do
17
17
  with_args :"products,categorizations:has_many_through", :"product:belongs_to" do
18
18
  it "should generate categories migration" do
19
19
  subject.should generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_categories_table.rb") { |content|
20
- content.should =~ /t.integer \:product_id/ &&
20
+ content.should =~ /t.integer :product_id/ &&
21
21
  (
22
- content.should_not =~ /t.integer \:products_id/ ||
23
- content.should_not =~ /t.integer \:categorizations_id/
22
+ content.should_not =~ /t.integer :products_id/ ||
23
+ content.should_not =~ /t.integer :categorizations_id/
24
24
  )
25
25
  }
26
26
  end
27
27
 
28
28
  it "should generate model with has_many categorizations" do
29
29
  subject.should generate("app/models/adminpanel/category.rb") { |content|
30
- content.should =~ /has_many \:categorizations/
30
+ content.should =~ /has_many :categorizations/
31
31
  }
32
32
  end
33
33
 
34
34
  it "should generate model with has_many products through categorizations" do
35
35
  subject.should generate("app/models/adminpanel/category.rb") { |content|
36
- content.should =~ /has_many \:products, \:through => \:categorizations/
36
+ content.should =~ /has_many :products, :through => :categorizations/
37
37
  }
38
38
  end
39
39
 
@@ -76,28 +76,35 @@ describe "adminpanel:resource" do
76
76
  :"name:string", :"quantity:integer" do
77
77
  it "should generate migration with correct values" do
78
78
  subject.should generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_products_table.rb") { |content|
79
- content.should =~ /t.text \:description/ &&
80
- content.should =~ /t.text \:long_text/ &&
81
- content.should =~ /t.float \:price/ &&
82
- content.should =~ /t.string \:date/ &&
83
- content.should =~ /t.string \:name/ &&
84
- content.should =~ /t.integer \:quantity/
79
+ content.should =~ /t.text :description/ &&
80
+ content.should =~ /t.text :long_text/ &&
81
+ content.should =~ /t.float :price/ &&
82
+ content.should =~ /t.string :date/ &&
83
+ content.should =~ /t.string :name/ &&
84
+ content.should =~ /t.integer :quantity/
85
85
  }
86
86
  end
87
87
  end
88
88
 
89
- with_args :"image:images" do
89
+ with_args :"photo:images" do
90
90
  it "should generate model with image relationship" do
91
91
  subject.should generate("app/models/adminpanel/product.rb") { |content|
92
- content.should =~ /has_many :images, :foreign_key => "foreign_key", :conditions => \{ :model => "product" \}/
93
- }
94
- end
95
-
96
- it "should accept nested attributes for image" do
97
- subject.should generate("app/models/adminpanel/product.rb") { |content|
98
- content.should =~ /accepts_nested_attributes_for :images, :allow_destroy => true/
92
+ content.should =~ /mount_images :photos/ &&
93
+ content.should =~ /'photos' => \{/ &&
94
+ content.should =~ /'type' => 'adminpanel_file_field'/
99
95
  }
100
96
  end
97
+ #
98
+ # it "should generate a photos uploader" do
99
+ # subject.should generate("app/uploader/adminpanel/photos_uploader.rb")
100
+ # end
101
+ #
102
+ # it "should generate a photo model" do
103
+ # subject.should generate("app/models/adminpanel/photo.rb"){ |content|
104
+ # content.should =~ /mount_uploader :file, CameraUploader/ &&
105
+ # content.should =~ /:camera_id/
106
+ # }
107
+ # end
101
108
  end
102
109
 
103
110
 
@@ -118,21 +125,21 @@ describe "adminpanel:resource" do
118
125
 
119
126
  it "should generate model with description hash" do
120
127
  subject.should generate("app/models/adminpanel/product.rb") { |content|
121
- content.should =~ /\{\"description\" => \{/ &&
122
- content.should =~ /\"type\" => \"wysiwyg_field\", /&&
123
- content.should =~ /\"name\" => \"description\", / &&
124
- content.should =~ /\"label\" => \"description\", / &&
125
- content.should =~ /\"placeholder\" => \"description\"\}\}/
128
+ content.should =~ /'description' => \{/ &&
129
+ content.should =~ /'type' => 'wysiwyg_field',/&&
130
+ content.should =~ /'name' => 'description',/ &&
131
+ content.should =~ /'label' => 'description',/ &&
132
+ content.should =~ /'placeholder' => 'description'\}/
126
133
  }
127
134
  end
128
135
 
129
136
  it "should generate model with name hash" do
130
137
  subject.should generate("app/models/adminpanel/product.rb") { |content|
131
- content.should =~ /\{\"name\" => \{/
132
- content.should =~ /\"type\" => \"text_field\", /
133
- content.should =~ /\"name\" => \"name\", /
134
- content.should =~ /\"label\" => \"name\", /
135
- content.should =~ /\"placeholder\" => \"name\"\}\}/
138
+ content.should =~ /'name' => \{/
139
+ content.should =~ /'type' => 'text_field',/
140
+ content.should =~ /'name' => 'name',/
141
+ content.should =~ /'label' => 'name',/
142
+ content.should =~ /'placeholder' => 'name'\}/
136
143
  }
137
144
  end
138
145
 
@@ -12,7 +12,6 @@ Factory.define :gallery, :class => Adminpanel::Gallery do |gallery|
12
12
  end
13
13
 
14
14
  Factory.define :image_section, :class => Adminpanel::Image do |image|
15
- image.model "Section"
16
15
  image.file { fixture_file_upload(Rails.root.join('app', 'assets', 'images', 'hipster.jpg'), 'image/jpeg') }
17
16
  end
18
17
 
@@ -26,9 +25,8 @@ Factory.define :category, :class => Adminpanel::Category do |category|
26
25
  category.name "Test Category"
27
26
  end
28
27
 
29
- Factory.define :image_resource, :class => Adminpanel::Image do |image|
30
- image.model "Product"
31
- image.file { fixture_file_upload(Rails.root.join('app', 'assets', 'images', 'hipster.jpg'), 'image/jpeg') }
28
+ Factory.define :photo, :class => Adminpanel::Photo do |photo|
29
+ photo.file { fixture_file_upload(Rails.root.join('app', 'assets', 'images', 'hipster.jpg'), 'image/jpeg') }
32
30
  end
33
31
 
34
32
  Factory.define :section_with_gallery, :class => Adminpanel::Section do |section|
@@ -38,4 +36,4 @@ Factory.define :section_with_gallery, :class => Adminpanel::Section do |section|
38
36
  section.has_description false
39
37
  section.name "section_name"
40
38
  section.page "index"
41
- end
39
+ end