Class: Jpmobile::Filter
- Inherits:
-
Object
- Object
- Jpmobile::Filter
- Defined in:
- lib/jpmobile/rack/filter.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Filter
constructor
A new instance of Filter.
Constructor Details
#initialize(app) ⇒ Filter
Returns a new instance of Filter.
6 7 8 |
# File 'lib/jpmobile/rack/filter.rb', line 6 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/jpmobile/rack/filter.rb', line 10 def call(env) # 入力を保存 mobile = env['rack.jpmobile'] status, env, response = @app.call(env) if env['Content-Type']&.match?(%r{text/html|application/xhtml\+xml}) if mobile && mobile.apply_filter? type, charset = env['Content-Type'].split(/;\s*charset=/) body = response_to_body(response) body = body.gsub(/<input name="utf8" type="hidden" value="#{[0x2713].pack("U")}"[^>]*?>/, ' ') body = body.gsub(/<input name="utf8" type="hidden" value="✓"[^>]*?>/, ' ') response, charset = mobile.to_external(body, type, charset) if type && charset env['Content-Type'] = "#{type}; charset=#{charset}" end elsif Jpmobile::Emoticon.pc_emoticon? body = response_to_body(response) response = Jpmobile::Emoticon.emoticons_to_image(body) end end new_response = ::Rack::Response.new(response, status, env) new_response.finish end |