Skip to content

Commit

Permalink
Remove homeland-jobs, use zip plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Feb 4, 2020
1 parent d36daf1 commit 4f0679a
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 59 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ gem "exception-track"
gem "status-page"

# Homeland Plugins
gem "homeland-jobs"
gem "homeland-note"
gem "homeland-press"
gem "homeland-site"
Expand Down
5 changes: 2 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ GEM
activesupport (>= 4.2.0)
hashie (3.6.0)
hiredis (0.6.3)
homeland-jobs (0.3.1)
rails
homeland-note (0.2.2)
rails
homeland-press (0.4.2)
Expand Down Expand Up @@ -469,7 +467,6 @@ DEPENDENCIES
font-awesome-rails
form-select
hiredis
homeland-jobs
homeland-note
homeland-press
homeland-site
Expand Down Expand Up @@ -524,3 +521,5 @@ DEPENDENCIES
twemoji
uglifier

BUNDLED WITH
2.1.4
24 changes: 11 additions & 13 deletions app/controllers/admin/plugins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,21 @@ def show
end

def create
tmp = params[:file].tempfile
FileUtils.move tmp.path, Rails.root.join("plugins")
basename = File.basename(tmp.path)
zip_filename = Rails.root.join("plugins", basename)
`cd plugins; unzip -o #{zip_filename}`
Homeland.reboot
redirect_to admin_plugins_path, notice: "插件安装成功,如列表没有更新,请再次刷新页面。"
ensure
FileUtils.rm_f(zip_filename)
if Homeland::Plugin.install(params[:file])
Homeland.reboot
redirect_to admin_plugins_path, notice: "插件安装成功,如列表没有更新,请再次刷新页面。"
else
redirect_to admin_plugins_path, alert: "插件安装失败,请检查 ZIP 包确定是否正确。"
end
end

def destroy
if @plugin.uninstallable?
FileUtils.rm_rf(@plugin.source_path)
if @plugin.destroy
Homeland.reboot
redirect_to admin_plugins_path, notice: "卸载成功,如列表没有更新,请再次刷新页面"
else
redirect_to admin_plugins_path, alert: "卸载失败。"
end
Homeland.reboot
redirect_to admin_plugins_path, notice: "卸载成功,如列表没有更新,请再次刷新页面"
end

private
Expand Down
10 changes: 0 additions & 10 deletions app/controllers/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def show
@user_like_reply_ids = current_user&.like_reply_ids_by_replies(@replies) || []

check_current_user_status_for_topic
set_special_node_active_menu
end

def new
Expand Down Expand Up @@ -180,13 +179,4 @@ def check_current_user_status_for_topic
# 是否收藏
@has_favorited = current_user.favorite_topic?(@topic)
end

def set_special_node_active_menu
if Setting.has_module?(:jobs)
# FIXME: Monkey Patch for homeland-jobs
if @node&.id == 25
@current = ["/jobs"]
end
end
end
end
6 changes: 1 addition & 5 deletions app/models/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Setting < RailsSettings::Base

# = Basic
field :app_name, default: (ENV["app_name"] || "Homeland"), readonly: true
# Plugin module, [topic,home,wiki,site,note,team,github,editor.code,press,jobs]
# Plugin module, [topic,home,wiki,site,note,team,github,editor.code,press]
field :modules, default: (ENV["modules"] || "all"), type: :array, readonly: true
# User profile module default: all [company,twitter,website,tagline,location,alipay,paypal,qq,weibo,wechat,douban,dingding,aliwangwang,facebook,instagram,dribbble,battle_tag,psn_id,steam_id]
field :profile_fields, default: (ENV["profile_fields"] || "all"), type: :array, readonly: true
Expand Down Expand Up @@ -144,10 +144,6 @@ class Setting < RailsSettings::Base
field :google_analytics_key, default: ""

class << self
def modules
["home", "topic", "jobs", "wiki", "site", "note", "team", "github", "editor.code"]
end

def editable_keys
EDITABLE_KEYS
end
Expand Down
29 changes: 9 additions & 20 deletions app/views/topics/_node_info.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@
<div class="summary<%= ' collapse' if node.collapse_summary? %>" id="node-summary">
<%= sanitize_markdown node.summary_html %>
</div>

