cloud_crooner 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/CHANGELOG.md +5 -0
- data/README.md +45 -11
- data/lib/cloud_crooner/cloud_crooner.rb +4 -2
- data/lib/cloud_crooner/version.rb +1 -1
- data/spec/cloud_crooner_spec.rb +40 -21
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96c6f6bcbfc3bc6923aa74ee75f875a9c8be8f37
|
4
|
+
data.tar.gz: df7ffd57e4962c7ad2343b2960c6a553d603301c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b522ae4cb68eeb23cb34421928954824fdecc6fd7ce894332916403f1492a696110401795d0adae3a4c63a09930e840748f66c98b4568dd91f1d6745db649383
|
7
|
+
data.tar.gz: f7878e04dea4a3349fc84daddb4069dfd3a6c090e7d77de60728d446d49de18add7b9b5ea770d646da28d854532940f42e8933cd2fd0b0d53250317462c6d48b
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Manage your Sinatra app's assets with [Sprockets](https://github.com/sstephenson/sprockets) and sync them with [Amazon S3](http://aws.amazon.com/s3/).
|
4
4
|
|
5
|
-
Cloud Crooner will run a Sprockets instance and configure helpers for your views. Create a rake task to
|
5
|
+
Cloud Crooner will run a Sprockets instance and configure helpers for your views. Create a rake task to compile your assets and upload them to the cloud, and use helper methods to make sure you're always pointing to the right asset paths for your environment. In prod, your assets will have appended to their names an MD5 hash of their contents which updates when your assets change, ensuring that your users will always be served the freshest assets without needing to worry about expiring caches.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -20,7 +20,7 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Configuration
|
22
22
|
|
23
|
-
Cloud Crooner has many configuration options which can be set in a configure block
|
23
|
+
Cloud Crooner has many configuration options which can be set in a configure block. [Explicit configuration is optional.](#no-configuration)
|
24
24
|
|
25
25
|
CloudCrooner.configure do |config|
|
26
26
|
config.prefix = '/assets'
|
@@ -32,7 +32,7 @@ Cloud Crooner has many configuration options which can be set in a configure blo
|
|
32
32
|
|
33
33
|
`prefix` - the path from root where you keep your assets. By default it is `/assets`. Your compiled assets will be placed in `public_folder/prefix.` It will also be the pseudo-folder on S3 where your assets will be stored, so the paths will look something like `http://bucket-name.s3.amazonaws.com/prefix/filename`.
|
34
34
|
|
35
|
-
`sprockets` - by default, this will be your Sprockets environment and it will load paths the config option `asset_paths`.
|
35
|
+
`sprockets` - by default, this will be your Sprockets environment and it will add to its load path the paths set in the config option `asset_paths`.
|
36
36
|
|
37
37
|
`asset_paths` - the [load paths](https://github.com/sstephenson/sprockets#the-load-path) for your Sprockets instance. By default it will add the `prefix` directory.
|
38
38
|
|
@@ -42,13 +42,16 @@ Cloud Crooner has many configuration options which can be set in a configure blo
|
|
42
42
|
|
43
43
|
`backups_to_keep` - the number of compiled asset backups to keep. Default is 2. When running the sync task, if an asset's content has changed, it will be recompiled. If there are already more than the set number of backups present, the oldest asset will be deleted locally, removed from the manifest, and deleted remotely.
|
44
44
|
|
45
|
-
|
45
|
+
### Amazon S3 settings and credentials
|
46
|
+
[See "Hooking Up With Your Amazon S3 Account" for details.](#hooking-up-with-your-amazon-s3-account)
|
46
47
|
|
47
|
-
`
|
48
|
-
|
49
|
-
`aws_access_id_key` - aws credentials. [See below for details.](#hooking_up )
|
48
|
+
`bucket_name` - the name of your AWS S3 bucket.
|
50
49
|
|
51
|
-
`
|
50
|
+
`region` - the region of your AWS S3 bucket.
|
51
|
+
|
52
|
+
`aws_access_id_key` - aws credentials.
|
53
|
+
|
54
|
+
`aws_secret_access_key` - aws credentials.
|
52
55
|
|
53
56
|
### No Configuration
|
54
57
|
|
@@ -56,9 +59,9 @@ If you're keen to run everything on defaults, you will still need to run one com
|
|
56
59
|
|
57
60
|
CloudCrooner.configure_sprockets_helpers
|
58
61
|
|
59
|
-
Normally this is called at the end of the configure method.
|
62
|
+
Normally this is called at the end of the `CloudCrooner.configure` method. This method also assumes you have put the S3 settings into ENV outside of the app.
|
60
63
|
|
61
|
-
###
|
64
|
+
### Hooking Up With Your Amazon S3 Account
|
62
65
|
|
63
66
|
After you have created an S3 account, [you will will be provided with an "access key id" and a "secret access key"](https://console.aws.amazon.com/iam/home?#security_credential). You will also need your bucket name and the bucket's region. One of the ways to find the region is by going to the [S3 console](https://console.aws.amazon.com/s3/) and checking the end of the URL: it will look something like us-west-1. Cloud Crooner will look for your AWS credentials in your ENV by default. _Do not put your credentials anywhere they can be checked into source control._ I would suggest loading them into the env with your bash login scripts. The env keys that will be checked by default are:
|
64
67
|
|
@@ -78,7 +81,7 @@ You may also set these in the Cloud Crooner config block, but please do not dire
|
|
78
81
|
|
79
82
|
## Setting Up Your App:
|
80
83
|
|
81
|
-
I have thrown together a very simple application as an example.
|
84
|
+
[I have thrown together a very simple application as an example.](https://github.com/bambery/cloud_crooner_example)
|
82
85
|
|
83
86
|
In a file of your choosing (in this case `/config/cloud_crooner_config.rb`) run the configuration block with your desired settings.
|
84
87
|
|
@@ -103,6 +106,16 @@ In config.ru, require this file, and set up the following:
|
|
103
106
|
run App # your application class name
|
104
107
|
end
|
105
108
|
|
109
|
+
You have to register the helpers in your application so they can find your assets:
|
110
|
+
|
111
|
+
class App < Sinatra::Base
|
112
|
+
helpers do
|
113
|
+
include Sprockets::Helpers
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
The helpers which you can use are [detailed below](#helpers).
|
118
|
+
|
106
119
|
To compile and upload the assets, in your rakefile:
|
107
120
|
|
108
121
|
require './config/cloud_crooner_config.rb'
|
@@ -125,6 +138,27 @@ Running your app in development mode will serve uncompiled assets locally (from
|
|
125
138
|
|
126
139
|
If you want to precompile and upload your assets every time you spin up your app, you can put the configure block directly into config.ru and after config run CloudCrooner.sync.
|
127
140
|
|
141
|
+
|
142
|
+
## Helpers
|
143
|
+
|
144
|
+
Helper methods are provided for use in your views using the [sprockets-helpers](https://github.com/petebrowne/sprockets-helpers) gem.
|
145
|
+
|
146
|
+
`stylesheet_tag` - put this in your views to insert an html tag referencing a stylesheet in the Sprockets load path. For example, if you have `/assets/stylesheets/application.scss` and have placed `assets/stylesheets` in the load path, you would write:
|
147
|
+
<%= stylesheet_tag 'application' %>
|
148
|
+
and in dev it will compile to
|
149
|
+
<link rel="stylesheet" href="/assets/application.css">
|
150
|
+
in prod it will compile to
|
151
|
+
<link rel="stylesheet" href="http://my-bucket.s3.amazonaws.com/assets/application.css">
|
152
|
+
|
153
|
+
`javascript_tag` - similar to `stylesheet_tag`
|
154
|
+
|
155
|
+
`asset_tag` - similar to stylesheet, but you pass a block to generate a tag of your choosing.
|
156
|
+
asset_tag('main.js') { |path| "<script src=#{path}></script>" }
|
157
|
+
will generate
|
158
|
+
<script src=/main.js></script>
|
159
|
+
|
160
|
+
`asset_path` - returns the path to an asset, no tag.
|
161
|
+
|
128
162
|
## Notes About Sass and Sprockets
|
129
163
|
|
130
164
|
If you are using sass files, you should use the [ sprockets-sass ](https://github.com/petebrowne/sprockets-sass) and [ sass ](https://github.com/nex3/sass) gems to help Sprockets cope (sprockets-sass still necessary as of 06/30/13 for functional Sinatra @imports, email me if this changes).
|
data/spec/cloud_crooner_spec.rb
CHANGED
@@ -292,27 +292,46 @@ describe CloudCrooner do
|
|
292
292
|
|
293
293
|
end # describe
|
294
294
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
295
|
+
describe 'compiling and syncing assets' do
|
296
|
+
|
297
|
+
it 'compiles assets' do
|
298
|
+
within_construct do |c|
|
299
|
+
mock_environment(c)
|
300
|
+
CloudCrooner.assets_to_compile = ['a.css', 'b.css']
|
301
|
+
(CloudCrooner.storage.local_compiled_assets).should == []
|
302
|
+
CloudCrooner.compile_sprockets_assets
|
303
|
+
|
304
|
+
expect(CloudCrooner.storage.local_compiled_assets).to eq(['assets/' + CloudCrooner.sprockets['a.css'].digest_path, 'assets/' + CloudCrooner.sprockets['b.css'].digest_path])
|
305
|
+
end # construct
|
306
|
+
end # it
|
307
|
+
|
308
|
+
it 'compiles and syncs assets to the cloud', :moo => true do
|
309
|
+
within_construct do |c|
|
310
|
+
mock_environment(c)
|
311
|
+
CloudCrooner.assets_to_compile = ['a.css', 'b.css']
|
312
|
+
mock_fog(CloudCrooner.storage)
|
313
|
+
CloudCrooner.sync
|
314
|
+
|
315
|
+
expect(local_equals_remote?(CloudCrooner.storage)).to be_true
|
316
|
+
end # construct
|
317
|
+
end # it
|
318
|
+
|
319
|
+
it 'compiles and does not sync assets if remote_enabled is false' do
|
320
|
+
within_construct do |c|
|
321
|
+
mock_environment(c)
|
322
|
+
CloudCrooner.configure do |config|
|
323
|
+
config.assets_to_compile = ['a.css', 'b.css']
|
324
|
+
config.remote_enabled = false
|
325
|
+
end
|
326
|
+
mock_fog(CloudCrooner.storage)
|
327
|
+
CloudCrooner.sync
|
328
|
+
|
329
|
+
expect(local_equals_remote?(CloudCrooner.storage)).to be_false
|
330
|
+
expect(CloudCrooner.storage.bucket.versions.first).to be_nil
|
331
|
+
end # construct
|
332
|
+
end # it
|
333
|
+
|
334
|
+
end # describe
|
316
335
|
|
317
336
|
after(:each) do
|
318
337
|
reload_crooner
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloud_crooner
|
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
|
- bambery
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- .gitignore
|
133
133
|
- .rspec
|
134
134
|
- .rvmrc
|
135
|
+
- CHANGELOG.md
|
135
136
|
- Gemfile
|
136
137
|
- LICENSE.txt
|
137
138
|
- README.md
|
@@ -164,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
165
|
version: '0'
|
165
166
|
requirements: []
|
166
167
|
rubyforge_project:
|
167
|
-
rubygems_version: 2.0.
|
168
|
+
rubygems_version: 2.0.3
|
168
169
|
signing_key:
|
169
170
|
specification_version: 4
|
170
171
|
summary: Manage assets with Sprockets, precompile them into static assets, then upload
|