增加新建博客的功能
This commit is contained in:
parent
87f1ce9b55
commit
8d8c9f6226
3
Gemfile
3
Gemfile
|
@ -36,6 +36,7 @@ gem 'jquery-rails'
|
|||
|
||||
# gem 'capistrano'
|
||||
|
||||
gem "bluecloth"
|
||||
#gem "bluecloth"
|
||||
gem "redcarpet"
|
||||
gem "simple_form"
|
||||
gem 'database_cleaner'
|
||||
|
|
|
@ -29,7 +29,6 @@ GEM
|
|||
i18n (~> 0.6)
|
||||
multi_json (~> 1.0)
|
||||
arel (3.0.2)
|
||||
bluecloth (2.2.0)
|
||||
bson (1.6.4)
|
||||
bson_ext (1.6.4)
|
||||
bson (~> 1.6.4)
|
||||
|
@ -91,6 +90,7 @@ GEM
|
|||
rake (0.9.2.2)
|
||||
rdoc (3.12)
|
||||
json (~> 1.4)
|
||||
redcarpet (2.1.1)
|
||||
rspec (2.10.0)
|
||||
rspec-core (~> 2.10.0)
|
||||
rspec-expectations (~> 2.10.0)
|
||||
|
@ -130,13 +130,13 @@ PLATFORMS
|
|||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
bluecloth
|
||||
bson_ext
|
||||
coffee-rails (~> 3.2.1)
|
||||
database_cleaner
|
||||
jquery-rails
|
||||
mongoid
|
||||
rails (= 3.2.6)
|
||||
redcarpet
|
||||
rspec-rails (>= 2.8.1)
|
||||
sass-rails (~> 3.2.3)
|
||||
simple_form
|
||||
|
|
|
@ -1,3 +1,25 @@
|
|||
# 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://jashkenas.github.com/coffee-script/
|
||||
#
|
||||
|
||||
$(document).ready ->
|
||||
|
||||
preview = $('.preview')
|
||||
content = $('#post_content')
|
||||
|
||||
$('#content').click ->
|
||||
preview.hide()
|
||||
content.show()
|
||||
$(this).addClass('active')
|
||||
$('#preview').removeClass('active')
|
||||
|
||||
$('#preview').click ->
|
||||
content.hide()
|
||||
$(this).addClass('active')
|
||||
$('#content').removeClass('active')
|
||||
preview.html('Loading...')
|
||||
preview.show()
|
||||
$.post $(this).attr('url'), text: content.val(), (data)->
|
||||
preview.html(data)
|
||||
|
||||
|
|
|
@ -1,3 +1,60 @@
|
|||
// Place all the styles related to the admin/posts controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
||||
h3 {
|
||||
font-size: 40px;
|
||||
margin-bottom: 10px;
|
||||
padding-bottom: 5px;
|
||||
border-bottom: 1px solid #CCC;
|
||||
}
|
||||
|
||||
#post_content {
|
||||
width: 800px;
|
||||
height: 390px;
|
||||
}
|
||||
|
||||
div.submit {
|
||||
display: block;
|
||||
line-height: 40px;
|
||||
width: 805px;
|
||||
background-color: #CCC;
|
||||
padding-left: 16px;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
ul.tab {
|
||||
margin: 10px 0 10px 0;
|
||||
overflow: hidden;
|
||||
li {
|
||||
float: left;
|
||||
padding: 5px 5px;
|
||||
border: 1px solid #CCC;
|
||||
cursor: pointer;
|
||||
}
|
||||
li.active {
|
||||
border-bottom: none;
|
||||
border-top: 1px solid #CCC;
|
||||
}
|
||||
li:not(.active) {
|
||||
border-top: none;
|
||||
border-top-right-radius: none;
|
||||
border-top-left-radius: none;
|
||||
}
|
||||
li#content {
|
||||
border-top-left-radius: 10px;
|
||||
border-right: none;
|
||||
}
|
||||
li#preview {
|
||||
border-right-bottom-radius: 10px;
|
||||
border-top-right-radius: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
div.preview {
|
||||
width: 800px;
|
||||
min-height: 396px;
|
||||
border: 1px solid #CCC;
|
||||
padding: 5px 5px;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,3 +2,8 @@
|
|||
width: 1100px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin: 10px 0 5px 0;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
class Admin::PostsController < ApplicationController
|
||||
layout false
|
||||
def new
|
||||
@post = Post.new
|
||||
end
|
||||
|
@ -14,8 +13,22 @@ class Admin::PostsController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
@post = Post.new( params[:post] )
|
||||
if @post.save
|
||||
flash[:notice] = "success!"
|
||||
redirect_to :action=>:index
|
||||
else
|
||||
flash[:alert] = "fail!"
|
||||
render :action=>:new
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
end
|
||||
|
||||
def preview
|
||||
text = params[:text] || ""
|
||||
md = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink=>true)
|
||||
render :text => md.render(text)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
<%= simple_form_for(@post) do %>
|
||||
<%= simple_form_for(@post, :url=> admin_posts_path(@post)) do |f| %>
|
||||
<%= f.input :title %>
|
||||
<%= f.input :content %>
|
||||
<%= f.select :type %>
|
||||
<ul class="tab">
|
||||
<li class="active" id="content">content</li>
|
||||
<li id="preview" url='<%= preview_admin_posts_path %>'>preview</li>
|
||||
</ul>
|
||||
<%= f.input :content, :as=> :text, :label=>false %>
|
||||
<div class="preview"></div>
|
||||
<%= f.input :type %>
|
||||
<div class="submit">
|
||||
<%= f.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
@ -2,6 +2,11 @@ WBlog::Application.routes.draw do
|
|||
root :to => 'blogs#index'
|
||||
resources :blogs, :only=>[:index, :show]
|
||||
namespace :admin do
|
||||
resources :posts
|
||||
resources :posts do
|
||||
collection do
|
||||
post :preview
|
||||
end
|
||||
end
|
||||
end
|
||||
match '/admin' => 'admin/posts#new'
|
||||
end
|
||||
|
|
|
@ -1,47 +1,16 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Admin::PostsController do
|
||||
|
||||
describe "GET 'new'" do
|
||||
it "returns http success" do
|
||||
get 'new'
|
||||
response.should be_success
|
||||
end
|
||||
it "preview should return ok" do
|
||||
post :preview
|
||||
response.body.should == ""
|
||||
post :preview, text: '123'
|
||||
response.body.should == "<p>123</p>\n"
|
||||
post :preview, text: <<-EOF
|
||||
```ruby
|
||||
puts 'hello world'
|
||||
```
|
||||
EOF
|
||||
response.body.should == "<p><code>ruby\nputs 'hello world'\n</code></p>\n"
|
||||
end
|
||||
|
||||
describe "GET 'edit'" do
|
||||
it "returns http success" do
|
||||
get 'edit'
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET 'destroy'" do
|
||||
it "returns http success" do
|
||||
get 'destroy'
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET 'index'" do
|
||||
it "returns http success" do
|
||||
get 'index'
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET 'create'" do
|
||||
it "returns http success" do
|
||||
get 'create'
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET 'update'" do
|
||||
it "returns http success" do
|
||||
get 'update'
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,18 +2,4 @@ require 'spec_helper'
|
|||
|
||||
describe BlogsController do
|
||||
|
||||
describe "GET 'index'" do
|
||||
it "returns http success" do
|
||||
get 'index'
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET 'show'" do
|
||||
it "returns http success" do
|
||||
get 'show'
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue