stylo 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/TODO +2 -2
- data/features/fixtures/nested_folder_grand_parent.css +5 -0
- data/features/fixtures/nested_folder_grand_parent_with_parent_with_child.css +11 -0
- data/features/step_definitions/stylo_steps.rb +11 -1
- data/features/stylesheets.feature +16 -1
- data/lib/stylo/combiner.rb +8 -5
- data/lib/stylo/pipeline_steps/javascript.rb +1 -1
- data/lib/stylo/pipeline_steps/sass.rb +2 -2
- data/lib/stylo/pipeline_steps/stylesheet.rb +2 -2
- data/spec/combiner_spec.rb +27 -11
- data/spec/pipeline_steps/javascript_spec.rb +6 -5
- data/spec/pipeline_steps/sass_spec.rb +6 -5
- data/spec/pipeline_steps/stylesheet_spec.rb +6 -5
- data/stylo.gemspec +4 -2
- metadata +7 -5
data/Rakefile
CHANGED
@@ -18,7 +18,7 @@ begin
|
|
18
18
|
gem.add_development_dependency "sinatra", ">= 0"
|
19
19
|
gem.add_development_dependency "rails", ">= 3.0.0"
|
20
20
|
gem.add_runtime_dependency "haml", ">= 3.0.21"
|
21
|
-
gem.version = "0.
|
21
|
+
gem.version = "0.6.0"
|
22
22
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
23
23
|
end
|
24
24
|
Jeweler::GemcutterTasks.new
|
data/TODO
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
make configuration nicer and more flexible
|
2
2
|
add minification for javascript
|
3
3
|
add minification for css
|
4
|
-
make it so sass is
|
4
|
+
make it so sass is not used if the sass gem is not available (without making the pipeline configuration messy)
|
@@ -2,10 +2,20 @@ Given /^"([^"]*)" is located at "([^"]*)" in the asset location$/ do |filename,
|
|
2
2
|
cp fixture_path(filename), temp_path(folder)
|
3
3
|
end
|
4
4
|
|
5
|
+
Given /^a folder "([^"]*)" exists at "([^"]*)" in the asset location$/ do |folder_name, folder|
|
6
|
+
mkdir temp_path("#{folder}/#{folder_name}")
|
7
|
+
end
|
8
|
+
|
9
|
+
|
5
10
|
When /^a request is made for "([^"]*)"$/ do |path|
|
6
11
|
get path
|
7
12
|
end
|
8
13
|
|
14
|
+
When /^a request is made for "([^"]*)" the following error should be raised$/ do |path, expected_error|
|
15
|
+
proc { get path }.should raise_error(expected_error)
|
16
|
+
end
|
17
|
+
|
18
|
+
|
9
19
|
Then /^the response body should look like "([^"]*)"$/ do |filename|
|
10
20
|
last_response.body.should == load_fixture(filename)
|
11
21
|
end
|
@@ -29,4 +39,4 @@ end
|
|
29
39
|
|
30
40
|
When /^css combining is disabled$/ do
|
31
41
|
Stylo::Config.css_combining_enabled = false
|
32
|
-
end
|
42
|
+
end
|
@@ -25,6 +25,14 @@ Feature: Stylesheet serving
|
|
25
25
|
When a request is made for "stylesheets/grand_parent.css"
|
26
26
|
Then the response body should look like "grand_parent_with_parent_with_child.css"
|
27
27
|
|
28
|
+
Scenario: Stylesheet combining in nested folders
|
29
|
+
Given "nested_folder_grand_parent.css" is located at "stylesheets" in the asset location
|
30
|
+
And a folder "a_folder" exists at "stylesheets" in the asset location
|
31
|
+
And "parent.css" is located at "stylesheets/a_folder" in the asset location
|
32
|
+
And "child.css" is located at "stylesheets/a_folder" in the asset location
|
33
|
+
When a request is made for "stylesheets/nested_folder_grand_parent.css"
|
34
|
+
Then the response body should look like "nested_folder_grand_parent_with_parent_with_child.css"
|
35
|
+
|
28
36
|
Scenario: Stylesheet responses should have the correct headers
|
29
37
|
Given "child.css" is located at "stylesheets" in the asset location
|
30
38
|
When a request is made for "stylesheets/child.css"
|
@@ -35,4 +43,11 @@ Feature: Stylesheet serving
|
|
35
43
|
Scenario: Stylesheets should be cached
|
36
44
|
Given "child.css" is located at "stylesheets" in the asset location
|
37
45
|
When a request is made for "stylesheets/child.css"
|
38
|
-
Then the "Cache-Control" header should be "public, max-age=86400"
|
46
|
+
Then the "Cache-Control" header should be "public, max-age=86400"
|
47
|
+
|
48
|
+
Scenario: When a referenced stylesheet does not exist
|
49
|
+
Given "parent.css" is located at "stylesheets" in the asset location
|
50
|
+
When a request is made for "stylesheets/parent.css" the following error should be raised
|
51
|
+
"""
|
52
|
+
Cannot find referenced asset 'child.css'.
|
53
|
+
"""
|
data/lib/stylo/combiner.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
module Stylo
|
2
2
|
class Combiner
|
3
|
-
def initialize(
|
3
|
+
def initialize(require_pattern)
|
4
4
|
@require_pattern = require_pattern
|
5
|
-
@asset_directory = asset_directory
|
6
5
|
end
|
7
6
|
|
8
|
-
def process(content)
|
7
|
+
def process(base_directory, content)
|
9
8
|
content.gsub @require_pattern do |match|
|
10
|
-
|
9
|
+
required_dir = File.dirname($1)
|
10
|
+
required_dir = required_dir == '.' ? base_directory : File.join(base_directory, required_dir)
|
11
|
+
|
12
|
+
raise "Cannot find referenced asset '#{$1}'." if !(content = AssetLoader.load_content(File.join(base_directory, $1)))
|
13
|
+
process(required_dir, content)
|
11
14
|
end
|
12
15
|
end
|
13
16
|
end
|
14
|
-
end
|
17
|
+
end
|
@@ -8,7 +8,7 @@ module Stylo
|
|
8
8
|
return unless content = AssetLoader.load_content(response.path)
|
9
9
|
|
10
10
|
if Config.javascript_combining_enabled
|
11
|
-
content = Combiner.new(File.dirname(response.path),
|
11
|
+
content = Combiner.new(REQUIRE_PATTERN).process(File.dirname(response.path), content)
|
12
12
|
end
|
13
13
|
|
14
14
|
response.set_body content, :javascript
|
@@ -8,11 +8,11 @@ module Stylo
|
|
8
8
|
content = AssetLoader.load_content(response.path.gsub('.css', '.scss'))
|
9
9
|
return if content.nil?
|
10
10
|
|
11
|
-
combined_content = Combiner.new(File.dirname(response.path),
|
11
|
+
combined_content = Combiner.new(REQUIRE_PATTERN).process(File.dirname(response.path), content)
|
12
12
|
processed_content = ::Sass::Engine.new(combined_content, {:syntax => :scss}).render
|
13
13
|
|
14
14
|
response.set_body(processed_content, :css)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
-
end
|
18
|
+
end
|
@@ -8,11 +8,11 @@ module Stylo
|
|
8
8
|
return unless content = AssetLoader.load_content(response.path)
|
9
9
|
|
10
10
|
if Config.css_combining_enabled
|
11
|
-
content = Combiner.new(File.dirname(response.path),
|
11
|
+
content = Combiner.new(REQUIRE_PATTERN).process(File.dirname(response.path), content)
|
12
12
|
end
|
13
13
|
|
14
14
|
response.set_body content, :css
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
-
end
|
18
|
+
end
|
data/spec/combiner_spec.rb
CHANGED
@@ -2,13 +2,13 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Stylo::Combiner do
|
4
4
|
let(:request_path_directory) { 'assets' }
|
5
|
-
let(:combiner) { Stylo::Combiner.new(
|
5
|
+
let(:combiner) { Stylo::Combiner.new(/require "(.*)";/) }
|
6
6
|
|
7
7
|
describe "when the content does not contain the require pattern" do
|
8
8
|
let(:content) { "This is some text." }
|
9
9
|
|
10
10
|
it "should return the content" do
|
11
|
-
combiner.process(content).should == content
|
11
|
+
combiner.process(request_path_directory, content).should == content
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -22,20 +22,36 @@ describe Stylo::Combiner do
|
|
22
22
|
it "should load required content from the asset loader" do
|
23
23
|
Stylo::AssetLoader.should_receive(:load_content).with('assets/some_other_file').and_return('the required content.')
|
24
24
|
|
25
|
-
combiner.process(content)
|
25
|
+
combiner.process(request_path_directory, content)
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
describe "when the required content exists" do
|
29
|
+
before(:each) do
|
30
|
+
Stylo::AssetLoader.stub(:load_content).with('assets/some_other_file').and_return('the required content.')
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return the required content" do
|
34
|
+
combiner.process(request_path_directory, content).should == 'the required content. and then some other content'
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "and the required content has the require pattern" do
|
38
|
+
it "should combine the content recursively" do
|
39
|
+
Stylo::AssetLoader.stub(:load_content).with('assets/some_other_file').and_return('require "yet_another_file"; the required content.')
|
40
|
+
Stylo::AssetLoader.stub(:load_content).with('assets/yet_another_file').and_return('the other required content.')
|
41
|
+
|
42
|
+
combiner.process(request_path_directory, content).should == "the other required content. the required content. and then some other content"
|
43
|
+
end
|
44
|
+
end
|
30
45
|
end
|
31
46
|
|
32
|
-
describe "
|
33
|
-
|
34
|
-
|
35
|
-
|
47
|
+
describe "when the required content does not exist" do
|
48
|
+
before(:each) do
|
49
|
+
Stylo::AssetLoader.stub(:load_content).with('assets/some_other_file').and_return(nil)
|
50
|
+
end
|
36
51
|
|
37
|
-
|
52
|
+
it "should raise an error" do
|
53
|
+
proc { combiner.process(request_path_directory, content) }.should raise_error("Cannot find referenced asset 'some_other_file'.")
|
38
54
|
end
|
39
55
|
end
|
40
56
|
end
|
41
|
-
end
|
57
|
+
end
|
@@ -17,6 +17,7 @@ describe Stylo::PipelineSteps::Javascript do
|
|
17
17
|
|
18
18
|
describe "and the request is for a javascript asset" do
|
19
19
|
let(:response) { Stylo::Response.new('javascripts/test.js') }
|
20
|
+
let(:base_path) { File.dirname(response.path) }
|
20
21
|
|
21
22
|
before(:each) do
|
22
23
|
|
@@ -45,8 +46,8 @@ describe Stylo::PipelineSteps::Javascript do
|
|
45
46
|
|
46
47
|
before(:each) do
|
47
48
|
Stylo::AssetLoader.stub(:load_content).and_return(javascript_content)
|
48
|
-
Stylo::Combiner.stub(:new).with(
|
49
|
-
combiner.stub(:process).with(javascript_content).and_return(combined_javascript_content)
|
49
|
+
Stylo::Combiner.stub(:new).with(/\/\/\/require "(.*)";/).and_return(combiner)
|
50
|
+
combiner.stub(:process).with(base_path, javascript_content).and_return(combined_javascript_content)
|
50
51
|
end
|
51
52
|
|
52
53
|
describe "and combining is enabled" do
|
@@ -55,8 +56,8 @@ describe Stylo::PipelineSteps::Javascript do
|
|
55
56
|
end
|
56
57
|
|
57
58
|
it "should tell the combiner to process the javascript content" do
|
58
|
-
Stylo::Combiner.should_receive(:new).with(
|
59
|
-
combiner.should_receive(:process).with(javascript_content).and_return(combined_javascript_content)
|
59
|
+
Stylo::Combiner.should_receive(:new).with(/\/\/\/require "(.*)";/).and_return(combiner)
|
60
|
+
combiner.should_receive(:process).with(base_path, javascript_content).and_return(combined_javascript_content)
|
60
61
|
|
61
62
|
step.call(response)
|
62
63
|
end
|
@@ -99,4 +100,4 @@ describe Stylo::PipelineSteps::Javascript do
|
|
99
100
|
response.body.should == 'some-content'
|
100
101
|
end
|
101
102
|
end
|
102
|
-
end
|
103
|
+
end
|
@@ -19,6 +19,7 @@ describe Stylo::PipelineSteps::Sass do
|
|
19
19
|
let(:requested_path) { 'stylesheets/test.css' }
|
20
20
|
let(:sass_path) { 'stylesheets/test.scss' }
|
21
21
|
let(:response) { Stylo::Response.new(requested_path) }
|
22
|
+
let(:base_path) { File.dirname(response.path) }
|
22
23
|
|
23
24
|
it "should ask the asset loader to load the sass stylesheet content" do
|
24
25
|
Stylo::AssetLoader.should_receive(:load_content).with(sass_path).and_return(nil)
|
@@ -45,15 +46,15 @@ describe Stylo::PipelineSteps::Sass do
|
|
45
46
|
|
46
47
|
before(:each) do
|
47
48
|
Stylo::AssetLoader.stub(:load_content).and_return(stylesheet_content)
|
48
|
-
Stylo::Combiner.stub(:new).with(
|
49
|
-
combiner.stub(:process).with(stylesheet_content).and_return(combined_stylesheet_content)
|
49
|
+
Stylo::Combiner.stub(:new).with(/@import "(.*)";/).and_return(combiner)
|
50
|
+
combiner.stub(:process).with(base_path, stylesheet_content).and_return(combined_stylesheet_content)
|
50
51
|
::Sass::Engine.stub(:new).with(combined_stylesheet_content, {:syntax => :scss}).and_return(sass_engine)
|
51
52
|
sass_engine.stub(:render).and_return(processed_content)
|
52
53
|
end
|
53
54
|
|
54
55
|
it "should tell the combiner to process the stylesheet content" do
|
55
|
-
Stylo::Combiner.should_receive(:new).with(
|
56
|
-
combiner.should_receive(:process).with(stylesheet_content).and_return(combined_stylesheet_content)
|
56
|
+
Stylo::Combiner.should_receive(:new).with(/@import "(.*)";/).and_return(combiner)
|
57
|
+
combiner.should_receive(:process).with(base_path, stylesheet_content).and_return(combined_stylesheet_content)
|
57
58
|
|
58
59
|
step.call(response)
|
59
60
|
end
|
@@ -91,4 +92,4 @@ describe Stylo::PipelineSteps::Sass do
|
|
91
92
|
end
|
92
93
|
end
|
93
94
|
|
94
|
-
end
|
95
|
+
end
|
@@ -17,6 +17,7 @@ describe Stylo::PipelineSteps::Stylesheet do
|
|
17
17
|
|
18
18
|
describe "and the request is for a stylesheet" do
|
19
19
|
let(:response) { Stylo::Response.new('stylesheets/test.css') }
|
20
|
+
let(:base_path) { File.dirname(response.path) }
|
20
21
|
|
21
22
|
before(:each) do
|
22
23
|
|
@@ -45,8 +46,8 @@ describe Stylo::PipelineSteps::Stylesheet do
|
|
45
46
|
|
46
47
|
before(:each) do
|
47
48
|
Stylo::AssetLoader.stub(:load_content).and_return(stylesheet_content)
|
48
|
-
Stylo::Combiner.stub(:new).with(
|
49
|
-
combiner.stub(:process).with(stylesheet_content).and_return(combined_stylesheet_content)
|
49
|
+
Stylo::Combiner.stub(:new).with(/@import "(.*)";/).and_return(combiner)
|
50
|
+
combiner.stub(:process).with(base_path, stylesheet_content).and_return(combined_stylesheet_content)
|
50
51
|
end
|
51
52
|
|
52
53
|
describe "and combining is enabled" do
|
@@ -55,8 +56,8 @@ describe Stylo::PipelineSteps::Stylesheet do
|
|
55
56
|
end
|
56
57
|
|
57
58
|
it "should tell the combiner to process the stylesheet content" do
|
58
|
-
Stylo::Combiner.should_receive(:new).with(
|
59
|
-
combiner.should_receive(:process).with(stylesheet_content).and_return(combined_stylesheet_content)
|
59
|
+
Stylo::Combiner.should_receive(:new).with(/@import "(.*)";/).and_return(combiner)
|
60
|
+
combiner.should_receive(:process).with(base_path, stylesheet_content).and_return(combined_stylesheet_content)
|
60
61
|
|
61
62
|
step.call(response)
|
62
63
|
end
|
@@ -100,4 +101,4 @@ describe Stylo::PipelineSteps::Stylesheet do
|
|
100
101
|
response.body.should == 'some-content'
|
101
102
|
end
|
102
103
|
end
|
103
|
-
end
|
104
|
+
end
|
data/stylo.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{stylo}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.6.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["mwagg"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-03}
|
13
13
|
s.description = %q{Server side stylesheet combining for readonly hosting environments}
|
14
14
|
s.email = %q{michael@guerillatactics.co.uk}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,6 +32,8 @@ Gem::Specification.new do |s|
|
|
32
32
|
"features/fixtures/grand_parent.js",
|
33
33
|
"features/fixtures/grand_parent_with_parent_with_child.css",
|
34
34
|
"features/fixtures/grand_parent_with_parent_with_child.js",
|
35
|
+
"features/fixtures/nested_folder_grand_parent.css",
|
36
|
+
"features/fixtures/nested_folder_grand_parent_with_parent_with_child.css",
|
35
37
|
"features/fixtures/parent.css",
|
36
38
|
"features/fixtures/parent.js",
|
37
39
|
"features/fixtures/parent_with_child.css",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stylo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 6
|
9
|
+
- 0
|
10
|
+
version: 0.6.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- mwagg
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-03 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -131,6 +131,8 @@ files:
|
|
131
131
|
- features/fixtures/grand_parent.js
|
132
132
|
- features/fixtures/grand_parent_with_parent_with_child.css
|
133
133
|
- features/fixtures/grand_parent_with_parent_with_child.js
|
134
|
+
- features/fixtures/nested_folder_grand_parent.css
|
135
|
+
- features/fixtures/nested_folder_grand_parent_with_parent_with_child.css
|
134
136
|
- features/fixtures/parent.css
|
135
137
|
- features/fixtures/parent.js
|
136
138
|
- features/fixtures/parent_with_child.css
|