Sha256: d182eebb8dbd9390e2329d44655e29b00f2b1429224fa23aa9b76743e0ed8f29

Contents?: true

Size: 1.25 KB

Versions: 11

Compression:

Stored size: 1.25 KB

Contents

# -*- coding: utf-8 -*-
require 'rack/utils'
require 'singleton'

module Jpmobile
  module Rack
    module_function
    def mount_middlewares
      # 漢字コード・絵文字フィルター
      ::Rails.application.middleware.insert_before('ActionDispatch::ParamsParser', Jpmobile::Rack::ParamsFilter)
      ::Rails.application.middleware.insert_before('ActionDispatch::ParamsParser', Jpmobile::Rack::Filter)
    end
  end

  class Configuration
    include Singleton

    attr_accessor :form_accept_charset_conversion
    attr_accessor :smart_phone_emoticon_compatibility

    def initialize
      @form_accept_charset_conversion     = false
      @smart_phone_emoticon_compatibility = false
    end

    def mobile_filter
      ::Jpmobile::Rack.mount_middlewares
    end
  end
end

module Rack
  class Request
    def params
      self.GET.merge(self.POST)
    end
  end

  # UTF-8 で match させるようにする
  module Utils
    def escape(s)
      s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/) {
        '%'+$1.unpack('H2'*bytesize($1)).join('%').upcase
      }.tr(' ', '+')
    end
    module_function :escape
    def unescape(s)
      s.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/){
        [$1.delete('%')].pack('H*')
      }
    end
    module_function :unescape
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
jpmobile-3.0.9 lib/jpmobile/rack.rb
jpmobile-3.0.8 lib/jpmobile/rack.rb
jpmobile-3.0.7 lib/jpmobile/rack.rb
jpmobile-2.0.11 lib/jpmobile/rack.rb
jpmobile-1.0.12 lib/jpmobile/rack.rb
jpmobile-1.0.11 lib/jpmobile/rack.rb
jpmobile-2.0.10 lib/jpmobile/rack.rb
jpmobile-3.0.6 lib/jpmobile/rack.rb
jpmobile-1.0.10 lib/jpmobile/rack.rb
jpmobile-2.0.9 lib/jpmobile/rack.rb
jpmobile-3.0.5 lib/jpmobile/rack.rb