homeland 0.0.9 → 1.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +139 -43
  4. data/Rakefile +23 -0
  5. data/app/assets/javascripts/homeland/application.coffee +31 -0
  6. data/app/assets/javascripts/homeland/bootstrap.min.js +7 -0
  7. data/{lib/generators/homeland/install/templates/javascripts → app/assets/javascripts/homeland}/jquery.timeago.js +13 -13
  8. data/app/assets/javascripts/homeland/tether.min.js +1 -0
  9. data/app/assets/stylesheets/homeland/application.scss +114 -0
  10. data/app/assets/stylesheets/homeland/bootstrap-theme.scss +165 -0
  11. data/app/assets/stylesheets/homeland/bootstrap.min.css +5 -0
  12. data/app/assets/stylesheets/homeland/markdown.scss +13 -0
  13. data/app/assets/stylesheets/homeland/tether.min.css +1 -0
  14. data/app/controllers/homeland/application_controller.rb +37 -12
  15. data/app/controllers/homeland/replies_controller.rb +25 -11
  16. data/app/controllers/homeland/topics_controller.rb +50 -58
  17. data/app/helpers/homeland/application_helper.rb +45 -13
  18. data/app/models/homeland/concerns/markdown_body.rb +17 -0
  19. data/app/models/homeland/concerns/pagination.rb +14 -0
  20. data/app/models/homeland/concerns/soft_delete.rb +29 -0
  21. data/app/models/homeland/concerns/user_methods.rb +23 -0
  22. data/app/models/homeland/node.rb +10 -25
  23. data/app/models/homeland/reply.rb +16 -17
  24. data/app/models/homeland/topic.rb +19 -29
  25. data/app/views/homeland/replies/_reply.html.erb +35 -0
  26. data/app/views/homeland/replies/edit.html.erb +17 -27
  27. data/app/views/homeland/shared/_error_messages.html.erb +2 -4
  28. data/app/views/homeland/topics/_form.html.erb +21 -24
  29. data/app/views/homeland/topics/_node_info.html.erb +9 -0
  30. data/app/views/homeland/topics/_reply_form.html.erb +16 -0
  31. data/app/views/homeland/topics/_topic.html.erb +17 -26
  32. data/app/views/homeland/topics/edit.html.erb +6 -10
  33. data/app/views/homeland/topics/index.html.erb +28 -51
  34. data/app/views/homeland/topics/new.html.erb +5 -10
  35. data/app/views/homeland/topics/show.html.erb +16 -89
  36. data/app/views/layouts/homeland/application.html.erb +42 -0
  37. data/config/locales/homeland.en.yml +40 -0
  38. data/config/locales/homeland.zh-CN.yml +8 -0
  39. data/config/routes.rb +6 -8
  40. data/db/migrate/20160321125035_create_homeland_nodes.rb +15 -0
  41. data/db/migrate/20160321125610_create_homeland_topics.rb +25 -0
  42. data/db/migrate/20160321125920_create_homeland_replies.rb +16 -0
  43. data/db/migrate/20160322062228_add_reply_to_id_to_replies.rb +7 -0
  44. data/lib/generators/homeland/controllers_generator.rb +14 -0
  45. data/lib/generators/homeland/i18n_generator.rb +22 -0
  46. data/lib/generators/homeland/install_generator.rb +8 -54
  47. data/lib/generators/homeland/templates/config/initializers/homeland.rb +34 -0
  48. data/lib/generators/homeland/views_generator.rb +3 -10
  49. data/lib/homeland.rb +29 -3
  50. data/lib/homeland/action_view/will_paginate.rb +38 -0
  51. data/lib/homeland/configuration.rb +66 -0
  52. data/lib/homeland/engine.rb +4 -27
  53. data/lib/homeland/markup.rb +17 -0
  54. data/lib/homeland/markup/base.rb +11 -0
  55. data/lib/homeland/markup/html.rb +12 -0
  56. data/lib/homeland/markup/markdown.rb +17 -0
  57. data/lib/homeland/markup/simple.rb +14 -0
  58. data/lib/homeland/version.rb +3 -0
  59. data/lib/tasks/homeland_tasks.rake +4 -0
  60. metadata +119 -38
  61. data/Changelogs.md +0 -29
  62. data/app/assets/images/reply.png +0 -0
  63. data/app/assets/javascripts/homeland.coffee +0 -51
  64. data/app/assets/stylesheets/homeland.scss +0 -100
  65. data/app/helpers/homeland/topics_helper.rb +0 -14
  66. data/app/models/homeland/section.rb +0 -21
  67. data/app/views/homeland/topics/_base.html.erb +0 -4
  68. data/app/views/homeland/topics/_sidebar.html.erb +0 -49
  69. data/app/views/homeland/topics/feed.builder +0 -20
  70. data/lib/generators/homeland/install/templates/images/jquery.chosen.png +0 -0
  71. data/lib/generators/homeland/install/templates/initializer.rb +0 -8
  72. data/lib/generators/homeland/install/templates/javascripts/jquery.chosen.js +0 -898
  73. data/lib/generators/homeland/install/templates/javascripts/jquery.hotkeys.js +0 -99
  74. data/lib/generators/homeland/install/templates/locales/homeland.zh-CN.yml +0 -14
  75. data/lib/generators/homeland/install/templates/stylesheets/jquery.chosen.scss +0 -367
  76. data/lib/homeland/setting.rb +0 -37
