Skip to content

Commit

Permalink
Change charset with hankaku_filter :input => true jpmobilegh-26
Browse files Browse the repository at this point in the history
  • Loading branch information
rust committed Sep 13, 2011
1 parent 6485238 commit 3f2a0c5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/jpmobile/filter.rb
Expand Up @@ -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
Expand All @@ -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

Expand Down
Expand Up @@ -4,4 +4,7 @@ class HankakuInputFilterController < FilterControllerBase
def index_xhtml
render "index_xhtml", :layout => "xhtml"
end

def with_charset
end
end
@@ -0,0 +1 @@
<%= link_to 'リンク', '#' -%>
13 changes: 13 additions & 0 deletions test/rails/overrides/app/views/layouts/with_charset.html.erb
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>RailsRoot</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%= csrf_meta_tag %>
</head>
<body>

<%= yield %>

</body>
</html>

0 comments on commit 3f2a0c5

Please sign in to comment.