From da7ccafc2fc495220110a0fa28d8dab2c665bbb1 Mon Sep 17 00:00:00 2001 From: SHIMOMURA Sho Date: Sat, 7 Sep 2013 23:41:26 +0900 Subject: [PATCH] refactor desktop notification plugin refs #140 --- .../lib/desktopnotification.rb | 35 ++++--------------- .../spec/lib/desktopnotification_spec.rb | 25 ------------- 2 files changed, 6 insertions(+), 54 deletions(-) delete mode 100644 plugins/as_desktopnotification/spec/lib/desktopnotification_spec.rb diff --git a/plugins/as_desktopnotification/lib/desktopnotification.rb b/plugins/as_desktopnotification/lib/desktopnotification.rb index 9a1866da6..5e6a2bd14 100644 --- a/plugins/as_desktopnotification/lib/desktopnotification.rb +++ b/plugins/as_desktopnotification/lib/desktopnotification.rb @@ -1,32 +1,9 @@ class DesktopnotificationListener < AsakusaSatellite::Hook::Listener - def read_js(filename) - js_path = Rails.root.join 'plugins/as_desktopnotification/app/assets/javascripts' - File.read(js_path.join filename) - end + js_path = plugin_root + "app/assets/javascripts/" - render_on :account_setting_item, :partial => "desktopnotification_setting" - - def global_footer(context) - controller = context[:request][:controller] - action = context[:request][:action] - - case {:controller => controller, :action => action} - when {:controller => "account", :action => "index"} - <<-JS - - - JS - when {:controller => "chat", :action => "room"} - <<-JS - - - JS - end - end - - private - def render(context, options) - context[:controller].send(:render_to_string, {:locals => context}.merge(options)) - end + render_on :account_setting_item, :partial => "desktopnotification_setting" + render_on :script_in_account_setting, :jsfile => js_path + "desktopnotification.js" + render_on :script_in_account_setting, :jsfile => js_path + "desktopnotification_setting.js" + render_on :script_in_chat_room, :jsfile => js_path + "desktopnotification.js" + render_on :script_in_chat_room, :jsfile => js_path + "desktopnotification_notify.js" end - diff --git a/plugins/as_desktopnotification/spec/lib/desktopnotification_spec.rb b/plugins/as_desktopnotification/spec/lib/desktopnotification_spec.rb deleted file mode 100644 index 1b3f9d039..000000000 --- a/plugins/as_desktopnotification/spec/lib/desktopnotification_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require File.dirname(__FILE__) + '/../../../../spec/spec_helper' -require 'desktopnotification' - -describe DesktopnotificationListener do - before do - @listener = DesktopnotificationListener.new({}) - end - - describe "account/index" do - subject { - context = {:request => {:controller => "account", :action => "index"}} - @listener.global_footer(context) - } - it { should =~ /