homeland-press 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +40 -0
- data/Rakefile +35 -0
- data/app/assets/config/homeland_press_manifest.js +2 -0
- data/app/assets/javascripts/homeland/press/application.coffee +30 -0
- data/app/assets/stylesheets/homeland/press/application.scss +92 -0
- data/app/controllers/homeland/press/application_controller.rb +9 -0
- data/app/controllers/homeland/press/posts_controller.rb +84 -0
- data/app/helpers/homeland/press/application_helper.rb +5 -0
- data/app/models/homeland/press/ability.rb +40 -0
- data/app/models/post.rb +45 -0
- data/app/views/homeland/press/posts/_form.html.erb +17 -0
- data/app/views/homeland/press/posts/_post.html.erb +14 -0
- data/app/views/homeland/press/posts/edit.html.erb +9 -0
- data/app/views/homeland/press/posts/index.html.erb +36 -0
- data/app/views/homeland/press/posts/new.html.erb +9 -0
- data/app/views/homeland/press/posts/show.html.erb +36 -0
- data/app/views/layouts/homeland/press/application.html.erb +18 -0
- data/app/views/notifications/_press_published.html.erb +11 -0
- data/config/locales/homeland.press.zh-CN.yml +22 -0
- data/config/routes.rb +11 -0
- data/db/migrate/20170227080755_create_posts.rb +23 -0
- data/lib/homeland/press/engine.rb +27 -0
- data/lib/homeland/press/user_mixin.rb +9 -0
- data/lib/homeland/press/version.rb +6 -0
- data/lib/homeland/press.rb +8 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f5b84324fb6f5a62ef35dd35a57074e258d3cc1
|
4
|
+
data.tar.gz: a03a24d19c22b14301bc02dee1c628d8baecace8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2f6e17c71956a5a8320866456218908dab5c0d3be72fa5eb4a5d7294cfcdd64f3b3dba8f5c3698aadb28818787d417bf0133b2d5d2857f093bc811eb87dcbb4c
|
7
|
+
data.tar.gz: a0b9ff13771a8e9dc123dd2de361ec451d9b871a2824164958dc2cb3bfdd63e81b806a350ce552a6886fc7b772010c61522c9745139304d7b86eae7d979c9c7c
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Jason Lee
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
Homeland::Press
|
2
|
+
--------------
|
3
|
+
|
4
|
+
A Press plugin for [Homeland](https://gethomeland.com) .
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your Homeland application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'homeland-press'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
```bash
|
19
|
+
$ bundle
|
20
|
+
```
|
21
|
+
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
You need use this plugin on Homeland development.
|
26
|
+
|
27
|
+
Gemfile
|
28
|
+
|
29
|
+
```
|
30
|
+
gem 'homeland-press', path: '../homeland-press'
|
31
|
+
````
|
32
|
+
|
33
|
+
And run `bundle install` and `rails db:migrate`
|
34
|
+
|
35
|
+
Now, the plugin has auto mount on Homeland.
|
36
|
+
|
37
|
+
Visit http://localhost:3000/posts
|
38
|
+
|
39
|
+
## License
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
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::Press'
|
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
|
+
task default: :test
|
@@ -0,0 +1,30 @@
|
|
1
|
+
window.PostView = Backbone.View.extend
|
2
|
+
el: "body"
|
3
|
+
events:
|
4
|
+
"click .editor-toolbar .edit a": "toggleEditView"
|
5
|
+
"click .editor-toolbar .preview a": "togglePreviewView"
|
6
|
+
|
7
|
+
initialize: (opts) ->
|
8
|
+
$("<div id='preview' class='markdown form-control' style='display:none;'></div>").insertAfter( $('#post_body') )
|
9
|
+
window._editor = new Editor()
|
10
|
+
|
11
|
+
toggleEditView: (e) ->
|
12
|
+
$(e.target).parent().addClass('active')
|
13
|
+
$('.preview a').parent().removeClass('active')
|
14
|
+
$('#preview').hide()
|
15
|
+
$('#post_body').show()
|
16
|
+
false
|
17
|
+
|
18
|
+
togglePreviewView: (e) ->
|
19
|
+
$(e.target).parent().addClass('active')
|
20
|
+
$('.edit a').parent().removeClass('active')
|
21
|
+
$('#preview').html('Loading...')
|
22
|
+
$('#post_body').hide()
|
23
|
+
$('#preview').show()
|
24
|
+
$.post '/posts/preview', {body: $('#post_body').val()}, (data)->
|
25
|
+
$('#preview').html(data)
|
26
|
+
false
|
27
|
+
false
|
28
|
+
|
29
|
+
document.addEventListener 'turbolinks:load', ->
|
30
|
+
window._postView = new PostView()
|
@@ -0,0 +1,92 @@
|
|
1
|
+
/*
|
2
|
+
*= require_self
|
3
|
+
*/
|
4
|
+
|
5
|
+
.sub-navbar .container,
|
6
|
+
.main-container {
|
7
|
+
max-width: 960px;
|
8
|
+
}
|
9
|
+
|
10
|
+
#homeland-press {
|
11
|
+
|
12
|
+
|
13
|
+
textarea#post_body { height: 400px; }
|
14
|
+
|
15
|
+
.toolbar {
|
16
|
+
margin-bottom: 15px;
|
17
|
+
border-bottom: 2px solid #eee;
|
18
|
+
padding-bottom: 15px;
|
19
|
+
}
|
20
|
+
|
21
|
+
.filter {
|
22
|
+
font-size: 15px;
|
23
|
+
}
|
24
|
+
|
25
|
+
#post-list {
|
26
|
+
.panel-body {
|
27
|
+
}
|
28
|
+
|
29
|
+
.post {
|
30
|
+
margin-bottom: 15px;
|
31
|
+
border-bottom: 1px solid #eee;
|
32
|
+
padding-bottom: 15px;
|
33
|
+
|
34
|
+
&:last-child {
|
35
|
+
border-bottom: 0;
|
36
|
+
margin-bottom: 0px;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
.post-title { font-size: 18px; line-height: 22px; margin-bottom: 0px; }
|
41
|
+
.post-summary {
|
42
|
+
padding: 10px 0;
|
43
|
+
font-size: 14px; color: #888;
|
44
|
+
}
|
45
|
+
.post-info {
|
46
|
+
color: #aaa;
|
47
|
+
a { color: #aaa; }
|
48
|
+
}
|
49
|
+
|
50
|
+
&.post-upcoming {
|
51
|
+
.post-title { font-size: 16px; }
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
#post-detail {
|
57
|
+
.panel-body {
|
58
|
+
padding: 60px;
|
59
|
+
}
|
60
|
+
|
61
|
+
h1 {
|
62
|
+
text-align: center; margin-bottom: 15px;
|
63
|
+
font-size: 24px;
|
64
|
+
}
|
65
|
+
|
66
|
+
.post-opts,
|
67
|
+
.post-info,
|
68
|
+
.post-actions {
|
69
|
+
text-align: center;
|
70
|
+
color: #999;
|
71
|
+
}
|
72
|
+
|
73
|
+
.post-info {
|
74
|
+
.media-object { display: inline; }
|
75
|
+
a { color: #777;}
|
76
|
+
a.user-name { color: #0069D6; font-weight: bold; }
|
77
|
+
}
|
78
|
+
|
79
|
+
.post-actions {
|
80
|
+
margin-top: 15px;
|
81
|
+
.likeable {
|
82
|
+
border: 1px solid #eee;
|
83
|
+
padding: 10px 20px;
|
84
|
+
border-radius: 3px;
|
85
|
+
text-decoration: none !important;
|
86
|
+
&:hover {
|
87
|
+
background: #f0f0f0;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Homeland::Press
|
2
|
+
class PostsController < Homeland::Press::ApplicationController
|
3
|
+
before_action :authenticate_user!, only: [:new, :create, :update, :publish, :destroy]
|
4
|
+
before_action :set_post, only: [:show, :edit, :update, :publish, :destroy]
|
5
|
+
|
6
|
+
# GET /posts
|
7
|
+
def index
|
8
|
+
@posts = Post.published.order('published_at desc, id desc').page(params[:page]).per(10)
|
9
|
+
end
|
10
|
+
|
11
|
+
def upcoming
|
12
|
+
@posts = Post.upcoming.order('id desc').page(params[:page]).per(10)
|
13
|
+
render 'index'
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /posts/1
|
17
|
+
def show
|
18
|
+
@post.hits.incr(1)
|
19
|
+
end
|
20
|
+
|
21
|
+
def preview
|
22
|
+
out = Homeland::Markdown.call(params[:body])
|
23
|
+
render plain: out
|
24
|
+
end
|
25
|
+
|
26
|
+
# GET /posts/new
|
27
|
+
def new
|
28
|
+
authorize! :create, Post
|
29
|
+
@post = Post.new
|
30
|
+
end
|
31
|
+
|
32
|
+
# GET /posts/1/edit
|
33
|
+
def edit
|
34
|
+
authorize! :update, @post
|
35
|
+
end
|
36
|
+
|
37
|
+
# POST /posts
|
38
|
+
def create
|
39
|
+
authorize! :create, Post
|
40
|
+
@post = Post.new(post_params)
|
41
|
+
@post.user_id = current_user.id
|
42
|
+
|
43
|
+
if @post.save
|
44
|
+
redirect_to @post, notice: '文章提交成功,需要等待管理员审核。'
|
45
|
+
else
|
46
|
+
render :new
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# PATCH/PUT /posts/1
|
51
|
+
def update
|
52
|
+
authorize! :update, @post
|
53
|
+
if @post.update(post_params)
|
54
|
+
redirect_to @post, notice: '文章更新成功。'
|
55
|
+
else
|
56
|
+
render :edit
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def publish
|
61
|
+
authorize! :publish, @post
|
62
|
+
@post.published!
|
63
|
+
redirect_to posts_path, notice: "文章审核成功。"
|
64
|
+
end
|
65
|
+
|
66
|
+
# DELETE /posts/1
|
67
|
+
def destroy
|
68
|
+
authorize! :destroy, @post
|
69
|
+
@post.destroy
|
70
|
+
redirect_to posts_url, notice: '文章删除成功。'
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
# Use callbacks to share common setup or constraints between actions.
|
75
|
+
def set_post
|
76
|
+
@post = Post.find_by_slug!(params[:id])
|
77
|
+
end
|
78
|
+
|
79
|
+
# Only allow a trusted parameter "white list" through.
|
80
|
+
def post_params
|
81
|
+
params.require(:post).permit(:title, :slug, :body, :summary)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Homeland::Press
|
2
|
+
class Ability
|
3
|
+
include CanCan::Ability
|
4
|
+
|
5
|
+
attr_reader :user
|
6
|
+
|
7
|
+
def initialize(u)
|
8
|
+
@user = u
|
9
|
+
if @user.blank?
|
10
|
+
roles_for_anonymous
|
11
|
+
elsif @user.roles?(:admin)
|
12
|
+
can :manage, Post
|
13
|
+
elsif @user.roles?(:member)
|
14
|
+
roles_for_members
|
15
|
+
else
|
16
|
+
roles_for_anonymous
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
# 普通会员权限
|
23
|
+
def roles_for_members
|
24
|
+
can :create, Post
|
25
|
+
can :update, Post, user_id: user.id, status: Post.statuses[:upcoming]
|
26
|
+
can :destroy, Post, user_id: user.id, status: Post.statuses[:upcoming]
|
27
|
+
basic_read_only
|
28
|
+
end
|
29
|
+
|
30
|
+
# 未登录用户权限
|
31
|
+
def roles_for_anonymous
|
32
|
+
cannot :manage, Post
|
33
|
+
basic_read_only
|
34
|
+
end
|
35
|
+
|
36
|
+
def basic_read_only
|
37
|
+
can [:read, :upcoming], Post
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/app/models/post.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
class Post < ApplicationRecord
|
2
|
+
belongs_to :user
|
3
|
+
has_many :comments
|
4
|
+
|
5
|
+
enum status: %i(upcoming published rejected)
|
6
|
+
|
7
|
+
counter :hits
|
8
|
+
|
9
|
+
before_save :generate_summary
|
10
|
+
before_create :generate_published_at
|
11
|
+
|
12
|
+
def to_param
|
13
|
+
self.slug.blank? ? self.id : self.slug
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.find_by_slug!(slug)
|
17
|
+
Post.find_by(slug: slug) || Post.find_by(id: slug) || raise(ActiveRecord::RecordNotFound.new(slug: slug))
|
18
|
+
end
|
19
|
+
|
20
|
+
def published_at
|
21
|
+
super || self.updated_at
|
22
|
+
end
|
23
|
+
|
24
|
+
def published!
|
25
|
+
self.update(published_at: Time.now)
|
26
|
+
super
|
27
|
+
if self.user_id
|
28
|
+
Notification.create(notify_type: 'press_published',
|
29
|
+
user_id: self.user_id,
|
30
|
+
target: self)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def generate_published_at
|
37
|
+
self.published_at = Time.now
|
38
|
+
end
|
39
|
+
|
40
|
+
def generate_summary
|
41
|
+
if self.summary.blank?
|
42
|
+
self.summary = self.body.split("\n").first(10).join("\n")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<%= simple_form_for(post) do |f| %>
|
2
|
+
<%= render "/shared/error_messages", target: post %>
|
3
|
+
|
4
|
+
<%= f.input :title %>
|
5
|
+
<%= f.input :slug %>
|
6
|
+
<%= f.input :summary, as: :text %>
|
7
|
+
|
8
|
+
<%= render "/shared/editor_toolbar" %>
|
9
|
+
|
10
|
+
<div class="form-group">
|
11
|
+
<%= f.text_area :body, class: 'topic-editor form-control', input_html: { rows: 20 } %>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div class="form-actions">
|
15
|
+
<%= f.submit t("common.save"), class: "btn btn-primary col-xs-2", 'data-disable-with' => t("common.saving"), 'data-tb' => "save-topic" %>
|
16
|
+
</div>
|
17
|
+
<% end %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<div class="post" id="post-<= post.id %>">
|
2
|
+
<div class="post-title"><%= link_to post.title, post %></div>
|
3
|
+
<% if post.published? %>
|
4
|
+
<div class="post-summary markdown">
|
5
|
+
<%= simple_format post.summary %>
|
6
|
+
</div>
|
7
|
+
<div class="post-info">
|
8
|
+
<%= user_name_tag(post.user) %> ·
|
9
|
+
<%= timeago(post.created_at) %> ·
|
10
|
+
<%= link_to "#{post.likes_count} 个赞", post %> ·
|
11
|
+
<%= link_to "#{post.comments_count} 条评论", post_path(post, anchor: 'comments') %>
|
12
|
+
</div>
|
13
|
+
<% end %>
|
14
|
+
</div>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<% title_tag "头条" %>
|
2
|
+
|
3
|
+
<% content_for :sub_navbar do %>
|
4
|
+
<div class="sub-navbar node-header hide-ios">
|
5
|
+
<div class="container">
|
6
|
+
<div class="pull-right">
|
7
|
+
<% if can? :create, Post %>
|
8
|
+
<%= link_to "提交新文章", new_post_path, class: 'btn btn-sm btn-primary' %>
|
9
|
+
<% end %>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<ul class="filter nav nav-pills">
|
13
|
+
<li class="<%= ' active' if action_name == 'index' %>">
|
14
|
+
<a href="<%= posts_path %>" data-turbolinks-action="replace">最近发布</a>
|
15
|
+
</li>
|
16
|
+
<% if can? :publish, Post %>
|
17
|
+
<li class="<%= ' active' if action_name == 'upcoming' %>">
|
18
|
+
<a href="<%= upcoming_posts_path %>" data-turbolinks-action="replace">待审核</a>
|
19
|
+
</li>
|
20
|
+
<% end %>
|
21
|
+
</ul>
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
<% end %>
|
25
|
+
|
26
|
+
<div id="post-list" class="panel panel-default post-<%= action_name %>">
|
27
|
+
<div class="panel-body">
|
28
|
+
<% if @posts.blank? %>
|
29
|
+
<div class="no-result">暂无任何文章</div>
|
30
|
+
<% else %>
|
31
|
+
<%= render partial: 'post', collection: @posts %>
|
32
|
+
<% end %>
|
33
|
+
|
34
|
+
<%= paginate @posts %>
|
35
|
+
</div>
|
36
|
+
</div>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<% title_tag @post.title %>
|
2
|
+
|
3
|
+
<div id="post-detail" class="panel panel-default">
|
4
|
+
<div class="panel-body">
|
5
|
+
<div class="post-opts">
|
6
|
+
<% if can?(:update, @post) %>
|
7
|
+
<%= link_to '编辑', edit_post_path, class: 'btn btn-sm btn-default' %>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<% if can?(:publish, @post) && @post.upcoming? %>
|
11
|
+
<%= link_to '审核通过', publish_post_path, method: 'put', class: 'btn btn-sm btn-success' %>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<% if can?(:destroy, @post) && @post.upcoming? %>
|
15
|
+
<%= link_to '删除', @post, method: 'delete', class: 'btn btn-sm btn-danger', data: { confirm: "确定要删除么?" } %>
|
16
|
+
<% end %>
|
17
|
+
</div>
|
18
|
+
<h1><%= @post.title %></h1>
|
19
|
+
<div class="post-info">
|
20
|
+
<%= user_name_tag(@post.user) %> ·
|
21
|
+
<%= timeago @post.created_at %> ·
|
22
|
+
<%= @post.hits %> 次阅读 ·
|
23
|
+
<a href="#comments"><%= @post.comments_count %> 条评论</a>
|
24
|
+
</div>
|
25
|
+
<div class="post-body markdown">
|
26
|
+
<%= markdown @post.body %>
|
27
|
+
</div>
|
28
|
+
<div class="post-actions">
|
29
|
+
<%= likeable_tag(@post) %>
|
30
|
+
</div>
|
31
|
+
</div>
|
32
|
+
</div>
|
33
|
+
|
34
|
+
<div id="comments">
|
35
|
+
<%= render "/shared/comments", commentable: @post %>
|
36
|
+
</div>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<% content_for :stylesheets do %>
|
2
|
+
<%= stylesheet_link_tag "homeland/press/application", media: "all" %>
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<% content_for :javascripts do %>
|
6
|
+
<%= javascript_include_tag "homeland/press/application" %>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<% content_for :main do %>
|
10
|
+
<script type="text/javascript">
|
11
|
+
$('.navbar-nav .nav-plugin-press').addClass("active");
|
12
|
+
</script>
|
13
|
+
<div id="homeland-press">
|
14
|
+
<%= yield %>
|
15
|
+
</div>
|
16
|
+
<% end %>
|
17
|
+
|
18
|
+
<%= render template: "/layouts/application" %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"zh-CN":
|
2
|
+
plugin:
|
3
|
+
press: "头条"
|
4
|
+
activerecord:
|
5
|
+
models:
|
6
|
+
post: "文章"
|
7
|
+
attributes:
|
8
|
+
post:
|
9
|
+
title: 标题
|
10
|
+
slug: Slug
|
11
|
+
body: 正文
|
12
|
+
summary: 摘要
|
13
|
+
simple_form:
|
14
|
+
hints:
|
15
|
+
post:
|
16
|
+
title: "请给文章起一个简短准确的标题,注意正确的英文名词拼写、大小写!"
|
17
|
+
slug: "文章的 URL 名称,也可以保持为空,这样将会用文章编号代替,例如 /posts/this-is-slug-for-use"
|
18
|
+
body: "用 Markdown 语法编写文章正文"
|
19
|
+
summary: "如果可以的话,用一段简短的文字描述此文的重点内容"
|
20
|
+
placeholders:
|
21
|
+
post:
|
22
|
+
slug: ""
|
data/config/routes.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
class CreatePosts < ActiveRecord::Migration[5.0]
|
2
|
+
def change
|
3
|
+
create_table :posts do |t|
|
4
|
+
t.string :title, null: false
|
5
|
+
t.string :slug, null: false
|
6
|
+
t.text :body, null: false
|
7
|
+
t.string :summary, limit: 5000
|
8
|
+
t.string :banner
|
9
|
+
t.integer :user_id
|
10
|
+
t.integer :likes_count, null: false, default: 0
|
11
|
+
t.integer :comments_count, null: false, default: 0
|
12
|
+
t.integer :status, null: false, default: 0
|
13
|
+
t.datetime :published_at, null: false
|
14
|
+
|
15
|
+
t.timestamps
|
16
|
+
end
|
17
|
+
|
18
|
+
add_index :posts, :slug
|
19
|
+
add_index :posts, :status
|
20
|
+
add_index :posts, :published_at
|
21
|
+
add_index :posts, :user_id
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Homeland
|
2
|
+
module Press
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
isolate_namespace Homeland::Press
|
5
|
+
|
6
|
+
initializer 'homeland_press.init' do |app|
|
7
|
+
Homeland.register_plugin do |plugin|
|
8
|
+
plugin.name = 'press'
|
9
|
+
plugin.display_name = '头条'
|
10
|
+
plugin.description = 'A Press plugin for Homeland.'
|
11
|
+
plugin.navbar_link = true
|
12
|
+
plugin.user_menu_link = true
|
13
|
+
plugin.root_path = "/posts"
|
14
|
+
plugin.spec_path = config.root.join('spec')
|
15
|
+
end
|
16
|
+
|
17
|
+
User.send :include, Homeland::Press::UserMixin
|
18
|
+
|
19
|
+
app.routes.prepend do
|
20
|
+
mount Homeland::Press::Engine, at: '/posts'
|
21
|
+
end
|
22
|
+
|
23
|
+
app.config.paths["db/migrate"].concat(config.paths["db/migrate"].expanded)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: homeland-press
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason Lee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-27 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: Press/Blog/News plugin for Homeland, this gem is only work on Homeland
|
28
|
+
Application.
|
29
|
+
email:
|
30
|
+
- huacnlee@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- MIT-LICENSE
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- app/assets/config/homeland_press_manifest.js
|
39
|
+
- app/assets/javascripts/homeland/press/application.coffee
|
40
|
+
- app/assets/stylesheets/homeland/press/application.scss
|
41
|
+
- app/controllers/homeland/press/application_controller.rb
|
42
|
+
- app/controllers/homeland/press/posts_controller.rb
|
43
|
+
- app/helpers/homeland/press/application_helper.rb
|
44
|
+
- app/models/homeland/press/ability.rb
|
45
|
+
- app/models/post.rb
|
46
|
+
- app/views/homeland/press/posts/_form.html.erb
|
47
|
+
- app/views/homeland/press/posts/_post.html.erb
|
48
|
+
- app/views/homeland/press/posts/edit.html.erb
|
49
|
+
- app/views/homeland/press/posts/index.html.erb
|
50
|
+
- app/views/homeland/press/posts/new.html.erb
|
51
|
+
- app/views/homeland/press/posts/show.html.erb
|
52
|
+
- app/views/layouts/homeland/press/application.html.erb
|
53
|
+
- app/views/notifications/_press_published.html.erb
|
54
|
+
- config/locales/homeland.press.zh-CN.yml
|
55
|
+
- config/routes.rb
|
56
|
+
- db/migrate/20170227080755_create_posts.rb
|
57
|
+
- lib/homeland/press.rb
|
58
|
+
- lib/homeland/press/engine.rb
|
59
|
+
- lib/homeland/press/user_mixin.rb
|
60
|
+
- lib/homeland/press/version.rb
|
61
|
+
homepage: https://github.com/ruby-china/homeland-press
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.6.8
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Press/Blog/News plugin for Homeland.
|
85
|
+
test_files: []
|