Skip to content

Commit

Permalink
Refactored.
Browse files Browse the repository at this point in the history
  • Loading branch information
bananagi committed Mar 19, 2011
1 parent 32d8e95 commit a27c274
Show file tree
Hide file tree
Showing 40 changed files with 716 additions and 1,108 deletions.
12 changes: 7 additions & 5 deletions lib/opensocial-wap.rb
@@ -1,13 +1,15 @@
require 'opensocial-wap/config/oauth'
require 'opensocial-wap/config/url'
require 'opensocial-wap/config/session'
require 'opensocial-wap/oauth/helpers/base'
require 'opensocial-wap/oauth/helpers/basic_helper'
require 'opensocial-wap/oauth/request_proxy/basic_rack_request'
require 'opensocial-wap/oauth/client/helper'
require 'opensocial-wap/oauth/client'

require 'opensocial-wap/routing/url_formatter'
require 'opensocial-wap/verifiers/opensocial_verifier'
require 'opensocial-wap/rack/opensocial_oauth'
require 'opensocial-wap/rack/opensocial_oauth_request_proxy'
require 'opensocial-wap/rack/request'
require 'opensocial-wap/client'
require 'opensocial-wap/client/helper'


if defined?(::Rails::Railtie)
require 'opensocial-wap/railtie'
Expand Down
30 changes: 8 additions & 22 deletions lib/opensocial-wap/action_controller/controller_hook.rb
Expand Up @@ -8,38 +8,24 @@ class Base
helper ::OpensocialWap::Helpers::FormTagHelper
helper ::OpensocialWap::Helpers::AssetTagHelper

DEFAULT_OPENSOCIAL_WAP_URL_OPTIONS = { :url_format => nil, :params => {} }.freeze
class_inheritable_accessor :opensocial_wap_enabled

class << self

# OpenSocial WAP Extension 用のURLを構築することを、コントローラに指定する.
def opensocial_wap(options = {})
def opensocial_wap
self.opensocial_wap_enabled = true
init_opensocoal_wap_options(options)

include ::OpensocialWap::ActionController::Redirecting
end

def opensocial_wap_options
@opensocial_wap_options ||= init_opensocoal_wap_options
@opensocial_wap_options.dup
end

# イニシャライザでの OpenSocial WAP Extension 設定に、コントローラ毎設定をマージして、
# クラスインスタンス変数にセットする.
def init_opensocoal_wap_options(options = nil)
@opensocial_wap_options = DEFAULT_OPENSOCIAL_WAP_URL_OPTIONS.dup
# アプリケーション初期化時に、Application#config にセットした設定をマージ.
app_config = Rails.application.config
if app_config.respond_to?(:opensocial_wap)
@opensocial_wap_options.merge!(app_config.opensocial_wap[:url_options] || {})
end
# コントローラレベルでの設定をマージ.
if options
@opensocial_wap_options.merge!(options)
@url_setgings = app_config.opensocial_wap[:url]
end
@opensocial_wap_options

include ::OpensocialWap::ActionController::Redirecting
end

def url_settings
@url_setgings
end
end
end
Expand Down
13 changes: 6 additions & 7 deletions lib/opensocial-wap/action_controller/metal/redirecting.rb
Expand Up @@ -6,24 +6,23 @@ module ActionController
module Redirecting
include ::OpensocialWap::Routing::UrlFor

# Opensocial WAP Extension の URL設定中の :redirect_url_format で指定した形式のURLにリダイレクトする.
# Opensocial WAP Extension の URL設定中の :redirect で指定した形式のURLにリダイレクトする.
def redirect_to(options = {}, response_status = {})
super
end

private

# :redirect_url_format で指定した形式のURLを返す.
# opensocial_wap[:url].redirect で指定した形式のURLを返す.
def _compute_redirect_to_location(options)
url = super
url_settings = nil
if (self.class.respond_to? :opensocial_wap_enabled) && (self.class.opensocial_wap_enabled == true)
osw_options = self.class.opensocial_wap_options.dup
redirect_url_format = osw_options[:redirect_url_format]
if redirect_url_format
osw_options[:url_format] = redirect_url_format
if self.class.url_settings
url_settings = self.class.url_settings.redirect
end
end
url_for(url, osw_options)
url_for(url, url_settings)
end
end
end
Expand Down
145 changes: 0 additions & 145 deletions lib/opensocial-wap/client.rb

This file was deleted.

19 changes: 0 additions & 19 deletions lib/opensocial-wap/client/helper.rb

This file was deleted.

