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,16 @@
1
+ class CreateHomelandReplies < ActiveRecord::Migration
2
+ def change
3
+ create_table :homeland_replies do |t|
4
+ t.integer :user_id
5
+ t.integer :topic_id
6
+ t.text :body
7
+ t.text :body_html
8
+ t.datetime :deleted_at
9
+
10
+ t.timestamps null: false
11
+ end
12
+
13
+ add_index :homeland_replies, :user_id
14
+ add_index :homeland_replies, :topic_id
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ class AddReplyToIdToReplies < ActiveRecord::Migration
2
+ def change
3
+ add_column :homeland_replies, :reply_to_id, :integer
4
+
5
+ add_index :homeland_replies, :reply_to_id
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ # coding: utf-8
2
+ require 'rails/generators'
3
+ module Homeland
4
+ module Generators
5
+ class ControllersGenerator < Rails::Generators::Base #:nodoc:
6
+ source_root File.expand_path("../../../../app/controllers", __FILE__)
7
+ desc "Used to copy Homeland's views to your application's views."
8
+
9
+ def copy_controllers
10
+ directory 'homeland', "app/controllers/homeland"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ require 'rails/generators'
2
+ module Homeland
3
+ module Generators
4
+ class I18nGenerator < Rails::Generators::Base
5
+ desc "Create Homeland's default I18n files"
6
+ source_root File.expand_path("../../../../", __FILE__)
7
+
8
+ def add_locales
9
+ %w(en.yml zh-CN.yml).each do |fname|
10
+ path = "#{Rails.root}/config/locales/homeland.#{fname}"
11
+ if File.exists?(path)
12
+ puts "Skipping config/locales/homeland.#{fname} creation, as file already exists!"
13
+ else
14
+ puts "Adding locale (config/locales/homeland.#{fname})..."
15
+ template "config/locales/homeland.#{fname}", path
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -2,68 +2,22 @@ require 'rails/generators'
2
2
  module Homeland
3
3
  module Generators
4
4
  class InstallGenerator < Rails::Generators::Base
5
-
6
- source_root File.expand_path("../install/templates", __FILE__)
7
-
5
+ desc "Create Homeland's base files"
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
8
  def add_initializer
9
9
  path = "#{Rails.root}/config/initializers/homeland.rb"
10
10
  if File.exists?(path)
11
11
  puts "Skipping config/initializers/homeland.rb creation, as file already exists!"
12
12
  else
13
13
  puts "Adding Homeland initializer (config/initializers/homeland.rb)..."
14
- template "initializer.rb", path
15
- end
16
- end
17
-
18
- def add_javascripts
19
- %w(jquery.hotkeys.js jquery.timeago.js jquery.chosen.js).each do |fname|
20
- path = "#{Rails.root}/vendor/assets/javascripts/#{fname}"
21
- if File.exists?(path)
22
- puts "Skipping vendor/assets/javascripts/#{fname} creation, as file already exists!"
23
- else
24
- puts "Adding assets (vendor/assets/javascripts/#{fname})..."
25
- template "javascripts/#{fname}", path
26
- end
14
+ template "config/initializers/homeland.rb", path
27
15
  end
28
16
  end
29
17
 
30
- def add_stylesheets
31
- %w(jquery.chosen.scss).each do |fname|
32
- path = "#{Rails.root}/vendor/assets/stylesheets/#{fname}"
33
- if File.exists?(path)
34
- puts "Skipping vendor/assets/stylesheets/#{fname} creation, as file already exists!"
35
- else
36
- puts "Adding assets (vendor/assets/stylesheets/#{fname})..."
37
- template "stylesheets/#{fname}", path
38
- end
39
- end
40
- end
41
-
42
- def add_images
43
- %w(jquery.chosen.png).each do |fname|
44
- path = "#{Rails.root}/vendor/assets/images/#{fname}"
45
- if File.exists?(path)
46
- puts "Skipping vendor/assets/images/#{fname} creation, as file already exists!"
47
- else
48
- puts "Adding assets (vendor/assets/images/#{fname})..."
49
- template "images/#{fname}", path
50
- end
51
- end
52
- end
53
-
54
- def add_locales
55
- %w(zh-CN.yml).each do |fname|
56
- path = "#{Rails.root}/config/locales/homeland.#{fname}"
57
- if File.exists?(path)
58
- puts "Skipping config/locales/homeland.#{fname} creation, as file already exists!"
59
- else
60
- puts "Adding assets (config/locales/homeland.#{fname})..."
61
- template "locales/homeland.#{fname}", path
62
- end
63
- end
18
+ def add_migrations
19
+ exec("rails homeland:install:migrations")
64
20
  end
65
-
66
-
67
21
  end
