Skip to content
This repository
Browse code

Add Posts feature

  • Loading branch information...
commit a04ab9462459e8b65f7e047541850382ef5760ca 1 parent 07e4889
Jason Lee authored

Showing 42 changed files with 578 additions and 94 deletions. Show diff stats Hide diff stats

  1. +1 1  Rakefile
  2. +3 0  app/assets/javascripts/posts.coffee
  3. +33 0 app/assets/stylesheets/posts.scss
  4. +56 0 app/assets/stylesheets/scaffolds.css.scss
  5. +90 0 app/controllers/cpanel/posts_controller.rb
  6. +1 1  app/controllers/gridfs_controller.rb
  7. +1 6 app/controllers/home_controller.rb
  8. +42 0 app/controllers/posts_controller.rb
  9. +14 0 app/helpers/posts_helper.rb
  10. +53 0 app/models/post.rb
  11. +1 0  app/models/user.rb
  12. BIN  app/views/.DS_Store
  13. +52 0 app/views/cpanel/posts/_form.html.erb
  14. +8 0 app/views/cpanel/posts/edit.html.erb
  15. +28 0 app/views/cpanel/posts/index.html.erb
  16. +6 0 app/views/cpanel/posts/new.html.erb
  17. +1 0  app/views/home/index.html.erb
  18. +6 3 app/views/layouts/application.html.erb
  19. +2 1  app/views/layouts/cpanel.html.erb
  20. +9 0 app/views/posts/_base.html.erb
  21. +41 0 app/views/posts/_form.html.erb
  22. +2 0  app/views/posts/edit.html.erb
  23. +27 0 app/views/posts/index.html.erb
  24. +2 0  app/views/posts/new.html.erb
  25. +34 0 app/views/posts/show.html.erb
  26. +1 1  config.ru
  27. +1 1  config/application.rb
  28. +10 29 config/config.yml.default
  29. +1 1  config/environment.rb
  30. +1 1  config/environments/development.rb
  31. +1 1  config/environments/production.rb
  32. +1 1  config/environments/test.rb
  33. +1 1  config/initializers/redis.rb
  34. +1 1  config/initializers/secret_token.rb
  35. +2 2 config/initializers/session_store.rb
  36. +8 1 config/locales/zh-CN.yml
  37. +3 3 config/mongoid.yml
  38. +4 5 config/mongoid.yml.default
  39. +1 0  config/redis.yml
  40. +1 0  config/redis.yml.default
  41. +16 8 config/routes.rb
  42. +12 26 db/seeds.rb
2  Rakefile
@@ -4,4 +4,4 @@
4 4 require File.expand_path('../config/application', __FILE__)
5 5 require 'rake'
6 6
7   -Homeland::Application.load_tasks
  7 +RubyChina::Application.load_tasks
3  app/assets/javascripts/posts.coffee
... ... @@ -0,0 +1,3 @@
  1 +window.Posts =
  2 + like : () ->
  3 + console.log "like"
33 app/assets/stylesheets/posts.scss
... ... @@ -0,0 +1,33 @@
  1 +#posts {
  2 + ul {
  3 + list-style: none;
  4 + margin:0;
  5 + padding:0;
  6 +
  7 + li {
  8 + margin:0 -10px;
  9 + border-top:1px solid #ddd;
  10 + padding:10px 10px;
  11 + .info {
  12 + color:#999;
  13 + }
  14 + }
  15 + }
  16 + .pagination { margin:0; border-top:1px solid #ddd; padding:10px 10px 0 10px; margin:0 -10px;}
  17 +}
  18 +
  19 +#post_show {
  20 + h1 { font-size:18px; line-height:150%; text-align: left; }
  21 + .info {
  22 + margin-bottom:5px;
  23 + color:#999;
  24 + font-size:12px;
  25 + }
  26 + .source { color:#666; text-align: right;}
  27 + .body { margin:15px 0; }
  28 + .tags { border-top:1px solid #ddd; padding-top:10px; }
  29 +}
  30 +
  31 +#post_author {
  32 + .inner { text-align: center; }
  33 +}
