Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update favicon;

Add SiteConfig feature, now can update some config in Control Panel.
Add Wiki page. not done.
  • Loading branch information...
commit 8cbc2b7f8073fe31f0c532316124cf7f1359b01d 1 parent b0369c6
@huacnlee huacnlee authored
Showing with 370 additions and 17 deletions.
  1. +5 −0 README.markdown
  2. BIN  app/.DS_Store
  3. BIN  app/assets/images/favicon.png
  4. BIN  app/assets/images/icon.png
  5. +3 −0  app/assets/javascripts/pages.js.coffee
  6. +3 −0  app/assets/stylesheets/pages.css.scss
  7. +22 −0 app/controllers/cpanel/site_configs_controller.rb
  8. +83 −0 app/controllers/pages_controller.rb
  9. +2 −0  app/helpers/pages_helper.rb
  10. +23 −0 app/models/page.rb
  11. +49 −0 app/models/site_config.rb
  12. BIN  app/views/.DS_Store
  13. +24 −0 app/views/cpanel/site_configs/_form.html.erb
  14. +4 −0 app/views/cpanel/site_configs/edit.html.erb
  15. +15 −0 app/views/cpanel/site_configs/index.html.erb
  16. +2 −12 app/views/home/index.html.erb
  17. +3 −5 app/views/layouts/application.html.erb
  18. +2 −0  app/views/layouts/cpanel.html.erb
  19. +41 −0 app/views/pages/_form.html.erb
  20. +6 −0 app/views/pages/edit.html.erb
  21. +1 −0  app/views/pages/index.html.erb
  22. +5 −0 app/views/pages/new.html.erb
  23. +35 −0 app/views/pages/show.html.erb
  24. +6 −0 config/environments/development.rb
  25. +32 −0 config/initializers/default_site_configs.rb
  26. +4 −0 config/routes.rb
  27. BIN  public/favicon.ico
