web_assets 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a1a2f8f50aac9cffebfc09b9166633d36314f9d1
4
+ data.tar.gz: 44db5065c91eb1025515d23c174c022f6fe6fa4a
5
+ SHA512:
6
+ metadata.gz: 5e10cfa8c9e61fa87e3ae3bf21e90b02b786dc22f20cbc88323cd594b3219d1b04271423bd87c714d1d7da5d5c6b4f454ef2ede667c567410ab0e960586c1886
7
+ data.tar.gz: decf11f9c7a236b081f54ed2ba8d007d5e0f36f3c4756df6fe9c8608d2b7050e48eab284cfae3a6202c14748290453a01dd4ccd15d8c0366f45c40726a046b25
data/.gitignore ADDED
@@ -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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in web_assets.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mathieu Lajugie
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.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # WebAssets
2
+
3
+ A command to pre-process web assets using Ruby tools, intended to be called
4
+ from a different language.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'web_assets'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install web_assets
19
+
20
+ ## Usage
21
+
22
+ TODO: Write usage instructions here
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/web_assets.rb ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "logger"
4
+ require "web_assets"
5
+
6
+ WebAssets::Runner.new(ARGV).run
@@ -0,0 +1,55 @@
1
+ module WebAssets
2
+
3
+ class Api
4
+
5
+ attr_reader :script_processor, :stylesheet_processor
6
+
7
+ def initialize script_processor, stylesheet_processor
8
+ @script_processor = script_processor
9
+ @stylesheet_processor = stylesheet_processor
10
+ end
11
+
12
+ def set_script_path path
13
+ script_processor.set_path path
14
+ end
15
+
16
+ def set_stylesheet_path path
17
+ stylesheet_processor.set_path path
18
+ end
19
+
20
+ def add_script_load_path path
21
+ script_processor.add_load_path path
22
+ end
23
+
24
+ def add_stylesheet_load_path path
25
+ stylesheet_processor.add_load_path path
26
+ end
27
+
28
+ def script_filenames filename
29
+ script_processor.filenames filename
30
+ end
31
+
32
+ def script_digest_filename filename
33
+ script_processor.digest_filename filename
34
+ end
35
+
36
+ def script_content filename, options = {}
37
+ options[:bundle] = options.fetch :bundle, true
38
+ options[:minify] = options.fetch :minify, false
39
+ options[:gzip] = options.fetch :gzip, false
40
+ script_processor.content filename, options
41
+ end
42
+
43
+ def stylesheet_digest_filename filename
44
+ stylesheet_processor.digest_filename filename
45
+ end
46
+
47
+ def stylesheet_content filename, options = {}
48
+ options[:minify] = options.fetch :minify, false
49
+ options[:gzip] = options.fetch :gzip, false
50
+ stylesheet_processor.content filename, options
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,48 @@
1
+ require "erlectricity"
2
+
3
+ module WebAssets
4
+
5
+ class ClientInterface
6
+
7
+ attr_reader :api, :input, :output
8
+
9
+ def initialize api, input: STDIN, output: STDOUT
10
+ @api, @input, @output = api, input, output
11
+ end
12
+
13
+ def listen
14
+ Kernel.receive input, output do |request| process request end
15
+ end
16
+
17
+ private
18
+
19
+ def process request
20
+ request.when [:append_javascript_path, String] do |path|
21
+ reply request, api.append_javascript_path(path)
22
+ end
23
+
24
+ request.when [:append_stylesheet_path, String] do |path|
25
+ reply request, api.append_stylesheet_path(path)
26
+ end
27
+
28
+ request.when [:javascript_filenames, String] do |filename|
29
+ reply request, api.javascript_filenames(filename)
30
+ end
31
+
32
+ request.when [:javascript_content, Array] do |filename, options|
33
+ reply request, api.javascript_content(filename, options)
34
+ end
35
+
36
+ request.when [:stylesheet_content, Array] do |filename, options|
37
+ reply request, api.stylesheet_content(filename, options)
38
+ end
39
+ end
40
+
41
+ def reply request, response
42
+ request.send! response
43
+ request.receive_loop
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,35 @@
1
+ require "optparse"
2
+
3
+ module WebAssets
4
+
5
+ class CommandLine
6
+
7
+ attr_reader :arguments
8
+
9
+ def initialize arguments
10
+ @arguments = arguments
11
+ end
12
+
13
+ def parse
14
+ options = {libs: [], debug: false}
15
+ parser(options).parse! arguments
16
+ options
17
+ end
18
+
19
+ private
20
+
21
+ def parser options
22
+ OptionParser.new do |o|
23
+ o.on "-r", "--require LIB", "require the library specified" do |lib|
24
+ options[:libs] << lib
25
+ end
26
+
27
+ o.on "-d", "--debug", "trace execution in a log file" do |debug|
28
+ options[:debug] = debug
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,23 @@
1
+ module WebAssets
2
+
3
+ class Gzipper
4
+
5
+ def self.compress content
6
+ stream = StringIO.new
7
+ gz = Zlib::GzipWriter.new stream, Zlib::BEST_COMPRESSION
8
+ gz.write content
9
+ gz.close
10
+ stream.string
11
+ end
12
+
13
+ def self.uncompress zipped
14
+ stream = StringIO.new zipped
15
+ gz = Zlib::GzipReader.new stream
16
+ content = gz.read
17
+ gz.close
18
+ content
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,52 @@
1
+ module WebAssets
2
+
3
+ class Runner
4
+
5
+ attr_reader :libs
6
+
7
+ def initialize arguments
8
+ options = CommandLine.new(arguments).parse
9
+ @debug = options.fetch :debug, false
10
+ @libs = options.fetch :libs, []
11
+ end
12
+
13
+ def debug?
14
+ @debug
15
+ end
16
+
17
+ def run
18
+ load_libs
19
+ listen_to_client
20
+ end
21
+
22
+ private
23
+
24
+ def load_libs
25
+ libs.each { |lib| require lib }
26
+ end
27
+
28
+ def listen_to_client
29
+ api = Api.new script_processor, stylesheet_processor
30
+ client_interface = ClientInterface.new api, input: STDIN, output: STDOUT
31
+ client_interface.listen
32
+ end
33
+
34
+ def logger
35
+ @logger ||= begin
36
+ logger = Logger.new debug? ? "web_assets.log" : STDERR
37
+ logger.level = debug? ? Logger::DEBUG : Logger::ERROR
38
+ logger
39
+ end
40
+ end
41
+
42
+ def script_processor
43
+ ScriptProcessor.new
44
+ end
45
+
46
+ def stylesheet_processor
47
+ StylesheetProcessor.new
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,49 @@
1
+ require "sprockets"
2
+ require "web_assets/gzipper"
3
+
4
+ module WebAssets
5
+
6
+ class ScriptProcessor
7
+
8
+ attr_reader :environment
9
+
10
+ def initialize
11
+ @environment = Sprockets::Environment.new
12
+ end
13
+
14
+ def set_path path
15
+ return [:error, "#{path} isn't an existing directory."] unless Dir.exists? path
16
+ environment.prepend_path path
17
+ :ok
18
+ end
19
+
20
+ def add_load_path path
21
+ return [:error, "#{path} isn't an existing directory."] unless Dir.exists? path
22
+ environment.append_path path
23
+ :ok
24
+ end
25
+
26
+ def paths
27
+ environment.paths.dup
28
+ end
29
+
30
+ def filenames filename
31
+ return [] unless bundle = environment[filename]
32
+ bundle.to_a.map(&:logical_path)
33
+ end
34
+
35
+ def digest_filename filename
36
+ return "" unless bundle = environment[filename]
37
+ bundle.digest_path
38
+ end
39
+
40
+ def content filename, options
41
+ environment.js_compressor = options[:minify] ? :uglifier : nil
42
+ return "" unless bundle = environment[filename]
43
+ content = options[:bundle] ? bundle.to_s : bundle.body
44
+ options[:gzip] ? Gzipper.compress(content) : content
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,110 @@
1
+ require "compass"
2
+ require "sass/plugin"
3
+ require "fileutils"
4
+ require "digest/md5"
5
+ require "web_assets/gzipper"
6
+
7
+ module WebAssets
8
+
9
+ class StylesheetProcessor
10
+
11
+ RE_EXTENSION = /\.(css|scss|sass)\z/
12
+
13
+ attr_reader :source_path
14
+
15
+ def initialize
16
+ Sass.load_paths.clear
17
+ end
18
+
19
+ def set_path path
20
+ return [:error, "#{path} isn't an existing directory."] unless Dir.exists? path
21
+ @source_path = path
22
+ :ok
23
+ end
24
+
25
+ def add_load_path path
26
+ return [:error, "#{path} isn't an existing directory."] unless Dir.exists? path
27
+ Sass.load_paths << path
28
+ :ok
29
+ end
30
+
31
+ def paths
32
+ Sass.load_paths.dup
33
+ end
34
+
35
+ def content filename, options
36
+ filepath = full_path filename.sub(RE_EXTENSION, '')
37
+ content = case
38
+ when File.exists?("#{filepath}.css")
39
+ File.read "#{filepath}.css"
40
+ when File.exists?("#{filepath}.scss")
41
+ render_sass_file filepath, :scss, render_options(options)
42
+ when File.exists?("#{filepath}.sass")
43
+ render_sass_file filepath, :sass, render_options(options)
44
+ else
45
+ ""
46
+ end
47
+ options[:gzip] ? Gzipper.compress(content) : content
48
+ end
49
+
50
+ def digest_filename filename
51
+ minified = content filename, minify: true
52
+ return "" if minified.empty?
53
+ hexdigest = digest.hexdigest minified
54
+ "#{File.basename filename, ".*"}-#{hexdigest}#{File.extname filename}"
55
+ end
56
+
57
+ private
58
+
59
+ def full_path filename
60
+ File.join source_path, filename
61
+ end
62
+
63
+ def render_options options
64
+ {
65
+ style: options[:minify] ? :compressed : :nested
66
+ }
67
+ end
68
+
69
+ def render_sass_file filepath, syntax, options
70
+ sass_filename = "#{filepath}.#{syntax}"
71
+ sass_options = compiler.sass_options.merge(
72
+ filename: sass_filename,
73
+ css_filename: "#{File.basename filepath}.css",
74
+ syntax: syntax,
75
+ cache: false
76
+ ).merge(options)
77
+ engine = Sass::Engine.new open(sass_filename).read, sass_options
78
+ engine.to_css
79
+ end
80
+
81
+ def compiler
82
+ @compiler ||= Compass::Compiler.new(
83
+ tmp_path,
84
+ source_path,
85
+ destination_path,
86
+ sass: Compass.sass_engine_options
87
+ )
88
+ end
89
+
90
+ def tmp_path
91
+ @tmp_path ||= File.join(Dir.pwd, "tmp").tap do |path|
92
+ FileUtils.mkdir path unless Dir.exists? path
93
+ end
94
+ end
95
+
96
+ def destination_path
97
+ File.join(tmp_path, "css").tap do |path|
98
+ FileUtils.mkdir path unless Dir.exists? path
99
+ end
100
+ end
101
+
102
+ def digest
103
+ @digest ||= Digest::MD5.new.update(VERSION)
104
+ .update(Compass::VERSION)
105
+ .update(Sass::VERSION)
106
+ end
107
+
108
+ end
109
+
110
+ end
@@ -0,0 +1,3 @@
1
+ module WebAssets
2
+ VERSION = "0.0.1"
3
+ end
data/lib/web_assets.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "web_assets/version"
2
+ require "web_assets/command_line"
3
+ require "web_assets/script_processor"
4
+ require "web_assets/stylesheet_processor"
5
+ require "web_assets/api"
6
+ require "web_assets/client_interface"
7
+ require "web_assets/runner"
8
+
9
+ module WebAssets
10
+ end
@@ -0,0 +1,2 @@
1
+ //= require ./lib/useful
2
+ var main = true;
@@ -0,0 +1 @@
1
+ console.log "in useful"
@@ -0,0 +1,2 @@
1
+ $my-red: #d11;
2
+ h1 { color: $my-red; }
@@ -0,0 +1 @@
1
+ body { background-color: #f1f1f1; }
@@ -0,0 +1,91 @@
1
+ require "spec_helper"
2
+
3
+ describe WebAssets::Api do
4
+
5
+ subject { WebAssets::Api.new script_processor, stylesheet_processor }
6
+
7
+ let(:script_processor) { instance_double "WebAssets::ScriptProcessor" }
8
+ let(:stylesheet_processor) { instance_double "WebAssets::StylesheetProcessor" }
9
+
10
+ it "#set_script_path delegates to its script processor" do
11
+ expect(script_processor)
12
+ .to receive(:set_path)
13
+ .with("/the/js/path")
14
+ .and_return(:ok)
15
+
16
+ expect(subject.set_script_path("/the/js/path")).to eq :ok
17
+ end
18
+
19
+ it "#set_stylesheet_path delegates to its stylesheet processor" do
20
+ expect(stylesheet_processor)
21
+ .to receive(:set_path)
22
+ .with("/the/css/path")
23
+ .and_return(:ok)
24
+
25
+ expect(subject.set_stylesheet_path("/the/css/path")).to eq :ok
26
+ end
27
+
28
+ it "#add_script_load_path delegates to its script processor" do
29
+ expect(script_processor)
30
+ .to receive(:add_load_path)
31
+ .with("/some/js/path")
32
+ .and_return(:ok)
33
+
34
+ expect(subject.add_script_load_path("/some/js/path")).to eq :ok
35
+ end
36
+
37
+ it "#add_stylesheet_load_path delegates to its stylesheet processor" do
38
+ expect(stylesheet_processor)
39
+ .to receive(:add_load_path)
40
+ .with("/some/css/path")
41
+ .and_return(:ok)
42
+
43
+ expect(subject.add_stylesheet_load_path("/some/css/path")).to eq :ok
44
+ end
45
+
46
+ it "#script_filenames delegates to its script processor" do
47
+ expect(script_processor)
48
+ .to receive(:filenames)
49
+ .with("application.js")
50
+ .and_return(["one.js", "two.js", "application.js"])
51
+
52
+ expect(subject.script_filenames("application.js")).to eq ["one.js", "two.js", "application.js"]
53
+ end
54
+
55
+ it "#script_digest_filename delegates to its script processor" do
56
+ expect(script_processor)
57
+ .to receive(:digest_filename)
58
+ .with("application.js")
59
+ .and_return("application-123123123.js")
60
+
61
+ expect(subject.script_digest_filename("application.js")).to eq "application-123123123.js"
62
+ end
63
+
64
+ it "#script_content delegates to its script processor" do
65
+ expect(script_processor)
66
+ .to receive(:content)
67
+ .with("application.js", bundle: true, minify: true, gzip: false)
68
+ .and_return("js content")
69
+
70
+ expect(subject.script_content("application.js", minify: true)).to eq "js content"
71
+ end
72
+
73
+ it "#stylesheet_digest_filename delegates to its stylesheet processor" do
74
+ expect(stylesheet_processor)
75
+ .to receive(:digest_filename)
76
+ .with("application.css")
77
+ .and_return("application-42424242.css")
78
+
79
+ expect(subject.stylesheet_digest_filename("application.css")).to eq "application-42424242.css"
80
+ end
81
+
82
+ it "#stylesheet_content delegates to its stylesheet processor" do
83
+ expect(stylesheet_processor)
84
+ .to receive(:content)
85
+ .with("application.css", minify: true, gzip: false)
86
+ .and_return("css content")
87
+
88
+ expect(subject.stylesheet_content("application.css", minify: true)).to eq "css content"
89
+ end
90
+
91
+ end
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+
3
+ describe WebAssets::CommandLine do
4
+
5
+ subject { WebAssets::CommandLine }
6
+
7
+ context "#parse" do
8
+
9
+ it "specifies a library name to load with --require" do
10
+ options = subject.new(%w[--require blah]).parse
11
+ expect(options[:libs]).to eq ["blah"]
12
+ end
13
+
14
+ it "can specify multiple libraries" do
15
+ options = subject.new(%w[-r one -r two -r three]).parse
16
+ expect(options[:libs]).to eq ["one", "two", "three"]
17
+ end
18
+
19
+ it "can set the debug flag" do
20
+ options = subject.new(%w[-d]).parse
21
+ expect(options[:debug]).to eq true
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,97 @@
1
+ require "spec_helper"
2
+
3
+ describe WebAssets::ScriptProcessor do
4
+
5
+ let(:js_fixture_path) { File.expand_path("../fixtures/javascripts", __dir__) }
6
+
7
+ context "#set_path" do
8
+
9
+ it "returns an error if the path doesn't exist" do
10
+ result = subject.set_path("/doesnt/exist")
11
+ expect(result).to eq [:error, "/doesnt/exist isn't an existing directory."]
12
+ end
13
+
14
+ it "sets the stylesheet files path" do
15
+ expect(subject.set_path(__dir__)).to eq :ok
16
+ end
17
+
18
+ end
19
+
20
+ context "#add_load_path" do
21
+
22
+ it "returns an error if the path doesn't exist" do
23
+ result = subject.add_load_path("/doesnt/exist")
24
+ expect(result).to eq [:error, "/doesnt/exist isn't an existing directory."]
25
+ end
26
+
27
+ it "adds the path to the processor load path" do
28
+ expect(subject.add_load_path(__dir__)).to eq :ok
29
+ expect(subject.paths).to eq [__dir__]
30
+ end
31
+
32
+ end
33
+
34
+ context "#filenames" do
35
+
36
+ it "returns an empty list if the file doesn't exist" do
37
+ expect(subject.filenames("no/file.js")).to eq []
38
+ end
39
+
40
+ it "returns the list of file dependencies and the file" do
41
+ subject.set_path js_fixture_path
42
+
43
+ expect(subject.filenames("application.js")).to eq ["lib/useful.js", "application.js"]
44
+ end
45
+
46
+ end
47
+
48
+ context "#content" do
49
+
50
+ before :each do
51
+ subject.set_path js_fixture_path
52
+ end
53
+
54
+ it "returns an empty string if the file doesn't exist" do
55
+ expect(subject.content("no/file.js", {})).to eq ""
56
+ end
57
+
58
+ it "returns the file content unless :bundle is true" do
59
+ content = subject.content("application.js", {})
60
+ expect(content).to eq "var main = true;\n"
61
+ end
62
+
63
+ it "returns the file bundle content if :bundle is true" do
64
+ content = subject.content("application.js", bundle: true)
65
+ expect(content).to eq "(function() {\n console.log(\"in useful\");\n\n}).call(this);\nvar main = true;\n"
66
+ end
67
+
68
+ it "returns the content minified if :minify is true" do
69
+ content = subject.content("application.js", bundle: true, minify: true)
70
+ expect(content).to eq "(function(){console.log(\"in useful\")}).call(this);var main=!0;"
71
+ end
72
+
73
+ it "returns the content gzipped if :gzip is true" do
74
+ gzipped = subject.content("application.js", bundle: true, minify: true, gzip: true)
75
+ content = WebAssets::Gzipper.uncompress gzipped
76
+ expect(content).to eq "(function(){console.log(\"in useful\")}).call(this);var main=!0;"
77
+ end
78
+
79
+ end
80
+
81
+ context "#digest_filename" do
82
+
83
+ before :each do
84
+ subject.set_path js_fixture_path
85
+ end
86
+
87
+ it "returns an empty string if the file doesn't exist" do
88
+ expect(subject.digest_filename("no/file.js")).to eq ""
89
+ end
90
+
91
+ it "returns the digest filename if the file exists" do
92
+ expect(subject.digest_filename("application.js")).to eq "application-73b969089909eeeaab9f39768912d755.js"
93
+ end
94
+
95
+ end
96
+
97
+ end
@@ -0,0 +1,83 @@
1
+ require "spec_helper"
2
+
3
+ describe WebAssets::StylesheetProcessor do
4
+
5
+ let(:css_fixture_path) { File.expand_path("../fixtures/stylesheets", __dir__) }
6
+
7
+ context "#set_path" do
8
+
9
+ it "returns an error if the path doesn't exist" do
10
+ result = subject.set_path("/doesnt/exist")
11
+ expect(result).to eq [:error, "/doesnt/exist isn't an existing directory."]
12
+ end
13
+
14
+ it "sets the stylesheet files path" do
15
+ expect(subject.set_path(__dir__)).to eq :ok
16
+ end
17
+
18
+ end
19
+
20
+ context "#add_load_path" do
21
+
22
+ it "returns an error if the path doesn't exist" do
23
+ result = subject.add_load_path("/doesnt/exist")
24
+ expect(result).to eq [:error, "/doesnt/exist isn't an existing directory."]
25
+ end
26
+
27
+ it "adds the path to the processor load path" do
28
+ expect(subject.add_load_path(__dir__)).to eq :ok
29
+ expect(subject.paths).to eq [__dir__]
30
+ end
31
+
32
+ end
33
+
34
+ context "#content" do
35
+
36
+ before :each do
37
+ subject.set_path css_fixture_path
38
+ end
39
+
40
+ it "returns an empty string if the file doesn't exist" do
41
+ expect(subject.content("no/file.css", {})).to eq ""
42
+ end
43
+
44
+ it "returns the css file content if it does exist" do
45
+ content = subject.content("static.css", {})
46
+ expect(content).to eq "body { background-color: #f1f1f1; }\n"
47
+ end
48
+
49
+ it "returns the pre-processed file content if it exists" do
50
+ content = subject.content("application.css", {})
51
+ expect(content).to match /color: #dd1111;/
52
+ end
53
+
54
+ it "returns the content minified if :minify is true" do
55
+ content = subject.content("application.css", minify: true)
56
+ expect(content).to eq "h1{color:#d11}\n"
57
+ end
58
+
59
+ it "returns the content gzipped if :gzip is true" do
60
+ gzipped = subject.content("application.css", gzip: true, minify: true)
61
+ content = WebAssets::Gzipper.uncompress gzipped
62
+ expect(content).to eq "h1{color:#d11}\n"
63
+ end
64
+
65
+ end
66
+
67
+ context "#digest_filename" do
68
+
69
+ before :each do
70
+ subject.set_path css_fixture_path
71
+ end
72
+
73
+ it "returns an empty string if the file doesn't exist" do
74
+ expect(subject.digest_filename("no/file.css")).to eq ""
75
+ end
76
+
77
+ it "returns the digest filename if the file exists" do
78
+ expect(subject.digest_filename("application.css")).to eq "application-1fc624e75863496c475c1f71d5d4d1e0.css"
79
+ end
80
+
81
+ end
82
+
83
+ end
@@ -0,0 +1,6 @@
1
+ require "bundler/setup"
2
+ require "web_assets"
3
+ require "pry"
4
+
5
+ RSpec.configure do |config|
6
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "web_assets/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "web_assets"
8
+ spec.version = WebAssets::VERSION
9
+ spec.authors = ["Mathieu Lajugie"]
10
+ spec.email = ["mathieul@gmail.com"]
11
+ spec.description = %q{Asset pipeline CLI to be executed from a different language.}
12
+ spec.summary = %q{A command to pre-process web assets using Ruby tools, intended to be called from a different language.}
13
+ spec.homepage = "https://github.com/mathieul/web_assets"
14
+ spec.license = "MIT"
15
+
16
+ spec.required_ruby_version = "~> 2.0"
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "compass", "~> 0.12.2"
24
+ spec.add_dependency "coffee-script", "~> 2.2.0"
25
+ spec.add_dependency "uglifier"
26
+ spec.add_dependency "sprockets", "~> 2.10.0"
27
+ spec.add_dependency "erlectricity", "~> 1.1.1"
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.3"
30
+ spec.add_development_dependency "rake"
31
+ spec.add_development_dependency "rspec", "~> 3.0.0.beta1"
32
+ spec.add_development_dependency "guard-rspec"
33
+ spec.add_development_dependency "pry-nav"
34
+ end
metadata ADDED
@@ -0,0 +1,222 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: web_assets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mathieu Lajugie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-28 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.12.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.12.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: coffee-script
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: uglifier
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: sprockets
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.10.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.10.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: erlectricity
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.1.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.1.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
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: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 3.0.0.beta1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 3.0.0.beta1
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-rspec
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-nav
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: Asset pipeline CLI to be executed from a different language.
154
+ email:
155
+ - mathieul@gmail.com
156
+ executables:
157
+ - web_assets.rb
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - ".gitignore"
162
+ - ".rspec"
163
+ - Gemfile
164
+ - Guardfile
165
+ - LICENSE.txt
166
+ - README.md
167
+ - Rakefile
168
+ - bin/web_assets.rb
169
+ - lib/web_assets.rb
170
+ - lib/web_assets/api.rb
171
+ - lib/web_assets/client_interface.rb
172
+ - lib/web_assets/command_line.rb
173
+ - lib/web_assets/gzipper.rb
174
+ - lib/web_assets/runner.rb
175
+ - lib/web_assets/script_processor.rb
176
+ - lib/web_assets/stylesheet_processor.rb
177
+ - lib/web_assets/version.rb
178
+ - spec/fixtures/javascripts/application.js
179
+ - spec/fixtures/javascripts/lib/useful.coffee
180
+ - spec/fixtures/stylesheets/application.scss
181
+ - spec/fixtures/stylesheets/static.css
182
+ - spec/lib/api_spec.rb
183
+ - spec/lib/command_line_spec.rb
184
+ - spec/lib/script_processor_spec.rb
185
+ - spec/lib/stylesheet_processor_spec.rb
186
+ - spec/spec_helper.rb
187
+ - web_assets.gemspec
188
+ homepage: https://github.com/mathieul/web_assets
189
+ licenses:
190
+ - MIT
191
+ metadata: {}
192
+ post_install_message:
193
+ rdoc_options: []
194
+ require_paths:
195
+ - lib
196
+ required_ruby_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - "~>"
199
+ - !ruby/object:Gem::Version
200
+ version: '2.0'
201
+ required_rubygems_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ requirements: []
207
+ rubyforge_project:
208
+ rubygems_version: 2.2.0
209
+ signing_key:
210
+ specification_version: 4
211
+ summary: A command to pre-process web assets using Ruby tools, intended to be called
212
+ from a different language.
213
+ test_files:
214
+ - spec/fixtures/javascripts/application.js
215
+ - spec/fixtures/javascripts/lib/useful.coffee
216
+ - spec/fixtures/stylesheets/application.scss
217
+ - spec/fixtures/stylesheets/static.css
218
+ - spec/lib/api_spec.rb
219
+ - spec/lib/command_line_spec.rb
220
+ - spec/lib/script_processor_spec.rb
221
+ - spec/lib/stylesheet_processor_spec.rb
222
+ - spec/spec_helper.rb