bread 0.0.6 → 0.0.7

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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -1
  3. data/bread.gemspec +1 -1
  4. data/lib/bread.rb +15 -10
  5. data/lib/bread/{crumb.rb → data/crumb.rb} +4 -4
  6. data/lib/bread/helper.rb +3 -25
  7. data/lib/bread/manager/actions.rb +37 -0
  8. data/lib/bread/manager/actions/action_scope.rb +32 -0
  9. data/lib/bread/manager/actions/controller_scope.rb +69 -0
  10. data/lib/bread/manager/actions/top_scope.rb +26 -0
  11. data/lib/bread/manager/crumbs.rb +52 -0
  12. data/lib/bread/manager/crumbs/crumb_scope.rb +39 -0
  13. data/lib/bread/manager/crumbs/top_scope.rb +25 -0
  14. data/lib/bread/manager/manager.rb +14 -0
  15. data/lib/bread/version.rb +1 -1
  16. data/test/dummy/app/assets/javascripts/product_photos.js +2 -0
  17. data/test/dummy/app/assets/stylesheets/product_photos.css +4 -0
  18. data/test/dummy/app/controllers/product_photos_controller.rb +67 -0
  19. data/test/dummy/app/controllers/products_controller.rb +12 -23
  20. data/test/dummy/app/helpers/product_photos_helper.rb +2 -0
  21. data/test/dummy/app/lib/bread/actions.rb +18 -0
  22. data/test/dummy/app/lib/bread/actions_next.rb +43 -0
  23. data/test/dummy/app/lib/bread/crumbs.rb +22 -0
  24. data/test/dummy/app/lib/bread/crumbs_next.rb +77 -0
  25. data/test/dummy/app/models/product.rb +8 -0
  26. data/test/dummy/app/models/product_photo.rb +10 -0
  27. data/test/dummy/app/models/user.rb +6 -0
  28. data/test/dummy/app/views/layouts/application.html.erb +10 -5
  29. data/test/dummy/app/views/product_photos/_form.html.erb +29 -0
  30. data/test/dummy/app/views/product_photos/edit.html.erb +6 -0
  31. data/test/dummy/app/views/product_photos/index.html.erb +31 -0
  32. data/test/dummy/app/views/product_photos/new.html.erb +5 -0
  33. data/test/dummy/app/views/product_photos/show.html.erb +19 -0
  34. data/test/dummy/config/initializers/devise.rb +254 -0
  35. data/test/dummy/config/locales/devise.en.yml +59 -0
  36. data/test/dummy/config/routes.rb +4 -1
  37. data/test/dummy/db/migrate/20140306111733_devise_create_users.rb +42 -0
  38. data/test/dummy/db/migrate/20140306114935_create_product_photos.rb +11 -0
  39. data/test/dummy/db/schema.rb +29 -1
  40. data/test/{bread_test.rb → dummy/test/bread_test.rb} +1 -0
  41. data/test/dummy/test/controllers/product_photos_controller_test.rb +98 -0
  42. data/test/dummy/test/controllers/products_controller_test.rb +94 -30
  43. data/test/dummy/test/fixtures/product_photos.yml +11 -0
  44. data/test/dummy/test/fixtures/products.yml +4 -4
  45. data/test/dummy/test/fixtures/users.yml +11 -0
  46. data/test/dummy/test/helpers/product_photos_helper_test.rb +4 -0
  47. data/test/{integration → dummy/test/integration}/navigation_test.rb +0 -0
  48. data/test/dummy/test/models/product_photo_test.rb +7 -0
  49. data/test/dummy/test/models/user_test.rb +7 -0
  50. data/test/dummy/test/support/asserts.rb +17 -0
  51. data/test/test_helper.rb +1 -1
  52. metadata +68 -14
  53. data/lib/bread/commands/config_command.rb +0 -15
  54. data/lib/bread/commands/controller_layout_command.rb +0 -44
  55. data/lib/bread/commands/crumb_to_command.rb +0 -23
  56. data/lib/bread/commands/ivars_command.rb +0 -16
  57. data/lib/bread/config.rb +0 -24
  58. data/lib/bread/controller.rb +0 -30
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,67 @@
1
+ class ProductPhotosController < ApplicationController
2
+ before_action :set_product
3
+ before_action :set_product_photo, only: [:show, :edit, :update, :destroy]
4
+
5
+ # GET /product_photos
6
+ def index
7
+ @product_photos = @product.product_photos
8
+ end
9
+
10
+ # GET /product_photos/1
11
+ def show
12
+ end
13
+
14
+ # GET /product_photos/new
15
+ def new
16
+ @product_photo = @product.product_photos.build
17
+ end
18
+
19
+ # GET /product_photos/1/edit
20
+ def edit
21
+ end
22
+
23
+ # POST /product_photos
24
+ def create
25
+ @product_photo = @product.product_photos.build(product_photo_params)
26
+
27
+ if @product_photo.save
28
+ redirect_to [@product, @product_photo], notice: 'Product photo was successfully created.'
29
+ else
30
+ render action: 'new'
31
+ end
32
+ end
33
+
34
+ # PATCH/PUT /product_photos/1
35
+ def update
36
+ if @product_photo.update(product_photo_params)
37
+ redirect_to [@product, @product_photo], notice: 'Product photo was successfully updated.'
38
+ else
39
+ render action: 'edit'
40
+ end
41
+ end
42
+
43
+ # DELETE /product_photos/1
44
+ def destroy
45
+ if @product_photo.destroy
46
+ redirect_to product_product_photos_url, notice: 'Product photo was successfully destroyed.'
47
+ else
48
+ render action: 'edit'
49
+ end
50
+ end
51
+
52
+ private
53
+ # Use callbacks to share common setup or constraints between actions.
54
+
55
+ def set_product
56
+ @product = Product.find(params[:product_id])
57
+ end
58
+
59
+ def set_product_photo
60
+ @product_photo = @product.product_photos.find(params[:id])
61
+ end
62
+
63
+ # Only allow a trusted parameter "white list" through.
64
+ def product_photo_params
65
+ params.require(:product_photo).permit(:product_id, :name, :order)
66
+ end
67
+ end
@@ -1,34 +1,20 @@
1
1
  class ProductsController < ApplicationController