View
5 README.markdown
@@ -4,6 +4,11 @@ This is source code of [Ruby China Group](http://ruby-china.org)
* You need install *Ruby 1.9.2*, *Rubygems* and *Rails 3.1* first.
* Install *Redis*, *MongoDb*
+
+ ```
+ gem install rails -v=3.1.1
+ bundle install
+ ```
## Contributors
View
BIN  app/.DS_Store
Binary file not shown
View
BIN  app/assets/images/favicon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  app/assets/images/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
3  app/assets/javascripts/pages.js.coffee
@@ -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://jashkenas.github.com/coffee-script/
View
3  app/assets/stylesheets/pages.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Pages controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
22 app/controllers/cpanel/site_configs_controller.rb
@@ -0,0 +1,22 @@
+# coding: utf-8
+class Cpanel::SiteConfigsController < Cpanel::ApplicationController
+
+ def index
+ @site_configs = SiteConfig.desc(:_id)
+ end
+
+ def edit
+ @site_config = SiteConfig.find(params[:id])
+ end
+
+ def update
+ @site_config = SiteConfig.find(params[:id])
+
+ if @site_config.update_attributes(params[:site_config])
+ redirect_to edit_cpanel_site_config_path(params[:id]), notice: "保存成功."
+ else
+ render action: "edit"
+ end
+ end
+
+end
View
83 app/controllers/pages_controller.rb
@@ -0,0 +1,83 @@
+class PagesController < ApplicationController
+ # GET /pages
+ # GET /pages.json
+ def index
+ @pages = Page.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @pages }
+ end
+ end
+
+ # GET /pages/1
+ # GET /pages/1.json
+ def show
+ @page = Page.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @page }
+ end
+ end
+
+ # GET /pages/new
+ # GET /pages/new.json
+ def new
+ @page = Page.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @page }
+ end
+ end
+
+ # GET /pages/1/edit
+ def edit
+ @page = Page.find(params[:id])
+ end
+
+ # POST /pages
+ # POST /pages.json
+ def create
+ @page = Page.new(params[:page])
+
+ respond_to do |format|
+ if @page.save
+ format.html { redirect_to @page, notice: 'Page was successfully created.' }
+ format.json { render json: @page, status: :created, location: @page }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @page.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /pages/1
+ # PUT /pages/1.json
+ def update
+ @page = Page.find(params[:id])
+
+ respond_to do |format|
+ if @page.update_attributes(params[:page])
+ format.html { redirect_to @page, notice: 'Page was successfully updated.' }
+ format.json { head :ok }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @page.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /pages/1
+ # DELETE /pages/1.json
+ def destroy
+ @page = Page.find(params[:id])
+ @page.destroy
+
+ respond_to do |format|
+ format.html { redirect_to pages_url }
+ format.json { head :ok }
+ end
+ end
+end
View
2  app/helpers/pages_helper.rb
@@ -0,0 +1,2 @@
+module PagesHelper
+end
View
23 app/models/page.rb
@@ -0,0 +1,23 @@
+# coding: utf-8
+# 单页的文档页面
+# 采用 Markdown 编写
+class Page
+ include Mongoid::Document
+ include Mongoid::Timestamps
+ include Mongoid::SoftDelete
+ include Mongoid::Versioning
+
+ # 页面地址
+ field :slug
+ field :title
+ # 原始 Markdown 内容
+ field :body
+ # Markdown 格式化后的 html
+ field :body_html
+ field :editors, :type => Array
+ field :locked, :type => Boolean
+
+ attr_protected :body_html, :locked, :editors
+ validates_presence_of :slug, :title, :body
+ validates_uniqueness_of :slug
+end
View
49 app/models/site_config.rb
@@ -0,0 +1,49 @@
+# coding: utf-8
+# 在数据库中的配置信息
+# 这里有存放首页,Wiki 等页面 HTML
+# 使用方法
+# SiteConfig.foo
+# SiteConfig.foo = "asdkglaksdg"
+class SiteConfig
+ include Mongoid::Document
+
+ field :key
+ field :value
+
+ index :key
+
+ validates_presence_of :key
+ validates_uniqueness_of :key
+
+ def self.method_missing(method, *args)
+ method_name = method.to_s
+ super(method, *args)
+ rescue NoMethodError
+ if method_name =~ /=$/
+ var_name = method_name.gsub('=', '')
+ value = args.first.to_s
+ # save
+ if item = find_by_key(key)
+ update_attribute(var_name, value)
+ else
+ SiteConfig.create(:key => key, :value => value)
+ end
+ else
+ if item = where(:key => method).first
+ item.value
+ else
+ nil
+ end
+ end
+ end
+
+ def self.find_by_key(key)
+ where(:key => key).first
+ end
+
+ def self.save_default(key, value)
+ if not find_by_id(key)
+ create(:key => key, :value => value.to_s)
+ end
+ end
+end
View
BIN  app/views/.DS_Store
Binary file not shown
View
24 app/views/cpanel/site_configs/_form.html.erb
@@ -0,0 +1,24 @@
+<%= form_for([:cpanel,@site_config]) do |f| %>
+ <fieldset>
+ <legend></legend>
+ <%= render 'shared/error_messages', :target => @site_config %>
+ <div class="clearfix">
+ <%= f.label :key %>
+ <div class="input">
+ <%= f.text_field :key, :class => "disabled", :disabled => "disabled" %>
+ <span class="help-inline">请勿修改 key</span>
+ </div>
+ </div>
+ <div class="clearfix">
+ <%= f.label :value %>
+ <div class="input">
+ <%= f.text_area :value, :class => "long", :rows => "20" %>
+ <span class="help-inline"></span>
+ </div>
+ </div>
+ <div class="actions">
+ <%= f.submit "保存", :class => "btn primary" %>
+ <a href="<%= cpanel_site_configs_path %>" class="btn">取消</a>
+ </div>
+ </fieldset>
+<% end %>
View
4 app/views/cpanel/site_configs/edit.html.erb
@@ -0,0 +1,4 @@
+<h1>修改设置</h1>
+
+<%= render 'form' %>
+
View
15 app/views/cpanel/site_configs/index.html.erb
@@ -0,0 +1,15 @@
+<h1>设置项</h1>
+
+<table>
+ <tr>
+ <th>key</th>
+ <th></th>
+ </tr>
+
+<% @site_configs.each do |site_config| %>
+ <tr>
+ <td><%= site_config.key %></td>
+ <td><%= link_to 'Edit', edit_cpanel_site_config_path(site_config) %></td>
+ </tr>
+<% end %>
+</table>
View
14 app/views/home/index.html.erb
@@ -1,15 +1,5 @@
<% content_for :sitemap do %>
<li class="active">首页</li>
<% end %>
-<div class="box" style="text-align:center;">
- <p><%= image_tag("big_logo.png") %></p>
- </p>
- <p>Ruby China Group, 致力于构建完善的 Ruby 中文社区。</p>
- <p>功能正在完善中,欢迎 <a href="http://github.com/huacnlee/ruby-china">贡献代码</a> 。</p>
- <p>诚邀有激情的活跃 Ruby 爱好者参与维护社区,联系 <b style="color:#c00;">lgn21st@gmail.com</b>
- <% if not current_user %>
- <div style="margin:40px 0;">
- <a href='/account/sign_in' class="btn primary">登录</a> <a href="/account/sign_up" class="btn success">加入 Ruby China</a>
- </div>
- <% end %>
-</div>
+
+<%= raw SiteConfig.index_html %>
View
8 app/views/layouts/application.html.erb
@@ -6,7 +6,7 @@
<%= yield :styles %>
<meta name="keywords" content="<%= @meta_keywords %>" />
<meta name="description" content="<%= @meta_description %>" />
- <link rel="shortcut icon" href="/favicon.ico?v=001" />
+ <link rel="shortcut icon" href="<%= asset_path("icon.png") %>" />
<%= csrf_meta_tag %>
<%= javascript_include_tag "application" %>
<%= auto_discovery_link_tag(:rss,feed_topics_url,:title => '订阅最新贴') %>
@@ -22,7 +22,7 @@
<ul class="nav">
<li<%= ' class=active' if ["posts"].index(params[:controller]) %>><a href="<%= posts_path %>">文章</a></li>
<li<%= ' class=active' if ["topics","replies"].index(params[:controller]) %>><a href="<%= topics_path %>">论坛</a></li>
- <li<%= ' class=active' if ["events"].index(params[:controller]) %>><a href="/events">近期活动</a></li>
+ <li<%= ' class=active' if ["pages"].index(params[:controller]) %>><a href="/wiki">资料库</a></li>
<li<%= ' class=active' if ["events"].index(params[:controller]) %>><a href="/sites">酷站</a></li>
</ul>
<form action="<%= search_topics_path %>" class="pull-left" method="get">
@@ -64,9 +64,7 @@
</div>
<footer class="footer">
<div class="container">
- <p class="copyright">
- &copy; Ruby China Group.
- </p>
+ <%= raw SiteConfig.footer_html %>
</div>
</footer>
<script type="text/javascript">
View
2  app/views/layouts/cpanel.html.erb
@@ -2,6 +2,7 @@
<html>
<head>
<title>RubyChina - Control Panel</title>
+ <link rel="shortcut icon" href="<%= asset_path("icon.png") %>" />
<%= stylesheet_link_tag "cpanel" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tag %>
@@ -13,6 +14,7 @@
<a href="<%= cpanel_root_path %>" class="brand">控制台</a>
<ul class="nav">
<li<%= " class=active" if params[:controller] == "cpanel/home" %>><a href="<%= cpanel_root_path %>">系统概况</a></li>
+ <li<%= " class='active'" if params[:controller] == "cpanel/site_configs" %>><a href="<%= cpanel_site_configs_path %>">全局设置</a></li>
<li<%= " class=active" if params[:controller] == "cpanel/users" %>><a href="<%= cpanel_users_path %>">用户</a></li>
<li<%= " class='active'" if params[:controller] == "cpanel/sections" %>><a href="<%= cpanel_sections_path %>">分类</a></li>
<li<%= " class='active'" if params[:controller] == "cpanel/nodes" %>><a href="<%= cpanel_nodes_path %>">节点</a></li>
View
41 app/views/pages/_form.html.erb
@@ -0,0 +1,41 @@
+<%= form_for(@page) do |f| %>
+ <% if @page.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@page.errors.count, "error") %> prohibited this page from being saved:</h2>
+
+ <ul>
+ <% @page.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :slug %><br />
+ <%= f.text_field :slug %>
+ </div>
+ <div class="field">
+ <%= f.label :title %><br />
+ <%= f.text_field :title %>
+ </div>
+ <div class="field">
+ <%= f.label :body %><br />
+ <%= f.text_field :body %>
+ </div>
+ <div class="field">
+ <%= f.label :body_html %><br />
+ <%= f.text_field :body_html %>
+ </div>
+ <div class="field">
+ <%= f.label :editors %><br />
+ <%= f.text_field :editors %>
+ </div>
+ <div class="field">
+ <%= f.label :locked %><br />
+ <%= f.check_box :locked %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
6 app/views/pages/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing page</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @page %> |
+<%= link_to 'Back', pages_path %>
View
1  app/views/pages/index.html.erb
@@ -0,0 +1 @@
+<%= raw SiteConfig.wiki_index_html %>
View
5 app/views/pages/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New page</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', pages_path %>
View
35 app/views/pages/show.html.erb
@@ -0,0 +1,35 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Slug:</b>
+ <%= @page.slug %>
+</p>
+
+<p>
+ <b>Title:</b>
+ <%= @page.title %>
+</p>
+
+<p>
+ <b>Body:</b>
+ <%= @page.body %>
+</p>
+
+<p>
+ <b>Body html:</b>
+ <%= @page.body_html %>
+</p>
+
+<p>
+ <b>Editors:</b>
+ <%= @page.editors %>
+</p>
+
+<p>
+ <b>Locked:</b>
+ <%= @page.locked %>
+</p>
+
+
+<%= link_to 'Edit', edit_page_path(@page) %> |
+<%= link_to 'Back', pages_path %>
View
6 config/environments/development.rb
@@ -39,3 +39,9 @@
:enable_starttls_auto => true }
end
+Rails::Rack::Logger.class_eval do
+ def before_dispatch_with_quiet_assets(env)
+ before_dispatch_without_quiet_assets(env) unless env['PATH_INFO'].index("/assets/") == 0
+ end
+ alias_method_chain :before_dispatch, :quiet_assets
+end
View
32 config/initializers/default_site_configs.rb
@@ -0,0 +1,32 @@
+# coding: utf-8
+# 默认配置项
+# 如需新增设置项,请在这里初始化默认值,然后到后台修改
+
+# 首页
+# SiteConfig.index_html
+SiteConfig.save_default("index_html",<<-eos
+<div class="box" style="text-align:center;">
+ <p><img alt="Big_logo" src="/assets/big_logo.png"></p>
+ <p></p>
+ <p>Ruby China Group, 致力于构建完善的 Ruby 中文社区。</p>
+ <p>功能正在完善中,欢迎 <a href="http://github.com/huacnlee/ruby-china">贡献代码</a> 。</p>
+ <p>诚邀有激情的活跃 Ruby 爱好者参与维护社区,联系 <b style="color:#c00;">lgn21st@gmail.com</b></p>
+</div>
+eos
+)
+
+# Wiki 首页 HTML
+SiteConfig.save_default("wiki_index_html",<<-eos
+<div class="box">
+ Wiki Home page. <a href="/wiki/new" class="btn primary">创建新页面</a>
+</div>
+eos
+)
+
+# Footer HTML
+SiteConfig.save_default("footer_html",<<-eos
+<p class="copyright">
+ &copy; Ruby China Group.
+</p>
+eos
+)
View
4 config/routes.rb
@@ -1,9 +1,12 @@
RubyChina::Application.routes.draw do
+ resources :pages
+
resources :posts do
collection do
end
end
+ resources :pages, :path => "wiki"
resources :comments
resources :notes
match "/uploads/*path" => "gridfs#serve"
@@ -36,6 +39,7 @@
namespace :cpanel do
root :to => "home#index"
+ resources :site_configs
resources :replies
resources :topics
resources :nodes
View
BIN  public/favicon.ico
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.