rails-assets-for-upyun 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/.gitignore +1 -0
- data/Gemfile +7 -0
- data/README.md +37 -0
- data/lib/rails-assets-for-upyun.rb +31 -0
- data/rails-assets-for-upyun.gemspec +18 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae55bd6d901a1f386c08e8973facec323c72ca1a
|
4
|
+
data.tar.gz: 5e9e96e06eb4db0d411f095676a4b1c86298c4cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 106f8028528be7597060259c6d139781c5ecf0b292efe2f29e952cfa9cd75aebb5aef8a87c35f6cef0f6470d89303936cce357272bb3e392323c3b46070fbf26
|
7
|
+
data.tar.gz: 2cbbc918f0bd15f62912a295430de3dfe3fff5a71c8c65b2e5fdf62be43647bfdfb508e15ca41c96cf79706a153c98c739b23314fba204f7be70b846167d81be
|
data/.gitignore
CHANGED
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -1,2 +1,39 @@
|
|
1
1
|
rails-assets-for-upyun
|
2
2
|
======================
|
3
|
+
把预编译好的静态资源发布到又拍云上(用`rake`)
|
4
|
+
|
5
|
+
## 用法
|
6
|
+
|
7
|
+
1. 在 `Gemfile` 里引用我: `gem "rails-assets-for-upyun"`
|
8
|
+
2. 首先设置好在生产环境中调用 UpYun 上的资源
|
9
|
+
|
10
|
+
```
|
11
|
+
# .. config/environments/production.rb
|
12
|
+
..
|
13
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
|
14
|
+
config.action_controller.asset_host = "awesome-bucket.b0.upaiyun.com"
|
15
|
+
..
|
16
|
+
```
|
17
|
+
|
18
|
+
3. 在 `Rakefile` 里添加一个任务(起一个最酷的名字!)
|
19
|
+
|
20
|
+
```
|
21
|
+
namespace :assets do
|
22
|
+
task :publish_my_holy_shinning_precompiled_miraculous_assets_to_the_almighty_upyun do
|
23
|
+
RailsAssetsForUpyun.publish 'awesome-bucket', 'notjustausername', 'thencomesthepassword'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
4. 然后你就可以在每次发布前(`rake assets:precompile`之后)运行一遍这个 rake 任务把他们同步到又拍云上去了。
|
29
|
+
|
30
|
+
## 卖点
|
31
|
+
|
32
|
+
* 调用 UpYun 提供的 API 进行增量发布,通过 HTTP 通讯,比 FTP 更加稳定、快速
|
33
|
+
* 使用 UpYun API 提供的签名授权,不明文传送密码,更加安全!
|
34
|
+
|
35
|
+
## 详解
|
36
|
+
|
37
|
+
```
|
38
|
+
RailsAssetsForUpyun.publish(bucket, username, password, bucket_path="/", localpath='public', upyun_ap="http://v0.api.upyun.com")
|
39
|
+
```
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class RailsAssetsForUpyun
|
2
|
+
def self.publish(bucket, username, password, bucket_path="/", localpath='public', upyun_ap="http://v0.api.upyun.com")
|
3
|
+
Dir[File.join localpath, "**", "*"].select{|f| File.file? f }.each do |file|
|
4
|
+
url = "/#{bucket}#{bucket_path}#{file[localpath.to_s.size + 1 .. -1]}"
|
5
|
+
date = Time.now.httpdate
|
6
|
+
size = RestClient.head("#{upyun_ap}#{url}", {\
|
7
|
+
Authorization: "UpYun #{username}:#{signature 'HEAD', url, date, 0, password}",
|
8
|
+
Date: date}) do |response, request, result, &block|
|
9
|
+
case response.code
|
10
|
+
when 200
|
11
|
+
response.headers[:x_upyun_file_size]
|
12
|
+
when 404
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
unless size == (file_size = File.size file)
|
17
|
+
file_content = File.read(file)
|
18
|
+
p "uploading #{file}.."
|
19
|
+
RestClient.put("#{upyun_ap}#{url}", file_content,{\
|
20
|
+
Authorization: "UpYun #{username}:#{signature 'PUT', url, date, file_size, password}",
|
21
|
+
Date: date,
|
22
|
+
mkdir: 'true',
|
23
|
+
Content_MD5: Digest::MD5.hexdigest(file_content),
|
24
|
+
})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
def self.signature(method, uri, date, content_length, password)
|
29
|
+
Digest::MD5.hexdigest "#{method}&#{uri}&#{date}&#{content_length}&#{Digest::MD5.hexdigest password}"
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "rails-assets-for-upyun"
|
6
|
+
s.version = "0.0.2"
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Michael Yin"]
|
9
|
+
s.email = ["layerssss@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/layerssss/rails-assets-for-upyun"
|
11
|
+
s.summary = %q{Rake task to push precompiled assets to Upyun}
|
12
|
+
s.description = %q{Rake task to push precompiled assets to Upyun}
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
s.license = 'MIT'
|
16
|
+
|
17
|
+
s.add_dependency "rest-client", [">= 1.6.7"]
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-assets-for-upyun
|
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
|
- Michael Yin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -32,8 +32,11 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- .gitignore
|
35
|
+
- Gemfile
|
35
36
|
- LICENSE
|
36
37
|
- README.md
|
38
|
+
- lib/rails-assets-for-upyun.rb
|
39
|
+
- rails-assets-for-upyun.gemspec
|
37
40
|
homepage: https://github.com/layerssss/rails-assets-for-upyun
|
38
41
|
licenses:
|
39
42
|
- MIT
|