8 changes: 4 additions & 4 deletions lib/opensocial-wap/config/oauth.rb
Expand Up @@ -10,11 +10,11 @@ def initialize
self.freeze
end

def oauth_helper(helper = nil)
if helper
@oauth_helper = helper
def helper_class(klass = nil)
if klass
@helper_class = klass
end
@oauth_helper
@helper_class
end

def api_endpoint(endpoint = nil)
Expand Down
21 changes: 0 additions & 21 deletions lib/opensocial-wap/config/session.rb

This file was deleted.

10 changes: 5 additions & 5 deletions lib/opensocial-wap/helpers/asset_tag_helper.rb
Expand Up @@ -8,14 +8,14 @@ module AssetTagHelper
include ::ActionView::Helpers::AssetTagHelper

# compute_public_path を上書き.
# コントローラ内もしくは初期化時に、:public_path_format が指定されていれば、パスを
# 初期化時に、opensocial_wap[:url] でURL形式が指定されていれば、パスを
# OpenSocial 用のものに書き換える.
def compute_public_path(source, dir, ext = nil, include_host = true)
path = super
osw_options = default_osw_options
if osw_options[:public_path_format]
osw_options[:url_format] = osw_options[:public_path_format]
path = url_for(path, osw_options)
if default_url_settings
# public_path で指定されているオプションを使用する.
url_settings = default_url_settings.public_path
path = url_for(path, url_settings)
end
path
end
Expand Down
10 changes: 4 additions & 6 deletions lib/opensocial-wap/helpers/base.rb
Expand Up @@ -4,12 +4,10 @@ module OpensocialWap
module Helpers
module Base

# Retrieves the options for url generation from the corresponding controller.
#
# イニシャライザもしくはコントローラで設定したURL生成オプションを取得して返す.
def default_osw_options
if controller.class.respond_to? 'opensocial_wap_options'
controller.class.opensocial_wap_options || {}
# イニシャライザで設定したURL生成オプションを取得して返す.
def default_url_settings
if controller.class.respond_to? 'url_settings'
controller.class.url_settings
else
nil
end
Expand Down
26 changes: 14 additions & 12 deletions lib/opensocial-wap/helpers/form_tag_helper.rb
Expand Up @@ -8,11 +8,11 @@ module FormTagHelper
include UrlHelper

# Rails オリジナル実装の form_tag と同じ.
# ただし、options ハッシュに、:osw_options ハッシュを渡すことができる.
# osw_options の優先順位は、options ハッシュ > コントローラで指定した値 > イニシャライザで指定した値.
# ただし、options ハッシュに、:url_settings をキーにした値を渡すことができる.
# url_settings の優先順位は、options ハッシュ > イニシャライザで指定した値.
#
# == 例
# form_tag('/posts', :osw_options => {:url_format=>:query})
# form_tag('/posts', :url_settings => {:format=>:query})
# # => <form action="?=url....." method="post">
#
def form_tag(url_for_options = {}, options = {}, *parameters_for_url, &block)
Expand All @@ -31,13 +31,13 @@ def html_options_for_form(url_for_options, options, *parameters_for_url)

options.stringify_keys.tap do |html_options|
html_options["enctype"] = "multipart/form-data" if html_options.delete("multipart")
# ows_options を、options から取り出す.
osw_options = extract_osw_options(html_options)
# url_settings を、options から取り出す.
url_settings = extract_url_settings(html_options)

# The following URL is unescaped, this is just a hash of options, and it is the
# responsability of the caller to escape all the values.
#html_options["action"] = url_for(url_for_options, *parameters_for_url)
html_options["action"] = url_for(url_for_options, osw_options)
html_options["action"] = url_for(url_for_options, url_settings)
html_options["accept-charset"] = accept_charset
html_options["data-remote"] = true if html_options.delete("remote")
end
Expand All @@ -46,15 +46,17 @@ def html_options_for_form(url_for_options, options, *parameters_for_url)
private

# html_options から Opensocial WAP用オプションを取り出す.
def extract_osw_options(html_options)
def extract_url_settings(html_options)
url_settings = nil
if html_options
osw_options = html_options.delete("opensocial_wap")
url_settings = html_options.delete("url_settings")
end
# コントローラで opensocial_wap が呼ばれていれば、osw_options を有効にする.
if controller.class.opensocial_wap_enabled
osw_options ||= {}
if !url_settings && default_url_settings
# コントローラで opensocial_wap が呼ばれていれば、url_settings を有効にする.
# form_tag 系では、:default の設定を使用する.
url_settings = default_url_settings.default
end
osw_options
url_settings
end
end
end
Expand Down

0 comments on commit a27c274

Please sign in to comment.