Commit 7099ab3b by Trong Huu Nguyen

Merge branch 'dhp_apply_bootstrap' into 'development'

[REVIEW] Apply bootstrap

See merge request !1
parents 13166288 30bbcb60
......@@ -30,6 +30,17 @@ gem 'jbuilder', '~> 2.5'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Provides a simple and extremely flexible way to upload files from Ruby applications
gem 'carrierwave', '~> 1.0'
# A ruby wrapper for ImageMagick or GraphicsMagick command line.
gem 'mini_magick'
# bootstrap-sass is a Sass-powered version of Bootstrap 3
gem 'bootstrap-sass', '~> 3.3.6'
# Faker, a port of Data::Faker from Perl, is used to easily generate fake data: names, addresses, phone numbers, etc.
gem 'faker', '~> 1.6', '>= 1.6.3'
# Kaminari is a Scope & Engine based, clean, powerful, agnostic, customizable and sophisticated paginator for Rails 4+
gem 'kaminari', '~> 1.0', '>= 1.0.1'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
......@@ -51,4 +62,4 @@ group :development do
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
\ No newline at end of file
......@@ -41,7 +41,12 @@ GEM
addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
arel (8.0.0)
autoprefixer-rails (7.1.1)
execjs
bindex (0.5.0)
bootstrap-sass (3.3.6)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
builder (3.2.3)
byebug (9.0.6)
capybara (2.14.0)
......@@ -51,6 +56,10 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
carrierwave (1.1.0)
activemodel (>= 4.0.0)
activesupport (>= 4.0.0)
mime-types (>= 1.16)
childprocess (0.7.0)
ffi (~> 1.0, >= 1.0.11)
coffee-rails (4.2.2)
......@@ -63,6 +72,8 @@ GEM
concurrent-ruby (1.0.5)
erubi (1.6.0)
execjs (2.7.0)
faker (1.6.6)
i18n (~> 0.5)
ffi (1.9.18)
globalid (0.4.0)
activesupport (>= 4.2.0)
......@@ -70,6 +81,18 @@ GEM
jbuilder (2.7.0)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
kaminari (1.0.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.0.1)
kaminari-activerecord (= 1.0.1)
kaminari-core (= 1.0.1)
kaminari-actionview (1.0.1)
actionview
kaminari-core (= 1.0.1)
kaminari-activerecord (1.0.1)
activerecord
kaminari-core (= 1.0.1)
kaminari-core (1.0.1)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
......@@ -82,6 +105,7 @@ GEM
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_magick (4.5.1)
mini_portile2 (2.2.0)
minitest (5.10.2)
multi_json (1.12.1)
......@@ -172,11 +196,16 @@ PLATFORMS
ruby
DEPENDENCIES
bootstrap-sass (~> 3.3.6)
byebug
capybara (~> 2.13)
carrierwave (~> 1.0)
coffee-rails (~> 4.2)
faker (~> 1.6, >= 1.6.3)
jbuilder (~> 2.5)
kaminari (~> 1.0, >= 1.0.1)
listen (>= 3.0.5, < 3.2)
mini_magick
mysql2 (>= 0.3.18, < 0.5)
puma (~> 3.7)
rails (~> 5.1.1)
......
// "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables"
@import "bootstrap-sprockets";
@import "bootstrap";
\ No newline at end of file
class CategoriesController < ApplicationController
def show
@category = Category.find(params[:id])
@products = @category.products.take(6)
end
end
\ No newline at end of file
class ProductsController < ApplicationController
end
\ No newline at end of file
class StaticPagesController < ApplicationController
def index
@latest_products = Product.page(params[:page]).per(10)
# @TODO: Get recommended products
@recommended_products = Product.last(6)
end
end
\ No newline at end of file
module ProductsHelper
def get_product_thumbnail(product, thumbnail_width, thumbnail_height)
product.image_url ||
"product/placeholder_#{thumbnail_width}x#{thumbnail_height}"
end
end
\ No newline at end of file
class Category < ApplicationRecord
has_many :products, dependent: :destroy
end
\ No newline at end of file
class Product < ApplicationRecord
belongs_to :category
end
\ No newline at end of file
<div class="row">
<div class="col-md-9 col-md-push-3">
<div class="category-header">
<h2><%= @category.title %></h2>
</div>
<div class="shop-row">
<div class="shop-container">
<ul class="products-list">
<%= render @products %>
</ul>
</div>
</div>
</div>
<!-- End .col-md-9 -->
<div class="col-md-3 col-md-pull-9 sidebar">
<%= render 'shared/sidebar' %>
</div>
</div>
<!-- End .row -->
\ No newline at end of file
<li class="first">
<%= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, remote: remote %>
</li>
<li class="dots">
<a href="#"><%= t('views.pagination.truncate').html_safe %></a>
</li>
<li class="last">
<%= link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, remote: remote %>
</li>
<li class="next">
<%= link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, rel: 'next', remote: remote %>
</li>
<li class="page<%= ' active' if page.current? %>">
<%= link_to page, url, opts = {:remote => remote, :class => page.current? ? 'active' : 'page-link', :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %>
</li>
<%= paginator.render do -%>
<nav aria-label="Page Navigation">
<ul class="pagination">
<%= first_page_tag unless current_page.first? %>
<%= prev_page_tag unless current_page.first? %>
<% each_page do |page| -%>
<% if page.display_tag? -%>
<%= page_tag page %>
<% elsif !page.was_truncated? -%>
<%= gap_tag %>
<% end -%>
<% end -%>
<% unless current_page.out_of_range? %>
<%= next_page_tag unless current_page.last? %>
<%= last_page_tag unless current_page.last? %>
<% end %>
</ul>
</nav>
<% end -%>
<li class="prev">
<%= link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, rel: 'prev', remote: remote %>
</li>
......@@ -9,6 +9,12 @@
</head>
<body>
<%= yield %>
<div id="main-container col2-left-layout">
<div class="container">
<%= yield %>
</div>
<!-- End .container -->
</div>
<!-- End .main-container -->
</body>
</html>
<li class="item">
<div class="product-img">
<a href="#">
<figure>
<%= image_tag(get_product_thumbnail(product, 170, 204), class: "small-image") %>
</figure>
</a>
</div>
<div class="product-shop">
<h2 class="product-name"><%= product.title %></h2>
<div class="price-box">
<div class="special-price">
<span class="price"><%= number_to_currency(product.price) %></span>
</div>
</div>
<div class="desc std">
<%= simple_format(product.description) %>
</div>
</div>
</li>
\ No newline at end of file
<ul class="products-grid">
<% @recommended_products.each do |product| %>
<li class="item col-lg-4 col-md-4 col-sm-6 col-xs-6 ">
<div class="product-item">
<div class="item-inner">
<div class="product-thumb">
<figure>
<a href="#">
<%= image_tag(get_product_thumbnail(product, 170, 204)) %>
</a>
</figure>
</div>
<div class="item-info">
<div class="info-inner">
<div class="item-title">
<%= link_to product.title, "#" %>
</div>
<div class="item-content">
<div class="item-price">
<div class="price-box">
<div class="regular-price">
<span class="price"><%= number_to_currency(product.price) %></span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</li>
<% end %>
</ul>
\ No newline at end of file
<div class="row">
<div class="col-main col-sm-9 col-xs-12 col-sm-push-3">
<div class="shop-inner">
<div class="page-title">
<h1>Recommended Items</h1>
</div>
<div class="product-grid-area">
<%= render 'products/recommended' %>
</div>
<div class="page-title">
<h1>Newest Items</h1>
</div>
<div class="product-list-area">
<ul id="products-list" class="products-list">
<%= render @latest_products %>
</ul>
</div>
<div class="pagination-area">
<%= paginate @latest_products %>
</div>
</div>
</div>
<aside class="sidebar col-sm-3 col-xs-12 col-sm-pull-9">
<%= render 'shared/sidebar' %>
</aside>
</div>
......@@ -12,10 +12,8 @@
default: &default
adapter: mysql2
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: root
password:
socket: /var/run/mysqld/mysqld.sock
password: 123123
development:
<<: *default
......
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root 'static_pages#index'
resources :categories
end
class CreateCategories < ActiveRecord::Migration[5.1]
def change
create_table :categories do |t|
t.string :title
t.text :description
end
end
end
class CreateProducts < ActiveRecord::Migration[5.1]
def change
create_table :products do |t|
t.string :title
t.text :description
t.text :sku
t.decimal :price, precision: 8, scale: 2
t.references :category, index: true
t.timestamps
end
end
end
class AddImageColumnsToProducts < ActiveRecord::Migration[5.1]
def change
add_column :products, :image_url, :string
end
end
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170606064132) do
create_table "categories", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "title"
t.text "description"
end
create_table "products", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "title"
t.text "description"
t.text "sku"
t.decimal "price", precision: 8, scale: 2
t.bigint "category_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "image_url"
t.index ["category_id"], name: "index_products_on_category_id"
end
add_foreign_key "products", "categories"
end
......@@ -5,3 +5,28 @@
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
# Delete all categories
Category.destroy_all
# Create Product Categories
4.times do |n|
title = "Category #{n}"
desc = Faker::Lorem.paragraphs
Category.create!(title: title, description: desc)
end
# Create Products
categories = Category.all
80.times do
categories.each do |cat|
title = Faker::Commerce.product_name
desc = Faker::Lorem.paragraphs
sku = "u-#{rand(1..999)}"
price = Faker::Commerce.price
cat.products.create!(title: title,
description: desc,
sku: sku,
price: price)
end
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment