assets_server 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0ca62291d4443481e6b99871b0bdf659fb13e0f1
4
+ data.tar.gz: d0478e554e1e621649d1918b91ea6a4299debf83
5
+ SHA512:
6
+ metadata.gz: dc279d8b09fc20c64bd34246007c7133187fd17448977ddfab0935547e1766be78738699070e0cc0044913e394fb11e9864524c6c8052ce115057c207171a140
7
+ data.tar.gz: 8474cd490b1a95f4a10e725f1df50adcccda229c0a8151625cd35b0013b71fc76ba47ee63d4b95a2fae7fe0715dbdd803be3330a1b08cedc6c12496d95be710c
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in assets_server.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jared Grippe
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ # AssetsServer
2
+
3
+ Compiles and serves static assets
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'assets_server'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install assets_server
18
+
19
+ ## Usage
20
+
21
+ require 'assets-server'
22
+ run AssetsServer.new(
23
+ # options
24
+ )
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'assets_server/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "assets_server"
8
+ spec.version = AssetsServer::VERSION
9
+ spec.authors = ["Jared Grippe"]
10
+ spec.email = ["jared@deadlyicon.com"]
11
+ spec.description = %q{compiles and serves static assets}
12
+ spec.summary = %q{compiles and serves static assets}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+
22
+ spec.add_dependency "compass"
23
+ spec.add_dependency "sprockets"
24
+ spec.add_dependency "tilt"
25
+ spec.add_dependency "let"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.3"
28
+ spec.add_development_dependency "rake"
29
+ spec.add_development_dependency "rspec"
30
+ spec.add_development_dependency "rack-test"
31
+ spec.add_development_dependency "shotgun"
32
+ spec.add_development_dependency "pry"
33
+ end
@@ -0,0 +1,59 @@
1
+ require "assets_server/version"
2
+ require "sprockets"
3
+
4
+ # AssetsServer
5
+ #
6
+ # Usage
7
+ #
8
+ # AssetsServer.new(
9
+ # root: './assets',
10
+ # directories: %w{javascripts stylesheets images templates fonts}
11
+ # paths: ['javascripts','stylesheets','vendor/javascripts','vendor/stylesheets'],
12
+ # compass: true,
13
+ # )
14
+ #
15
+ class AssetsServer
16
+
17
+ OptionError = Class.new(ArgumentError)
18
+
19
+ def initialize(options={})
20
+ @root = options.fetch(:root){ Bundler.root if defined? Bundler }
21
+ @directories = options.fetch(:directories){ %w{javascripts stylesheets images} }
22
+ @paths = options.fetch(:paths){
23
+ @directories + @directories.map{|d| "vendor/#{d}" }
24
+ }
25
+ @compass = options.fetch(:compass){ false }
26
+ use_compass! if compass?
27
+ end
28
+
29
+ def call(env)
30
+ sprockets_environment.call(env)
31
+ end
32
+
33
+ def root
34
+ @root or raise OptionError, "root option not set for #{self.class}"
35
+ end
36
+
37
+ def paths
38
+ @paths or raise OptionError, "paths option not set for #{self.class}"
39
+ end
40
+
41
+ def compass?
42
+ !!@compass
43
+ end
44
+
45
+ def sprockets_environment
46
+ return @sprockets_environment if defined? @sprockets_environment
47
+ @sprockets_environment = Sprockets::Environment.new(root)
48
+ paths.each do |path|
49
+ @sprockets_environment.append_path path
50
+ end
51
+ @sprockets_environment
52
+ end
53
+
54
+ def use_compass!
55
+ require "compass"
56
+ sprockets_environment.append_path Compass::Frameworks['compass'].path+'/stylesheets'
57
+ end
58
+
59
+ end
@@ -0,0 +1,3 @@
1
+ class AssetsServer
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+
3
+ describe AssetsServer do
4
+
5
+ let(:options){ {} }
6
+ subject(:app){ AssetsServer.new(options) }
7
+
8
+
9
+ describe "#call" do
10
+ it "should delegate to sprockets_environment" do
11
+ env = double(:env)
12
+ app.sprockets_environment.should_receive(:call).with(env)
13
+ app.call(env)
14
+ end
15
+ end
16
+
17
+ describe "#root" do
18
+ context "when the root is given" do
19
+ let(:options){ {root: '/tmp/foo'} }
20
+ it "should return the given root" do
21
+ app.root.should == '/tmp/foo'
22
+ end
23
+ end
24
+ context "when the root is not given" do
25
+ let(:options){ {} }
26
+ it "should return Bundler.root" do
27
+ app.root.should == Bundler.root
28
+ end
29
+ end
30
+ context "when the root option is nil" do
31
+ let(:options){ {root: nil} }
32
+ it "should return Bundler.root" do
33
+ expect{ app.root }.to raise_error AssetsServer::OptionError, "root option not set for AssetsServer"
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "#paths" do
39
+ context "when the paths is given" do
40
+ let(:options){ {paths: ['/a/b', '/c/d']} }
41
+ it "should return the given paths" do
42
+ app.paths.should == ['/a/b', '/c/d']
43
+ end
44
+ end
45
+ context "when the paths is not given" do
46
+ let(:options){ {} }
47
+ it "should return the directories + vendor" do
48
+ app.paths.should == %w{
49
+ javascripts
50
+ stylesheets
51
+ images
52
+ vendor/javascripts
53
+ vendor/stylesheets
54
+ vendor/images
55
+ }
56
+ end
57
+ context "when directories is given" do
58
+ let(:options){ {directories: %w{shoes socks}} }
59
+ it "should return the directories + vendor" do
60
+ app.paths.should == %w{
61
+ shoes
62
+ socks
63
+ vendor/shoes
64
+ vendor/socks
65
+ }
66
+ end
67
+ end
68
+ end
69
+ context "when the paths option is nil" do
70
+ let(:options){ {paths: nil} }
71
+ it "should return Bundler.paths" do
72
+ expect{ app.paths }.to raise_error AssetsServer::OptionError, "paths option not set for AssetsServer"
73
+ end
74
+ end
75
+ end
76
+
77
+ describe "#compass?" do
78
+ context "when the option `compass: true' is given" do
79
+ let(:options){ {compass: true} }
80
+ it "should return true" do
81
+ app.should be_compass
82
+ end
83
+ end
84
+ context "when the option `compass: false' is given" do
85
+ let(:options){ {compass: false} }
86
+ it "should return false" do
87
+ app.should_not be_compass
88
+ end
89
+ end
90
+ context "when the option compass is not given" do
91
+ let(:options){ {} }
92
+ it "should return false" do
93
+ app.should_not be_compass
94
+ end
95
+ end
96
+ end
97
+
98
+ describe "#sprockets_environment" do
99
+ let(:options){ {root: '/foo/bar'} }
100
+ it "should return a Sprockets::Environment" do
101
+ app.sprockets_environment.should be_a Sprockets::Environment
102
+ app.sprockets_environment.root.should == '/foo/bar'
103
+ end
104
+ it "should append each append each path" do
105
+ app.sprockets_environment.paths.should == %w(
106
+ /foo/bar/javascripts
107
+ /foo/bar/stylesheets
108
+ /foo/bar/images
109
+ /foo/bar/vendor/javascripts
110
+ /foo/bar/vendor/stylesheets
111
+ /foo/bar/vendor/images
112
+ )
113
+ end
114
+ context "when compass is enabled" do
115
+ let(:options){ {compass: true} }
116
+ it "should append the compass framework stylesheets path" do
117
+ app.sprockets_environment.paths.should include Compass::Frameworks['compass'].path+'/stylesheets'
118
+ end
119
+ end
120
+ end
121
+
122
+ end
@@ -0,0 +1,13 @@
1
+ ENV['RACK_ENV'] ||= 'text'
2
+ require 'assets_server'
3
+ require 'rack/test'
4
+ require 'pry'
5
+
6
+ Dir[Bundler.root.join("spec/support/**/*.rb")].each {|f| require f}
7
+
8
+ RSpec.configure do |config|
9
+ config.order = "random"
10
+
11
+ config.include Rack::Test::Methods
12
+
13
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe "static assets" do
4
+
5
+ def root
6
+ @root ||= Bundler.root.join('spec/test_app')
7
+ end
8
+
9
+ def options
10
+ @options ||= {root: root, compass: true}
11
+ end
12
+
13
+ def app
14
+ @app ||= AssetsServer.new(options)
15
+ end
16
+
17
+ context "GET /application.js" do
18
+ before{ get '/application.js' }
19
+ it "should return the rendered asset" do
20
+ last_response.should be_ok
21
+ last_response.body.should == \
22
+ "function jQuery(){}\n;\nModal = {};\n\n\n\nApplication = {};\n"
23
+ end
24
+ end
25
+
26
+ context "GET /modal.js" do
27
+ before{ get '/modal.js' }
28
+ it "should return the rendered asset" do
29
+ last_response.should be_ok
30
+ last_response.body.should == "Modal = {};\n"
31
+ end
32
+ end
33
+
34
+ context "GET /application.css" do
35
+ before{ get '/application.css' }
36
+ it "should return the rendered asset" do
37
+ last_response.should be_ok
38
+ last_response.body.should == \
39
+ ".bootstrap {\n content: \"awesome\"; }\n\nhtml, body {\n padding: 0; }\n\n.page {\n width: 960px; }\n"
40
+ end
41
+ end
42
+
43
+ context "GET /laout.css" do
44
+ before{ get '/layout.css' }
45
+ it "should return the rendered asset" do
46
+ last_response.should_not be_ok
47
+ end
48
+ end
49
+
50
+ context "GET /bootstrap.css" do
51
+ before{ get '/bootstrap.css' }
52
+ it "should return the rendered asset" do
53
+ last_response.should_not be_ok
54
+ end
55
+ end
56
+
57
+ context "GET /1x1.png" do
58
+ before{ get '/1x1.png' }
59
+ it "should return the rendered asset" do
60
+ last_response.should be_ok
61
+ last_response.body.should == \
62
+ root.join('images/1x1.png').binread
63
+ end
64
+ end
65
+
66
+ context "GET /1x1-red.png" do
67
+ before{ get '/1x1-red.png' }
68
+ it "should return the rendered asset" do
69
+ last_response.should be_ok
70
+ last_response.body.should == \
71
+ root.join('vendor/images/1x1-red.png').binread
72
+ end
73
+ end
74
+
75
+ end
@@ -0,0 +1,4 @@
1
+ //= require jquery
2
+ //= require_tree .
3
+
4
+ Application = {};
@@ -0,0 +1 @@
1
+ Modal = {};
@@ -0,0 +1,2 @@
1
+ .page
2
+ width: 960px
@@ -0,0 +1,7 @@
1
+ @import "compass"
2
+ @import "bootstrap"
3
+
4
+ html,body
5
+ padding: 0
6
+
7
+ @import "layout"
@@ -0,0 +1 @@
1
+ function jQuery(){}
@@ -0,0 +1,3 @@
1
+ .bootstrap{
2
+ content: "awesome";
3
+ }
metadata ADDED
@@ -0,0 +1,214 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: assets_server
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jared Grippe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: compass
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sprockets
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tilt
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: let
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rack-test
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: shotgun
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: compiles and serves static assets
154
+ email:
155
+ - jared@deadlyicon.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - .gitignore
161
+ - Gemfile
162
+ - LICENSE.txt
163
+ - README.md
164
+ - Rakefile
165
+ - assets_server.gemspec
166
+ - lib/assets_server.rb
167
+ - lib/assets_server/version.rb
168
+ - spec/assets_server_spec.rb
169
+ - spec/spec_helper.rb
170
+ - spec/static_assets_spec.rb
171
+ - spec/test_app/images/1x1.png
172
+ - spec/test_app/javascripts/application.js
173
+ - spec/test_app/javascripts/modal.js
174
+ - spec/test_app/stylesheets/_layout.sass
175
+ - spec/test_app/stylesheets/application.sass
176
+ - spec/test_app/vendor/images/1x1-red.png
177
+ - spec/test_app/vendor/javascripts/jquery.js
178
+ - spec/test_app/vendor/stylesheets/_bootstrap.scss
179
+ homepage: ''
180
+ licenses:
181
+ - MIT
182
+ metadata: {}
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - '>='
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - '>='
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ requirements: []
198
+ rubyforge_project:
199
+ rubygems_version: 2.0.2
200
+ signing_key:
201
+ specification_version: 4
202
+ summary: compiles and serves static assets
203
+ test_files:
204
+ - spec/assets_server_spec.rb
205
+ - spec/spec_helper.rb
206
+ - spec/static_assets_spec.rb
207
+ - spec/test_app/images/1x1.png
208
+ - spec/test_app/javascripts/application.js
209
+ - spec/test_app/javascripts/modal.js
210
+ - spec/test_app/stylesheets/_layout.sass
211
+ - spec/test_app/stylesheets/application.sass
212
+ - spec/test_app/vendor/images/1x1-red.png
213
+ - spec/test_app/vendor/javascripts/jquery.js
214
+ - spec/test_app/vendor/stylesheets/_bootstrap.scss