2
2
  before_action :set_product, only: [:show, :edit, :update, :destroy]
3
3
 
4
-
5
-
6
- bread do
7
- # alias_actions :new, :create
8
- # alias_actions :edit, :update, :destroy
9
-
10
- actions(:index) { crumbs :root, :all_products, parent: nil }
11
- actions(:new, :create) { crumbs :make_product, parent: :index, lala: 1, lele: 2, lili: 3434 }
12
- actions(:by_category) { crumbs :products_by_category, parent: :index }
13
- actions(:show) do
14
- parent = @category.present? ? :by_category : :index
15
- crumbs(:view_product, parent: parent)
16
- end
17
- actions(:edit) { crumbs :change_product, parent: :show }
18
- actions(:timeline) { crumbs :product_timeline, parent: :show }
19
- end
20
-
21
-
22
-
23
-
24
4
  # GET /products
25
5
  def index
26
6
  @products = Product.all
27
7
  end
28
8
 
9
+ # GET /products/category/1
10
+ def by_category
11
+ @category = params[:category]
12
+ @products = Product.where(category: params[:category])
13
+ render :index
14
+ end
15
+
29
16
  # GET /products/1
30
17
  def show
31
- @category = "lalala"
32
18
  end
33
19
 
34
20
  # GET /products/new
@@ -62,8 +48,11 @@ class ProductsController < ApplicationController
62
48
 
63
49
  # DELETE /products/1
64
50
  def destroy