@@ -0,0 +1,9 @@
1
+ <% if @node %>
2
+ <div class="card">
3
+ <div class="card-block">
4
+ <h4 class="card-title"><%= node_tag(@node) %></h4>
5
+ <p class="card-text"><%= simple_format @node.description %></p>
6
+ <a href="<%= homeland.new_topic_path %>" class="btn btn-primary"><%= t('homeland.nav.new') %></a>
7
+ </div>
8
+ </div>
9
+ <% end %>
@@ -0,0 +1,16 @@
1
+ <nav id="reply-panel">
2
+ <div class="container">
3
+ <%= form_for(Homeland::Reply.new, url: reply_topic_path(@topic.id)) do |f| %>
4
+ <%= f.hidden_field :reply_to_id %>
5
+
6
+ <div class="row">
7
+ <div class="col-sm-8">
8
+ <%= f.text_area :body, class: 'form-control', rows: 5, placeholder: t('homeland.topics.type_reply') %>
9
+ </div>
10
+ <div class="col-sm-2">
11
+ <button type="submit" class="btn btn-primary"><%= t('homeland.submit') %></button>
12
+ </div>
13
+ </div>
14
+ <% end %>
15
+ </div>
16
+ </nav>
@@ -1,26 +1,17 @@
1
- <div class="topic topic_line">
2
- <div class="pull-left avatar">
3
- <%= user_avatar_tag(topic.user) %>
4
- </div>
5
- <div class="right_info">
6
- <div class="pull-right replies">
7
- <a href="<%= topic_path(topic.id) %>#reply<%= topic.replies_count %>" class="count">
8
- <%= topic.replies_count %>
9
- </a>
10
- </div>
11
- <div class="infos">
12
- <div class="title"><a href="<%= topic_path(topic) %>#reply<%= topic.replies_count %>" title="<%= topic.title %>"><%= truncate(topic.title, :length => 100) %></a></div>
13
- <div class="info leader">
14
- <%= user_name_tag(topic.user) %>
15
- <a href="<%= node_topics_path(topic.node_id) %>"><%= topic.node.name %></a> 中发起
16
- </div>
17
- <div class="info time">
18
- <% if topic.last_reply_user.blank? %>
19
- 发布于 <%= timeago(topic.created_at) %>
20
- <% else %>
21
- 最后由 <%= user_name_tag(topic.last_reply_user) %> 回复于 <%= timeago(topic.replied_at) %>
22
- <% end %>
23
- </div>
24
- </div>
25
- </div>
26
- </div>
1
+ <tr class="topic">
2
+ <td class="title">
3
+ <%= link_to topic.title, homeland.topic_path(topic) %>
4
+ </td>
5
+ <td class="node">
6
+ <%= node_tag(topic.node) %>
7
+ </td>
8
+ <td class="author">
9
+ <%= user_avatar_tag(topic) %>
10
+ </td>
11
+ <td class="replies">
12
+ <%= topic.replies_count %>
13
+ </td>
14
+ <td class="activity">
15
+ <%= timeago topic.activity_at %>
16
+ </td>
17
+ </tr>
@@ -1,11 +1,7 @@
1
- <%= render 'base' %>
2
- <% content_for :breadcrumb do %>
3
- <li class="active">修改</li>
4
- <% end %>
1
+ <ol class="breadcrumb">
2
+ <li><a href="<%= homeland.root_path %>"><%= t('homeland.nav.home') %></a></li>
3
+ <li><a href="<%= homeland.topic_path(@topic) %>" title="<%= @topic.title %>"><%= truncate @topic.title, length: 20 %></a></li>
4
+ <li class="active"><%= t('homeland.nav.edit') %></li>
5
+ </ol>
5
6
 
