homeland-site 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +16 -14
- data/app/controllers/homeland/site/admin/site_nodes_controller.rb +13 -11
- data/app/controllers/homeland/site/admin/sites_controller.rb +10 -8
- data/app/controllers/homeland/site/application_controller.rb +2 -0
- data/app/controllers/homeland/site/sites_controller.rb +7 -5
- data/app/helpers/homeland/site/application_helper.rb +2 -0
- data/app/models/homeland/site/ability.rb +15 -13
- data/app/models/site.rb +6 -12
- data/app/models/site_node.rb +2 -0
- data/config/routes.rb +2 -0
- data/lib/homeland/site.rb +2 -0
- data/lib/homeland/site/engine.rb +6 -4
- data/lib/homeland/site/version.rb +5 -3
- data/lib/tasks/homeland/site_tasks.rake +2 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40c71bf6deffd894bf5261deb02a8ec60b106f3a066afd16d2b8504af0385234
|
4
|
+
data.tar.gz: a9603686ccf52a4abfc0bcbd542e340f0ae39126c1b126555aaa1ced2ff07549
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e258f8bc22fdfb98fb95b1f1c7abb001275b29dec6b68639f797613569384be4fc50ee241646882656fa882e1d4f5d53ebfaa28261beab10ce35914b0474eb3
|
7
|
+
data.tar.gz: 4449d9f8e0b0f3b44216bb3c10c0488f4fc316e973a3435c534ba86e10850bc6399530d6dbc4007e2d1bfbf600bf691c37d6d41969f26a03b70f2a57387580c0
|
data/Rakefile
CHANGED
@@ -1,34 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
begin
|
2
|
-
require
|
4
|
+
require "bundler/setup"
|
3
5
|
rescue LoadError
|
4
|
-
puts
|
6
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
7
|
end
|
6
8
|
|
7
|
-
require
|
9
|
+
require "rdoc/task"
|
8
10
|
|
9
11
|
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
-
rdoc.rdoc_dir =
|
11
|
-
rdoc.title =
|
12
|
-
rdoc.options <<
|
13
|
-
rdoc.rdoc_files.include(
|
14
|
-
rdoc.rdoc_files.include(
|
12
|
+
rdoc.rdoc_dir = "rdoc"
|
13
|
+
rdoc.title = "Homeland::Site"
|
14
|
+
rdoc.options << "--line-numbers"
|
15
|
+
rdoc.rdoc_files.include("README.md")
|
16
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
15
17
|
end
|
16
18
|
|
17
19
|
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
-
load
|
20
|
+
load "rails/tasks/engine.rake"
|
19
21
|
|
20
22
|
|
21
|
-
load
|
23
|
+
load "rails/tasks/statistics.rake"
|
22
24
|
|
23
25
|
|
24
26
|
|
25
|
-
require
|
27
|
+
require "bundler/gem_tasks"
|
26
28
|
|
27
|
-
require
|
29
|
+
require "rake/testtask"
|
28
30
|
|
29
31
|
Rake::TestTask.new(:test) do |t|
|
30
|
-
t.libs <<
|
31
|
-
t.pattern =
|
32
|
+
t.libs << "test"
|
33
|
+
t.pattern = "test/**/*_test.rb"
|
32
34
|
t.verbose = false
|
33
35
|
end
|
34
36
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Homeland::Site
|
2
4
|
module Admin
|
3
5
|
class SiteNodesController < ::Admin::ApplicationController
|
@@ -22,34 +24,34 @@ module Homeland::Site
|
|
22
24
|
@site_node = SiteNode.new(site_node_params)
|
23
25
|
|
24
26
|
if @site_node.save
|
25
|
-
redirect_to(admin_site_nodes_path, notice:
|
27
|
+
redirect_to(admin_site_nodes_path, notice: "Site node 创建成功。")
|
26
28
|
else
|
27
|
-
render action:
|
29
|
+
render action: "new"
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
33
|
def update
|
32
34
|
if @site_node.update(site_node_params)
|
33
|
-
redirect_to(admin_site_nodes_path, notice:
|
35
|
+
redirect_to(admin_site_nodes_path, notice: "Site node 更新成功。")
|
34
36
|
else
|
35
|
-
render action:
|
37
|
+
render action: "edit"
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
41
|
def destroy
|
40
42
|
@site_node.destroy
|
41
|
-
redirect_to(admin_site_nodes_path, notice:
|
43
|
+
redirect_to(admin_site_nodes_path, notice: "删除成功。")
|
42
44
|
end
|
43
45
|
|
44
46
|
private
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
def site_node_params
|
49
|
+
params[:site_node].permit!
|
50
|
+
end
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
|
52
|
+
def set_site_node
|
53
|
+
@site_node = SiteNode.find(params[:id])
|
54
|
+
end
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Homeland::Site
|
2
4
|
module Admin
|
3
5
|
class SitesController < ::Admin::ApplicationController
|
@@ -7,7 +9,7 @@ module Homeland::Site
|
|
7
9
|
def index
|
8
10
|
@sites = ::Site.unscoped.recent.includes(:user, :site_node)
|
9
11
|
if params[:q].present?
|
10
|
-
@sites = @sites.where(
|
12
|
+
@sites = @sites.where("name LIKE ?", "%#{params[:q]}%")
|
11
13
|
end
|
12
14
|
@sites = @sites.page(params[:page])
|
13
15
|
end
|
@@ -26,17 +28,17 @@ module Homeland::Site
|
|
26
28
|
@site = ::Site.new(params[:site].permit!)
|
27
29
|
|
28
30
|
if @site.save
|
29
|
-
redirect_to(admin_sites_path, notice:
|
31
|
+
redirect_to(admin_sites_path, notice: "Site 创建成功。")
|
30
32
|
else
|
31
|
-
render action:
|
33
|
+
render action: "new"
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
35
37
|
def update
|
36
38
|
if @site.update(params[:site].permit!)
|
37
|
-
redirect_to(admin_sites_path, notice:
|
39
|
+
redirect_to(admin_sites_path, notice: "Site 更新成功。")
|
38
40
|
else
|
39
|
-
render action:
|
41
|
+
render action: "edit"
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
@@ -52,9 +54,9 @@ module Homeland::Site
|
|
52
54
|
|
53
55
|
private
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
-
|
57
|
+
def set_site
|
58
|
+
@site = ::Site.unscoped.find(params[:id])
|
59
|
+
end
|
58
60
|
end
|
59
61
|
end
|
60
62
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Homeland::Site
|
2
4
|
class SitesController < Homeland::Site::ApplicationController
|
3
5
|
def index
|
@@ -14,16 +16,16 @@ module Homeland::Site
|
|
14
16
|
@site = ::Site.new(site_params)
|
15
17
|
@site.user_id = current_user.id
|
16
18
|
if @site.save
|
17
|
-
redirect_to(sites_path, notice:
|
19
|
+
redirect_to(sites_path, notice: "提交成功。谢谢。")
|
18
20
|
else
|
19
|
-
render action:
|
21
|
+
render action: "new"
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
25
|
private
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
def site_params
|
28
|
+
params.require(:site).permit(:name, :desc, :url, :favorite, :site_node_id)
|
29
|
+
end
|
28
30
|
end
|
29
31
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Homeland::Site
|
2
4
|
class Ability
|
3
5
|
include CanCan::Ability
|
@@ -17,20 +19,20 @@ module Homeland::Site
|
|
17
19
|
|
18
20
|
protected
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
# 普通会员权限
|
23
|
+
def roles_for_site_editors
|
24
|
+
can :create, ::Site
|
25
|
+
basic_read_only
|
26
|
+
end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
# 未登录用户权限
|
29
|
+
def roles_for_anonymous
|
30
|
+
cannot :manage, ::Site
|
31
|
+
basic_read_only
|
32
|
+
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
def basic_read_only
|
35
|
+
can :read, ::Site
|
36
|
+
end
|
35
37
|
end
|
36
38
|
end
|
data/app/models/site.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Site < ApplicationRecord
|
2
4
|
include SoftDelete
|
3
5
|
|
@@ -5,7 +7,7 @@ class Site < ApplicationRecord
|
|
5
7
|
belongs_to :user
|
6
8
|
|
7
9
|
validates :url, :name, :site_node_id, presence: true
|
8
|
-
validates :url, uniqueness: true
|
10
|
+
validates :url, format: { with: /https?:\/\/[\S]+/ }, uniqueness: true
|
9
11
|
|
10
12
|
after_save :update_cache_version
|
11
13
|
after_destroy :update_cache_version
|
@@ -14,17 +16,9 @@ class Site < ApplicationRecord
|
|
14
16
|
CacheVersion.sites_updated_at = Time.now.to_i
|
15
17
|
end
|
16
18
|
|
17
|
-
before_validation :fix_urls
|
18
|
-
def fix_urls
|
19
|
-
unless url.blank?
|
20
|
-
url = self.url.gsub(%r{http[s]{0,1}://}, '').split('/').join('/')
|
21
|
-
self.url = "http://#{url}"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
19
|
def favicon_url
|
26
|
-
return
|
27
|
-
domain = url.
|
28
|
-
"https://favicon.
|
20
|
+
return "" if url.blank?
|
21
|
+
domain = URI.parse(url).host.sub("www.", "")
|
22
|
+
"https://favicon.ruby-china.com/ip2/#{domain}.ico"
|
29
23
|
end
|
30
24
|
end
|
data/app/models/site_node.rb
CHANGED
data/config/routes.rb
CHANGED
data/lib/homeland/site.rb
CHANGED
data/lib/homeland/site/engine.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Homeland::Site
|
2
4
|
class Engine < ::Rails::Engine
|
3
5
|
isolate_namespace Homeland::Site
|
4
6
|
|
5
|
-
initializer
|
6
|
-
next unless Setting.has_module?(:site)
|
7
|
+
initializer "homeland.site.init" do |app|
|
8
|
+
next unless (defined? Setting) && Setting.has_module?(:site)
|
7
9
|
Homeland.register_plugin do |plugin|
|
8
10
|
plugin.name = Homeland::Site::NAME
|
9
|
-
plugin.display_name =
|
11
|
+
plugin.display_name = "酷站"
|
10
12
|
plugin.version = Homeland::Site::VERSION
|
11
13
|
plugin.description = Homeland::Site::DESCRIPTION
|
12
14
|
plugin.navbar_link = true
|
@@ -16,7 +18,7 @@ module Homeland::Site
|
|
16
18
|
end
|
17
19
|
|
18
20
|
app.routes.prepend do
|
19
|
-
mount Homeland::Site::Engine =>
|
21
|
+
mount Homeland::Site::Engine => "/"
|
20
22
|
end
|
21
23
|
app.config.paths["db/migrate"].concat(config.paths["db/migrate"].expanded)
|
22
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: homeland-site
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -98,8 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
|
-
|
102
|
-
rubygems_version: 2.7.6
|
101
|
+
rubygems_version: 3.0.3
|
103
102
|
signing_key:
|
104
103
|
specification_version: 4
|
105
104
|
summary: Site plugin for Homeland
|