Added bootstrap for Design, extensions, Homepage, api versioning

This commit is contained in:
saurabhbhatia 2013-12-26 17:49:49 +08:00
parent edfb099308
commit be9aee93db
57 changed files with 463 additions and 119 deletions

View File

@ -9,7 +9,14 @@ gem 'bson_ext'
gem 'mongoid_slug', github: 'digitalplaywright/mongoid-slug'
gem 'carrierwave'
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
gem 'mongoid-grid_fs', github: 'ahoward/mongoid-grid_fs'
gem 'anjlab-bootstrap-rails', :require => 'bootstrap-rails',
:github => 'anjlab/bootstrap-rails',
:branch => '3.0.0'
gem "font-awesome-rails", github: "bokmann/font-awesome-rails"
gem 'rmagick'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

View File

@ -1,3 +1,27 @@
GIT
remote: git://github.com/ahoward/mongoid-grid_fs.git
revision: 059012a2c2a9e0a5d6e67137752c3e918689c88a
specs:
mongoid-grid_fs (1.9.0)
mime-types (~> 1.19)
mongoid (>= 3.0, < 5.0)
GIT
remote: git://github.com/anjlab/bootstrap-rails.git
revision: addb7143365f97f938e3bdbb2ccfc52591230eda
branch: 3.0.0
specs:
anjlab-bootstrap-rails (3.0.0.rc2)
railties (>= 3.0)
sass (>= 3.2)
GIT
remote: git://github.com/bokmann/font-awesome-rails.git
revision: 24ad375ed3db511c84310085889b2cbf0f650420
specs:
font-awesome-rails (4.0.3.0)
railties (>= 3.2, < 5.0)
GIT
remote: git://github.com/digitalplaywright/mongoid-slug.git
revision: fb929a5d5b2a580fed367c6cd25772ce9e92e80a
@ -108,6 +132,7 @@ GEM
rake (10.1.1)
rdoc (3.12.2)
json (~> 1.4)
rmagick (2.13.2)
sass (3.2.13)
sass-rails (4.0.1)
railties (>= 4.0.0, < 5.0)
@ -144,16 +169,20 @@ PLATFORMS
ruby
DEPENDENCIES
anjlab-bootstrap-rails!
bson_ext
carrierwave
carrierwave-mongoid
coffee-rails (~> 4.0.0)
font-awesome-rails!
jbuilder (~> 1.2)
jquery-rails
mongoid!
mongoid-grid_fs!
mongoid_slug!
puma
rails (= 4.0.2)
rmagick
sass-rails (~> 4.0.0)
sdoc
turbolinks

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -12,5 +12,6 @@
//
//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require turbolinks
//= require_tree .

View File

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@ -9,5 +9,7 @@
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require twitter/bootstrap
*= require sticky-footer-navbar
*= require_tree .
*/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the extensions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -0,0 +1,46 @@
/* Sticky footer styles
-------------------------------------------------- */
html,
body {
height: 100%;
/* The html and body elements cannot have any padding or margin. */
}
/* Wrapper for page content to push down footer */
#wrap {
min-height: 100%;
height: auto !important;
height: 100%;
/* Negative indent footer by its height */
margin: 0 auto -60px;
/* Pad bottom by footer height */
padding: 0 0 60px;
}
/* Set the fixed height of the footer here */
#footer {
height: 60px;
background-color: #f5f5f5;
}
/* Custom page CSS
-------------------------------------------------- */
/* Not required for template or sticky footer method. */
#wrap > .container {
padding: 60px 15px 0;
}
.container .credit {
margin: 20px 0;
}
#footer > .container {
padding-left: 15px;
padding-right: 15px;
}
code {
font-size: 80%;
}

View File

@ -0,0 +1,15 @@
module Api
module V1
class ExtensionsController < ApplicationController
respond_to :json
def index
respond_with Extension.all
end
def show
respond_with Extension.find(params[:id])
end
end
end
end

View File

