comable_frontend 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 10dec2ca9318ce2ef297d434cf57ac8ea50030d7
4
+ data.tar.gz: a8126652a4b4f513adb207a636e123ea7625abde
5
+ SHA512:
6
+ metadata.gz: 27c637c54425d5507b2af9594931de4aa6785eddc1f9a587d41f781e1b216d421c9dc30b752eb70b1ab9bd2a0947a4f5a10966751ae2df56abc5fc166e02f627
7
+ data.tar.gz: c97d2246135a7e13881928e8e29ff9ef572506c35c97dc278ca11c79509c79525ac5cce23cd8b0314afd71fad6cd148857b68c0dc0ec3a52eba339b74471c109
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,84 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ $LOAD_PATH.unshift File.expand_path('..', __FILE__)
10
+ require 'tasks/release'
11
+
12
+ RDoc::Task.new(:rdoc) do |rdoc|
13
+ rdoc.rdoc_dir = 'rdoc'
14
+ rdoc.title = 'Comable'
15
+ rdoc.options << '--line-numbers'
16
+ rdoc.rdoc_files.include('lib/**/*.rb')
17
+ end
18
+
19
+ if ENV['COMABLE_NESTED']
20
+ task default: ['app:spec', 'rubocop']
21
+ else
22
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
23
+ load 'rails/tasks/engine.rake'
24
+
25
+ namespace :app do
26
+ namespace :spec do
27
+ desc 'Run the code examples'
28
+ RSpec::Core::RakeTask.new(:all) do |t|
29
+ FRAMEWORKS.each do |framework|
30
+ t.pattern << ",#{framework}/spec/**{,/*/**}/*_spec.rb"
31
+ end
32
+ end
33
+
34
+ FRAMEWORKS.each do |framework|
35
+ desc "Run the code examples in #{framework}/spec"
36
+ RSpec::Core::RakeTask.new(framework) do |t|
37
+ t.pattern = "../#{framework}/spec/**{,/*/**}/*_spec.rb"
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ namespace :db do
44
+ task 'migrate' => 'app:db:migrate'
45
+ task 'app:db:migrate' => 'migrate:all'
46
+
47
+ namespace :migrate do
48
+ task :all do
49
+ FRAMEWORKS.each do |framework|
50
+ command = "cd #{framework} && test -d db && bundle exec rake db:migrate RAILS_ENV=#{Rails.env} COMABLE_NESTED=true"
51
+ puts command
52
+ system command
53
+ end
54
+ end
55
+ end
56
+
57
+ namespace :migrate do
58
+ task 'reset' => 'app:db:migrate:reset'
59
+ task 'app:db:migrate:reset' => 'app:db:migrate'
60
+ task 'app:db:migrate' => 'reset:all'
61
+
62
+ namespace :reset do
63
+ task :all do
64
+ FRAMEWORKS.each do |framework|
65
+ command = "cd #{framework} && test -d db && bundle exec rake db:migrate:reset RAILS_ENV=#{Rails.env} COMABLE_NESTED=true"
66
+ puts command
67
+ system command
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ task default: ['app:spec:all', 'rubocop']
75
+ end
76
+
77
+ Bundler::GemHelper.install_tasks
78
+
79
+ # from https://github.com/rspec/rspec-rails/issues/936
80
+ task 'test:prepare'
81
+
82
+ task :rubocop do
83
+ exec 'rubocop'
84
+ end
@@ -0,0 +1,5 @@
1
+ module Comable
2
+ class ApplicationController < ActionController::Base
3
+ include Comable::ApplicationHelper
4
+ end
5
+ end
@@ -0,0 +1,40 @@
1
+ module Comable
2
+ class CartsController < ApplicationController
3
+ def show
4
+ end
5
+
6
+ def add
7
+ product = Comable::Product.where(id: params[:product_id]).first
8
+ return redirect_by_product_not_found unless product
9
+
10
+ if product.sku?
11
+ stock = product.stocks.where(id: params[:stock_id]).first
12
+ return redirect_by_product_not_found unless stock
13
+ end
14
+
15
+ # TODO: 在庫確認
16
+ current_customer.add_cart_item(stock || product, quantity: params[:quantity].to_i)
17
+
18
+ flash[:notice] = I18n.t('comable.carts.add_product')
19
+ redirect_to cart_path
20
+ end
21
+
22
+ def update
23
+ stock = Comable::Stock.where(id: params[:stock_id]).first
24
+ return redirect_by_product_not_found unless stock
25
+
26
+ # TODO: 在庫確認
27
+ current_customer.reset_cart_item(stock, quantity: params[:quantity].to_i)
28
+
29
+ flash[:notice] = I18n.t('comable.carts.update')
30
+ redirect_to cart_path
31
+ end
32
+
33
+ private
34
+
35
+ def redirect_by_product_not_found
36
+ flash[:error] = I18n.t('comable.carts.product_not_found')
37
+ redirect_to :back
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,115 @@
1
+ module Comable
2
+ class OrdersController < ApplicationController
3
+ before_filter :load_order
4
+ before_filter :verify
5
+ before_filter :redirect_for_logged_in_customer, only: [:new, :orderer]
6
+ after_filter :save_order, except: :create
7
+
8
+ rescue_from ActiveRecord::RecordInvalid, with: :record_invalid
9
+ rescue_from Comable::InvalidOrder, with: :order_invalid
10
+
11
+ include Decoratable
12
+
13
+ def new
14
+ end
15
+
16
+ def orderer
17
+ case request.method_symbol
18
+ when :post
19
+ redirect_to comable.delivery_order_path
20
+ end
21
+ end
22
+
23
+ def delivery
24
+ case request.method_symbol
25
+ when :post
26
+ redirect_to comable.payment_order_path
27
+ end
28
+ end
29
+
30
+ def payment
31
+ case request.method_symbol
32
+ when :post
33
+ redirect_to comable.confirm_order_path
34
+ end
35
+ end
36
+
37
+ def confirm
38
+ end
39
+
40
+ def create
41
+ order = current_customer.order
42
+ if order.complete?
43
+ flash[:notice] = I18n.t('comable.orders.success')
44
+ else
45
+ flash[:alert] = I18n.t('comable.orders.failure')
46
+ redirect_to comable.confirm_order_path
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def verify
53
+ return if current_customer.cart.any?
54
+ flash[:alert] = I18n.t('comable.carts.empty')
55
+ redirect_to comable.cart_path
56
+ end
57
+
58
+ def load_order
59
+ @order = current_customer.preorder(order_params || {})
60
+ end
61
+
62
+ def save_order
63
+ @order.save
64
+ end
65
+
66
+ def order_params
67
+ return unless params[:order]
68
+ case action_name.to_sym
69
+ when :orderer
70
+ order_params_for_orderer
71
+ when :delivery
72
+ order_params_for_delivery
73
+ when :payment
74
+ order_params_for_payment
75
+ end
76
+ end
77
+
78
+ def order_params_for_orderer
79
+ params.require(:order).permit(
80
+ :family_name,
81
+ :first_name
82
+ )
83
+ end
84
+
85
+ def order_params_for_delivery
86
+ params.require(:order).permit(
87
+ order_deliveries_attributes: [
88
+ :id,
89
+ :family_name,
90
+ :first_name
91
+ ]
92
+ )
93
+ end
94
+
95
+ def order_params_for_payment
96
+ params.require(:order).permit(
97
+ Comable::Payment.table_name.singularize.foreign_key.to_sym
98
+ )
99
+ end
100
+
101
+ def redirect_for_logged_in_customer
102
+ return redirect_to delivery_order_path if current_customer.logged_in?
103
+ end
104
+
105
+ def record_invalid
106
+ flash[:alert] = I18n.t('comable.orders.failure')
107
+ redirect_to comable.cart_path
108
+ end
109
+
110
+ def order_invalid(exception)
111
+ flash[:alert] = exception.message
112
+ redirect_to comable.cart_path
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,11 @@
1
+ module Comable
2
+ class ProductsController < ApplicationController
3
+ def index
4
+ @products = Comable::Product.all
5
+ end
6
+
7
+ def show
8
+ @product = Comable::Product.find(params[:id])
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ h1 カート
2
+
3
+ ul.cart
4
+ - current_customer.cart.each do |cart_item|
5
+ = form_tag comable.cart_path, method: :put do
6
+ - stock = cart_item.stock
7
+ - product = stock.product
8
+ li.product
9
+ h2.name
10
+ = link_to stock.name, comable.product_path(product)
11
+ .caption
12
+ = product.caption
13
+ .price
14
+ = number_to_currency product.price
15
+ .quantity
16
+ - selected = cart_item.quantity
17
+ = select_tag :quantity, options_for_select(1.upto([10, selected].max).to_a, selected)
18
+ = hidden_field_tag :stock_id, stock.id
19
+ = submit_tag '変更'
20
+
21
+ .order
22
+ = link_to '注文', comable.new_order_path
@@ -0,0 +1,25 @@
1
+ h1 注文情報確認
2
+
3
+ .order
4
+ .orderer
5
+ .family_name
6
+ = @order.family_name
7
+ .first_name
8
+ = @order.first_name
9
+ .deliveries
10
+ - @order.order_deliveries.each do |order_delivery|
11
+ .first_name
12
+ = order_delivery.family_name
13
+ .first_name
14
+ = order_delivery.first_name
15
+ .details
16
+ - order_delivery.order_details.each do |order_detail|
17
+ .name
18
+ = order_detail.product.name
19
+ .price
20
+ = order_detail.price
21
+ .quantity
22
+ = order_detail.quantity
23
+
24
+ = form_for @order, as: :order, url: comable.order_path, method: :post do |f|
25
+ = f.submit
@@ -0,0 +1,5 @@
1
+ h1 注文完了
2
+
3
+ .order
4
+ .code
5
+ = @order.code
@@ -0,0 +1,8 @@
1
+ h1 配送先情報入力
2
+
3
+ .orderer
4
+ = form_for @order, as: :order, url: comable.delivery_order_path, method: :put do |f|
5
+ = f.fields_for :order_deliveries do |order_delivery|
6
+ = order_delivery.text_field :family_name, placeholder: '姓'
7
+ = order_delivery.text_field :first_name, placeholder: '名'
8
+ = f.submit
@@ -0,0 +1,4 @@
1
+ h1 注文
2
+
3
+ .order
4
+ = link_to '規約に同意して注文', comable.orderer_order_path
@@ -0,0 +1,7 @@
1
+ h1 注文者情報入力
2
+
3
+ .orderer
4
+ = form_for @order, as: :order, url: comable.orderer_order_path, method: :put do |f|
5
+ = f.text_field :family_name, placeholder: '姓'
6
+ = f.text_field :first_name, placeholder: '名'
7
+ = f.submit
@@ -0,0 +1,12 @@
1
+ h1 決済方法
2
+
3
+ .order.payment
4
+ = form_for @order, as: :order, url: comable.payment_order_path, method: :put do |f|
5
+ ul
6
+ - Comable::Payment.all.each.with_index do |payment, index|
7
+ li
8
+ - payment_foreign_key = Comable::Payment.table_name.singularize.foreign_key.to_sym
9
+ - checked_flag = @order.payment ? (@order.payment.id == payment.id) : index.zero?
10
+ = f.radio_button payment_foreign_key, payment.id, checked: checked_flag
11
+ = f.label payment_foreign_key, payment.name, value: payment.id
12
+ = f.submit
@@ -0,0 +1,11 @@
1
+ h1 商品一覧
2
+
3
+ ul.products
4
+ - @products.each do |product|
5
+ li.product
6
+ h2.name
7
+ = link_to product.name, comable.product_path(product)
8
+ .caption
9
+ = product.caption
10
+ .price
11
+ = number_to_currency product.price
@@ -0,0 +1,21 @@
1
+ .product
2
+ h1.name
3
+ = @product.name
4
+ .caption
5
+ = @product.caption
6
+ .price
7
+ = number_to_currency @product.price
8
+
9
+ = form_tag comable.add_cart_path do
10
+ - if @product.sku?
11
+ .sku
12
+ = sku_table @product, border: 1
13
+
14
+ - if @product.unsold?
15
+ .add_cart
16
+ = hidden_field_tag :product_id, @product.id
17
+ = select_tag :quantity, options_for_select(1.upto(10).to_a)
18
+ = submit_tag 'カートに入れる'
19
+ - else
20
+ .sold_out
21
+ | 品切れ中
@@ -0,0 +1,11 @@
1
+ doctype html
2
+ html
3
+ head
4
+ title Comable
5
+ = stylesheet_link_tag "comable/application", media: "all"
6
+ = javascript_include_tag "comable/application"
7
+ = csrf_meta_tags
8
+ body
9
+ - flash.each do |name, msg|
10
+ = content_tag(:div, msg, id: "flash_#{name}")
11
+ == yield
data/config/routes.rb ADDED
@@ -0,0 +1,23 @@
1
+ Comable::Core::Engine.routes.draw do
2
+ get '/' => 'products#index'
3
+
4
+ resources :products
5
+
6
+ resource :cart do
7
+ collection do
8
+ post :add
9
+ end
10
+ end
11
+
12
+ resource :order do
13
+ collection do
14
+ get :orderer
15
+ put :orderer
16
+ get :delivery
17
+ put :delivery
18
+ get :payment
19
+ put :payment
20
+ get :confirm
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ require 'comable_core'
2
+
3
+ require 'slim'
4
+
5
+ module Comable
6
+ module Frontend
7
+ class Engine < ::Rails::Engine
8
+ config.generators do |g|
9
+ g.template_engine :slim
10
+ g.test_framework :rspec, fixture: true
11
+ g.fixture_replacement :factory_girl, dir: 'spec/factories'
12
+ end
13
+
14
+ # XXX: a code below to delegate comable:install:migrations to comable_core
15
+ config.paths['db/migrate'] = []
16
+ end
17
+ end
18
+ end
@@ -0,0 +1 @@
1
+ require 'comable/frontend/engine'
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :comable_backend do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: comable_frontend
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - YOSHIDA Hiroki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: comable_core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: slim-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Provide frontend functions for Comable.
56
+ email:
57
+ - hyoshida@appirits.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - MIT-LICENSE
63
+ - Rakefile
64
+ - app/controllers/comable/application_controller.rb
65
+ - app/controllers/comable/carts_controller.rb
66
+ - app/controllers/comable/orders_controller.rb
67
+ - app/controllers/comable/products_controller.rb
68
+ - app/views/comable/carts/show.slim
69
+ - app/views/comable/orders/confirm.slim
70
+ - app/views/comable/orders/create.slim
71
+ - app/views/comable/orders/delivery.slim
72
+ - app/views/comable/orders/new.slim
73
+ - app/views/comable/orders/orderer.slim
74
+ - app/views/comable/orders/payment.slim
75
+ - app/views/comable/products/index.slim
76
+ - app/views/comable/products/show.slim
77
+ - app/views/layouts/comable/application.slim
78
+ - config/routes.rb
79
+ - lib/comable/frontend/engine.rb
80
+ - lib/comable_frontend.rb
81
+ - lib/tasks/comable_backend_tasks.rake
82
+ homepage: https://github.com/hyoshida/comable#comable
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.2.2
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Provide frontend functions for Comable.
106
+ test_files: []
107
+ has_rdoc: