sprock-assets 0.9.0 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ script: rspec
@@ -1,33 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sprock-assets (0.0.1)
4
+ sprock-assets (0.9.3)
5
5
  sprockets
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- addressable (2.3.2)
11
- capybara (1.1.2)
12
- mime-types (>= 1.16)
13
- nokogiri (>= 1.3.3)
14
- rack (>= 1.0.0)
15
- rack-test (>= 0.5.4)
16
- selenium-webdriver (~> 2.0)
17
- xpath (~> 0.1.4)
18
- childprocess (0.3.5)
19
- ffi (~> 1.0, >= 1.0.6)
20
10
  diff-lcs (1.1.3)
21
- ffi (1.1.5)
22
11
  hike (1.2.1)
23
- libwebsocket (0.1.5)
24
- addressable
25
- mime-types (1.19)
26
12
  multi_json (1.3.6)
27
- nokogiri (1.5.5)
28
13
  rack (1.4.1)
29
- rack-test (0.6.2)
30
- rack (>= 1.0)
31
14
  rake (0.9.2.2)
32
15
  rspec (2.11.0)
33
16
  rspec-core (~> 2.11.0)
@@ -37,26 +20,17 @@ GEM
37
20
  rspec-expectations (2.11.3)
38
21
  diff-lcs (~> 1.1.3)
39
22
  rspec-mocks (2.11.3)
40
- rubyzip (0.9.9)
41
- selenium-webdriver (2.25.0)
42
- childprocess (>= 0.2.5)
43
- libwebsocket (~> 0.1.3)
44
- multi_json (~> 1.0)
45
- rubyzip
46
- sprockets (2.6.0)
23
+ sprockets (2.8.1)
47
24
  hike (~> 1.2)
48
25
  multi_json (~> 1.0)
49
26
  rack (~> 1.0)
50
27
  tilt (~> 1.1, != 1.3.0)
51
28
  tilt (1.3.3)
52
- xpath (0.1.4)
53
- nokogiri (~> 1.3)
54
29
 
55
30
  PLATFORMS
56
31
  ruby
57
32
 
58
33
  DEPENDENCIES
59
- capybara
60
34
  rack
61
35
  rake
62
36
  rspec
@@ -20,13 +20,29 @@ class SprockAssets
20
20
  assets_path: 'app',
21
21
  javascripts_path: 'app/assets/javascripts',
22
22
  stylesheets_path: 'app/assets/stylesheets',
23
+ compile: false
23
24
  }.merge(settings)
24
25
 
26
+
27
+ javascript_file = "#{Dir.pwd}/#{@settings[:javascripts_path]}/application.js"
28
+ unless File.exists? javascript_file
29
+ raise "Javascript application file (#{javascript_file}) was not found"
30
+ end
31
+
32
+ stylesheet_file = "#{Dir.pwd}/#{@settings[:stylesheets_path]}/application.css"
33
+ unless File.exists? stylesheet_file
34
+ raise "Stylesheet application file (#{stylesheet_file}) was not found"
35
+ end
36
+
25
37
  @assets = Sprockets::Environment.new(Dir.pwd) do |assets|
26
38
  assets.logger = Logger.new(STDOUT)
27
39
  assets.append_path @settings[:assets_path]
28
40
  assets.append_path @settings[:javascripts_path]
29
41
  assets.append_path @settings[:stylesheets_path]
42
+ if @settings[:compile]
43
+ assets.js_compressor = Uglifier.new({ mangle: true })
44
+ assets.css_compressor = YUI::CssCompressor.new
45
+ end
30
46
  end
31
47
  end
32
48
 
@@ -38,22 +54,4 @@ class SprockAssets
38
54
  @assets.call env
39
55
  end
40
56
  end
