Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add pages comparision

  • Loading branch information...
commit 2c22b5622446d85a091c5ddbd5970aafe6b599d3 1 parent 189a3e4
@maccman authored
Showing with 353 additions and 27 deletions.
  1. +2 −2 Gemfile.lock
  2. +4 −0 app/assets/javascripts/app/controllers/pages.js.coffee
  3. +2 −1  app/assets/javascripts/app/index.js.coffee
  4. +4 −1 app/assets/javascripts/app/models/page.js.coffee
  5. +2 −4 app/assets/javascripts/app/views/pages/edit.jst.eco
  6. +22 −8 app/assets/javascripts/app/views/pages/index.jst.eco
  7. +2 −4 app/assets/javascripts/app/views/pages/new.jst.eco
  8. +1 −1  app/assets/javascripts/app/views/pages/show.jst.eco
  9. +36 −0 app/assets/stylesheets/application.css
  10. +0 −4 app/assets/stylesheets/pages.css
  11. +16 −0 app/assets/stylesheets/posts.css
  12. +83 −0 app/controllers/posts_controller.rb
  13. +2 −0  app/helpers/posts_helper.rb
  14. +3 −0  app/models/post.rb
  15. +13 −0 app/views/layouts/posts.html.erb
  16. +27 −0 app/views/posts/_form.html.erb
  17. +3 −0  app/views/posts/edit.html.erb
  18. +25 −0 app/views/posts/index.html.erb
  19. +3 −0  app/views/posts/new.html.erb
  20. +14 −0 app/views/posts/show.html.erb
  21. +2 −0  config/routes.rb
  22. +0 −1  db/migrate/20110616103504_create_pages.rb
  23. +10 −0 db/migrate/20111116005853_create_posts.rb
  24. +8 −1 db/schema.rb
  25. +9 −0 test/fixtures/posts.yml
  26. +49 −0 test/functional/posts_controller_test.rb
  27. +4 −0 test/unit/helpers/posts_helper_test.rb
  28. +7 −0 test/unit/post_test.rb
