simple_showcase_admin 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/javascripts/simple_showcase_admin/application.js +23 -0
  5. data/app/assets/javascripts/simple_showcase_admin/jquery.photo_featured.js +3 -0
  6. data/app/assets/javascripts/simple_showcase_admin/jquery.photos.js +18 -0
  7. data/app/assets/stylesheets/simple_showcase_admin/application.css.scss +123 -0
  8. data/app/controllers/simple_showcase_admin/application_controller.rb +10 -0
  9. data/app/controllers/simple_showcase_admin/categories_controller.rb +44 -0
  10. data/app/controllers/simple_showcase_admin/details_controller.rb +20 -0
  11. data/app/controllers/simple_showcase_admin/items_controller.rb +48 -0
  12. data/app/controllers/simple_showcase_admin/password_resets_controller.rb +40 -0
  13. data/app/controllers/simple_showcase_admin/sessions_controller.rb +25 -0
  14. data/app/helpers/simple_showcase_admin/application_helper.rb +12 -0
  15. data/app/helpers/simple_showcase_admin/items_helper.rb +15 -0
  16. data/app/mailers/simple_showcase_admin/user_mailer.rb +12 -0
  17. data/app/models/simple_showcase_admin/category.rb +20 -0
  18. data/app/models/simple_showcase_admin/item.rb +24 -0
  19. data/app/models/simple_showcase_admin/photo.rb +13 -0
  20. data/app/models/simple_showcase_admin/user.rb +25 -0
  21. data/app/uploaders/image_uploader.rb +22 -0
  22. data/app/views/layouts/simple_showcase_admin/application.html.haml +47 -0
  23. data/app/views/simple_showcase_admin/categories/edit.html.haml +9 -0
  24. data/app/views/simple_showcase_admin/categories/index.html.haml +26 -0
  25. data/app/views/simple_showcase_admin/categories/new.html.haml +9 -0
  26. data/app/views/simple_showcase_admin/categories/show.html.haml +49 -0
  27. data/app/views/simple_showcase_admin/details/edit.html.haml +11 -0
  28. data/app/views/simple_showcase_admin/details/show.html.haml +7 -0
  29. data/app/views/simple_showcase_admin/items/_photos.html.haml +12 -0
  30. data/app/views/simple_showcase_admin/items/edit.html.haml +26 -0
  31. data/app/views/simple_showcase_admin/items/index.html.haml +48 -0
  32. data/app/views/simple_showcase_admin/items/new.html.haml +24 -0
  33. data/app/views/simple_showcase_admin/items/show.html.haml +15 -0
  34. data/app/views/simple_showcase_admin/password_resets/edit.html.haml +9 -0
  35. data/app/views/simple_showcase_admin/password_resets/new.html.haml +8 -0
  36. data/app/views/simple_showcase_admin/sessions/new.html.haml +19 -0
  37. data/app/views/simple_showcase_admin/user_mailer/reset_password_email.html.haml +8 -0
  38. data/config/initializers/simple_form.rb +177 -0
  39. data/config/initializers/sorcery.rb +386 -0
  40. data/config/routes.rb +13 -0
  41. data/db/migrate/001_sorcery_core.rb +15 -0
  42. data/db/migrate/002_sorcery_remember_me.rb +15 -0
  43. data/db/migrate/003_sorcery_reset_password.rb +17 -0
  44. data/db/migrate/004_add_slug_to_users.rb +7 -0
  45. data/db/migrate/005_add_first_name_to_users.rb +6 -0
  46. data/db/migrate/006_create_categories.rb +9 -0
  47. data/db/migrate/007_create_items.rb +10 -0
  48. data/db/migrate/008_create_photos.rb +9 -0
  49. data/db/migrate/009_add_category_id_to_items.rb +6 -0
  50. data/db/migrate/010_add_slug_to_categories.rb +7 -0
  51. data/db/migrate/011_add_slug_to_items.rb +6 -0
  52. data/db/migrate/012_add_item_id_to_photos.rb +5 -0
  53. data/db/migrate/013_add_featured_to_photos.rb +5 -0
  54. data/db/migrate/014_add_landscape_to_photos.rb +5 -0
  55. data/lib/generators/simple_showcase_admin/install_generator.rb +69 -0
  56. data/lib/simple_showcase_admin/configuration.rb +11 -0
  57. data/lib/simple_showcase_admin/engine.rb +21 -0
  58. data/lib/simple_showcase_admin/version.rb +3 -0
  59. data/lib/simple_showcase_admin.rb +5 -0
  60. data/lib/tasks/simple_showcase_admin_tasks.rake +4 -0
  61. data/test/dummy/README.rdoc +261 -0
  62. data/test/dummy/Rakefile +7 -0
  63. data/test/dummy/app/assets/javascripts/application.js +15 -0
  64. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  65. data/test/dummy/app/controllers/application_controller.rb +3 -0
  66. data/test/dummy/app/helpers/application_helper.rb +2 -0
  67. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  68. data/test/dummy/config/application.rb +59 -0
  69. data/test/dummy/config/boot.rb +10 -0
  70. data/test/dummy/config/database.yml +25 -0
  71. data/test/dummy/config/environment.rb +5 -0
  72. data/test/dummy/config/environments/development.rb +37 -0
  73. data/test/dummy/config/environments/production.rb +67 -0
  74. data/test/dummy/config/environments/test.rb +37 -0
  75. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  76. data/test/dummy/config/initializers/inflections.rb +15 -0
  77. data/test/dummy/config/initializers/mime_types.rb +5 -0
  78. data/test/dummy/config/initializers/secret_token.rb +7 -0
  79. data/test/dummy/config/initializers/session_store.rb +8 -0
  80. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  81. data/test/dummy/config/locales/en.yml +5 -0
  82. data/test/dummy/config/routes.rb +4 -0
  83. data/test/dummy/config.ru +4 -0
  84. data/test/dummy/public/404.html +26 -0
  85. data/test/dummy/public/422.html +26 -0
  86. data/test/dummy/public/500.html +25 -0
  87. data/test/dummy/public/favicon.ico +0 -0
  88. data/test/dummy/script/rails +6 -0
  89. data/test/integration/navigation_test.rb +10 -0
  90. data/test/simple_showcase_admin_test.rb +7 -0
  91. data/test/test_helper.rb +15 -0
  92. metadata +477 -0
