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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d1b94bb5556d9af3cc47d69d51a73730473dc3713c74e1cd0e8c6a5a3743632
4
- data.tar.gz: fe10814918a2471d20f423a30aa5764669c36b454bd2d2d7c5199d7d0e6c09cb
3
+ metadata.gz: 40c71bf6deffd894bf5261deb02a8ec60b106f3a066afd16d2b8504af0385234
4
+ data.tar.gz: a9603686ccf52a4abfc0bcbd542e340f0ae39126c1b126555aaa1ced2ff07549
5
5
  SHA512:
6
- metadata.gz: d880752a1d77960818fff5290007a9070352a9091dad078a89abe846d92806435d1bb5178e23f5eead04a6ff56b8ca31b9b459d7340aa8f4a50ac4311a967c00
7
- data.tar.gz: 8ffec9aa3b4fa0a9ff78384be5f9713b95491ba2fb1bf6fa0d8106ece9e44db6512d62294d848ccd495a31018a42481ef86395a2428009025e074b900428ebf0
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 'bundler/setup'
4
+ require "bundler/setup"
3
5
  rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
5
7
  end
6
8
 
7
- require 'rdoc/task'
9
+ require "rdoc/task"
8
10
 
9
11
  RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'Homeland::Site'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.md')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
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 'rails/tasks/engine.rake'
20
+ load "rails/tasks/engine.rake"
19
21
 
20
22
 
21
- load 'rails/tasks/statistics.rake'
23
+ load "rails/tasks/statistics.rake"
22
24
 
23
25
 
24
26
 
25
- require 'bundler/gem_tasks'
27
+ require "bundler/gem_tasks"
26
28
 
27
- require 'rake/testtask'
29
+ require "rake/testtask"
28
30
 
29
31
  Rake::TestTask.new(:test) do |t|
30
- t.libs << 'test'
31
- t.pattern = 'test/**/*_test.rb'
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: 'Site node 创建成功。')
27
+ redirect_to(admin_site_nodes_path, notice: "Site node 创建成功。")
26
28
  else
27
- render action: 'new'
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: 'Site node 更新成功。')
35
+ redirect_to(admin_site_nodes_path, notice: "Site node 更新成功。")
34
36
  else
35
- render action: 'edit'
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
- def site_node_params
47
- params[:site_node].permit!
48
- end
48
+ def site_node_params
49
+ params[:site_node].permit!
50
+ end
49
51
 
50
- def set_site_node
51
- @site_node = SiteNode.find(params[:id])
52
- end
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('name LIKE ?', "%#{params[:q]}%")
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: 'Site 创建成功。')
31
+ redirect_to(admin_sites_path, notice: "Site 创建成功。")
30
32
  else
31
- render action: 'new'
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: 'Site 更新成功。')
39
+ redirect_to(admin_sites_path, notice: "Site 更新成功。")
38
40
  else
39
- render action: 'edit'
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
- def set_site
56
- @site = ::Site.unscoped.find(params[:id])
57
- end
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 ApplicationController < ::ApplicationController
3
5
  protect_from_forgery with: :exception
@@ -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: 'new'
21
+ render action: "new"
20
22
  end
21
23
  end
22
24
 
23
25
  private
24
26
 
25
- def site_params
26
- params.require(:site).permit(:name, :desc, :url, :favorite, :site_node_id)
27
- end
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
2
4
  module Site
3
5
  module ApplicationHelper
@@ -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
- def roles_for_site_editors
22
- can :create, ::Site
23
- basic_read_only
24
- end
22
+ # 普通会员权限
23
+ def roles_for_site_editors
24
+ can :create, ::Site
25
+ basic_read_only
26
+ end
25
27
 
26
- # 未登录用户权限
27
- def roles_for_anonymous
28
- cannot :manage, ::Site
29
- basic_read_only
30
- end
28
+ # 未登录用户权限
29
+ def roles_for_anonymous
30
+ cannot :manage, ::Site
31
+ basic_read_only
32
+ end
31
33
 
32
- def basic_read_only
33
- can :read, ::Site
34
- end
34
+ def basic_read_only
35
+ can :read, ::Site
36
+ end
35
37
  end
36
38
  end
@@ -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 '' if url.blank?
27
- domain = url.gsub('http://', '')
28
- "https://favicon.b0.upaiyun.com/ip2/#{domain}.ico"
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class SiteNode < ApplicationRecord
2
4
  second_level_cache expires_in: 2.weeks
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Homeland::Site::Engine.routes.draw do
2
4
  resources :sites
3
5
  namespace :admin do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "homeland/site/version"
2
4
  require "homeland/site/engine"
3
5
 
@@ -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 'homeland.site.init' do |app|
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
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Homeland
2
4
  module Site
3
- VERSION = '0.2.1'
4
- NAME = 'site'
5
- DESCRIPTION = 'Site for Homeland.'
5
+ VERSION = "0.3.0"
6
+ NAME = "site"
7
+ DESCRIPTION = "Site for Homeland."
6
8
  end
7
9
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # desc "Explaining what the task does"
2
4
  # task :homeland_site do
3
5
  # # Task goes here
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.2.1
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: 2018-10-26 00:00:00.000000000 Z
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
- rubyforge_project:
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