65
- @product.destroy
66
- redirect_to products_url, notice: 'Product was successfully destroyed.'
51
+ if @product.destroy
52
+ redirect_to products_url, notice: 'Product was successfully destroyed.'
53
+ else
54
+ render action: 'edit'
55
+ end
67
56
  end
68
57
 
69
58
  private
@@ -0,0 +1,2 @@
1
+ module ProductPhotosHelper
2
+ end
@@ -0,0 +1,18 @@
1
+ Bread.actions.config do
2
+
3
+ controller :products, parent_crumbs: [:@root] do
4
+ actions(:index) { crumbs :@products }
5
+ actions(:new) { crumbs :@products, :@new_product }
6
+ actions(:by_category) { crumbs :@products, :@products_by_category }
7
+ actions(:show) { crumbs :@products, :@product }
8
+ actions(:edit) { crumbs :@products, :@product, :@edit_product }
9
+ end
10
+
11
+ controller :product_photos, parent_crumbs: [:@root, :@products, :@product] do
12
+ actions(:index) { crumbs :@photos }
13
+ actions(:new) { crumbs :@photos, :@new_photo }
14
+ actions(:show) { crumbs :@photos, :@photo }
15
+ actions(:edit) { crumbs :@photos, :@photo, :@edit_photo }
16
+ end
17
+
18
+ end
@@ -0,0 +1,43 @@
1
+ Bread.actions.config do
2
+
3
+ scaffold :banners
4
+ scaffold :testemonials
5
+ scaffold :providers
6
+
7
+
8
+ scaffold :contacts do
9
+ action(:by_category) { crumbs :list_contacts, :contacts_category }
10
+
11
+ collection do
12
+ action(:by_category) { crumbs :list_contacts, :contacts_category }
13
+ end
14
+
15
+ scaffold :addresses
16
+ scaffold :photos
17
+ end
18
+
19
+ controller :products, parent_crumbs: [:root] do
20
+ action(:index) { crumbs :list_products }
21
+ action(:new) { crumbs :list_products, :create_product }
22
+
23
+ action(:category) { crumbs :list_products, :products_category }
24
+
25
+ action(:show) { crumbs :list_products, :show_product }
26
+ action(:edit) { crumbs :list_products, :show_product, :update_product }
27
+ end
28
+
29
+ controller :product_photos, parent_action: 'products#show' do
30
+ action(:index) { crumbs :@photos }
31
+ action(:new) { crumbs :@photos, :@new_photo }
32
+ action(:show) { crumbs :@photos, :@photo }
33
+ action(:edit) { crumbs :@photos, :@photo, :@edit_photo }
34
+ end
35
+
36
+ controller :product_photos, parent_action: 'products#show' do
37
+ action(:index) { crumbs :photos }
38
+ action(:new) { crumbs :photos, :new_photo }
39
+ action(:show) { crumbs :photos, :photo }
40
+ action(:edit) { crumbs :photos, :photo, :edit_photo }
41
+ end
42
+
43
+ end
@@ -0,0 +1,22 @@
1
+ Bread.crumbs.config do
2
+
3
+ crumb(:@root) { to "Home", :root, icon: 'home' }
4
+
5
+ # products
6
+ crumb(:@products) { to "Products", h.products_path }
7
+ crumb(:@new_product) { to "New", h.new_product_path }
8
+ crumb(:@edit_product) { to "Edit", h.edit_product_path }
9
+ crumb(:@products_by_category) { to @category, h.by_category_products_path(@category) }
10
+ crumb(:@product) {
11
+ cat = @product.category
12
+ to cat, h.by_category_products_path(category: cat) if !cat.blank?
13
+ to @product.unchanged_name, h.product_path(@product)
14
+ }
15
+
16
+ # photos
17
+ crumb(:@photos) { to "Photos", h.product_product_photos_path }
18
+ crumb(:@new_photo) { to "New", h.new_product_product_photo_path }
19
+ crumb(:@edit_photo) { to "Edit", h.edit_product_product_photo_path }
20
+ crumb(:@photo) { to @product_photo.unchanged_name, h.product_product_photo_path }
21
+
22
+ end
@@ -0,0 +1,77 @@
1
+ Bread.crumbs.config do
2
+
3
+
4
+ crumb(:root) { to "Home", :root, icon: 'home' }
5
+
6
+ # products
7
+ crumb(:list_products) { to "Products", :products }
8
+ crumb(:create_product) { to "Add", [:new, :product] }
9
+ crumb(:update_product) { to "Edit", [:edit, @product] }
10
+
11
+ crumb(:products_by_category) { to @category, [@product, :by_catetory, @category] if @category }
12
+
13
+ crumb(:show_product) {
14
+ cat = @product.category
15
+ unless cat.blank?
16
+ to cat, controller.by_category_products_path(cat)
17
+ end
18
+ to @product.unchanged_name, @product
19
+ }
20
+
21
+ # photos
22
+ crumb(:list_photos) { to "Photos", [@product, :product_photos] }
23
+ crumb(:create_photo) { to "Add", [:new, @product, :product_photo] }
24
+ crumb(:update_photo) { to "Edit", [:edit, @product, @product_photo] }
25
+ crumb(:show_photo) { to @product_photo.unchanged_name, [@product, @product_photo] }
26
+
27
+ scaffold :contacts
28
+ scaffold :addresses
29
+ scaffold :testimonials
30
+ scaffold :providers
31
+ scaffold :photos
32
+
33
+ scaffold :products do
34
+ member do
35
+ crumb(:details)
36
+ crumb(:details) { to "Details", [@product, :details] }
37
+ end
38
+ collection do
39
+ crumb(:by_category) { to @category, [:products, :by_category, @category] }
40
+ end
41
+ end
42
+
43
+ scaffold :products
44
+
45
+ crumb(:@products) { to "Products", [:products] }
46
+ crumb(:@new_product) { to "New", [:new, :product] }
47
+ crumb(:@product) { to @product.crumb, [@product] }
48
+ crumb(:@edit_product) { to "Edit", [:edit, @product] }
49
+
50
+
51
+
52
+ crumb(:@products) { to "Products", h.products_path }
53
+ crumb(:@new_product) { to "New", h.new_product_path }
54
+ crumb(:@product) { to @product.crumb, h.product_path(@product) }
55
+ crumb(:@edit_product) { to "Edit", h.edit_product_path(@product) }
56
+
57
+
58
+
59
+ crumb(:@products) { to "Products", h.products_path }
60
+ crumb(:@new_product) { to "New", h.new_product_path }
61
+ crumb(:@product) { to @product.crumb, h.product_path }
62
+ crumb(:@edit_product) { to "Edit", h.edit_product_path }
63
+
64
+
65
+
66
+
67
+ scaffold :photos
68
+
69
+ crumb(:@photos) { to "Photos", [@product, :photos] }
70
+ crumb(:@new_photo) { to "New", [:new, @product, :photo] }
71
+ crumb(:@photo) { to @photo.crumb, [@product, @photo] }
72
+ crumb(:@edit_photo) { to "Edit", [:edit, @product, @photo] }
73
+
74
+
75
+ puts "TODO: rake bread".on_red
76
+
77
+ end
@@ -1,2 +1,10 @@
1
1
  class Product < ActiveRecord::Base