<% if node.name == '招聘' %>
<hr />
<ul class="nav nav-pills prefix-filter">
<% cache "prefixes", expires_in: 7.days do %>
<% Location.hot.limit(12).each do |prefix| %>
<li class="nav-item"><%= link_to prefix.name, homeland_jobs.jobs_path(location: prefix.name), class: "nav-link" %></li>
<% end %>
<% end %>
</ul>
<% end %>
<% else %>
<%= render 'node_selector' %>
<ul class="filter nav nav-pills">
Expand All @@ -40,17 +29,17 @@
<a href="<%= main_app.popular_topics_path %>" data-turbolinks-action="replace">优质帖子</a>
</li>
<% if admin? %>
<li class="<%= ' active' if action_name == 'banned' %>">
<%= link_to('已屏蔽', main_app.banned_topics_path, data: { 'turbolinks-action': 'replace' }) %>
</li>
<li class="<%= ' active' if action_name == 'banned' %>">
<%= link_to('已屏蔽', main_app.banned_topics_path, data: { 'turbolinks-action': 'replace' }) %>
</li>
<% end %>
<% if !mobile? %>
<li class="<%= ' active' if action_name == 'no_reply' %>">
<%= link_to('无人问津', main_app.no_reply_topics_path, data: { 'turbolinks-action': 'replace' }) %>
</li>
<li class="<%= ' active' if action_name == 'last_reply' %>">
<%= link_to('最新回复', main_app.last_reply_topics_path, data: { 'turbolinks-action': 'replace' }) %>
</li>
<li class="<%= ' active' if action_name == 'no_reply' %>">
<%= link_to('无人问津', main_app.no_reply_topics_path, data: { 'turbolinks-action': 'replace' }) %>
</li>
<li class="<%= ' active' if action_name == 'last_reply' %>">
<%= link_to('最新回复', main_app.last_reply_topics_path, data: { 'turbolinks-action': 'replace' }) %>
</li>
<% end %>
<li class="<%= ' active' if action_name == 'last' %>">
<%= link_to('最新发布', main_app.last_topics_path, data: { 'turbolinks-action': 'replace' }) %>
Expand Down
11 changes: 5 additions & 6 deletions lib/homeland.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ def find_plugin(name)
end

def boot
ActiveSupport.on_load(:after_initialize) do
puts "=> Booting Homeland" unless Rails.env.test?
Homeland::Plugin.boot
puts "=> Plugins: #{Homeland.plugins.collect(&:name).join(", ")}" unless Rails.env.test?
@@boot_at = Time.now
end
puts "=> Booting Homeland" unless Rails.env.test?
Homeland::Plugin.boot
puts "=> Plugins: #{Homeland.plugins.collect(&:name).join(", ")}" unless Rails.env.test?
@@boot_at = Time.now
# end
end

def reboot
Expand Down
31 changes: 31 additions & 0 deletions lib/homeland/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def <=>(other)
Setting.modules.index(self.name).to_i <=> Setting.modules.index(other.name).to_i
end

def destroy
return false unless self.uninstallable?
FileUtils.rm_rf(self.source_path)
true
end

class << self
# Booting Homeland plugins
def boot
Expand All @@ -54,6 +60,31 @@ def boot
require boot_file
end
end

# Must run on after Rails initialize
# Because of the plugins wants to override the autoload classes.
# ActiveSupport.on_load(:after_initialize) do
ActiveSupport.on_load(:after_initialize) do
Homeland.plugins.each do |plugin|
begin
require plugin.name
rescue LoadError
end
end
end
end

# Install a new plugin via zip rack_file
# Homeland::Plugin.install(params[:file])
def install(zip_file)
tmp = zip_file.tempfile
FileUtils.move tmp.path, Rails.root.join("plugins")
basename = File.basename(tmp.path)
zip_filename = Rails.root.join("plugins", basename)
`cd plugins; unzip -o #{zip_filename}`
true
ensure
FileUtils.rm_f(zip_filename) if zip_filename
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/plugins/plugin_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Homeland::PluginTest < ActiveSupport::TestCase
refute_equal nil, Homeland.plugins.sort.find { |p| p.name == "foo" }
refute_equal nil, Homeland.plugins.sort.find { |p| p.name == "dar" }

Setting.stub(:modules, ["home", "topic", "jobs", "wiki", "site", "note", "team", "github", "editor.code"]) do
Setting.stub(:modules, ["home", "topic", "wiki", "site", "note", "team", "github", "editor.code"]) do
assert_kind_of Array, Homeland.plugins.sort
end
end
Expand Down

0 comments on commit 4f0679a

Please sign in to comment.