ungarbled 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ungarbled.rb +1 -0
- data/lib/ungarbled/action_controller_ext.rb +3 -3
- data/lib/ungarbled/encoder.rb +6 -6
- data/lib/ungarbled/encoder/japanese.rb +1 -1
- data/lib/ungarbled/middleware.rb +39 -0
- data/lib/ungarbled/railtie.rb +1 -1
- data/lib/ungarbled/version.rb +1 -1
- metadata +8 -7
- data/README.rdoc +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e27966865cca49ad7de84c0ab1dfdcf2ee4fb0b1
|
4
|
+
data.tar.gz: 3b1392f104e2e7ba89544f18e7a625c94e328b2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f766260edcff6afe18de4838f7403010114c48da1385092f8fb081118b457b4349fe32fc69a4cf80e69248d92b1a8fea6fd08805278dda839da44b64eae5ff3c
|
7
|
+
data.tar.gz: 73ed2120afc81be6d58b2d9758f3c7831864c5db61d29e51ef4fbcbd4870351cc98e5afec9e24c5415c6a7f8ebf74c2908923d2e653a1aca99043fdc3ab3b245
|
data/lib/ungarbled.rb
CHANGED
@@ -15,9 +15,9 @@ module Ungarbled
|
|
15
15
|
|
16
16
|
def filename_encoder(options)
|
17
17
|
@filename_encoder ||= Ungarbled::Encoder.new(browser)
|
18
|
-
|
19
|
-
Rails.configuration.ungarbled.
|
20
|
-
@filename_encoder.tap { |e| e.
|
18
|
+
lang = options[:lang] ||
|
19
|
+
Rails.configuration.ungarbled.default_lang
|
20
|
+
@filename_encoder.tap { |e| e.lang = lang }
|
21
21
|
end
|
22
22
|
|
23
23
|
def encode_filename(filename, options = {})
|
data/lib/ungarbled/encoder.rb
CHANGED
@@ -9,18 +9,18 @@ module Ungarbled
|
|
9
9
|
def initialize(browser, options = {})
|
10
10
|
@browser = browser
|
11
11
|
@options = options
|
12
|
-
self.
|
12
|
+
self.lang = options.delete(:lang) || :base
|
13
13
|
end
|
14
14
|
|
15
|
-
attr_accessor :
|
15
|
+
attr_accessor :lang, :delegate
|
16
16
|
|
17
|
-
def
|
18
|
-
@delegate = "::Ungarbled::Encoder::#{
|
17
|
+
def lang=(lang)
|
18
|
+
@delegate = "::Ungarbled::Encoder::#{lang.to_s.classify}"
|
19
19
|
.constantize.send(:new, @browser, @options)
|
20
|
-
@
|
20
|
+
@lang = lang.to_sym
|
21
21
|
rescue NameError
|
22
22
|
raise NotImplementedError,
|
23
|
-
"Encoder #{
|
23
|
+
"Encoder #{lang.to_s.classify} is not implemented"
|
24
24
|
end
|
25
25
|
|
26
26
|
def method_missing(name, *args)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Ungarbled
|
2
|
+
class Middleware
|
3
|
+
DISPOSITION_KEY = 'Content-Disposition'
|
4
|
+
DISPOSITION_REGEX = /^(?:attachment|inline); filename="(.+)"$/
|
5
|
+
|
6
|
+
def initialize(app, options = {})
|
7
|
+
@app = app
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
req = Rack::Request.new(env)
|
13
|
+
browser = Browser.new(
|
14
|
+
ua: req.user_agent,
|
15
|
+
accept_language: req.env['HTTP_ACCEPT_LANGUAGE']
|
16
|
+
)
|
17
|
+
encoder = Ungarbled::Encoder.new(browser, @options)
|
18
|
+
status, headers, res = @app.call(env)
|
19
|
+
disposition = headers[DISPOSITION_KEY]
|
20
|
+
|
21
|
+
if sending_file?(headers) && disposition
|
22
|
+
headers[DISPOSITION_KEY] =
|
23
|
+
encode_disposition(encoder, disposition)
|
24
|
+
end
|
25
|
+
|
26
|
+
[status, headers, res]
|
27
|
+
end
|
28
|
+
|
29
|
+
def sending_file?(headers)
|
30
|
+
headers['Content-Transfer-Encoding'] = 'binary'
|
31
|
+
end
|
32
|
+
|
33
|
+
def encode_disposition(encoder, disposition)
|
34
|
+
replacing = DISPOSITION_REGEX.match(disposition)[1]
|
35
|
+
replaced = encoder.encode(replacing)
|
36
|
+
disposition.gsub(replacing, replaced)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/ungarbled/railtie.rb
CHANGED
@@ -6,7 +6,7 @@ module Ungarbled
|
|
6
6
|
config.ungarbled = ActiveSupport::OrderedOptions.new
|
7
7
|
|
8
8
|
# Now only Japanese is supported
|
9
|
-
config.ungarbled.
|
9
|
+
config.ungarbled.default_lang = :japanese
|
10
10
|
|
11
11
|
initializer 'ungarbled' do
|
12
12
|
::ActionController::Base.send :include, Ungarbled::ActionControllerExt
|
data/lib/ungarbled/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ungarbled
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yukihiro hara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: browser
|
@@ -122,7 +122,8 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
-
description:
|
125
|
+
description: Ungarble multibyte download filename on certain platform. Rails integration
|
126
|
+
included.
|
126
127
|
email:
|
127
128
|
- yukihr@gmail.com
|
128
129
|
executables: []
|
@@ -130,13 +131,13 @@ extensions: []
|
|
130
131
|
extra_rdoc_files: []
|
131
132
|
files:
|
132
133
|
- MIT-LICENSE
|
133
|
-
- README.rdoc
|
134
134
|
- Rakefile
|
135
135
|
- lib/ungarbled.rb
|
136
136
|
- lib/ungarbled/action_controller_ext.rb
|
137
137
|
- lib/ungarbled/encoder.rb
|
138
138
|
- lib/ungarbled/encoder/base.rb
|
139
139
|
- lib/ungarbled/encoder/japanese.rb
|
140
|
+
- lib/ungarbled/middleware.rb
|
140
141
|
- lib/ungarbled/railtie.rb
|
141
142
|
- lib/ungarbled/version.rb
|
142
143
|
homepage: https://github.com/yukihr/ungarbled
|
@@ -149,9 +150,9 @@ require_paths:
|
|
149
150
|
- lib
|
150
151
|
required_ruby_version: !ruby/object:Gem::Requirement
|
151
152
|
requirements:
|
152
|
-
- - "
|
153
|
+
- - "~>"
|
153
154
|
- !ruby/object:Gem::Version
|
154
|
-
version: '
|
155
|
+
version: '1.9'
|
155
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
157
|
requirements:
|
157
158
|
- - ">="
|
@@ -162,6 +163,6 @@ rubyforge_project:
|
|
162
163
|
rubygems_version: 2.2.0
|
163
164
|
signing_key:
|
164
165
|
specification_version: 4
|
165
|
-
summary:
|
166
|
+
summary: Ungarble filename for downloads.
|
166
167
|
test_files: []
|
167
168
|
has_rdoc:
|
data/README.rdoc
DELETED