2
+ has_many :product_photos, dependent: :restrict_with_error
3
+ validates_presence_of :name
4
+ validates_length_of :name, minimum: 3
5
+
6
+ def unchanged_name
7
+ changes['name'].to_a.first || name
8
+ end
9
+
2
10
  end
@@ -0,0 +1,10 @@
1
+ class ProductPhoto < ActiveRecord::Base
2
+ belongs_to :product
3
+ validates_presence_of :name, :product
4
+ validates_length_of :name, minimum: 3
5
+
6
+ def unchanged_name
7
+ changes['name'].to_a.first || name
8
+ end
9
+
10
+ end
@@ -0,0 +1,6 @@
1
+ class User < ActiveRecord::Base
2
+ # Include default devise modules. Others available are:
3
+ # :confirmable, :lockable, :timeoutable and :omniauthable
4
+ devise :database_authenticatable, :registerable,
5
+ :recoverable, :rememberable, :trackable, :validatable
6
+ end
@@ -9,13 +9,18 @@
9
9
  <body>
10
10
 
11
11
  <ul id="breadcrumbs">
12
- <% bread.each do |crumb| %>
13
- <li class="<%= 'active' if crumb.current? %>">
14
- <%= link_to crumb.title, crumb.path, class: "icon icon-#{crumb[:icon]}" %>
15
- </li>
16
- <% end %>
12
+ <% bread.each do |crumb| %>
13
+ <li class="<%= 'active' if crumb.current? %>">
14
+ <%= link_to crumb.title, crumb.path, class: "icon icon-#{crumb[:icon]}" %>
15
+ </li>
16
+ <% end %>
17
17
  </ul>