56 app/assets/stylesheets/scaffolds.css.scss
... ... @@ -0,0 +1,56 @@
  1 +body {
  2 + background-color: #fff;
  3 + color: #333;
  4 + font-family: verdana, arial, helvetica, sans-serif;
  5 + font-size: 13px;
  6 + line-height: 18px; }
  7 +
  8 +p, ol, ul, td {
  9 + font-family: verdana, arial, helvetica, sans-serif;
  10 + font-size: 13px;
  11 + line-height: 18px; }
  12 +
  13 +pre {
  14 + background-color: #eee;
  15 + padding: 10px;
  16 + font-size: 11px; }
  17 +
  18 +a {
  19 + color: #000;
  20 + &:visited {
  21 + color: #666; }
  22 + &:hover {
  23 + color: #fff;
  24 + background-color: #000; } }
  25 +
  26 +div {
  27 + &.field, &.actions {
  28 + margin-bottom: 10px; } }
  29 +
  30 +#notice {
  31 + color: green; }
  32 +
  33 +.field_with_errors {
  34 + padding: 2px;
  35 + background-color: red;
  36 + display: table; }
  37 +
  38 +#error_explanation {
  39 + width: 450px;
  40 + border: 2px solid red;
  41 + padding: 7px;
  42 + padding-bottom: 0;
  43 + margin-bottom: 20px;
  44 + background-color: #f0f0f0;
  45 + h2 {
  46 + text-align: left;
  47 + font-weight: bold;
  48 + padding: 5px 5px 5px 15px;
  49 + font-size: 12px;
  50 + margin: -7px;
  51 + margin-bottom: 0px;
  52 + background-color: #c00;
  53 + color: #fff; }
  54 + ul li {
  55 + font-size: 12px;
  56 + list-style: square; } }
90 app/controllers/cpanel/posts_controller.rb
... ... @@ -0,0 +1,90 @@
  1 +# coding: utf-8
  2 +class Cpanel::PostsController < Cpanel::ApplicationController
  3 + # GET /posts
  4 + # GET /posts.xml
  5 + def index
  6 + @posts = Post.unscoped.desc(:_id).includes(:user).paginate :page => params[:page], :per_page => 30
  7 +
  8 + respond_to do |format|
  9 + format.html # index.html.erb
  10 + format.xml { render :xml => @posts }
  11 + end
  12 + end
  13 +
  14 + # GET /posts/1
  15 + # GET /posts/1.xml
  16 + def show
  17 + @post = Post.unscoped.find(params[:id])
  18 +
  19 + respond_to do |format|
  20 + format.html # show.html.erb
  21 + format.xml { render :xml => @post }
  22 + end
  23 + end
  24 +
  25 + # GET /posts/new
  26 + # GET /posts/new.xml
  27 + def new
  28 + @post = Post.new
  29 +
  30 + respond_to do |format|
  31 + format.html # new.html.erb
  32 + format.xml { render :xml => @post }
  33 + end
  34 + end
  35 +
  36 + # GET /posts/1/edit
  37 + def edit
  38 + @post = Post.unscoped.find(params[:id])
  39 + @post.tag_list = @post.tags.join(", ")
  40 + end
  41 +
  42 + # POST /posts
  43 + # POST /posts.xml
  44 + def create
  45 + @post = Post.new(params[:post])
  46 +
  47 + respond_to do |format|
  48 + if @post.save
  49 + format.html { redirect_to(cpanel_posts_path, :notice => 'Post was successfully created.') }
  50 + format.xml { render :xml => @post, :status => :created, :location => @post }
  51 + else
  52 + format.html { render :action => "new" }
  53 + format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
  54 + end
  55 + end
  56 + end
  57 +
  58 + # PUT /posts/1
  59 + # PUT /posts/1.xml
  60 + def update
  61 + @post = Post.unscoped.find(params[:id])
  62 + @post.title = params[:post][:title]
  63 + @post.body = params[:post][:body]
  64 + @post.tag_list = params[:post][:tag_list]
  65 + @post.user_id = params[:post][:user_id]
  66 + @post.state = params[:post][:state]
  67 +
  68 + respond_to do |format|
  69 + if @post.update_attributes(params[:post])
  70 + format.html { redirect_to(cpanel_posts_path, :notice => 'Post was successfully updated.') }
  71 + format.xml { head :ok }
  72 + else
  73 + format.html { render :action => "edit" }
  74 + format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
  75 + end
  76 + end
  77 + end
  78 +
  79 + # DELETE /posts/1
  80 + # DELETE /posts/1.xml
  81 + def destroy
  82 + @post = Post.unscoped.find(params[:id])
  83 + @post.destroy
  84 +
  85 + respond_to do |format|
  86 + format.html { redirect_to(cpanel_posts_path) }
  87 + format.xml { head :ok }
  88 + end
  89 + end
  90 +end
2  app/controllers/gridfs_controller.rb
... ... @@ -1,7 +1,7 @@
1 1 require 'mongo'
2 2 class GridfsController < ActionController::Metal
3 3 def serve
4   - gridfs_path = env["PATH_INFO"].gsub("/file/", "")
  4 + gridfs_path = env["PATH_INFO"].gsub("/uploads/", "")
5 5 begin
6 6 gridfs_file = Mongo::GridFileSystem.new(Mongoid.database).open(gridfs_path, 'r')
7 7 self.response_body = gridfs_file.read
7 app/controllers/home_controller.rb
@@ -5,12 +5,7 @@ class HomeController < ApplicationController
5 5 skip_before_filter :verify_authenticity_token, :only => [:auth_callback]
6 6
7 7 def index
8   - if !fragment_exist? "home/last_topics"
9   - @last_topics = Topic.recent.limit(10)
10   - end
11   - if !fragment_exist? "home/actived_topics"
12   - @actived_topics = Topic.last_actived.limit(10)
13   - end
  8 +
14 9 end
15 10
16 11 def auth_callback
42 app/controllers/posts_controller.rb
... ... @@ -0,0 +1,42 @@
  1 +# coding: utf-8
  2 +class PostsController < ApplicationController
  3 + before_filter :require_user, :only => [:new, :edit, :create, :update, :destroy]
  4 + def index
  5 + @posts = Post.normal.recent.paginate :page => params[:page], :per_page => 2
  6 + end
  7 +
  8 + def show
  9 + @post = Post.find(params[:id])
  10 + @post.hits.incr
  11 + end
  12 +
  13 + def new
  14 + @post = Post.new
  15 + end
  16 +
  17 + def edit
  18 + @post = Post.find(params[:id])
  19 + @post.tag_list = @post.tags.join(", ")
  20 + end
  21 +
  22 + def create
  23 + @post = Post.new(params[:post])
  24 + @post.user_id = current_user.id
  25 +
  26 + if @post.save
  27 + redirect_to @post, notice: '投稿成功,需等待审核通过以后才能显示到文章列表。'
  28 + else
  29 + render action: "new"
  30 + end
  31 + end
  32 +
  33 + def update
  34 + @post = current_user.posts.find(params[:id])
  35 +
  36 + if @post.update_attributes(params[:post])
  37 + redirect_to @post, notice: '文章更新成功。'
  38 + else
  39 + render action: "edit"
  40 + end
  41 + end
  42 +end
14 app/helpers/posts_helper.rb
... ... @@ -0,0 +1,14 @@
  1 +module PostsHelper
  2 + def post_title_tag(post, opts = {})
  3 + return "" if post.blank?
  4 + raw "<a href='#{post_path(post.id)}' title='#{post.title}'>#{post.title}</a>"
  5 + end
  6 +
  7 + def post_tags_tag(post, opts = {})
  8 + return "" if post.blank? or post.tags.blank?
  9 + limit = 5
  10 + tags = post.tags
  11 + tags = tags[0..limit-1] if tags.count > limit
  12 + raw tags.collect { |tag| "<a href='#{tag_posts_path(tag)}' class='tag'>#{tag}</a>" }.join(", ")
  13 + end
  14 +end
53 app/models/post.rb
... ... @@ -0,0 +1,53 @@
  1 +# coding: utf-8
  2 +class Post
  3 + include Mongoid::Document
  4 + include Mongoid::Timestamps
  5 + include Mongoid::SoftDelete
  6 + include Redis::Search
  7 + include Redis::Objects
  8 +
  9 + STATE = {
  10 + :draft => 0,
  11 + :normal => 1
  12 + }
  13 +
  14 + field :title, :type => String
  15 + field :body, :type => String
  16 + field :state, :type => Integer, :default => STATE[:draft]
  17 + field :tags, :type => Array, :default => []
  18 + # 来源名称
  19 + field :source
  20 + # 来源地址
  21 + field :source_url
  22 + belongs_to :user
  23 +
  24 + counter :hits, :default => 0
  25 +
  26 + attr_protected :state, :user_id
  27 + attr_accessor :tag_list
  28 +
  29 + validates_presence_of :title, :body, :tag_list
  30 +
  31 + scope :normal, where(:state => STATE[:normal])
  32 + scope :recent, desc(:_id)
  33 +
  34 + before_save :split_tags
  35 + def split_tags
  36 + if !self.tag_list.blank? and self.tags.blank?
  37 + self.tags = self.tag_list.split(/,|,/).collect { |tag| tag.strip }.uniq
  38 + end
  39 + end
  40 +
  41 + # 给下拉框用
  42 + def self.state_collection
  43 + STATE.collect { |s| [s[0], s[1]]}
  44 + end
  45 +
  46 + def state_s
  47 + case self.state
  48 + when 0 then "<span class='label important'>草稿</span>"
  49 + else
  50 + "<span class='label success'>已审核</span>"
  51 + end
  52 + end
  53 +end
1  app/models/user.rb
@@ -23,6 +23,7 @@ class User
23 23 has_many :notes
24 24 has_many :replies
25 25 embeds_many :authorizations
  26 + has_many :posts
26 27
27 28 attr_accessor :password_confirmation
28 29 attr_protected :verified, :replies_count
BIN  app/views/.DS_Store
Binary file not shown
52 app/views/cpanel/posts/_form.html.erb
... ... @@ -0,0 +1,52 @@
  1 +<%= form_for([:cpanel,@post]) do |f| %>
  2 +<fieldset>
  3 + <legend></legend>
  4 + <%= render 'shared/error_messages', :target => @post %>
  5 +
  6 + <div class="clearfix">
  7 + <%= f.label :title %>
  8 + <div class="input">
  9 + <%= f.text_field :title, :class => "span10" %>
  10 + </div>
  11 + </div>
  12 + <div class="clearfix">
  13 + <%= f.label :body %>
  14 + <div class="input">
  15 + <%= f.text_area :body, :class => "span13", :style => "height:400px" %>
  16 + </div>
  17 + </div>
  18 + <div class="clearfix">
  19 + <%= f.label :user_id %>
  20 + <div class="input">
  21 + <%= f.text_field :user_id %> <%= @post.user.name if @post.user %>
  22 + </div>
  23 + </div>
  24 + <div class="clearfix">
  25 + <%= f.label :tag_list %>
  26 + <div class="input">
  27 + <%= f.text_field :tag_list, :class => "xxlarge" %>
  28 + </div>
  29 + </div>
  30 + <div class="clearfix">
  31 + <%= f.label :source %>
  32 + <div class="input">
  33 + <%= f.text_field :source, :class => "span3", :placeholder => "某某博客" %>
  34 + </div>
  35 + </div>
  36 + <div class="clearfix">
  37 + <%= f.label :source_url %>
  38 + <div class="input">
  39 + <%= f.text_field :source_url, :class => "xxlarge", :placeholder => "http://" %>
  40 + </div>
  41 + </div>
  42 + <div class="clearfix">
  43 + <%= f.label :state %>
  44 + <div class="input">
  45 + <%= f.select :state, Post.state_collection %>
  46 + </div>
  47 + </div>
  48 + <div class="actions">
  49 + <button class="btn primary">保存</button> or
  50 + <%= link_to 'Back', cpanel_posts_path %>
  51 + </div>
  52 +<% end %>
8 app/views/cpanel/posts/edit.html.erb
... ... @@ -0,0 +1,8 @@
  1 +<% content_for :sitemap do %>
  2 + <a href="<%= cpanel_posts_path %>">帖子</a> &gt; <span class="current">修改</span>
  3 +<% end %>
  4 +<h1>Editing post</h1>
  5 +
  6 +<%= render 'form' %>
  7 +
  8 +
28 app/views/cpanel/posts/index.html.erb
... ... @@ -0,0 +1,28 @@
  1 +<% content_for :sitemap do %>
  2 + <span class="current">文章</span>
  3 +<% end %>
  4 +<h1>文章列表</h1>
  5 +
  6 +<table class="grid">
  7 + <tr class="head">
  8 + <td class="first">ID</td>
  9 + <td style="width:400px">Title</td>
  10 + <td>User</td>
  11 + <td>at</td>
  12 + <td>State</td>
  13 + <td></td>
  14 + </tr>
  15 +
  16 +<% @posts.each do |post| %>
  17 + <tr class="<%= 'deleted' if !post.deleted_at.blank? %>">
  18 + <td class="first"><%= post.id %></td>
  19 + <td><%= truncate(post.title,:length => 30) %></td>
  20 + <td><%= post.user.name if post.user %></td>
  21 + <td><%= l post.created_at,:format => :short %></td>
  22 + <td><%= raw post.state_s %></td>
  23 + <td><%= link_to '修改', edit_cpanel_post_path(post) %>
  24 + <%= link_to '删除', cpanel_post_path(post), :confirm => 'Are you sure?', :method => :delete %></td>
  25 + </tr>
  26 +<% end %>
  27 +</table>
  28 +<%= will_paginate1 @posts %>
6 app/views/cpanel/posts/new.html.erb
... ... @@ -0,0 +1,6 @@
  1 +<% content_for :sitemap do %>
  2 + <a href="<%= cpanel_posts_path %>">文章</a> &gt; <span class="current">新建</span>
  3 +<% end %>
  4 +<h1>New post</h1>
  5 +
  6 +<%= render 'form' %>
1  app/views/home/index.html.erb
... ... @@ -0,0 +1 @@
  1 +Ruby China Group.
9 app/views/layouts/application.html.erb
@@ -20,8 +20,10 @@
20 20 <a href="/"><%= Setting.app_name %></a>
21 21 </h3>
22 22 <ul class="nav">
23   - <li<%= ' class=active' if ["home","topics","replies"].index(params[:controller]) %>><a href="<%= root_path %>">论坛</a></li>
24   - <li<%= ' class=active' if ["notes"].index(params[:controller]) %>><a href="<%= notes_path %>">记事本</a></li>
  23 + <li<%= ' class=active' if ["posts"].index(params[:controller]) %>><a href="<%= posts_path %>">文章</a></li>
  24 + <li<%= ' class=active' if ["topics","replies"].index(params[:controller]) %>><a href="<%= topics_path %>">论坛</a></li>
  25 + <li<%= ' class=active' if ["events"].index(params[:controller]) %>><a href="/events">Event</a></li>
  26 + <li<%= ' class=active' if ["events"].index(params[:controller]) %>><a href="/sites">酷站</a></li>
25 27 </ul>
26 28 <form action="<%= search_topics_path %>" class="pull-left" method="get">
27 29 <input type="text" name="key" placeholder="搜索" <% if params[:action] == "search" and params[:key] %>value="<%= params[:key] %>"<% end %> />
@@ -34,6 +36,7 @@
34 36 <li><a href="<%= user_path(current_user.login) %>">我的主页</a></li>
35 37 <% if not params[:controller].match(/cpanel/) %>
36 38 <li><a href="<%= edit_user_registration_path %>">个人资料设置</a></li>
  39 + <li><a href="<%= notes_path %>">记事本</a></li>
37 40 <% if admin? current_user %><li><a href="/cpanel">后台</a></li><% end %>
38 41 <% end %>
39 42 <li><a href="<%= destroy_user_session_path %>">退出</a></li>
@@ -62,7 +65,7 @@
62 65 <footer class="footer">
63 66 <div class="container">
64 67 <p class="copyright">
65   - <%= raw Setting.foot_html %> Powered by <a href="http://github.com/huacnlee/homeland" target="_blank">Homeland</a> <%= APP_VERSION %>.
  68 + &copy; Ruby China Group.
66 69 </p>
67 70 </div>
68 71 </footer>
3  app/views/layouts/cpanel.html.erb
... ... @@ -1,7 +1,7 @@
1 1 <!DOCTYPE html>
2 2 <html>
3 3 <head>
4   - <title>Homeland - Control Panel</title>
  4 + <title>RubyChina - Control Panel</title>
5 5 <%= stylesheet_link_tag "cpanel" %>
6 6 <%= javascript_include_tag "application" %>
7 7 <%= csrf_meta_tag %>
@@ -16,6 +16,7 @@
16 16 <li<%= " class=active" if params[:controller] == "cpanel/users" %>><a href="<%= cpanel_users_path %>">用户</a></li>
17 17 <li<%= " class='active'" if params[:controller] == "cpanel/sections" %>><a href="<%= cpanel_sections_path %>">分类</a></li>
18 18 <li<%= " class='active'" if params[:controller] == "cpanel/nodes" %>><a href="<%= cpanel_nodes_path %>">节点</a></li>
  19 + <li<%= " class='active'" if params[:controller] == "cpanel/posts" %>><a href="<%= cpanel_posts_path %>">文章</a></li>
19 20 <li<%= " class='active'" if params[:controller] == "cpanel/topics" %>><a href="<%= cpanel_topics_path %>">帖子</a></li>
20 21 <li<%= " class='active'" if params[:controller] == "cpanel/replies" %>><a href="<%= cpanel_replies_path %>">回复</a></li>
21 22 <li<%= " class='active'" if params[:controller] == "cpanel/photos" %>><a href="<%= cpanel_photos_path %>">图片</a></li>
9 app/views/posts/_base.html.erb
... ... @@ -0,0 +1,9 @@
  1 +<%= content_for :sitemap do %>
  2 + <a href="<%= posts_path %>">文章</a> <span class="divider">/</span>
  3 +<% end %>
  4 +<%= content_for :styles do %>
  5 + <%= stylesheet_link_tag "posts" %>
  6 +<% end %>
  7 +<%= content_for :scripts do %>
  8 + <%= javascript_include_tag "posts" %>
  9 +<% end %>
41 app/views/posts/_form.html.erb
... ... @@ -0,0 +1,41 @@
  1 +<div class="box">
  2 +<%= form_for(@post) do |f| %>
  3 + <fieldset>
  4 + <legend>投稿</legend>
  5 + <%= render "shared/error_messages", :target => @post %>
  6 + <div class="clearfix">
  7 + <%= f.label :title %>
  8 + <div class="input">
  9 + <%= f.text_field :title, :class => "xxlarge" %>
  10 + </div>
  11 + </div>
  12 + <div class="clearfix">
  13 + <%= f.label :body %>
  14 + <div class="input">
  15 + <%= f.text_area :body, :class => "long", :rows => "30" %>
  16 + </div>
  17 + </div>
  18 + <div class="clearfix">
  19 + <%= f.label :tag_list %>
  20 + <div class="input">
  21 + <%= f.text_field :tag_list, :class => "xxlarge", :placeholder => "Ruby, MongoDb" %>
  22 + </div>
  23 + </div>
  24 + <div class="clearfix">
  25 + <%= f.label :source %>
  26 + <div class="input">
  27 + <%= f.text_field :source, :class => "span3", :placeholder => "某某博客" %>
  28 + </div>
  29 + </div>
  30 + <div class="clearfix">
  31 + <%= f.label :source_url %>
  32 + <div class="input">
  33 + <%= f.text_field :source_url, :class => "xxlarge", :placeholder => "http://" %>
  34 + </div>
  35 + </div>
  36 + <div class="actions">
  37 + <%= f.submit "投稿", :class => "btn primary" %>
  38 + </div>
  39 + </fieldset>
  40 +<% end %>
  41 +</div>
2  app/views/posts/edit.html.erb
... ... @@ -0,0 +1,2 @@
  1 +<%= render "base" %>
  2 +<%= render 'form' %>
27 app/views/posts/index.html.erb
... ... @@ -0,0 +1,27 @@
  1 +<%= render "base" %>
  2 +<% content_for :sitemap do %>
  3 + <span class="current">最新发布的文章</span>
  4 +<% end %>
  5 +<div class="sidebar">
  6 + <div class="box">
  7 + <%= link_to '投稿', new_post_path, :class => "btn success" %>
  8 + </div>
  9 +</div>
  10 +
  11 +<div class="content">
  12 + <div id="posts" class="box">
  13 + <h1>最近发布的文章</h1>
  14 + <ul>
  15 + <% @posts.each do |item| %>
  16 + <li>
  17 + <div class="title"><%= post_title_tag(item) %></div>
  18 + <div class="info">
  19 + 发布: <%= timeago(item.created_at) %>, <%= item.hits %> 次阅读
  20 + </div>
  21 + </li>
  22 + <% end %>
  23 + </ul>
  24 + <%= will_paginate1 @posts %>
  25 + </div>
  26 +</div>
  27 +
2  app/views/posts/new.html.erb
... ... @@ -0,0 +1,2 @@
  1 +<%= render "base" %>
  2 +<%= render 'form' %>
34 app/views/posts/show.html.erb
... ... @@ -0,0 +1,34 @@
  1 +<%= render "base" %>
  2 +<%= content_for :sitemap do %><span class="current">阅读</span><% end %>
  3 +
  4 +<div class="sidebar">
  5 + <div id="post_author" class="box">
  6 + <h2>提交者</h2>
  7 + <div class="inner">
  8 + <div class="avatar"><%= raw user_avatar_tag(@post.user, :large) %></div>
  9 + <div class="name"><%= user_name_tag(@post.user) %></div>
  10 + </div>
  11 + </div>
  12 + <div class="box">
  13 + <h2>你可能也喜欢</h2>
  14 + <div class="inner">
  15 + </div>
  16 + </div>
  17 +</div>
  18 +
  19 +<div class="content">
  20 + <div id="post_show" class="box">
  21 + <h1><%= @post.title %></h1>
  22 + <div class="info">
  23 + <%= user_name_tag(@post.user) %> 投稿于: <%= timeago(@post.created_at) %> , <%= @post.hits %> 次阅读
  24 + </div>
  25 + <div class="source">
  26 + 文章来源:<a href="<%= @post.source_url %>?ref=<%= Setting.domain %>" target="_blank"><%= @post.source %></a>
  27 + </div>
  28 + <div class="body"><%= raw simple_format @post.body %></div>
  29 + <div class="votes">
  30 +
  31 + </div>
  32 + <div class="tags">标签: <%= post_tags_tag(@post) %></div>
  33 + </div>
  34 +</div>
2  config.ru
... ... @@ -1,4 +1,4 @@
1 1 # This file is used by Rack-based servers to start the application.
2 2
3 3 require ::File.expand_path('../config/environment', __FILE__)
4   -run Homeland::Application
  4 +run RubyChina::Application
2  config/application.rb
@@ -12,7 +12,7 @@
12 12 end
13 13
14 14
15   -module Homeland
  15 +module RubyChina
16 16 class Application < Rails::Application
17 17 # Custom directories with classes and modules you want to be autoloadable.
18 18 config.autoload_paths += %W(#{config.root}/uploaders)
39 config/config.yml.default
... ... @@ -1,39 +1,20 @@
1   -development:
2   - # 网站名称
3   - app_name: "Homeland"
4   - # 页脚版权
5   - foot_html: "&copy; Homeland."
6   - # 网站的域名
  1 +defaults: &defaults
  2 + app_name: "Ruby China Group"
  3 + foot_html: "&copy; Ruby China Group."
7 4 domain: "127.0.0.1:3000"
8   - # 设置管理员,在下面填写需要设置为管理员的用户 email
9 5 admin_emails:
10 6 - "admin@admin.com"
11 7 google_analytics_key: ""
12   - smtp_username: 'support@app.com'
  8 + smtp_username: 'support@ruby-china.org'
13 9 smtp_password: '123456'
14 10 upload_url: "http://127.0.0.1:3000/file"
15   - google_group_email: "homeland-test@googlegroups.com"
  11 + google_group_email: "shanghaionrails@googlegroups.com"
  12 +
  13 +development:
  14 + <<: *defaults
16 15
17 16 test:
18   - app_name: "Homeland"
19   - foot_html: "&copy; Homeland."
20   - domain: "127.0.0.1:3000"
21   - admin_emails:
22   - - "admin@admin.com"
23   - google_analytics_key: ""
24   - smtp_username: 'support@app.com'
25   - smtp_password: '123456'
26   - upload_url: "http://127.0.0.1:3000/file"
27   - google_group_email: "homeland-test@googlegroups.com"
  17 + <<: *defaults
28 18
29 19 production:
30   - app_name: "Homeland"
31   - foot_html: "&copy; Homeland."
32   - domain: "127.0.0.1:3000"
33   - admin_emails:
34   - - "admin@admin.com"
35   - google_analytics_key: ""
36   - smtp_username: 'support@app.com'
37   - smtp_password: '123456'
38   - upload_url: "http://l.yourdomain.com"
39   - google_group_email: "homeland-test@googlegroups.com"
  20 + <<: *defaults
2  config/environment.rb
@@ -3,4 +3,4 @@
3 3 require File.expand_path('../application', __FILE__)
4 4
5 5 # Initialize the rails application
6   -Homeland::Application.initialize!
  6 +RubyChina::Application.initialize!
2  config/environments/development.rb
... ... @@ -1,6 +1,6 @@
1 1 # coding: utf-8
2 2 require "redis-store"
3   -Homeland::Application.configure do
  3 +RubyChina::Application.configure do
4 4 # Settings specified here will take precedence over those in config/environment.rb
5 5
6 6 # In the development environment your application's code is reloaded on
2  config/environments/production.rb
... ... @@ -1,6 +1,6 @@
1 1 # coding: utf-8
2 2 require "redis-store"
3   -Homeland::Application.configure do
  3 +RubyChina::Application.configure do
4 4 # Settings specified here will take precedence over those in config/environment.rb
5 5
6 6 # The production environment is meant for finished, "live" apps.
2  config/environments/test.rb
... ... @@ -1,5 +1,5 @@
1 1 # coding: utf-8
2   -Homeland::Application.configure do
  2 +RubyChina::Application.configure do
3 3 # Settings specified here will take precedence over those in config/environment.rb
4 4
5 5 # The test environment is used exclusively to run your application's
2  config/initializers/redis.rb
@@ -6,7 +6,7 @@
6 6 redis_config = YAML.load_file("#{Rails.root}/config/redis.yml")[Rails.env]
7 7
8 8 redis_search = Redis.new(:host => redis_config['host'],:port => redis_config['port'])
9   -redis_search = Redis::Namespace.new("homeland:redis_search", :redis => redis_search)
  9 +redis_search = Redis::Namespace.new(redis_config['redis_search_namespace'], :redis => redis_search)
10 10 redis_search.select("3")
11 11 Redis::Search.configure do |config|
12 12 config.redis = redis_search
2  config/initializers/secret_token.rb
@@ -4,4 +4,4 @@
4 4 # If you change this key, all old signed cookies will become invalid!
5 5 # Make sure the secret is at least 30 characters and all random,
6 6 # no regular words or you'll be exposed to dictionary attacks.
7   -Homeland::Application.config.secret_token = '5070365ffe9d3ad7ed04e0ce080fe7ae9da2bd8497297a695118f91519a4c7b26fce69a024a888e768bacf2e376395921b557ea5cc50999b0e1d86993b908225'
  7 +RubyChina::Application.config.secret_token = '5070365ffe9d3ad7ed04e0ce080fe7ae9da2bd8497297a695118f91519a4c7b26fce69a024a888e768bacf2e376395921b557ea5cc50999b0e1d86993b908225'
4 config/initializers/session_store.rb
... ... @@ -1,11 +1,11 @@
1 1 # coding: utf-8
2 2 # Be sure to restart your server when you modify this file.
3 3
4   -Homeland::Application.config.session_store :cookie_store,
  4 +RubyChina::Application.config.session_store :cookie_store,
5 5 :key => '_homeland_session',
6 6 :expire_after => 86400*90
7 7
8 8 # Use the database for sessions instead of the cookie-based default,
9 9 # which shouldn't be used to store highly confidential information
10 10 # (create the session table with "rake db:sessions:create")
11   -# Homeland::Application.config.session_store :active_record_store
  11 +# RubyChina::Application.config.session_store :active_record_store
9 config/locales/zh-CN.yml
@@ -3,6 +3,7 @@
3 3 models:
4 4 user: "用户"
5 5 topic: "话题"
  6 + post: 文章
6 7 attributes:
7 8 user:
8 9 name: "名字"
@@ -24,7 +25,13 @@
24 25 user_id: "用户"
25 26 body: "正文"
26 27 reply:
27   - body: "回复内容"
  28 + body: "回复内容"
  29 + post:
  30 + title: 标题
  31 + body: 正文
  32 + tag_list: 标签
  33 + source: 来源
  34 + source_url: 来源地址
28 35 errors:
29 36 models:
30 37 user: 用户
6 config/mongoid.yml
@@ -8,15 +8,15 @@ defaults: &defaults
8 8
9 9 development:
10 10 <<: *defaults
11   - database: homeland_development
  11 + database: ruby_china_dev
12 12
13 13 test:
14 14 <<: *defaults
15   - database: homeland_test
  15 + database: ruby_china_test
16 16
17 17 # set these environment variables on your prod server
18 18 production:
19   - database: homeland
  19 + database: ruby_china
20 20 host: '127.0.0.1'
21 21 # port:
22 22 # username: ''
9 config/mongoid.yml.default
@@ -8,17 +8,16 @@ defaults: &defaults
8 8
9 9 development:
10 10 <<: *defaults
11   - database: homeland_development
  11 + database: ruby_china_dev
12 12
13 13 test:
14 14 <<: *defaults
15   - database: homeland_test
  15 + database: ruby_china_test
16 16
17 17 # set these environment variables on your prod server
18 18 production:
19   - database: homeland
  19 + database: ruby_china
20 20 host: '127.0.0.1'
21 21 # port:
22 22 # username: ''
23   - # password: ''
24   -
  23 + # password: ''
1  config/redis.yml
... ... @@ -1,6 +1,7 @@
1 1 defaults: &defaults
2 2 host: '127.0.0.1'
3 3 port: 6379
  4 + redis_search_namespace: 'rc:rs'
4 5 development:
5 6 <<: *defaults
6 7 test:
1  config/redis.yml.default
... ... @@ -1,6 +1,7 @@
1 1 defaults: &defaults
2 2 host: '127.0.0.1'
3 3 port: 6379
  4 + redis_search_namespace: 'rc:rs'
4 5 development:
5 6 <<: *defaults
6 7 test:
24 config/routes.rb
... ... @@ -1,18 +1,25 @@
1   -Homeland::Application.routes.draw do
  1 +RubyChina::Application.routes.draw do
  2 +
  3 + resources :posts do
  4 + collection do
  5 + get :tag
  6 + end
  7 + end
  8 +
2 9 resources :notes
3   - match "/file/*path" => "gridfs#serve"
4   - root :to => "topics#index"
  10 + match "/uploads/*path" => "gridfs#serve"
  11 + root :to => "home#index"
5 12 match "auth/:provider/callback", :to => "home#auth_callback"
6 13 match "auth/:provider/unbind", :to => "home#auth_unbind"
7 14
8 15 devise_for :users, :path => "account"
9   - resources :users, :path => "u", :only => :show
  16 + resources :users, :only => :show
10 17
11 18 resources :nodes
12 19
13   - match "n:id" => "topics#node", :as => :node_topics
14   - match "t/last" => "topics#recent", :as => :recent_topics
15   - resources :topics, :path => "t" do
  20 + match "topics/node:id" => "topics#node", :as => :node_topics
  21 + match "topics/last" => "topics#recent", :as => :recent_topics
  22 + resources :topics do
16 23 member do
17 24 post :reply
18 25 end
@@ -21,7 +28,7 @@
21 28 get :feed
22 29 end
23 30 end
24   - resources :replies, :path => "r"
  31 + resources :replies
25 32 resources :photos do
26 33 collection do
27 34 get :tiny_new
@@ -36,5 +43,6 @@
36 43 resources :sections
37 44 resources :users
38 45 resources :photos
  46 + resources :posts
39 47 end
40 48 end
38 db/seeds.rb
@@ -6,18 +6,16 @@
6 6 #
7 7 # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
8 8 # Mayor.create(:name => 'Daley', :city => cities.first)
9   -s1 = Section.create(:name => "Apple")
10   -Node.create(:name => "Mac OS X",:summary => "...", :section_id => s1.id)
11   -Node.create(:name => "iOS",:summary => "...", :section_id => s1.id)
12   -Node.create(:name => "iPhone",:summary => "...", :section_id => s1.id)
13   -Node.create(:name => "iPad",:summary => "...", :section_id => s1.id)
14   -Node.create(:name => "iMac",:summary => "...", :section_id => s1.id)
15   -Node.create(:name => "iWork",:summary => "...", :section_id => s1.id)
16   -Node.create(:name => "Xcode",:summary => "...", :section_id => s1.id)
17   -s2 = Section.create(:name => "技术控")
18   -Node.create(:name => "Ruby",:summary => "...", :section_id => s2.id)
  9 +s1 = Section.create(:name => "Ruby")
  10 +Node.create(:name => "Ruby",:summary => "...", :section_id => s1.id)
  11 +Node.create(:name => "Ruby on Rails",:summary => "...", :section_id => s1.id)
  12 +Node.create(:name => "Gem",:summary => "...", :section_id => s1.id)
  13 +s2 = Section.create(:name => "Web Development")
19 14 Node.create(:name => "Python",:summary => "...", :section_id => s2.id)
20 15 Node.create(:name => "Javascript",:summary => "...", :section_id => s2.id)
  16 +Node.create(:name => "CoffeeScript",:summary => "...", :section_id => s2.id)
  17 +Node.create(:name => "HAML",:summary => "...", :section_id => s2.id)
  18 +Node.create(:name => "SASS",:summary => "...", :section_id => s2.id)
21 19 Node.create(:name => "MongoDB",:summary => "...", :section_id => s2.id)
22 20 Node.create(:name => "Redis",:summary => "...", :section_id => s2.id)
23 21 Node.create(:name => "Git",:summary => "...", :section_id => s2.id)
@@ -26,23 +24,11 @@
26 24 Node.create(:name => "Google",:summary => "...", :section_id => s2.id)
27 25 Node.create(:name => "Java",:summary => "...", :section_id => s2.id)
28 26 Node.create(:name => "Tornado",:summary => "...", :section_id => s2.id)
29   -Node.create(:name => "Ruby on Rails",:summary => "...", :section_id => s2.id)
30   -Node.create(:name => "Django",:summary => "...", :section_id => s2.id)
31 27 Node.create(:name => "Linux",:summary => "...", :section_id => s2.id)
32   -Node.create(:name => "服务器",:summary => "...", :section_id => s2.id)
33 28 Node.create(:name => "Nginx",:summary => "...", :section_id => s2.id)
34   -Node.create(:name => "云",:summary => "...", :section_id => s2.id)
35   -s3 = Section.create(:name => "生活")
36   -Node.create(:name => "跳蚤市场",:summary => "...", :section_id => s3.id)
37   -Node.create(:name => "爱读书",:summary => "...", :section_id => s3.id)
38   -Node.create(:name => "电影",:summary => "...", :section_id => s3.id)
39   -Node.create(:name => "音乐",:summary => "...", :section_id => s3.id)
40   -Node.create(:name => "摄影",:summary => "...", :section_id => s3.id)
41   -Node.create(:name => "美食",:summary => "...", :section_id => s3.id)
42   -Node.create(:name => "信用卡",:summary => "...", :section_id => s3.id)
43   -Node.create(:name => "旅行",:summary => "...", :section_id => s3.id)
44   -Node.create(:name => "职业",:summary => "...", :section_id => s3.id)
45   -s6 = Section.create(:name => "社区")
  29 +Node.create(:name => "Apache",:summary => "...", :section_id => s2.id)
  30 +Node.create(:name => "Cloud",:summary => "...", :section_id => s2.id)
  31 +s6 = Section.create(:name => "Ruby China")
46 32 Node.create(:name => "公告",:summary => "...", :section_id => s6.id)
47 33 Node.create(:name => "反馈",:summary => "...", :section_id => s6.id)
48   -Node.create(:name => "Homeland",:summary => "...", :section_id => s6.id)
  34 +Node.create(:name => "开发",:summary => "...", :section_id => s6.id)

0 comments on commit a04ab94

Please sign in to comment.
Something went wrong with that request. Please try again.