6
- <%= render 'sidebar' %>
7
- <div class="content">
8
- <div class="box">
9
- <%= render 'form' %>
10
- </div>
11
- </div>
7
+ <%= render 'form' %>
@@ -1,53 +1,30 @@
1
- <%= render 'base' %>
2
- <% content_for :breadcrumb do %>
3
- <% if @node.blank? %>
4
- <li>首页</li>
5
- <% else %>
6
- <li><%= @node.name %></li>
7
- <% end %>
8
- <% end %>
9
- <%= render 'sidebar' %>
1
+ <div class="topics">
2
+ <%= render 'node_info' %>
10
3
 
11
- <div class="content">
12
- <div class="box">
13
- <% if !@node.blank? %>
14
- <div id="node_info">
15
- <p>
16
- <h1><%= @node.name %></h1>
17
- <span class="total">共有 <%= @node.topics_count %> 个讨论主题</span>
18
- </p>
19
- </div>
20
- <% else %>
21
- <h1 class="bbs_name">论坛</h1>
22
- <% end %>
23
- <div class="topics">
24
- <%= render :partial => "topic", :collection => @topics %>
25
- </div>
26
-
27
- <% if params[:action] == "index" %>
28
- <div class="more">
29
- <a href="<%= recent_topics_path %>">查看更多最近发布的帖子...</a>
30
- </div>
31
- <% elsif params[:action] == "node" or params[:action] == "search" %>
32
- <%= will_paginate @topics %>
33
- <% end %>
34
- </div>
35
- <% if params[:action] == "index" %>
36
- <div id="sections" class="box">
37
- <h2>节点分类导航</h2>
38
- <ul>
39
- <% @sections.each do |section| %>
40
- <li>
41
- <label><%= section.name %></label>
42
- <div class="items">
43
- <% section.nodes.each do |node| %>
44
- <a href="<%= node_topics_path(node.id) %>" title="<%= node.name %>"><%= node.name %></a>
45
- <% end %>
46
- </div>
47
- </li>
48
- <% end %>
49
- </ul>
50
- </div>
51
- <% end %>
52
- </div>
4
+ <table class="table">
5
+ <thead class="thead-default">
6
+ <tr class="topic">
7
+ <th class="title"><%= t('activerecord.attributes.homeland/topic.title')%></th>
8
+ <th class="node"><%= t('activerecord.attributes.homeland/topic.node')%></th>
9
+ <th class="author"><%= t('activerecord.attributes.homeland/topic.user')%></th>
10
+ <th class="replies"><%= t('activerecord.attributes.homeland/topic.replies_count')%></th>
11
+ <th class="activity"><%= t('activerecord.attributes.homeland/topic.activity')%></th>
12
+ </tr>
13
+ </thad>
14
+ <tbody>
15
+ <% if @topics.blank? %>
16
+ <tr>
17
+ <th>
18
+ <span class="text-mutted">
19
+ <%= t('homeland.topics.empty') %>
20
+ </span>
21
+ </td>
22
+ </tr>
23
+ <% else %>
24
+ <%= render @topics %>
25
+ <% end %>
26
+ </tbody>
27
+ </table>
53
28
 
