homeland-wiki 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +34 -0
  3. data/Rakefile +37 -0
  4. data/app/assets/config/homeland_press_manifest.js +3 -0
  5. data/app/assets/javascripts/homeland/wiki/application.coffee +32 -0
  6. data/app/assets/stylesheets/homeland/wiki/application.scss +34 -0
  7. data/app/controllers/homeland/wiki/admin/page_versions_controller.rb +23 -0
  8. data/app/controllers/homeland/wiki/admin/pages_controller.rb +55 -0
  9. data/app/controllers/homeland/wiki/application_controller.rb +5 -0
  10. data/app/controllers/homeland/wiki/pages_controller.rb +86 -0
  11. data/app/helpers/homeland/wiki/application_helper.rb +10 -0
  12. data/app/models/homeland/wiki/ability.rb +26 -0
  13. data/app/models/page.rb +74 -0
  14. data/app/models/page_version.rb +7 -0
  15. data/app/views/homeland/wiki/admin/page_versions/index.html.erb +32 -0
  16. data/app/views/homeland/wiki/admin/page_versions/show.html.erb +20 -0
  17. data/app/views/homeland/wiki/admin/pages/_form.html.erb +12 -0
  18. data/app/views/homeland/wiki/admin/pages/edit.html.erb +6 -0
  19. data/app/views/homeland/wiki/admin/pages/index.html.erb +31 -0
  20. data/app/views/homeland/wiki/pages/_form.html.erb +25 -0
  21. data/app/views/homeland/wiki/pages/_sidebar.html.erb +14 -0
  22. data/app/views/homeland/wiki/pages/comments.html.erb +18 -0
  23. data/app/views/homeland/wiki/pages/edit.html.erb +8 -0
  24. data/app/views/homeland/wiki/pages/index.html.erb +14 -0
  25. data/app/views/homeland/wiki/pages/new.html.erb +8 -0
  26. data/app/views/homeland/wiki/pages/recent.html.erb +19 -0
  27. data/app/views/homeland/wiki/pages/show.html.erb +47 -0
  28. data/app/views/layouts/homeland/wiki/application.html.erb +18 -0
  29. data/config/locales/pages.en.yml +9 -0
  30. data/config/locales/pages.zh-CN.yml +9 -0
  31. data/config/locales/pages.zh-TW.yml +9 -0
  32. data/config/routes.rb +21 -0
  33. data/lib/homeland/wiki.rb +7 -0
  34. data/lib/homeland/wiki/engine.rb +28 -0
  35. data/lib/homeland/wiki/version.rb +7 -0
  36. metadata +92 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ffedcf29dc9556d5e14b77be5275716ca387310f