41
-
42
- # Public: Generates the configured file structure for an applications assets.
43
- def generate_assets
44
- FileUtils.mkdir_p "#{@settings[:javascripts_path]}/coffee"
45
- FileUtils.mkdir_p "#{@settings[:stylesheets_path]}/scss"
46
- File.open("#{@settings[:javascripts_path]}/application.js", 'w') do |application_js|
47
- application_js << (<<-EOS).gsub(' ', '')
48
- //= require_tree ./coffee
49
- EOS
50
- end
51
- File.open("#{@settings[:stylesheets_path]}/application.css", 'w') do |application_css|
52
- application_css << (<<-EOS).gsub(' ', '')
53
- /*
54
- *= require_tree ./scss
55
- */
56
- EOS
57
- end
58
- end
59
57
  end
@@ -1,4 +1,4 @@
1
1
  class SprockAssets
2
2
  # Public: String version number of SprockAsset gem.
3
- VERSION = '0.9.0'
3
+ VERSION = '0.9.4'
4
4
  end
data/readme.md CHANGED
@@ -1,14 +1,16 @@
1
1
  # SprockAssets
2
+ [![Build Status](https://secure.travis-ci.org/nickbarth/SprockAssets.png?branch=master)](https://travis-ci.org/nickbarth/SprockAssets)
3
+ [![Dependency Status](https://gemnasium.com/nickbarth/SprockAssets.png)](https://gemnasium.com/nickbarth/SprockAssets)
2
4
 
3
- SprockAssets is a Rack Middleware you can include in your application for compiling your assets on the fly with Sprockets.
5
+ SprockAssets is a Rack middleware that makes compiling your assets on the fly with Sprockets easy and fast.
4
6
 
5
7
  ## Usage
6
8
 
7
- Here's how to use it.
9
+ Here is how to use it.
8
10
 
9
11
  ### Add it to your Gemfile
10
12
 
11
- gem 'sprock-assets', require 'sprock_assets'
13
+ gem 'sprock-assets', require: 'sprock_assets'
12
14
 
13
15
  ### Vanilla Rack apps
14
16
 
@@ -18,7 +20,7 @@ Add a use to your `config.ru`
18
20
 
19
21
  ### Sinatra
20
22
 
21
- If you're using Sinatra, you can use the flash hash just like in Rails:
23
+ You can use assets just like in Rails.
22
24
 
23
25
  require 'sinatra/base'
24
26
  require 'sprock_assets'
@@ -27,30 +29,26 @@ If you're using Sinatra, you can use the flash hash just like in Rails:
27
29
  use SprockAssets
28
30
  end
29
31
 
30
- ### Generate default assets
32
+ ### Create and update the source files
31
33
 
32
- Use the built in generator to generate some default assets.
33
-
34
- sprock-assets generate_assets
35
-
36
- It will create a directory structure and default assets based on the configured settings.
37
-
38
- tree app/
39
- app/
40
- └── assets
41
- ├── javascripts
42
- │   ├── application.js
43
- │   └── coffee
44
- └── stylesheets
45
- ├── application.css.scss
46
- └── scss
34
+ <table>
35
+ <tr>
36
+ <th>Default source file</th>
37
+ </tr>
38
+ <tr>
39
+ <td>app/assets/stylesheets/application.css</td>
40
+ </tr>
41
+ <tr>
42
+ <td>app/assets/javascripts/application.js</td>
43
+ </tr>
44
+ </table>
47
45
 
48
46
  ### Serve compiled assets
49
47
 
50
48
  ruby config.ru
51
49
  curl http://localhost/assets/stylesheets/application.css
52
50
  curl http://localhost/assets/javascripts/application.js
53
-
51
+
54
52
  Your compiled assets will now be served at their corresponding URIs.
55
53
 
56
54
  ### License
@@ -1,6 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SprockAssets do
4
+ Uglifier = Module.new
5
+ YUI = Module.new
6
+ YUI::CssCompressor = Module.new
7
+
8
+ before(:each) do
9
+ File.stub(:exists? => true)
10
+ Uglifier.stub(:new)
11
+ YUI::CssCompressor.stub(:new)
12
+ end
13
+
4
14
  context 'on Rack initialize' do
5
15
  it 'takes in custom paths' do
6
16
  env = Sprockets::Environment.any_instance
@@ -11,6 +21,13 @@ describe SprockAssets do
11
21
  javascripts_path: 'JAVASCRIPTS_PATH',
12
22
  stylesheets_path: 'STYLESHEETS_PATH'
13
23
  end
24
+
25
+ it 'sets compressors on compile flag' do
26
+ env = Sprockets::Environment.any_instance
27
+ env.should_receive(:js_compressor=)
28
+ env.should_receive(:css_compressor=)
29
+ SprockAssets.new nil, compile: true
30
+ end
14
31
  end
15
32
 
16
33
  context 'on Rack request' do
@@ -26,23 +43,4 @@ describe SprockAssets do
26
43
  rack_app.call 'PATH_INFO' => '/other/'
27
44
  end
28
45
  end
29
-
30
- context 'on generate asset call' do
31
- before(:each) do
32
- FileUtils.stub(:mkdir_p)
33
- File.stub(:open)
34
- end
35
-
36
- it 'should create the correct folders' do
37
- FileUtils.should_receive(:mkdir_p).with('app/assets/stylesheets/scss')
38
- FileUtils.should_receive(:mkdir_p).with('app/assets/javascripts/coffee')
39
- SprockAssets.new(nil).generate_assets
40
- end
41
-
42
- it 'should write an application.css and a application.js file' do
43
- File.should_receive(:open).with('app/assets/javascripts/application.js', 'w')
44
- File.should_receive(:open).with('app/assets/stylesheets/application.css', 'w')
45
- SprockAssets.new(nil).generate_assets
46
- end
47
- end
48
46
  end
@@ -11,13 +11,11 @@ Gem::Specification.new do |gem|
11
11
  gem.summary = 'A Ruby Gem for compiling assets through Sprock.'
12
12
  gem.description = 'SprockAssets is a Rack Middleware you can include in your application for compiling your assets on the fly with Sprockets.'
13
13
  gem.homepage = 'https://github.com/nickbarth/SprockAssets'
14
- gem.executables = ['sprock-assets']
15
14
 
16
15
  gem.add_dependency('sprockets')
17
16
  gem.add_development_dependency('rake')
18
17
  gem.add_development_dependency('rack')
19
18
  gem.add_development_dependency('rspec')
20
- gem.add_development_dependency('capybara')
21
19
 
22
20
  gem.files = `git ls-files`.split($/)
23
21
  gem.test_files = gem.files.grep /spec/
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprock-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -75,37 +75,20 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: capybara
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '0'
86
- type: :development
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
78
  description: SprockAssets is a Rack Middleware you can include in your application
95
79
  for compiling your assets on the fly with Sprockets.
96
80
  email:
97
81
  - nick@nickbarth.ca
98
- executables:
99
- - sprock-assets
82
+ executables: []
100
83
  extensions: []
101
84
  extra_rdoc_files: []
102
85
  files:
103
86
  - .gitignore
104
87
  - .rspec
88
+ - .travis.yml
105
89
  - Gemfile
106
90
  - Gemfile.lock
107
91
  - Rakefile
108
- - bin/sprock-assets
109
92
  - lib/sprock_assets.rb
110
93
  - lib/sprock_assets/version.rb
111
94
  - readme.md
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'sprock_assets'
4
-
5
- if %w(-v --version).include? ARGV.first
6
- puts "sprock-assets, version #{SprockAssets::VERSION}"
7
- elsif 'generate_assets' == ARGV.first
8
- SprockAssets.new(nil).generate_assets
9
- else
10
- puts (<<-EOS).gsub('^ ', '')
11
- usage: sprock-assets [switches] [commands]
12
- switches:
13
- -v/--version displays version number
14
- -h/--help displays this help
15
- commands:
16
- generate_assets generates default assets
17
- EOS
18
- end