29
+ <%= homeland_paginate @topics %>
30
+ </div>
@@ -1,11 +1,6 @@
1
- <%= render 'base' %>
2
- <% content_for :breadcrumb do %>
3
- <li class="active">新建贴子</li>
4
- <% end %>
1
+ <ol class="breadcrumb">
2
+ <li><a href="<%= homeland.root_path %>"><%= t('homeland.nav.home') %></a></li>
3
+ <li class="active"><%= t('homeland.nav.new') %></li>
4
+ </ol>
5
5
 
6
- <%= render 'sidebar' %>
7
- <div class="content">
8
- <div class="box">
9
- <%= render 'form' %>
10
- </div>
11
- </div>
6
+ <%= render 'form' %>
@@ -1,94 +1,21 @@
1
- <%= render 'base' %>
2
- <%= content_for :breadcrumb do %>
3
- <li class="active">查看贴子</li>
4
- <% end %>
5
- <%= render 'sidebar' %>
6
- <div class="content">
7
- <div class="topics box">
8
- <div class="topic">
9
- <div class="pull-right avatar_large">
10
- <%= user_avatar_tag(@topic.user) %>
11
- </div>
12
- <div class="infos">
13
- <h1><%= truncate(@topic.title, :length => 100) %></h1>
14
- <div class="info leader">
15
- 由 <%= user_name_tag(@topic.user) %>
16
- 在 <a href="<%= node_topics_path(@topic.node_id) %>"><%= @topic.node.name %></a> 节点中发起
17
- </div>
18
- <div class="info time">
19
- <% if @topic.last_reply_user.blank? %>
20
- 发布于 <%= timeago(@topic.created_at) %>
21
- <% else %>
22
- 最后由 <%= user_name_tag(@topic.last_reply_user) %> 回复于 <%= timeago(@topic.replied_at) %>
23
- <% end %>
24
- </div>
25
- </div>
26
- </div>
27
- <div class="body">
28
- <%= format_topic_body(@topic.body) %>
29
- </div>
30
- <div class="tools">
31
- <% if owner?(@topic) %>
32
- <a href="<%= edit_topic_path(@topic.id) %>">修改</a>
33
- <%= link_to "删除", topic_path(@topic.id), :method => :delete, :confirm => "确定要删除么?" %>
34
- <% end %>
35
- </div>
36
- </div>
37
- <% if @replies.blank? %>
38
- <div class="no_result">
39
- 暂无回复。
1
+ <div class="row">
2
+ <div class="topic-detail col-lg-9">
3
+ <h1>
4
+ <%= @topic.title %>
5
+ <%= node_tag(@topic.node) %>
6
+ </h1>
7
+
8
+ <div class="topic-content">
9
+ <%= render partial: 'homeland/replies/reply', locals: { reply: @topic } %>
40
10
  </div>
41
- <% else %>
42
- <div id="replies" class="box">
43
- <div class="total">
44
- 截止 <%= l @topic.replied_at, :format => :long %>, 共收到 <%= @topic.replies_count %> 条回复
11
+
12
+ <div class="replies">
13
+ <%= render @replies %>
45
14
  </div>