@ -1,74 +1,15 @@
module Api
module V1
class TemplatesController < ApplicationController
before_action :set_template, only: [:show, :edit, :update, :destroy]
respond_to :json
# GET /templates
# GET /templates.json
def index
@templates = Template.all
respond_with Template.all
end
# GET /templates/1
# GET /templates/1.json
def show
end
# GET /templates/new
def new
@template = Template.new
end
# GET /templates/1/edit
def edit
end
# POST /templates
# POST /templates.json
def create
@template = Template.new(template_params)
respond_to do |format|
if @template.save
format.html { redirect_to @template, notice: 'Template was successfully created.' }
format.json { render action: 'show', status: :created, location: @template }
else
format.html { render action: 'new' }
format.json { render json: @template.errors, status: :unprocessable_entity }
respond_with Template.find(params[:id])
end
end
end
# PATCH/PUT /templates/1
# PATCH/PUT /templates/1.json
def update
respond_to do |format|
if @template.update(template_params)
format.html { redirect_to @template, notice: 'Template was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @template.errors, status: :unprocessable_entity }
end
end
end
# DELETE /templates/1
# DELETE /templates/1.json
def destroy
@template.destroy
respond_to do |format|
format.html { redirect_to templates_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_template
@template = Template.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def template_params
params.require(:template).permit(:title, :author)
end
end

View File

@ -0,0 +1,74 @@
class ExtensionsController < ApplicationController
before_action :set_extension, only: [:show, :edit, :update, :destroy]
# GET /extensions
# GET /extensions.json
def index
@extensions = Extension.all
end
# GET /extensions/1
# GET /extensions/1.json
def show
end
# GET /extensions/new
def new
@extension = Extension.new
end
# GET /extensions/1/edit
def edit
end
# POST /extensions
# POST /extensions.json
def create
@extension = Extension.new(extension_params)
respond_to do |format|
if @extension.save
format.html { redirect_to @extension, notice: 'Extension was successfully created.' }
format.json { render action: 'show', status: :created, location: @extension }
else
format.html { render action: 'new' }
format.json { render json: @extension.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /extensions/1
# PATCH/PUT /extensions/1.json
def update
respond_to do |format|
if @extension.update(extension_params)
format.html { redirect_to @extension, notice: 'Extension was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @extension.errors, status: :unprocessable_entity }
end
end
end
# DELETE /extensions/1
# DELETE /extensions/1.json
def destroy
@extension.destroy
respond_to do |format|
format.html { redirect_to extensions_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_extension
@extension = Extension.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def extension_params
params.require(:extension).permit(:title, :author, :preview, :preview_cache, :extension, :extension_cache)
end
end

View File

@ -1,4 +1,6 @@
class HomeController < ApplicationController
def index
@templates = Template.desc(:created_at).limit(3)
@extensions = Extension.desc(:created_at).limit(3)
end
end

View File

@ -69,6 +69,6 @@ class TemplatesController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def template_params
params.require(:template).permit(:title, :author)
params.require(:template).permit(:title, :author,:preview, :preview_cache, :template, :template_cache)
end
end

View File

@ -0,0 +1,2 @@
module ExtensionsHelper
end

15
app/models/extension.rb Normal file
View File

@ -0,0 +1,15 @@
class Extension
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Slug
field :title, type: String
field :author, type: String
field :preview, type: String
field :extension, type: String
field :description, type: String
slug :title, history: true
mount_uploader :preview, ImageUploader
mount_uploader :extension, ProductUploader
end

View File

@ -1,11 +1,14 @@
class Template
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Slug
field :title, type: String
field :author, type: String
field :preview, type: String
field :template, type: String
slug :title, history: true
mount_uploader :preview, ImageUploader
mount_uploader :template, ProductUploader
end

View File

@ -3,7 +3,7 @@
class ImageUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
@ -32,9 +32,9 @@ class ImageUploader < CarrierWave::Uploader::Base
# end
# Create different versions of your uploaded files:
# version :thumb do
# process :scale => [50, 50]
# end
version :thumb do
process :resize_to_fit => [300, 300]
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:

View File

@ -0,0 +1,37 @@
<%= form_for(@extension) do |f| %>
<% if @extension.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@extension.errors.count, "error") %> prohibited this extension from being saved:</h2>
<ul>
<% @extension.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :author %><br>
<%= f.text_field :author %>
</div>
<label>Preview</label>
<%= f.file_field :preview %>
<%= f.hidden_field :preview_cache %>
</p>
<p>
<label>Module</label>
<%= f.file_field :extension %>
<%= f.hidden_field :extension_cache %>
</p>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

View File

@ -0,0 +1,6 @@
<h1>Editing extension</h1>
<%= render 'form' %>
<%= link_to 'Show', @extension %> |
<%= link_to 'Back', extensions_path %>

View File

@ -0,0 +1,10 @@
<div class="row">
<% @extensions.each do |extension| %>
<div class="col-lg-4">
<h3><%=link_to extension.title, extension %></h3>
<p><b>Author:</b> <%= extension.author %></p>
<p><%=image_tag extension.preview.thumb.url%></p>
<p><%=link_to 'Download', extension.extension.url, :class=> 'btn btn-success'%></p>
<p><%= link_to 'View details &raquo;'.html_safe ,extension, :class=>"btn btn-primary"%></p>
</div>
<%end%>

View File

@ -0,0 +1,4 @@
json.array!(@extensions) do |extension|
json.extract! extension, :id, :title, :author
json.url extension_url(extension, format: :json)
end

View File

@ -0,0 +1,5 @@
<h1>New extension</h1>
<%= render 'form' %>
<%= link_to 'Back', extensions_path %>

View File

@ -0,0 +1,14 @@
<p id="notice"><%= notice %></p>
<p>
<strong>Title:</strong>
<%= @extension.title %>
</p>
<p>
<strong>Author:</strong>
<%= @extension.author %>
</p>
<%= link_to 'Edit', edit_extension_path(@extension) %> |
<%= link_to 'Back', extensions_path %>

View File

@ -0,0 +1 @@
json.extract! @extension, :id, :title, :author, :created_at, :updated_at

View File

@ -1,2 +1,25 @@
<h1>Home#index</h1>
<p>Find me in app/views/home/index.html.erb</p>
<h2>Top Templates</h2>
<div class="row">
<% @templates.each do |template| %>
<div class="col-lg-4">
<h3><%=link_to template.title, template %></h3>
<p><b>Author:</b> <%= template.author %></p>
<p><%=image_tag template.preview.thumb.url%></p>
<p><%= link_to 'View details &raquo;'.html_safe ,template, :class=>"btn btn-primary"%></p>
</div>
<%end%>
</div>
<%= link_to 'More &raquo;'.html_safe,templates_path, :class=>"btn btn-danger"%>
<h2>Top Modules</h2>
<div class="row">
<% @extensions.each do |extension| %>
<div class="col-lg-4">
<h3><%=link_to extension.title, extension %></h3>
<p><b>Author:</b> <%= extension.author %></p>
<p><%=image_tag extension.preview.thumb.url%></p>
<p><%= link_to 'View details &raquo;'.html_safe ,extension, :class=>"btn btn-primary"%></p>
</div>
<%end%>
</div>
<%= link_to 'More &raquo;'.html_safe,extensions_path, :class=>"btn btn-danger"%>

View File

@ -1,14 +1,48 @@
<!DOCTYPE html>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Mtstore</title>
<title>RulingOrbit - Template &#38; Module Store</title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
</head>
<body>
<!-- Wrap all page content here
-->
<div id="wrap">
<!-- Fixed navbar
-->
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle" data-target=".navbar-collapse" data-toggle="collapse" type="button">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/"><%= image_tag 'orbit-logo.png', :height => 19, :width => 19%>rbit Store</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">
<%= link_to "Home", root_path %>
</li>
<li>
<%= link_to "Templates", templates_path %>
</li>
<li>
<%= link_to "Modules", extensions_path %>
</li>
</ul>
</div>
<!-- /.nav-collapse
-->
</div>
</div>
<div class="container">
<%= yield %>
</div>
</div>
</body>
</html>

View File

@ -24,11 +24,13 @@
<%= f.file_field :preview %>
<%= f.hidden_field :preview_cache %>
</p>
<p>
<label>Template</label>
<%= f.file_field :template %>
<%= f.hidden_field :template_cache %>
</p>
<div class="actions">
<%= f.submit %>
</div>

View File

@ -1,29 +1,10 @@
<h1>Listing templates</h1>
<table>
<thead>
<tr>
<th>Title</th>
<th>Author</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<div class="row">
<% @templates.each do |template| %>
<tr>
<td><%= template.title %></td>
<td><%= template.author %></td>
<td><%= link_to 'Show', template %></td>
<td><%= link_to 'Edit', edit_template_path(template) %></td>
<td><%= link_to 'Destroy', template, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<div class="col-lg-4">
<h3><%=link_to template.title, template %></h3>
<p><b>Author:</b> <%= template.author %></p>
<p><%=image_tag template.preview.thumb.url%></p>
<p><%=link_to 'Download', template.template.url, :class=> 'btn btn-success'%></p>
<p><%= link_to 'View details &raquo;'.html_safe ,template, :class=>"btn btn-primary"%></p>
</div>
<%end%>
</tbody>
</table>
<br>
<%= link_to 'New Template', new_template_path %>

View File

@ -1,11 +1,16 @@
require 'api_constraints'
Mtstore::Application.routes.draw do
namespace :api, defaults: {format: 'json'} do
namespace :v1 do
scope module: :v1, constraints: ApiConstraints.new(version: 1, default: :true) do
resources :templates
resources :extensions
end
end
resources :templates
resources :extensions
get "home/index"
# The priority is based upon order of creation: first created -> highest priority.

10
lib/api_constraints.rb Normal file
View File

@ -0,0 +1,10 @@
class ApiConstraints
def initialize(options)
@version = options[:version]
@default = options[:default]
end
def matches?(req)
@default || req.headers['Accept'].include?("application/vnd.example.v#{@version}")
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 688 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 929 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 910 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 804 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

View File

@ -0,0 +1,49 @@
require 'test_helper'
class ExtensionsControllerTest < ActionController::TestCase
setup do
@extension = extensions(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:extensions)
end
test "should get new" do
get :new
assert_response :success
end
test "should create extension" do
assert_difference('Extension.count') do
post :create, extension: { author: @extension.author, title: @extension.title }
end
assert_redirected_to extension_path(assigns(:extension))
end
test "should show extension" do
get :show, id: @extension
assert_response :success
end
test "should get edit" do
get :edit, id: @extension
assert_response :success
end
test "should update extension" do
patch :update, id: @extension, extension: { author: @extension.author, title: @extension.title }
assert_redirected_to extension_path(assigns(:extension))
end
test "should destroy extension" do
assert_difference('Extension.count', -1) do
delete :destroy, id: @extension
end
assert_redirected_to extensions_path
end
end

9
test/fixtures/extensions.yml vendored Normal file
View File

@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
title: MyString
author: MyString
two:
title: MyString
author: MyString

View File

@ -0,0 +1,4 @@
require 'test_helper'
class ExtensionsHelperTest < ActionView::TestCase
end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class ExtensionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end