@@ -0,0 +1,15 @@
1
+ module SimpleShowcaseAdmin
2
+ module ItemsHelper
3
+ def new_child_fields_template(form_builder)
4
+ content_tag(:div, :id => "photos_fields_template", :style => "display: none") do
5
+ form_builder.fields_for(:photos, Photo.new, :child_index => "new_photos") do |f|
6
+ render(:partial => 'photos', :locals => { :f => f })
7
+ end
8
+ end
9
+ end
10
+
11
+ def add_child_link(name, association)
12
+ link_to(name, "javascript:void(0)", :class => "add_child btn btn-mini", :"data-association" => association)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module SimpleShowcaseAdmin
2
+ class UserMailer < ActionMailer::Base
3
+ default from: "notifier@mandyjane.co.uk"
4
+ def reset_password_email user
5
+ @user = user
6
+ @url = "http://0.0.0.0:3000/password_resets/#{user.reset_password_token}/edit"
7
+ mail(:to => user.email,
8
+ :subject => "Your password has been reset")
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,20 @@
1
+ require 'friendly_id'
2
+
3
+ module SimpleShowcaseAdmin
4
+ class Category < ActiveRecord::Base
5
+ attr_accessible :category, :slug
6
+ has_many :items, dependent: :destroy
7
+
8
+ extend FriendlyId
9
+ friendly_id :category, use: :slugged
10
+
11
+ validates_presence_of :category
12
+ validates_uniqueness_of :category
13
+
14
+ before_save :format
15
+
16
+ def format
17
+ self.category = self.category.titleize
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ require 'friendly_id'
2
+
3
+ module SimpleShowcaseAdmin
4
+ class Item < ActiveRecord::Base
5
+ belongs_to :category
6
+ has_many :photos, dependent: :destroy
7
+ accepts_nested_attributes_for :photos, reject_if: proc { |a| a[:id].blank? && a[:image].blank? }, allow_destroy: true
8
+ attr_accessible :photos_attributes, :title, :description
9
+
10
+ extend FriendlyId
11
+ friendly_id :title, use: :slugged
12
+
13
+ validates_presence_of :title
14
+ validates_presence_of :description
15
+
16
+ validates_uniqueness_of :title
17
+
18
+ before_validation :format
19
+
20
+ def format
21
+ self.title = self.title.downcase.titleize
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ module SimpleShowcaseAdmin
2
+ class Photo < ActiveRecord::Base
3
+ attr_accessible :image, :featured, :landscape
4
+ mount_uploader :image, ImageUploader
5
+ before_save :reset_featured_post, :if => :featured_changed?
6
+
7
+ def reset_featured_post
8
+ if self.featured?
9
+ Photo.update_all :featured => false
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ require 'friendly_id'
2
+
3
+ module SimpleShowcaseAdmin
4
+ class User < ActiveRecord::Base
5
+ attr_accessible :first_name, :email, :password, :password_confirmation, :slug
6
+ authenticates_with_sorcery!
7
+
8
+ extend FriendlyId
9
+ friendly_id :first_name, use: :slugged
10
+
11
+ before_save :format_attributes
12
+
13
+ validates_presence_of :first_name
14
+ validates_presence_of :email
15
+ validates_presence_of :password, on: :create
16
+ validates_confirmation_of :password
17
+ validates_confirmation_of :email, on: :update
18
+ validates_length_of :password, minimum: 6
19
+
20
+ def format_attributes
21
+ self.email = self.email.downcase
22
+ self.first_name = self.first_name.titleize
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ class ImageUploader < CarrierWave::Uploader::Base
4
+ include CarrierWave::RMagick
5
+ storage :file
6
+
7
+ def store_dir
8
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
9
+ end
10
+
11
+ def extension_white_list
12
+ %w(jpg jpeg gif png bmp tiff)
13
+ end
14
+
15
+ def filename
16
+ !super.nil? ? super.chomp(File.extname(super)) + '.png' : super
17
+ end
18
+
19
+ process :resize_to_fit => [750, 502]
20
+ process :convert => 'png'
21
+
22
+ end
@@ -0,0 +1,47 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title Administrator Area
5
+ = stylesheet_link_tag "simple_showcase_admin/application"
6
+ = javascript_include_tag "simple_showcase_admin/application"
7
+ = csrf_meta_tag
8
+ %body
9
+ #container
10
+ .navbar.navbar-fixed-top
11
+ .navbar-inner
12
+ .container
13
+ - if current_user
14
+ %ul.nav
15
+ %li.dropdown
16
+ = link_to "Categories <b class='caret'></b>".html_safe, '#', :class => 'dropdown-toggle', "data-toggle" => "dropdown"
17
+ %ul.dropdown-menu
18
+ - if SimpleShowcaseAdmin::Category.all.count > 0
19
+ %li= link_to 'Manage Categories', [ :categories]
20
+ %li.divider
21
+ - else
22
+ %li= link_to 'Create a Category', [:new, :category]
23
+ - SimpleShowcaseAdmin::Category.all.each do |c|
24
+ %li= link_to c.category, [ c]
25
+ - unless featured_photo_exists
26
+ %li.warning.label.label-important(rel="popover" data-content="You can select an image to be featured by editing a product and selecting 'Featured?' for one of the associated images." data-original-title="Please Select An Image To Be Featured.")
27
+ %i.icon-info-sign.icon-white
28
+ No Feature Photo Has Been Selected!
29
+ %ul.nav.pull-right
30
+ %li.dropdown
31
+ = link_to "<i class='icon-user icon-white'></i> #{current_user.first_name} <b class='caret'></b>".html_safe, '#', :class => 'dropdown-toggle', "data-toggle" => "dropdown"
32
+ %ul.dropdown-menu
33
+ %li= link_to 'Your Details', detail_path(current_user)
34
+ %li.divider
35
+ %li= link_to 'Log Out', logout_path
36
+ .container
37
+ .flash
38
+ - if flash[:alert]
39
+ .message.alert.alert-error
40
+ = link_to '&times;'.html_safe, '#', class: 'close', "data-dismiss" => "alert"
41
+ = flash[:alert]
42
+ - if flash[:notice]
43
+ .message.alert.alert-success
44
+ = link_to '&times;'.html_safe, '#', class: 'close', "data-dismiss" => "alert"
45
+ = flash[:notice]
46
+ .content
47
+ = yield
@@ -0,0 +1,9 @@
1
+ %h1 Edit Category
2
+ %br
3
+ %br
4
+ = simple_form_for(@category, :html => {:multipart => true, :class => 'form-horizontal'}, :url => category_path(@category)) do |f|
5
+ = f.error_notification
6
+ = f.input :category, input_html: { class: "span6" }
7
+ .form-actions
8
+ = f.button :submit, 'Save', :class => 'btn-primary'
9
+ = link_to 'Cancel', categories_path, class: 'btn'
@@ -0,0 +1,26 @@
1
+ %h1 Listing Categories
2
+
3
+ = link_to 'New Category', new_category_path, :class => 'btn-primary btn pull-right'
4
+
5
+ %br
6
+ %br
7
+
8
+ = paginate @categories
9
+
10
+ %table.table.table-bordered.table-striped
11
+ %thead
12
+ %tr
13
+ %th Category
14
+ %th &nbsp
15
+
16
+ %tbody
17
+ - @categories.each do |category|
18
+ %tr
19
+ %td= category.category
20
+ %td
21
+ = link_to 'View', category_path(category), :class => 'btn'
22
+ = link_to 'Edit', edit_category_path(category), :class => 'btn btn-primary'
23
+ = link_to 'Delete', category_path(category), :confirm => 'Are you sure?', :method => :delete, :class => 'btn btn-danger'
24
+
25
+ = paginate @categories
26
+
@@ -0,0 +1,9 @@
1
+ %h1 New Category
2
+ %br
3
+ %br
4
+ = simple_form_for([ @category], :html => {:multipart => true, :class => 'form-horizontal'}) do |f|
5
+ = f.error_notification
6
+ = f.input :category, input_html: { class: "span6" }
7
+ .form-actions
8
+ = f.button :submit, 'Save', :class => 'btn-primary'
9
+ = link_to 'Cancel', categories_path, class: 'btn'
@@ -0,0 +1,49 @@
1
+ %h1 #{@category.category.titleize} Category
2
+
3
+ %br
4
+ %br
5
+
6
+ %table.table.table-bordered.table-striped
7
+ %thead
8
+ %tr
9
+ %th Category
10
+ %th Date Created
11
+ %th &nbsp
12
+
13
+ %tbody
14
+ %tr
15
+ %td= @category.category
16
+ %td=l @category.created_at
17
+ %td
18
+ = link_to 'Edit', edit_category_path(@category), :class => 'btn btn-primary'
19
+ = link_to 'Delete', category_path(@category), :confirm => 'Are you sure?', :method => :delete, :class => 'btn btn-danger'
20
+
21
+ %br
22
+ %br
23
+
24
+ %h2
25
+ Category Items
26
+ = link_to "New Item", new_category_item_path(@category), class: 'btn btn-primary pull-right'
27
+
28
+ %br
29
+
30
+ = paginate @items
31
+
32
+ %table.table.table-bordered.table-striped
33
+ %thead
34
+ %tr
35
+ %th Title
36
+ %th Description
37
+ %th
38
+
39
+ %tbody
40
+ - @items.each do |item|
41
+ %tr
42
+ %td= item.title
43
+ %td= item.description.truncate(150)
44
+ %td.right
45
+ = link_to 'View', [ @category, item], :class => 'btn'
46
+ = link_to 'Edit', [:edit, @category, item], :class => 'btn btn-primary'
47
+ = link_to 'Delete', [ @category, item], :confirm => 'Are you sure?', :method => :delete, :class => 'btn btn-danger'
48
+
49
+ = paginate @items
@@ -0,0 +1,11 @@
1
+ %h1 Edit Your Details
2
+ %br
3
+ %br
4
+ = simple_form_for(@user, :html => { :class => 'form-horizontal' }, :url => detail_path(@user)) do |f|
5
+ = f.input :email, :input_html => { :class => "span6" }
6
+ = f.input :email_confirmation, :input_html => { :class => "span6" }, required: true
7
+ = f.input :password, :input_html => { :class => "span6" }
8
+ = f.input :password_confirmation, :input_html => { :class => "span6" }
9
+ .form-actions
10
+ = f.button :submit, 'Save', :class => 'btn-primary'
11
+ = link_to 'Cancel', detail_path(@user), class: 'btn'
@@ -0,0 +1,7 @@
1
+ %br
2
+ = @user.first_name
3
+ %br
4
+ = @user.email
5
+ %br
6
+ %br
7
+ = link_to 'Edit Details', edit_detail_path(@user), :class => 'btn btn-primary'
@@ -0,0 +1,12 @@
1
+ .photo-fields
2
+ .controls.item-photo
3
+ - if f.object.new_record?
4
+ = f.file_field :image
5
+ - else
6
+ = image_tag f.object.image.url
7
+ %label.checkbox
8
+ - if SimpleShowcaseAdmin::Config.featured_image
9
+ Featured?
10
+ = f.check_box :featured
11
+ = link_to 'Remove', '#', class: 'remove_child btn btn-mini btn-danger'
12
+ = f.hidden_field :_destroy, class: :destroy
@@ -0,0 +1,26 @@
1
+ %h1 Edit Item
2
+ %br
3
+ %br
4
+ = simple_form_for([@category, @item], :html => {:multipart => true, :class => 'form-horizontal'}) do |f|
5
+ - f.object.errors.full_messages.each do |msg|
6
+ = msg
7
+ = f.error_notification
8
+ = f.input :title, input_html: { class: "span6" }
9
+ = f.input :description, input_html: { class: "span6" }
10
+ .control-group#foo
11
+ = new_child_fields_template f
12
+ = f.label :image, 'Photos', class: 'control-label'
13
+ .controls
14
+ %div.hint
15
+ Supports
16
+ %b.red .jpg .jpeg .png .bmp
17
+ and
18
+ %b.red .tiff
19
+ formats
20
+ = f.fields_for :photos, @photos do |builder|
21
+ = render "photos", f: builder
22
+ .control-group#photo-inputs
23
+ .controls= add_child_link "Add Another Photo", :photos
24
+ .form-actions
25
+ = f.button :submit, 'Save', :class => 'btn-primary'
26
+ = link_to 'Cancel', category_path(@category), class: 'btn'
@@ -0,0 +1,48 @@
1
+ %h1 #{@category.category.titleize} Category
2
+
3
+ %br
4
+ %br
5
+
6
+ %table.table.table-bordered.table-striped
7
+ %thead
8
+ %tr
9
+ %th Category
10
+ %th Date Created
11
+ %th &nbsp
12
+
13
+ %tbody
14
+ %tr
15
+ %td= @category.category
16
+ %td=l @category.created_at
17
+ %td
18
+ = link_to 'Edit', edit_category_path(@category), :class => 'btn btn-primary'
19
+ = link_to 'Delete', category_path(@category), :confirm => 'Are you sure?', :method => :delete, :class => 'btn btn-danger'
20
+
21
+ %br
22
+ %br
23
+
24
+ %h2
25
+ Category Items
26
+ = link_to "New Item", new_category_item_path(@category), class: 'btn btn-primary pull-right'
27
+
28
+ %br
29
+
30
+ = paginate @items
31
+
32
+ %table.table.table-bordered.table-striped
33
+ %thead
34
+ %tr
35
+ %th Items
36
+ %th &nbsp
37
+
38
+ %tbody
39
+ - @items.each do |item|
40
+ %tr
41
+ %td= item.title
42
+ %td= item.description.truncate(150)
43
+ %td
44
+ = link_to 'View', category_item_path(@item), :class => 'btn'
45
+ = link_to 'Edit', edit_category_item_path(@item), :class => 'btn btn-primary'
46
+ = link_to 'Delete', category_item_path(@item), :confirm => 'Are you sure?', :method => :delete, :class => 'btn btn-danger'
47
+
48
+ = paginate @items
@@ -0,0 +1,24 @@
1
+ %h1 New Item
2
+ %br
3
+ %br
4
+ = simple_form_for([:category, @item], :html => {:multipart => true, :class => 'form-horizontal'}) do |f|
5
+ = f.error_notification
6
+ = f.input :title, input_html: { class: "span6" }
7
+ = f.input :description, input_html: { class: "span6" }
8
+ .control-group
9
+ = f.label :image, 'Photos', class: 'control-label'
10
+ .controls
11
+ %div.hint
12
+ Supports
13
+ %b.red .jpg .jpeg .png .bmp
14
+ and
15
+ %b.red .tiff
16
+ formats
17
+ = f.simple_fields_for :photos, @photos do |builder|
18
+ = render "photos", f: builder
19
+ .control-group
20
+ .controls= add_child_link "Add Another Photo", :photos
21
+ = new_child_fields_template f
22
+ .form-actions
23
+ = f.button :submit, 'Save', :class => 'btn-primary'
24
+ = link_to 'Cancel', category_path(params[:category_id]), class: 'btn'
@@ -0,0 +1,15 @@
1
+ = link_to 'Back', category_path(@category), class: 'btn'
2
+ %br
3
+ %br
4
+ %h1= @item.title
5
+ %br
6
+ %br
7
+ %p= markdown(@item.description)
8
+ %br
9
+ - @item.photos.each.with_index do |p, i|
10
+ - if p.image.present?
11
+ = image_tag p.image.url, alt: "#{@item.title.parameterize}-#{i+1}"
12
+ %br
13
+ %br
14
+ = link_to 'Edit', [:edit, @category, @item], class: 'btn btn-primary'
15
+ = link_to 'Delete', [@category, @item], method: :delete, class: 'btn btn-danger', confirm: 'Are you sure?'