46
- <% @replies.each_with_index do |reply,i| %>
47
- <div class="reply" id="reply<%= i + 1 %>">
48
- <div class="pull-left face"><%= user_avatar_tag(reply.user) %></div>
49
- <div class="infos">
50
- <div class="info clearfix">
51
- <span class="name"><%= user_name_tag(reply.user) %></span>
52
- <span class="time"><%= i + 1 %>楼, 回复于 <%= timeago(reply.created_at) %>
53
- <% if owner?(reply) %>
54
- <a href="<%= edit_reply_path(reply.id) %>">修改</a>
55
- <% end %>
56
- </span>
57
- </div>
58
- <div class="body">
59
- <%= format_topic_body(reply.body) %>
60
- </div>
61
- </div>
62
- </div>
63
- <% end %>
64
- <script type="text/javascript">
65
- $(document).ready(function(){
66
- atDatas = []
67
- $(".reply .name a").text(function(idx,text) { atDatas.push(text) });
68
- $('#reply_body').atWho("@",{'data':atDatas});
69
- })
70
- </script>
71
- </div>
72
- <% end %>
73
- <% if current_user %>
74
- <div id="reply" class="form box">
75
- <h4>回复</h4>
76
- <%= form_for(Homeland::Reply.new,:url => reply_topic_path(params[:id])) do |f| %>
77
- <div class="pull-right">
78
- <button type="submit" class="btn btn-primary">提交回复</button><br />
79
- <span class="help-inline">Ctrl+Enter</span>
80
- </div>
81
- <div class="clearfix">
82
- <%= f.text_area :body,:class => "span10", :rows => "4" %>
83
- </div>
84
15
 
85
- <% end %>
86
16
  </div>
87
- <% else %>
88
- <div id="reply" class="form box">
89
- <div style="padding:20px;">
90
- 需要 <a href='/account/sign_in' class="btn btn-primary">登录</a> 后回复方可回复, 如果你还没有账号 <a href="/account/sign_up" class="btn btn-success"> 点击这里注册</a>。
91
- </div>
92
- </div>
93
- <% end %>
17
+
18
+
94
19
  </div>
20
+
21
+ <%= render 'reply_form' %>
@@ -0,0 +1,42 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= @page_title %></title>
5
+ <%= stylesheet_link_tag "homeland/application", media: "all" %>
6
+ <%= javascript_include_tag "homeland/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <nav class="navbar navbar-light bg-faded">
12
+ <div class="container">
13
+ <a class="navbar-brand" href="<%= main_app.root_path %>"><%= t('homeland.nav.home') %></a>
14
+ <ul class="nav navbar-nav main-nav">
15
+ <li class="nav-item<%= ' active' if controller_name == 'topics' and action_name == 'index' %>">
16
+ <a class="nav-link" href="<%= homeland.root_path %>"><%= t('homeland.nav.latest') %></a>
17
+ </li>
18
+ <li class="nav-item<%= ' active' if controller_name == 'topics' and action_name == 'features' %>">
19
+ <a class="nav-link" href="<%= homeland.features_topics_path %>"><%= t('homeland.nav.features') %></a>
20
+ </li>
21
+ <li class="nav-item<%= ' active' if controller_name == 'topics' and action_name == 'recent' %>">
22
+ <a class="nav-link" href="<%= homeland.recent_topics_path %>"><%= t('homeland.nav.recent') %></a>
23
+ </li>
24
+ </ul>
25
+ <ul class="nav navbar-nav pull-xs-right">
26
+ <li class="nav-item<%= ' active' if controller_name == 'topics' and action_name == 'new' %>">
27
+ <a class="btn btn-primary-outline" href="<%= homeland.new_topic_path %>"><i class="fa fa-plus"></i> <%= t('homeland.nav.new') %></a>
28
+ </li>
29
+ </ul>
30
+ </div>
31
+ </nav>
32
+
33
+ <div class="main-layout">
34
+ <div class="container">
35
+ <%= notice_message %>
36
+
37
+ <%= yield %>
38
+ </div>
39
+ </div>
40
+
41
+ </body>
42
+ </html>
@@ -0,0 +1,40 @@
1
+ en:
2
+ activerecord:
3
+ models:
4
+ homeland/topic: "Topic"
5
+ homeland/reply: "Reply"
6
+ attributes:
7
+ homeland/topic:
8
+ title: "Subject"
9
+ body: "Content"
10
+ node: "Channel"
11
+ replies_count: "Replies"
12
+ user: "Author"
13
+ activity: "Activity"
14
+ homeland/reply:
15
+ body: "Content"
16
+ homeland:
17
+ nav:
18
+ home: 'Homeland'
19
+ latest: 'Latest'
20
+ features: 'Features'
21
+ recent: 'Recent'
22
+ node: "Channel"
23
+ new: "New Topic"
24
+ edit: 'Edit'
25
+ topics:
26
+ empty: 'Ther have no subject created.'
27
+ type_reply: 'Write your reply here...'
28
+ reply_to: "Reply To"
29
+ submiting: 'Submiting...'
30
+ submit: 'Submit'
31
+ cancel: 'Cancel'
32
+ reply: 'Reply'
33
+ access_denied: "Access denied."
34
+ are_you_sure_to_delete: "Are you sure to delete?"
35
+ topic_created: "Topic created success."
36
+ topic_updated: "Topic updated success."
37
+ topic_deleted: "Topic deleted success."
38
+ reply_created: "Reply created success."
39
+ reply_deleted: "Reply deleted success."
40
+ reply_updated: "Reply updated success."
@@ -0,0 +1,8 @@
1
+ zh-CN:
2
+ homeland:
3
+ nav:
4
+ home: '网站首页'
5
+ topics: '讨论区'
6
+ submiting: '提交中...'
7
+ submit: '提交'
8
+ cancel: '取消'
@@ -1,16 +1,14 @@
1
1
  Homeland::Engine.routes.draw do