4
+ data.tar.gz: 4de8f046b38214d11606fa3ae1cdae7bd7445dcb
5
+ SHA512:
6
+ metadata.gz: 7b32ad8f0188cb84499561e28bf11f27d6975269137bec2a9c876a6e68adb19fef47285d2c51d8b0e13d2b9ec35f6b66f4a0c06b83824f7dbaa183714d9016ef
7
+ data.tar.gz: f398e902ee2126272d128c7beb1c2f6bfa841e8844adbc9d7ea2bedd726dfc8ab54b3b7e7884b114fc02e96e421ec29d05b7e94b41206b244eecc01ee15df9bd
@@ -0,0 +1,34 @@
1
+ Homeland::Wiki
2
+ --------------
3
+
4
+ Wiki 栏目插件 for [Homeland](https://gethomeland.com)
5
+
6
+ 简单的实现 /wiki 栏目,并在导航栏显示。
7
+
8
+ ## Usage
9
+
10
+ ## Installation
11
+
12
+ 在 Homeland 应用的 Gemfile 增加:
13
+
14
+ ```ruby
15
+ gem 'homeland-wiki'
16
+ ```
17
+
18
+ And then execute:
19
+ ```bash
20
+ $ bundle
21
+ ```
22
+
23
+ ## Configuration
24
+
25
+ 修改 Homeland 的 `modules` 配置,增加 `wiki` 以启用。
26
+
27
+ ```yml
28
+ defaults: &defaults
29
+ # add "press" to modules
30
+ modules: 'topic,...,wiki'
31
+ ```
32
+
33
+ ## License
34
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Homeland::Wiki'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'test'
31
+ t.pattern = 'test/**/*_test.rb'
32
+ t.verbose = false
33
+ end
34
+
35
+
36
+ task default: :test
37
+
@@ -0,0 +1,3 @@
1
+ //= link_directory ../javascripts/homeland/press.js
2
+ //= link_directory ../stylesheets/homeland/press.css
3
+
@@ -0,0 +1,32 @@
1
+ # Place all the behaviors and hooks related to the matching controller here.
2
+ # All this logic will automatically be available in application.js.
3
+ # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
4
+ #
5
+ window.PageView = Backbone.View.extend
6
+ el: "body"
7
+ events:
8
+ "click .editor-toolbar .edit a": "toggleEditView"
9
+ "click .editor-toolbar .preview a": "togglePreviewView"
10
+
11
+ initialize: (opts) ->
12
+ @parentView = opts.parentView
13
+ $("<div id='preview' class='markdown form-control'></div>").insertAfter( $('#page_body') )
14
+ window._editor = new Editor()
15
+
16
+ toggleEditView: (e) ->
17
+ $(e.target).parent().addClass('active')
18
+ $('.preview a').parent().removeClass('active')
19
+ $('#preview').hide()
20
+ $('#page_body').show()
21
+ false
22
+
23
+ togglePreviewView: (e) ->
24
+ $(e.target).parent().addClass('active')
25
+ $('.edit a').parent().removeClass('active')
26
+ $('#preview').html('Loading...')
27
+ $('#page_body').hide()
28
+ $('#preview').show()
29
+ $.post '/wiki/preview', {body: $('#page_body').val()}, (data)->
30
+ $('#preview').html(data)
31
+ false
32
+ false
@@ -0,0 +1,34 @@
1
+ /*
2
+ *= require_self
3
+ */
4
+ .page-pages {
5
+ .sidebar {
6
+ strong { color: #999; }
7
+ ul {
8
+ padding: 10px 10px 10px 30px;
9
+ li { line-height: 180%; }
10
+ }
11
+ }
12
+
13
+ .page-detail {
14
+ .panel-heading {
15
+ padding: 15px;
16
+ h1 { font-size: 20px; color: #111; margin: 0; margin-bottom: 6px;}
17
+ }
18
+ .info {
19
+ text-align:right;
20
+ padding:10px;
21
+ border-bottom:1px solid #eaeaea;
22
+ margin:-10px -10px 0;
23
+ background: #f5f5f5;
24
+ border-radius: 3px 3px 0 0;
25
+ margin-bottom:20px;
26
+ }
27
+ .editors {
28
+ h3 { font-size:14px; color:#999;}
29
+ .media-object { display: inline; }
30
+ .buttons { margin-top: 10px; }
31
+ }
32
+ }
33
+ }
34
+
@@ -0,0 +1,23 @@
1
+ module Homeland::Wiki::Admin
2
+ class PageVersionsController < ::Admin::ApplicationController
3
+ def index
4
+ @page = Page.find(params[:page_id])
5
+ @page_versions = @page.versions.order(version: :desc).page(params[:page])
6
+ end
7
+
8
+ def show
9
+ @page = Page.find(params[:page_id])
10
+ @page_version = @page.versions.find(params[:id])
11
+ end
12
+
13
+ def revert
14
+ @page = Page.find(params[:page_id])
15
+ @page_version = @page.versions.find(params[:id])
16
+ if @page.revert_version(@page_version.version)
17
+ redirect_to admin_page_versions_path(params[:page_id]), notice: "Wiki 内容已经撤销到了版本 #{@page_version.version}"
18
+ else
19
+ redirect_to admin_page_versions_path(params[:page_id]), alert: "版本撤销失败,原因: #{@page.errors.full_messages.join('<br />')}"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,55 @@
1
+ module Homeland::Wiki::Admin
2
+ class PagesController < ::Admin::ApplicationController
3
+ before_action :set_page, only: [:show, :edit, :update, :destroy]
4
+
5
+ def index
6
+ @pages = Page.unscoped.order(id: :desc).page(params[:page])
7
+ end
8
+
9
+ def show
10
+ end
11
+
12
+ def new
13
+ @page = Page.new
14
+ end
15
+
16
+ def edit
17
+ end
18
+
19
+ def create
20
+ @page = Page.new(params[:page].permit!)
21
+
22
+ if @page.save
23
+ redirect_to(admin_pages_path, notice: 'Page was successfully created.')
24
+ else
25
+ render action: 'new'
26
+ end
27
+ end
28
+
29
+ def update
30
+ @page.title = params[:page][:title]
31
+ @page.body = params[:page][:body]
32
+ @page.slug = params[:page][:slug]
33
+ @page.locked = params[:page][:locked]
34
+ @page.user_id = current_user.id
35
+
36
+ if @page.save
37
+ redirect_to(admin_pages_path, notice: 'Page was successfully updated.')
38
+ else
39
+ render action: 'edit'
40
+ end
41
+ end
42
+
43
+ def destroy
44
+ @page.destroy
45
+
46
+ redirect_to(admin_pages_path)
47
+ end
48
+
49
+ private
50
+
51
+ def set_page
52
+ @page = Page.unscoped.find_by_slug(params[:id])
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,5 @@
1
+ module Homeland::Wiki
2
+ class ApplicationController < ::ApplicationController
3
+ helper ApplicationHelper
4
+ end
5
+ end
@@ -0,0 +1,86 @@
1
+ module Homeland::Wiki
2
+ class PagesController < Homeland::Wiki::ApplicationController
3
+ require_module_enabled! :wiki
4
+ authorize_resource :page
5
+ before_action :set_page, only: [:show, :edit, :update, :destroy, :comments]
6
+
7
+ etag { Setting.wiki_sidebar_html }
8
+
9
+ def index
10
+ fresh_when(Setting.wiki_index_html)
11
+ end
12
+
13
+ def recent
14
+ @pages = Page.recent.page(params[:page])
15
+ fresh_when(@pages)
16
+ end
17
+
18
+ def show
19
+ if @page.blank?
20
+ if current_user.blank?
21
+ render_404
22
+ return
23
+ end
24
+
25
+ redirect_to new_page_path(title: params[:id]), notice: 'Page not Found, Please create a new page'
26
+ return
27
+ end
28
+
29
+ @page.hits.incr(1)
30
+ fresh_when(@page)
31
+ end
32
+
33
+ def comments
34
+ render_404 if @page.blank?
35
+ end
36
+
37
+ def new
38
+ @page = Page.new
39
+ @page.slug = params[:title]
40
+ respond_to do |format|
41
+ format.html # new.html.erb
42
+ format.json { render json: @page }
43
+ end
44
+ end
45
+
46
+ def edit
47
+ end
48
+
49
+ def create
50
+ @page = Page.new(page_params)
51
+ @page.user_id = current_user.id
52
+ @page.version_enable = true
53
+
54
+ if @page.save
55
+ redirect_to page_path(@page.slug), notice: t('common.create_success')
56
+ else
57
+ render action: 'new'
58
+ end
59
+ end
60
+
61
+ def update
62
+ @page.version_enable = true
63
+ @page.user_id = current_user.id
64
+
65
+ if @page.update(page_params)
66
+ redirect_to page_path(@page.slug), notice: t('common.update_success')
67
+ else
68
+ render action: 'edit'
69
+ end
70
+ end
71
+
72
+ def preview
73
+ render plain: Homeland::Markdown.call(params[:body])
74
+ end
75
+
76
+ protected
77
+
78
+ def set_page
79
+ @page = Page.find_by_slug(params[:id])
80
+ end
81
+
82
+ def page_params
83
+ params.require(:page).permit(:title, :body, :slug, :change_desc)
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,10 @@
1
+ module Homeland::Wiki
2
+ module ApplicationHelper
3
+ delegate :comments_path, to: :main_app
4
+
5
+ def page_title_tag(page)
6
+ return '' if page.blank?
7
+ link_to(page.title, page_path(page.slug), class: 'page')
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,26 @@
1
+ module Homeland::Wiki
2
+ class Ability
3
+ include CanCan::Ability
4
+
5
+ attr_reader :user
6
+
7
+ def initialize(u)
8
+ @user = u
9
+ return roles_for_create_wiki if @user.present? && (@user.roles?(:admin) || @user.roles?(:wiki_editor))
10
+ roles_for_anonymous
11
+ end
12
+
13
+ protected
14
+
15
+ def roles_for_create_wiki
16
+ can :create, Page
17
+ can :edit, Page, locked: false
18
+ can :update, Page, locked: false
19
+ end
20
+
21
+ def roles_for_anonymous
22
+ can [:read, :recent, :preview, :comments], Page
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,74 @@
1
+ class Page < ApplicationRecord
2
+ include MarkdownBody
3
+ include Searchable
4
+
5
+ counter :hits, default: 0
6
+
7
+ second_level_cache expires_in: 2.weeks
8
+
9
+ has_many :versions, class_name: 'PageVersion'
10
+
11
+ attr_accessor :user_id, :change_desc, :version_enable
12
+
13
+ validates :slug, :title, :body, presence: true
14
+ # 当需要记录版本时,如果是更新,那么要求填写 :change_desc
15
+ validates :user_id, if: proc { |p| p.version_enable == true }, presence: true
16
+ validates :change_desc, if: proc { |p| p.version_enable == true && !p.new_record? }, presence: true
17
+ validates :slug, format: /\A[a-z0-9\-_]+\z/
18
+ validates :slug, uniqueness: true
19
+
20
+ before_save :append_editor
21
+ def append_editor
22
+ unless editor_ids.include?(user_id.to_i)
23
+ editor_ids << user_id.to_i
24
+ end
25
+ end
26
+
27
+ # 记录更新版本
28
+ after_save :create_version
29
+ def create_version
30
+ # 只有当 version_enable 为 true 的时候才记录版本
31
+ # 以免后台,以及其他的一些 update 时被误调用
32
+ return true unless version_enable
33
+ # 只有 body, title, slug 更改了才更新版本
34
+ if self.body_changed? || self.title_changed? || self.slug_changed?
35
+ update_column(:version, self.version + 1)
36
+ PageVersion.create(user_id: user_id,
37
+ page_id: id,
38
+ desc: change_desc || '',
39
+ version: version,
40
+ body: body,
41
+ title: title,
42
+ slug: slug)
43
+ end
44
+ end
45
+
46
+ def as_indexed_json(_options = {})
47
+ as_json(only: [:slug, :title, :body])
48
+ end
49
+
50
+ def indexed_changed?
51
+ slug_changed? || title_changed? || body_changed?
52
+ end
53
+
54
+ def to_param
55
+ slug
56
+ end
57
+
58
+ # 撤掉到指定版本
59
+ def revert_version(version)
60
+ page_version = PageVersion.where(page_id: id, version: version).first
61
+ return false if page_version.blank?
62
+ update(body: page_version.body,
63
+ title: page_version.title,
64
+ slug: page_version.slug)
65
+ end
66
+
67
+ def editors
68
+ User.where(id: editor_ids)
69
+ end
70
+
71
+ def self.find_by_slug(slug)
72
+ fetch_by_uniq_keys(slug: slug)
73
+ end
74
+ end
@@ -0,0 +1,7 @@
1
+ class PageVersion < ApplicationRecord
2
+ include MarkdownBody
3
+
4
+ belongs_to :user
5
+ belongs_to :page
6
+ end
7
+
@@ -0,0 +1,32 @@
1
+ <% content_for :sitemap do %>
2
+ <a href="<%= admin_pages_path %>">Wiki</a> <i class="fa fa-angle-right"></i>
3
+ <a href="<%= admin_page_path(params[:page_id]) %>">Page:<%= params[:page_id] %></a> <i class="fa fa-angle-right"></i>
4
+ <span class="current">版本历史</span>
5
+ <% end %>
6
+ <h1>Wiki 列表</h1>
7
+
8
+ <table class="table table-bordered table-striped table-condensed">
9
+ <tr class="head">
10
+ <td class="first">Version</td>
11
+ <td style="width:200px">Slug</td>
12
+ <td>Title</td>
13
+ <td>Desc</td>
14
+ <td>Creator</td>
15
+ <td>At</td>
16
+ <td></td>
17
+ </tr>
18
+
19
+ <% @page_versions.each do |item| %>
20
+ <tr>
21
+ <td class="first"><%= item.version %></td>
22
+ <td><%= item.slug %></td>
23
+ <td><%= item.title %></td>
24
+ <td><%= item.desc %></td>
25
+ <td><%= user_name_tag(item.user) %></td>
26
+ <td><%= l item.created_at, format: :long %></td>
27
+ <td><%= link_to 'View', admin_page_version_path(item.page_id, item.id) %>
28
+ <%= link_to 'Revert', revert_admin_page_version_path(item.page_id, item.id), 'data-confirm' => 'Are you sure?', method: :post %></td>
29
+ </tr>
30
+ <% end %>
31
+ </table>
32
+ <%= paginate @page_versions %>
@@ -0,0 +1,20 @@
1
+ <% content_for :sitemap do %>
2
+ <a href="<%= admin_pages_path %>">Wiki</a> <i class="fa fa-angle-right"></i>
3
+ <a href="<%= edit_admin_page_path(params[:page_id]) %>">Page:<%= params[:page_id] %></a> <i class="fa fa-angle-right"></i>
4
+ <a href="<%= admin_page_versions_path(params[:page_id]) %>">版本历史</a> <i class="fa fa-angle-right"></i>
5
+ <span class="current">明细</span>
6
+ <% end %>
7
+ <div class="pull-right">
8
+ <%= link_to 'Revert', revert_admin_page_version_path(@page_version.page_id, @page_version.id), 'data-confirm' => 'Are you sure?', method: :post, class: "btn btn-danger" %>
9
+ </div>
10
+ <div class="field">
11
+ <%= user_name_tag @page_version.user %> 修改与 <%= l @page_version.created_at, format: :long %>
12
+ </div>
13
+ <div class="field">
14
+ Slug: <%= @page_version.slug %>
15
+ </div>
16
+ <div class="field">
17
+ Title: <%= @page_version.title %>
18
+ </div>
19
+
20
+ <%= @page_version.body_html %>
@@ -0,0 +1,12 @@
1
+ <%= simple_form_for([:admin,@page]) do |f| %>
2
+ <%= render "shared/error_messages", target: @page %>
3
+ <fieldset>
4
+ <legend>Wiki页面编辑</legend>
5
+ <%= f.input :locked, as: :boolean, hint: "锁定后,前台非管理员将无法修改。" %>
6
+ <%= f.input :slug %>
7
+ <%= f.input :title, input_html: { class: "xxlarge" } %>
8
+ <%= f.input :body, as: :text, input_html: { class: "span8", rows: "30"} %>
9
+ <div class="form-actions">
10
+ <%= f.submit t("common.save"), class: "btn btn-primary", 'data-disable-with' => t("common.saving") %>
11
+ </div>
12
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <% content_for :sitemap do %>
2
+ <a href="<%= admin_pages_path %>">Wiki</a> <i class="fa fa-angle-right"></i> <span class="current">修改</span>
3
+ <% end %>
4
+ <h1>Editing page</h1>
5
+
6
+ <%= render 'form' %>
@@ -0,0 +1,31 @@
1
+ <% content_for :sitemap do %>
2
+ <span class="current">Wiki</span>
3
+ <% end %>
4
+
5
+ <table class="table table-bordered table-striped table-condensed">
6
+ <tr class="head">
7
+ <td class="first">ID</td>
8
+ <td style="width:200px">Slug</td>
9
+ <td>Title</td>
10
+ <td>at</td>
11
+ <td>lock</td>
12
+ <td>Version</td>
13
+ <td style="width:80px;"></td>
14
+ </tr>
15
+
16
+ <% @pages.each do |page| %>
17
+ <tr class="<%= 'deleted' if !page.deleted_at.blank? %>">
18
+ <td class="first"><%= page.id %></td>
19
+ <td><%= page.slug %></td>
20
+ <td><%= truncate(page.title, length: 30) %></td>
21
+ <td><%= l page.created_at, format: :short %></td>
22
+ <td><%= page.locked %></td>
23
+ <td><%= page.version %></td>
24
+ <td>
25
+ <%= link_to '', admin_page_versions_path(page.id), class: "fa fa-clock-o", title: "修改记录" %>
26
+ <%= link_to '', edit_admin_page_path(page), class: "fa fa-pencil" %>
27
+ <%= link_to '', admin_page_path(page), 'data-confirm' => 'Are you sure?', method: :delete, class: "fa fa-trash" %></td>
28
+ </tr>
29
+ <% end %>
30
+ </table>
31
+ <%= paginate @pages %>
@@ -0,0 +1,25 @@
1
+ <%= simple_form_for @page do |f| %>
2
+ <%= render "shared/error_messages", target: @page %>
3
+
4
+ <%= f.input :slug, hint: "#{Setting.base_url}/wiki/:slug"%>
5
+ <%= f.input :title, input_html: { class: "xxlarge" } %>
6
+
7
+ <div class="edit-tools">
8
+ <%= render "/shared/editor_toolbar" %>
9
+ </div>
10
+
11
+ <div class="form-group">
12
+ <%= f.text_area :body, rows: 30, class: 'form-control topic-editor' %>
13
+ <p class="help-block">
14
+ 请使用 Markdown 格式编写,可以试试用 <a href='https://www.typora.io' target='_blank'>Typora</a> 这个 App 来编写。
15
+ </p>
16
+ </div>
17
+
18
+ <% if not @page.new_record? %>
19
+ <%= f.input :change_desc, as: :text, input_html: { rows: "2" }, hint: t("pages.describe_this_time_change") %>
20
+ <% end %>
21
+ <div class="form-group">
22
+ <%= f.submit t("common.save"), class: "btn btn-primary", 'data-disable-with' => t("common.saving") %>
23
+ <%= link_to t("common.cancel"), pages_path, class: "btn btn-default reset" %>
24
+ </div>
25
+ <% end %>
@@ -0,0 +1,14 @@
1
+ <div class="sidebar wiki-sidebar col-sm-3">
2
+ <div class="panel panel-default">
3
+ <div class="panel-body">
4
+ <strong>导航</strong>
5
+ <ul>
6
+ <li><a href="/wiki">首页</a></li>
7
+ <li><%= link_to(t("pages.wiki_index"), recent_pages_path) %></li>
8
+ <li class="hide-ios"><%= link_to(t("pages.new_page"), new_page_path)%></li>
9
+ </ul>
10
+
11
+ <%= raw Setting.wiki_sidebar_html %>
12
+ </div>
13
+ </div>
14
+ </div>
@@ -0,0 +1,18 @@
1
+ <% title_tag [t('pages.comments'), @page.title].join(' · ') %>
2
+
3
+ <div class="row">
4
+ <div class="hide-ios">
5
+ <%= render 'sidebar' %>
6
+ </div>
7
+ <div class="col-md-9">
8
+ <div class="panel panel-default">
9
+ <div id="comments" class="panel-body">
10
+ 《<%= link_to @page.title, page_path(@page.slug) %>》 - <%= t('pages.comments') %>
11
+ </div>
12
+ </div>
13
+
14
+ <div class="hide-ios">
15
+ <%= render "/shared/comments", commentable: @page %>
16
+ </div>
17
+ </div>
18
+ </div>
@@ -0,0 +1,8 @@
1
+ <% title_tag t("pages.edit_page") %>
2
+
3
+ <div class="panel panel-default">
4
+ <div class="panel-heading"><%= t("pages.edit_page") %></div>
5
+ <div class="panel-body">
6
+ <%= render "form" %>
7
+ </div>
8
+ </div>
@@ -0,0 +1,14 @@
1
+ <% title_tag t("menu.wiki") %>
2
+
3
+ <div class="row">
4
+ <%= render 'sidebar' %>
5
+ <% if !turbolinks_app? %>
6
+ <div class="col-md-9">
7
+ <div class="panel panel-default">
8
+ <div class="panel-body">
9
+ <%= raw Setting.wiki_index_html %>
10
+ </div>
11
+ </div>
12
+ </div>
13
+ <% end %>
14
+ </div>
@@ -0,0 +1,8 @@
1
+ <% title_tag t("pages.edit_page") %>
2
+
3
+ <div class="panel panel-default">
4
+ <div class="panel-heading"><%= t("pages.new_page")%></div>
5
+ <div class="panel-body">
6
+ <%= render "form" %>
7
+ </div>
8
+ </div>
@@ -0,0 +1,19 @@
1
+ <% title_tag t('pages.wiki_index') %>
2
+
3
+ <div class="row">
4
+ <div class="hide-ios">
5
+ <%= render 'sidebar' %>
6
+ </div>
7
+ <div class="col-md-9">
8
+ <div class="panel panel-default">
9
+ <div class="panel-heading hide-ios"><%= t('pages.wiki_index') %></div>
10
+ <div class="panel-body">
11
+ <ul>
12
+ <% @pages.each do |item| %>
13
+ <li><%= page_title_tag(item) %></li>
14
+ <% end %>
15
+ </ul>
16
+ </div>
17
+ </div>
18
+ </div>
19
+ </div>
@@ -0,0 +1,47 @@
1
+ <% title_tag @page.title %>
2
+
3
+ <div class="row">
4
+ <div class="hide-ios">
5
+ <%= render 'sidebar' %>
6
+ </div>
7
+ <div class="col-md-9 page-detail">
8
+ <div class="panel panel-default">
9
+ <% if !@page.locked or admin? %>
10
+ <div class="panel-heading">
11
+ <h1><%= @page.title %></h1>
12
+ <div class="infos">
13
+ <%= link_to comments_page_path(@page.slug) do %>
14
+ <%= @page.comments_count %> 条评论
15
+ <% end %>,
16
+ <%= @page.version %> 次修正,<%= @page.hits %> 次阅读, <%= t("common.last_modified_at")%> <%= timeago(@page.updated_at) %>
17
+ <span class="pull-right opts hide-ios">
18
+ <%= link_to(icon_tag('pencil'), edit_page_path(@page)) if can? :edit, @page %>
19
+ </span>
20
+ </div>
21
+ </div>
22
+
23
+ <% end %>
24
+
25
+ <div class="panel-body markdown">
26
+ <article>
27
+ <%= @page.body_html %>
28
+ </article>
29
+ </div>
30
+
31
+ <div class="editors panel-footer clearfix">
32
+ <div class="heading">
33
+ <%= t("pages.wiki_page_contributors")%>
34
+ <span class="pull-right"><%= social_share_button_tag h("#{@page.title} via: @#{Setting.twitter_id} ") %></span>
35
+ </div>
36
+ <div class="avatars">
37
+ <% @page.editors.each do |item| %>
38
+ <%= user_avatar_tag(item, :xs) %>
39
+ <% end %>
40
+ </div>
41
+ <div class="buttons hide-ios">
42
+ <%= link_to "发表评论", comments_page_path(@page.slug, anchor: "new_comment"), class: "btn btn-success" %>
43
+ </div>
44
+ </div>
45
+ </div>
46
+ </div>
47
+ </div>
@@ -0,0 +1,18 @@
1
+ <% content_for :stylesheets do %>
2
+ <%= stylesheet_link_tag "homeland/wiki/application", media: "all" %>
3
+ <% end %>
4
+
5
+ <% content_for :javascripts do %>
6
+ <%= javascript_include_tag "homeland/wiki/application" %>
7
+ <% end %>
8
+
9
+ <% content_for :main do %>
10
+ <script type="text/javascript">
11
+ $('.navbar-nav .nav-plugin-wiki').addClass("active");
12
+ </script>
13
+ <div id="homeland-wiki">
14
+ <%= yield %>
15
+ </div>
16
+ <% end %>
17
+
18
+ <%= render template: "/layouts/application" %>
@@ -0,0 +1,9 @@
1
+ "en":
2
+ pages:
3
+ describe_this_time_change: "Please describe the purpose of this modification."
4
+ edit_page: "Edit Page"
5
+ new_page: "New Page"
6
+ wiki_index: "Wiki Index"
7
+ wiki_page_contributors: "Contributors:"
8
+ wiki_page_lock_warning: "This page is locked and only Adminstrators are authorised to modify."
9
+ comments: 'Comments'
@@ -0,0 +1,9 @@
1
+ "zh-CN":
2
+ pages:
3
+ describe_this_time_change: "描述你本次修改的内容。"
4
+ edit_page: "修改页面"
5
+ new_page: "创建 Wiki 页面"
6
+ wiki_index: "Wiki 目录索引"
7
+ wiki_page_contributors: "本页贡献者:"
8
+ wiki_page_lock_warning: "抱歉,此页面已被锁定,只能管理员才能修改。"
9
+ comments: '评论'
@@ -0,0 +1,9 @@
1
+ "zh-TW":
2
+ pages:
3
+ describe_this_time_change: "描述你本次修改的內容。"
4
+ edit_page: "修改頁面"
5
+ new_page: "創建新頁面"
6
+ wiki_index: "Wiki目錄"
7
+ wiki_page_contributors: "本頁貢獻者:"
8
+ wiki_page_lock_warning: "抱歉,此頁面已被鎖定,只能管理員才能修改。"
9
+ comments: '評論'
@@ -0,0 +1,21 @@
1
+ Homeland::Wiki::Engine.routes.draw do
2
+ resources :pages, path: 'wiki' do
3
+ collection do
4
+ get :recent
5
+ post :preview
6
+ end
7
+ member do
8
+ get :comments
9
+ end
10
+ end
11
+
12
+ namespace :admin do
13
+ resources :pages do
14
+ resources :versions, controller: :page_versions do
15
+ member do
16
+ post :revert
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ require "homeland/wiki/version"
2
+ require "homeland/wiki/engine"
3
+
4
+ module Homeland
5
+ module Wiki
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ module Homeland
2
+ module Wiki
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace Homeland::Wiki
5
+
6
+ initializer 'homeland.wiki.init' do |app|
7
+ if Setting.has_module?(:wiki)
8
+ Homeland.register_plugin do |plugin|
9
+ plugin.name = 'wiki'
10
+ plugin.display_name = 'Wiki'
11
+ plugin.description = Homeland::Wiki::DESCRIPTION
12
+ plugin.version = Homeland::Wiki::VERSION
13
+ plugin.navbar_link = true
14
+ plugin.user_menu_link = true
15
+ plugin.root_path = "/wiki"
16
+ plugin.admin_path = "/admin/pages"
17
+ plugin.admin_navbar_link = true
18
+ plugin.spec_path = config.root.join('spec')
19
+ end
20
+
21
+ app.routes.prepend do
22
+ mount Homeland::Wiki::Engine, at: '/'
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ module Homeland
2
+ module Wiki
3
+ NAME = 'wiki'
4
+ DESCRIPTION = 'Display Wiki channel in navbar for wike pages.'
5
+ VERSION = '0.0.1'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: homeland-wiki
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Griffin Qiu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5'
27
+ description: Display Wiki channel in navbar for wike pages.
28
+ email:
29
+ - griffinqiu@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - README.md
35
+ - Rakefile
36
+ - app/assets/config/homeland_press_manifest.js
37
+ - app/assets/javascripts/homeland/wiki/application.coffee
38
+ - app/assets/stylesheets/homeland/wiki/application.scss
39
+ - app/controllers/homeland/wiki/admin/page_versions_controller.rb
40
+ - app/controllers/homeland/wiki/admin/pages_controller.rb
41
+ - app/controllers/homeland/wiki/application_controller.rb
42
+ - app/controllers/homeland/wiki/pages_controller.rb
43
+ - app/helpers/homeland/wiki/application_helper.rb
44
+ - app/models/homeland/wiki/ability.rb
45
+ - app/models/page.rb
46
+ - app/models/page_version.rb
47
+ - app/views/homeland/wiki/admin/page_versions/index.html.erb
48
+ - app/views/homeland/wiki/admin/page_versions/show.html.erb
49
+ - app/views/homeland/wiki/admin/pages/_form.html.erb
50
+ - app/views/homeland/wiki/admin/pages/edit.html.erb
51
+ - app/views/homeland/wiki/admin/pages/index.html.erb
52
+ - app/views/homeland/wiki/pages/_form.html.erb
53
+ - app/views/homeland/wiki/pages/_sidebar.html.erb
54
+ - app/views/homeland/wiki/pages/comments.html.erb
55
+ - app/views/homeland/wiki/pages/edit.html.erb
56
+ - app/views/homeland/wiki/pages/index.html.erb
57
+ - app/views/homeland/wiki/pages/new.html.erb
58
+ - app/views/homeland/wiki/pages/recent.html.erb
59
+ - app/views/homeland/wiki/pages/show.html.erb
60
+ - app/views/layouts/homeland/wiki/application.html.erb
61
+ - config/locales/pages.en.yml
62
+ - config/locales/pages.zh-CN.yml
63
+ - config/locales/pages.zh-TW.yml
64
+ - config/routes.rb
65
+ - lib/homeland/wiki.rb
66
+ - lib/homeland/wiki/engine.rb
67
+ - lib/homeland/wiki/version.rb
68
+ homepage: https://github.com/ruby-china/homeland-wiki
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.6.8
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Display Wiki channel in navbar for wike pages.
92
+ test_files: []