asset_sync 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -315,6 +315,47 @@ A rake task is included within the **asset_sync** gem to enhance the rails preco
315
315
  end
316
316
  ```
317
317
 
318
+ ## Sinatra/Rack Support
319
+
320
+ You can use the gem with any Rack application, but you must specify two
321
+ additional options; `prefix` and `public_path`.
322
+
323
+ ```ruby
324
+ AssetSync.configure do |config|
325
+ config.fog_provider = 'AWS'
326
+ config.fog_directory = ENV['FOG_DIRECTORY']
327
+ config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
328
+ config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
329
+ config.prefix = "assets"
330
+ config.public_path = Pathname("./public")
331
+ end
332
+ ```
333
+
334
+ Then manually call `AssetSync.sync` at the end of your asset precompilation
335
+ task.
336
+
337
+ ```ruby
338
+ namespace :assets do
339
+ desc "Precompile assets"
340
+ task :precompile do
341
+ target = Pathname('./public/assets')
342
+ manifest = Sprockets::Manifest.new(sprockets, "./public/assets/manifest.json")
343
+
344
+ sprockets.each_logical_path do |logical_path|
345
+ if (!File.extname(logical_path).in?(['.js', '.css']) || logical_path =~ /application\.(css|js)$/) && asset = sprockets.find_asset(logical_path)
346
+ filename = target.join(logical_path)
347
+ FileUtils.mkpath(filename.dirname)
348
+ puts "Write asset: #{filename}"
349
+ asset.write_to(filename)
350
+ manifest.compile(logical_path)
351
+ end
352
+ end
353
+
354
+ AssetSync.sync
355
+ end
356
+ end
357
+ ```
358
+
318
359
  ## Todo
319
360
 
320
361
  1. Add some before and after filters for deleting and uploading
@@ -331,4 +372,4 @@ Inspired by:
331
372
 
332
373
  ## License
333
374
 
334
- MIT License. Copyright 2011 Rumble Labs Ltd. [rumblelabs.com](http://rumblelabs.com)
375
+ MIT License. Copyright 2011 Rumble Labs Ltd. [rumblelabs.com](http://rumblelabs.com)
data/asset_sync.gemspec CHANGED
@@ -6,7 +6,7 @@ require "asset_sync/version"
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "asset_sync"
8
8
  s.version = AssetSync::VERSION
9
- s.date = "2012-08-19"
9
+ s.date = "2012-08-23"
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.authors = ["Simon Hamilton", "David Rice", "Phil McClure"]
12
12
  s.email = ["shamilton@rumblelabs.com", "me@davidjrice.co.uk", "pmcclure@rumblelabs.com"]
@@ -11,6 +11,8 @@ module AssetSync
11
11
  attr_accessor :fail_silently
12
12
  attr_accessor :always_upload
13
13
  attr_accessor :ignored_files
14
+ attr_accessor :prefix
15
+ attr_accessor :public_path
14
16
  attr_accessor :enabled
15
17
 
16
18
  # FOG configuration
@@ -48,7 +50,7 @@ module AssetSync
48
50
  self.always_upload = []
49
51
  self.ignored_files = []
50
52
  self.enabled = true
51
- load_yml! if yml_exists?
53
+ load_yml! if defined?(Rails) && yml_exists?
52
54
  end
53
55
 
54
56
  def manifest_path
@@ -99,7 +101,11 @@ module AssetSync
99
101
 
100
102
  def assets_prefix
101
103
  # Fix for Issue #38 when Rails.config.assets.prefix starts with a slash
102
- Rails.application.config.assets.prefix.sub(/^\//, '')
104
+ self.prefix || Rails.application.config.assets.prefix.sub(/^\//, '')
105
+ end
106
+
107
+ def public_path
108
+ @public_path || Rails.public_path
103
109
  end
104
110
 
105
111
  def load_yml!
@@ -27,7 +27,7 @@ module AssetSync
27
27
  end
28
28
 
29
29
  def path
30
- Rails.public_path
30
+ self.config.public_path
31
31
  end
32
32
 
33
33
  def ignored_files
@@ -1,3 +1,3 @@
1
1
  module AssetSync
2
- VERSION = "0.4.3"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -0,0 +1,72 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe AssetSync do
4
+ include_context "mock without Rails"
5
+
6
+ describe 'with initializer' do
7
+ before(:each) do
8
+ AssetSync.config = AssetSync::Config.new
9
+ AssetSync.configure do |config|
10
+ config.fog_provider = 'AWS'
11
+ config.aws_access_key_id = 'aaaa'
12
+ config.aws_secret_access_key = 'bbbb'
13
+ config.fog_directory = 'mybucket'
14
+ config.fog_region = 'eu-west-1'
15
+ config.existing_remote_files = "keep"
16
+ config.prefix = "assets"
17
+ config.public_path = Pathname("./public")
18
+ end
19
+ end
20
+
21
+ it "should have prefix of assets" do
22
+ AssetSync.config.prefix.should == "assets"
23
+ end
24
+
25
+ it "should have prefix of assets" do
26
+ AssetSync.config.public_path.to_s.should == "./public"
27
+ end
28
+
29
+ it "should default AssetSync to enabled" do
30
+ AssetSync.config.enabled?.should be_true
31
+ AssetSync.enabled?.should be_true
32
+ end
33
+
34
+ it "should configure provider as AWS" do
35
+ AssetSync.config.fog_provider.should == 'AWS'
36
+ AssetSync.config.should be_aws
37
+ end
38
+
39
+ it "should should keep existing remote files" do
40
+ AssetSync.config.existing_remote_files?.should == true
41
+ end
42
+
43
+ it "should configure aws_access_key" do
44
+ AssetSync.config.aws_access_key_id.should == "aaaa"
45
+ end
46
+
47
+ it "should configure aws_secret_access_key" do
48
+ AssetSync.config.aws_secret_access_key.should == "bbbb"
49
+ end
50
+
51
+ it "should configure aws_access_key" do
52
+ AssetSync.config.fog_directory.should == "mybucket"
53
+ end
54
+
55
+ it "should configure fog_region" do
56
+ AssetSync.config.fog_region.should == "eu-west-1"
57
+ end
58
+
59
+ it "should configure existing_remote_files" do
60
+ AssetSync.config.existing_remote_files.should == "keep"
61
+ end
62
+
63
+ it "should default gzip_compression to false" do
64
+ AssetSync.config.gzip_compression.should be_false
65
+ end
66
+
67
+ it "should default manifest to false" do
68
+ AssetSync.config.manifest.should be_false
69
+ end
70
+
71
+ end
72
+ end
data/spec/spec_helper.rb CHANGED
@@ -16,6 +16,16 @@ RSpec.configure do |config|
16
16
  config.mock_framework = :rspec
17
17
  end
18
18
 
19
+ shared_context "mock without Rails" do
20
+ before(:each) do
21
+ if defined? Rails
22
+ Object.send(:remove_const, :Rails)
23
+ end
24
+ AssetSync.stub!(:log)
25
+ end
26
+ end
27
+
28
+
19
29
  shared_context "mock Rails" do
20
30
  before(:each) do
21
31
  unless defined? Rails
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asset_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-08-19 00:00:00.000000000 Z
14
+ date: 2012-08-23 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: fog
@@ -127,6 +127,7 @@ files:
127
127
  - spec/google_with_yml/config/asset_sync.yml
128
128
  - spec/rackspace_spec.rb
129
129
  - spec/rackspace_with_yml/config/asset_sync.yml
130
+ - spec/railsless_spec.rb
130
131
  - spec/spec_helper.rb
131
132
  - spec/storage_spec.rb
132
133
  homepage: https://github.com/rumblelabs/asset_sync
@@ -143,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
144
  version: '0'
144
145
  segments:
145
146
  - 0
146
- hash: -3610501310957449619
147
+ hash: 812394240063105414
147
148
  required_rubygems_version: !ruby/object:Gem::Requirement
148
149
  none: false
149
150
  requirements:
@@ -152,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
153
  version: '0'
153
154
  segments:
154
155
  - 0
155
- hash: -3610501310957449619
156
+ hash: 812394240063105414
156
157
  requirements: []
157
158
  rubyforge_project: asset_sync
158
159
  rubygems_version: 1.8.24
@@ -167,5 +168,6 @@ test_files:
167
168
  - spec/google_with_yml/config/asset_sync.yml
168
169
  - spec/rackspace_spec.rb
169
170
  - spec/rackspace_with_yml/config/asset_sync.yml
171
+ - spec/railsless_spec.rb
170
172
  - spec/spec_helper.rb
171
173
  - spec/storage_spec.rb