View
4 Gemfile.lock
@@ -92,7 +92,7 @@ GEM
rdoc (3.11)
json (~> 1.4)
sass (3.1.10)
- spine-rails (0.0.8)
+ spine-rails (0.0.9)
rails (>= 3.1.0)
sprockets (2.0.3)
hike (~> 1.2)
@@ -109,7 +109,7 @@ GEM
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.31)
- uglifier (1.0.4)
+ uglifier (1.1.0)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
View
4 app/assets/javascripts/app/controllers/pages.js.coffee
@@ -46,6 +46,7 @@ class Edit extends Spine.Controller
class Show extends Spine.Controller
events:
'click [data-type=back]': 'back'
+ 'click [data-type=edit]': 'edit'
constructor: ->
super
@@ -61,6 +62,9 @@ class Show extends Spine.Controller
back: ->
@navigate '/pages'
+
+ edit: ->
+ @navigate '/pages', @item.id, 'edit'
class Index extends Spine.Controller
events:
View
3  app/assets/javascripts/app/index.js.coffee
@@ -17,6 +17,7 @@ class App extends Spine.Controller
@append(@pages = new App.Pages)
- Spine.Route.setup()
+ App.Page.one 'refresh', ->
+ Spine.Route.setup()
window.App = App
View
5 app/assets/javascripts/app/models/page.js.coffee
@@ -1,3 +1,6 @@
class App.Page extends Spine.Model
@configure 'Page', 'name', 'body'
- @extend Spine.Model.Ajax
+ @extend Spine.Model.Ajax
+
+ validate: ->
+ 'name required' unless @name
View
6 app/assets/javascripts/app/views/pages/edit.jst.eco
@@ -6,16 +6,14 @@
<span>Name</span>
<input
type="text" name="name"
- value="<%= @name %>" required
- autofocus>
+ value="<%= @name %>" required autofocus>
</label>
<label>
<span>Body</span>
<input
type="text" name="body"
- value="<%= @body %>" required
->
+ value="<%= @body %>">
</label>
<button>Edit</button>
View
30 app/assets/javascripts/app/views/pages/index.jst.eco
@@ -1,12 +1,26 @@
<h1>Listing Pages</h1>
-<% for page in @pages: %>
- <div class="item" data-id="<%= page.id %>">
- <a data-type="show"><%= page.name %></a>
-
- <a data-type="edit">Edit</a>
- <a data-type="destroy">Destroy</a>
- </div>
+<table>
+ <tr>
+ <th>Name</th>
+ <th>Body</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% for page in @pages: %>
+ <tr class="item" data-id="<%= page.id %>">
+ <td><%= page.name %></td>
+ <td><%= page.body %></td>
+ <td><a data-type="show">Show</a></td>
+ <td><a data-type="edit">Edit</a></td>
+ <td><a data-type="destroy">Destroy</a></td>
+ </tr>
<% end %>
-<p><a data-type="new">New Page</a></p>
+</table>
+
+<br />
+
+<a data-type="new">New Page</a>
View
6 app/assets/javascripts/app/views/pages/new.jst.eco
@@ -6,16 +6,14 @@
<span>Name</span>
<input
type="text" name="name"
- value="<%= @name %>" required
- autofocus>
+ value="<%= @name %>" required autofocus>
</label>
<label>
<span>Body</span>
<input
type="text" name="body"
- value="<%= @body %>" required
->
+ value="<%= @body %>">
</label>
<button>Create</button>
View
2  app/assets/javascripts/app/views/pages/show.jst.eco
@@ -1,6 +1,6 @@
<h1>Show Page</h1>
-<a data-type="back">Back</a>
+<a data-type="back">Back</a> | <a data-type="edit">Edit</a>
<p>Name: <%= @name %></p>
<p>Body: <%= @body %></p>
View
36 app/assets/stylesheets/application.css
@@ -82,4 +82,40 @@ ul li {
label, label span {
display: block;
+}
+
+label {
+ margin: 10px 0;
+}
+
+label span {
+ margin: 0 0 5px 0;
+}
+
+input[type=text], textarea {
+ padding: 3px;
+ margin: 0;
+ border: 1px solid rgba(0, 0, 0, 0.25);
+
+ -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
+ -moz-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
+ box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
+}
+
+input[type=text]:focus, textarea:focus, select:focus {
+ outline: none;
+ border-color: rgba(104, 189, 244, 0.8);
+
+ -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2), 0 1px 5px 0 rgba(104, 189, 244, 0.6);
+ -moz-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2), 0 1px 5px 0 rgba(104, 189, 244, 0.6);
+ box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2), 0 1px 5px 0 rgba(104, 189, 244, 0.6);
+}
+
+textarea {
+ padding: 5px;
+ height: 80px;
+}
+
+input[type=text], textarea {
+ min-width: 200px;
}
View
4 app/assets/stylesheets/pages.css
@@ -17,8 +17,4 @@
.stack > *:not(.active) {
display: none;
-}
-
-label {
- margin: 10px 0;
}
View
16 app/assets/stylesheets/posts.css
@@ -0,0 +1,16 @@
+
+.posts {
+ width: 560px;
+ margin: 30px auto;
+ padding: 20px;
+ background: #FFF;
+ -webkit-box-shadow: rgba(100, 100, 100, 0.3) 0 2px 6px;
+ -moz-box-shadow: rgba(100, 100, 100, 0.3) 0 2px 6px;
+ box-shadow: rgba(100, 100, 100, 0.3) 0 2px 6px;
+ position: relative;
+ overflow: hidden;
+}
+
+.posts h1 {
+ margin-top: 0;
+}
View
83 app/controllers/posts_controller.rb
@@ -0,0 +1,83 @@
+class PostsController < ApplicationController
+ # GET /posts
+ # GET /posts.json
+ def index
+ @posts = Post.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @posts }
+ end
+ end
+
+ # GET /posts/1
+ # GET /posts/1.json
+ def show
+ @post = Post.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @post }
+ end
+ end
+
+ # GET /posts/new
+ # GET /posts/new.json
+ def new
+ @post = Post.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @post }
+ end
+ end
+
+ # GET /posts/1/edit
+ def edit
+ @post = Post.find(params[:id])
+ end
+
+ # POST /posts
+ # POST /posts.json
+ def create
+ @post = Post.new(params[:post])
+
+ respond_to do |format|
+ if @post.save
+ format.html { redirect_to @post, notice: 'Post was successfully created.' }
+ format.json { render json: @post, status: :created, location: @post }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @post.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /posts/1
+ # PUT /posts/1.json
+ def update
+ @post = Post.find(params[:id])
+
+ respond_to do |format|
+ if @post.update_attributes(params[:post])
+ format.html { redirect_to @post, notice: 'Post was successfully updated.' }
+ format.json { head :ok }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @post.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /posts/1
+ # DELETE /posts/1.json
+ def destroy
+ @post = Post.find(params[:id])
+ @post.destroy
+
+ respond_to do |format|
+ format.html { redirect_to posts_url }
+ format.json { head :ok }
+ end
+ end
+end
View
2  app/helpers/posts_helper.rb
@@ -0,0 +1,2 @@
+module PostsHelper
+end
View
3  app/models/post.rb
@@ -0,0 +1,3 @@
+class Post < ActiveRecord::Base
+ validates_presence_of :name
+end
View
13 app/views/layouts/posts.html.erb
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Spine Rails3</title>
+ <%= stylesheet_link_tag "application" %>
+ <%= csrf_meta_tags %>
+</head>
+<body>
+ <div class="posts">
+ <%= yield %>
+ </div>
+</body>
+</html>
View
27 app/views/posts/_form.html.erb
@@ -0,0 +1,27 @@
+<%= form_for(@post) do |f| %>
+ <% if @post.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
+
+ <ul>
+ <% @post.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <label>
+ <span>Name</span>
+ <%= f.text_field :name %>
+ </label>
+
+ <label>
+ <span>Body</span>
+ <%= f.text_area :body %>
+ </label>
+
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
3  app/views/posts/edit.html.erb
@@ -0,0 +1,3 @@
+<h1>Editing post</h1>
+
+<%= render 'form' %>
View
25 app/views/posts/index.html.erb
@@ -0,0 +1,25 @@
+<h1>Listing Posts</h1>
+
+<table>
+ <tr>
+ <th>Name</th>
+ <th>Body</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @posts.each do |post| %>
+ <tr>
+ <td><%= post.name %></td>
+ <td><%= post.body %></td>
+ <td><%= link_to 'Show', post %></td>
+ <td><%= link_to 'Edit', edit_post_path(post) %></td>
+ <td><%= link_to 'Destroy', post, confirm: 'Are you sure?', method: :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Post', new_post_path %>
View
3  app/views/posts/new.html.erb
@@ -0,0 +1,3 @@
+<h1>New post</h1>
+
+<%= render 'form' %>
View
14 app/views/posts/show.html.erb
@@ -0,0 +1,14 @@
+<p id="notice"><%= notice %></p>
+
+<%= link_to 'Edit', edit_post_path(@post) %> |
+<%= link_to 'Back', posts_path %>
+
+<p>
+ <b>Name:</b>
+ <%= @post.name %>
+</p>
+
+<p>
+ <b>Body:</b>
+ <%= @post.body %>
+</p>
View
2  config/routes.rb
@@ -1,4 +1,6 @@
SpineRails3::Application.routes.draw do
+ resources :posts
+
# The priority is based upon order of creation:
# first created -> highest priority.
View
1  db/migrate/20110616103504_create_pages.rb
@@ -2,7 +2,6 @@ class CreatePages < ActiveRecord::Migration
def change
create_table :pages do |t|
t.string :name
- t.string :slug
t.text :body
t.timestamps
View
10 db/migrate/20111116005853_create_posts.rb
@@ -0,0 +1,10 @@
+class CreatePosts < ActiveRecord::Migration
+ def change
+ create_table :posts do |t|
+ t.string :name
+ t.text :body
+
+ t.timestamps
+ end
+ end
+end
View
9 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110616103504) do
+ActiveRecord::Schema.define(:version => 20111116005853) do
create_table "pages", :force => true do |t|
t.string "name"
@@ -21,4 +21,11 @@
t.datetime "updated_at"
end
+ create_table "posts", :force => true do |t|
+ t.string "name"
+ t.text "body"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
end
View
9 test/fixtures/posts.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
+
+one:
+ name: MyString
+ body: MyText
+
+two:
+ name: MyString
+ body: MyText
View
49 test/functional/posts_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class PostsControllerTest < ActionController::TestCase
+ setup do
+ @post = posts(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:posts)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create post" do
+ assert_difference('Post.count') do
+ post :create, post: @post.attributes
+ end
+
+ assert_redirected_to post_path(assigns(:post))
+ end
+
+ test "should show post" do
+ get :show, id: @post.to_param
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @post.to_param
+ assert_response :success
+ end
+
+ test "should update post" do
+ put :update, id: @post.to_param, post: @post.attributes
+ assert_redirected_to post_path(assigns(:post))
+ end
+
+ test "should destroy post" do
+ assert_difference('Post.count', -1) do
+ delete :destroy, id: @post.to_param
+ end
+
+ assert_redirected_to posts_path
+ end
+end
View
4 test/unit/helpers/posts_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class PostsHelperTest < ActionView::TestCase
+end
View
7 test/unit/post_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class PostTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.