2
- root :to => "topics#index"
3
- get "topics/node_:id", :to => "topics#node", :as => :node_topics
4
- resources :topics do
2
+ root to: 'topics#index'
3
+ get 'c/:id', to: 'topics#node', as: :node_topics
4
+ resources :topics, path: 't' do
5
5
  member do
6
6
  post :reply
7
7
  end
8
8
  collection do
9
- get :node
10
- get :search
11
- get :feed
12
9
  get :recent
10
+ get :features
13
11
  end
14
12
  end
15
- resources :replies
16
- end
13
+ resources :replies, path: 'r'
14
+ end
@@ -0,0 +1,15 @@
1
+ class CreateHomelandNodes < ActiveRecord::Migration
2
+ def change
3
+ create_table :homeland_nodes do |t|
4
+ t.string :name, null: false
5
+ t.string :description
6
+ t.string :color
7
+ t.integer :sort, default: 0, null: false
8
+ t.integer :topics_count, null: false, default: 0
9
+
10
+ t.timestamps null: false
11
+ end
12
+
13
+ add_index :homeland_nodes, 'sort'
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ class CreateHomelandTopics < ActiveRecord::Migration
2
+ def change
3
+ create_table :homeland_topics do |t|
4
+ t.integer :node_id, null: false
5
+ t.integer :user_id, null: false
6
+ t.string :title, null: false
7
+ t.text :body
8
+ t.text :body_html
9
+ t.integer :last_reply_id
10
+ t.integer :last_reply_user_id
11
+ t.integer :last_active_mark, null: false, default: 0
12
+ t.datetime :replied_at
13
+ t.integer :replies_count, null: false, default: 0
14
+ t.datetime :deleted_at
15
+
16
+ t.timestamps null: false
17
+ end
18
+
19
+ add_index :homeland_topics, :deleted_at
20
+ add_index :homeland_topics, [:node_id, :deleted_at]
21
+ add_index :homeland_topics, :user_id
22
+ add_index :homeland_topics, [:last_active_mark, :deleted_at]
23
+ add_index :homeland_topics, [:node_id, :last_active_mark]
24
+ end
25
+ end