68
- end
69
- end
22
+ end
23
+ end
@@ -0,0 +1,34 @@
1
+ # Homeland Config
2
+ Homeland.configure do
3
+ # Markup type, [:markdown, :plain, :html], defualt: :markdown
4
+ # self.markup = :markdown
5
+
6
+ # App Name
7
+ # self.app_name = 'Homeland'
8
+
9
+ # Page Size
10
+ # self.per_page = 32
11
+
12
+ # Class name of you User model, default: 'User'
13
+ # self.user_class = 'User'
14
+
15
+ # Method of user name in User model, default: 'name'
16
+ # self.user_name_method = 'name'
17
+
18
+ # Method of user avatar in User model, default: nil
19
+ # self.user_avatar_url_method = nil
20
+
21
+ # Method of User model for check user do have permission manage Homeland.
22
+ # self.user_admin_method = 'admin?'
23
+
24
+ # Method name of user profile page path, in User model, default: 'profile_url'
25
+ # self.user_profile_url_method = 'profile_url'
26
+
27
+ # authenticate_user method in your Controller, default: 'authenticate_user!'
28
+ # If you use Devise, authenticate_user! is correct
29
+ # self.authenticate_user_method = 'authenticate_user!'
30
+
31
+ # current_user method name in your Controller, default: 'current_user'
32
+ # If you use Devise, current_user is correct
33
+ # self.current_user_method = 'current_user'
34
+ end
@@ -3,19 +3,12 @@ require 'rails/generators'
3
3
  module Homeland
4
4
  module Generators
5
5
  class ViewsGenerator < Rails::Generators::Base #:nodoc:
6
- source_root File.expand_path("../../../../app/views/homeland", __FILE__)
6
+ source_root File.expand_path("../../../../app/views", __FILE__)
7
7
  desc "Used to copy Homeland's views to your application's views."
8
8
 
9
9
  def copy_views
10
- view_directory :replies
11
- view_directory :shared
12
- view_directory :topics
13
- end
14
-
15
- protected
16
-
17
- def view_directory(name)
18
- directory name.to_s, "app/views/homeland/#{name}"
10
+ directory 'homeland', "app/views/homeland"
11
+ directory 'layouts/homeland', "app/views/layouts/homeland"
19
12
  end
20
13
  end
21
14
  end
@@ -1,6 +1,32 @@
1
- require "rails"
2
- require "homeland/setting"
1
+ require "homeland/version"
3
2
  require "homeland/engine"
3
+ require 'homeland/configuration'
4
+ require 'homeland/markup'
5
+ require 'homeland/action_view/will_paginate'
6
+ require 'font-awesome-rails'
4
7
 
5
8
  module Homeland
6
- end
9
+ class << self
10
+ attr_accessor :markups
11
+
12
+ def config
13
+ return @config if defined?(@config)
14
+ @config = Configuration.new
15
+ @config.markup = :markdown
16
+ @config.app_name = 'Homeland'
17
+ @config.per_page = 32
18
+ @config.user_class = 'User'
19
+ @config.user_name_method = 'name'
20
+ @config.user_avatar_url_method = nil
21
+ @config.user_admin_method = 'admin?'
22
+ @config.user_profile_url_method = 'profile_url'
23
+ @config.authenticate_user_method = 'authenticate_user!'
24
+ @config.current_user_method = 'current_user'
25
+ @config
26
+ end
27
+
28
+ def configure(&block)
29
+ config.instance_exec(&block)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,38 @@
1
+ require 'will_paginate/view_helpers/action_view'
2
+
3
+ module Homeland
4
+ module ActionView
5
+ module WillPaginate
6
+ def homeland_paginate(collection = nil, options = {})
7
+ options, collection = collection, nil if collection.is_a? Hash
8
+ # Taken from original will_paginate code to handle if the helper is not passed a collection object.
9
+ collection ||= infer_collection_from_controller
10
+ options[:renderer] ||= BootstrapLinkRenderer
11
+ options[:inner_window] ||= 2
12
+ will_paginate(collection, options).try :html_safe
13
+ end
14
+
15
+ class BootstrapLinkRenderer < ::WillPaginate::ActionView::LinkRenderer
16
+ protected
17
+
18
+ def html_container(html)
19
+ container_attributes[:class] = 'pagination'
20
+ tag(:ul, html, container_attributes)
21
+ end
22
+
23
+ def page_number(page)
24
+ tag :li, link(page, page, rel: rel_value(page), class: 'page-link'), class: (page == current_page ? 'page-item active' : 'page-item')
25
+ end
26
+
27
+ def gap
28
+ tag :li, link('&hellip;'.html_safe, '#'), class: 'page-item disabled'
29
+ end
30
+
31
+ def previous_or_next_page(page, text, classname)
32
+ tag :li, link(text, page || '#', class: 'page-link'),
33
+ class: [(classname[0..3] if @options[:page_links]), ("page-item #{classname}" if @options[:page_links]), ('page-item disabled' unless page)].join(' ')
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,66 @@
1
+ module Homeland
2
+ class Configuration
3
+ # Markup type, [:markdown, :plain, :html], defualt: :markdown
4
+ attr_accessor :markup
5
+ # class name of you User model, default: 'User'
6
+ attr_accessor :user_class
7
+
8
+ # method of user name in User model, default: 'name'
9
+ attr_accessor :user_name_method
10
+
11
+ # method of user avatar in User model, default: nil
12
+ #
13
+ # We suggest you give Homeland image size more than 48x48 px.
14
+ #
15
+ # Example:
16
+ #
17
+ # class User
18
+ # def homeland_avatar_url
19
+ # self.avatar.url('48x48')
20
+ # end
21
+ # end
22
+ #
23
+ # config.user_avatar_url_method = :homeland_avatar_url
24
+ #
25
+ attr_accessor :user_avatar_url_method
26
+
27
+ # method in User model for check user do have permission manage Homeland.
28
+ # default: 'admin?'
29
+ #
30
+ # Example:
31
+ #
32
+ # class User
33
+ # def admin?
34
+ # Setting.forum_admins.include?(self.email)
35
+ # end
36
+ # end
37
+ attr_accessor :user_admin_method
38
+
39
+ # method name of user profile page path, in User model, default: 'profile_url'
40
+ # Example:
41
+ #
42
+ # class User
43
+ # def profile_url
44
+ # "http://www.host.com/u/#{self.username}"
45
+ # end
46
+ # end
47
+ #
48
+ # config.user_profile_url_method = 'profile_url'
49
+ attr_accessor :user_profile_url_method
50
+
51
+ # current_user method name in your Controller, default: 'current_user'
52
+ attr_accessor :current_user_method
53
+
54
+ # authenticate_user method in your Controller, default: 'authenticate_user!'
55
+ attr_accessor :authenticate_user_method
56
+
57
+ # set Homeland Application Title, default: 'Homeland'
58
+ attr_accessor :app_name
59
+
60
+ # pagination size, default: 32
61
+ attr_accessor :per_page
62
+
63
+ # Content markup, allow: [:markdown, :html, :simple], default: :markdown
64
+ attr_accessor :markup
65
+ end
66
+ end
@@ -1,32 +1,9 @@
1
- # coding: utf-8
2
- module ::Homeland
1
+ module Homeland
3
2
  class Engine < ::Rails::Engine