18
18
 
19
+ <p class="notice"><%= notice %></p>
20
+ <p class="alert"><%= alert %></p>
21
+
22
+
23
+
19
24
  <%= yield %>
20
25
 
21
26
  </body>
@@ -0,0 +1,29 @@
1
+ <%= form_for([@product, @product_photo]) do |f| %>
2
+ <% if @product_photo.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@product_photo.errors.count, "error") %> prohibited this product_photo from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @product_photo.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :product %><br>
16
+ <%= f.text_field :product %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :name %><br>
20
+ <%= f.text_field :name %>
21
+ </div>
22
+ <div class="field">
23
+ <%= f.label :order %><br>
24
+ <%= f.number_field :order %>
25
+ </div>
26
+ <div class="actions">
27
+ <%= f.submit %>
28
+ </div>
29
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing product_photo</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', [@product, @product_photo] %> |
6
+ <%= link_to 'Back', [@product, :product_photos] %>
@@ -0,0 +1,31 @@
1
+ <h1>Listing product_photos</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th>Product</th>
7
+ <th>Name</th>
8
+ <th>Order</th>
9
+ <th></th>
10
+ <th></th>
11
+ <th></th>
12
+ </tr>
13
+ </thead>
14
+
15
+ <tbody>
16
+ <% @product_photos.each do |product_photo| %>
17
+ <tr>
18
+ <td><%= product_photo.product %></td>
19
+ <td><%= product_photo.name %></td>
20
+ <td><%= product_photo.order %></td>
21
+ <td><%= link_to 'Show', [@product, product_photo] %></td>
22
+ <td><%= link_to 'Edit', [:edit, @product, product_photo] %></td>
23
+ <td><%= link_to 'Destroy', [@product, product_photo], method: :delete, data: { confirm: 'Are you sure?' } %></td>
24
+ </tr>
25
+ <% end %>
26
+ </tbody>
27
+ </table>
28
+
29
+ <br>
30
+
31
+ <%= link_to 'New Product photo', [:new, @product, :product_photo] %>
@@ -0,0 +1,5 @@
1
+ <h1>New product_photo</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', [@product, :product_photos] %>
@@ -0,0 +1,19 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <strong>Product:</strong>
5
+ <%= @product_photo.product %>
6
+ </p>
7
+
8
+ <p>
9
+ <strong>Name:</strong>
10
+ <%= @product_photo.name %>
11
+ </p>
12
+
13
+ <p>
14
+ <strong>Order:</strong>
15
+ <%= @product_photo.order %>
16
+ </p>
17
+
18
+ <%= link_to 'Edit', [:edit, @product, @product_photo] %> |
19
+ <%= link_to 'Back', [@product, :product_photos] %>