From 3f2a0c5efa5f3e1eb06414a892b6ea1b6178d1c7 Mon Sep 17 00:00:00 2001 From: Shin-ichiro OGAWA Date: Tue, 13 Sep 2011 12:37:56 +0900 Subject: [PATCH] Change charset with hankaku_filter :input => true gh-26 --- lib/jpmobile/filter.rb | 7 ++++++- .../controllers/hankaku_input_filter_controller.rb | 3 +++ .../hankaku_input_filter/with_charset.html.erb | 1 + .../app/views/layouts/with_charset.html.erb | 13 +++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/rails/overrides/app/views/hankaku_input_filter/with_charset.html.erb create mode 100644 test/rails/overrides/app/views/layouts/with_charset.html.erb diff --git a/lib/jpmobile/filter.rb b/lib/jpmobile/filter.rb index b10e2cf8..9c409e43 100644 --- a/lib/jpmobile/filter.rb +++ b/lib/jpmobile/filter.rb @@ -40,6 +40,9 @@ def before(controller, options = {}) # 内部コードから外部コードに変換 def after(controller, options = {}) if apply_outgoing?(controller) and controller.response.body.is_a?(String) + if controller.request.mobile? + options.merge!(:charset => controller.request.mobile.default_charset) + end controller.response.body = to_external(controller.response.body, options) end end @@ -64,7 +67,9 @@ def to_external(str, options = {}) doc = convert_text_content(doc) - doc.to_html.gsub("\xc2\xa0"," ") + html = doc.to_html.gsub("\xc2\xa0"," ") + html = html.gsub(/charset=[a-z0-9\-]+/i, "charset=#{options[:charset]}") if options[:charset] + html end end diff --git a/test/rails/overrides/app/controllers/hankaku_input_filter_controller.rb b/test/rails/overrides/app/controllers/hankaku_input_filter_controller.rb index a40d8bca..69980c02 100644 --- a/test/rails/overrides/app/controllers/hankaku_input_filter_controller.rb +++ b/test/rails/overrides/app/controllers/hankaku_input_filter_controller.rb @@ -4,4 +4,7 @@ class HankakuInputFilterController < FilterControllerBase def index_xhtml render "index_xhtml", :layout => "xhtml" end + + def with_charset + end end diff --git a/test/rails/overrides/app/views/hankaku_input_filter/with_charset.html.erb b/test/rails/overrides/app/views/hankaku_input_filter/with_charset.html.erb new file mode 100644 index 00000000..3ae88b4c --- /dev/null +++ b/test/rails/overrides/app/views/hankaku_input_filter/with_charset.html.erb @@ -0,0 +1 @@ +<%= link_to 'リンク', '#' -%> diff --git a/test/rails/overrides/app/views/layouts/with_charset.html.erb b/test/rails/overrides/app/views/layouts/with_charset.html.erb new file mode 100644 index 00000000..e56ed4e7 --- /dev/null +++ b/test/rails/overrides/app/views/layouts/with_charset.html.erb @@ -0,0 +1,13 @@ + + + + RailsRoot + + <%= csrf_meta_tag %> + + + +<%= yield %> + + +