4
3
  isolate_namespace Homeland
5
-
6
- class << self
7
- attr_accessor :root
8
- def root
9
- @root ||= Pathname.new(File.expand_path('../../', __FILE__))
10
- end
11
- end
12
-
13
- config.to_prepare do
14
- if Homeland.user_class
15
- Homeland.user_class.has_many :topics, :class_name => "Homeland::Topic", :foreign_key => "user_id"
16
- Homeland.user_class.has_many :replies, :class_name => "Homeland::Reply", :foreign_key => "user_id"
17
- end
18
- end
19
- end
20
- end
21
-
22
4
 
23
- begin
24
- require 'kaminari'
25
- rescue LoadError
26
- begin
27
- require 'will_paginate'
28
- rescue LoadError
29
- puts "Please add the kaminari or will_paginate gem to your application's Gemfile. The Forem engine needs either kaminari or will_paginate in order to paginate."
30
- exit
5
+ initializer "homeland.i18n.load_path" do |app|
6
+ app.config.i18n.load_path += Dir["#{Rails.root}/config/locales/**/*.yml"]
7
+ end
31
8
  end
32
9
  end
@@ -0,0 +1,17 @@
1
+ require 'homeland/markup/base'
2
+ require 'homeland/markup/html'
3
+ require 'homeland/markup/markdown'
4
+ require 'homeland/markup/simple'
5
+
6
+ module Homeland
7
+ module Markup
8
+ class << self
9
+ # Convert Topic, Reply content with custom format
10
+ def render(raw)
11
+ const_name = "Homeland::Markup::#{Homeland.config.markup.to_s.classify}"
12
+ klass = const_name.constantize
13
+ klass.render(raw)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module Homeland
2
+ module Markup
3
+ class Base
4
+ class << self
5
+ def render(raw)
6
+ raise "Not implement render method."
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Homeland
2
+ module Markup
3
+ # HTML raw format
4
+ class Html < Base
5
+ class << self
6
+ def render(raw)
7
+ raw
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ module Homeland
2
+ module Markup
3
+ # Markdown format (github-markup)
4
+ class Markdown < Base
5
+ class << self
6
+ def render(raw)
7
+ begin
8
+ require 'github/markup'
9
+ rescue
10
+ puts "Error: You need add `gem 'github-markup'` into you Gemfile."
11
+ end
12
+ GitHub::Markup.render('raw.md', raw)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ module Homeland
2
+ module Markup
3
+ # Simple format, like Rails simple_format helper
4
+ class Simple < Base
5
+ class << self
6
+ include ActionView::Helpers::TextHelper
7
+
8
+ def render(raw)
9
+ simple_format(raw, {}, sanitize: false)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end