stylo 0.8.0 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
data/TODO CHANGED
@@ -1,3 +1,2 @@
1
1
  make configuration nicer and more flexible
2
- add minification for css
3
2
  set etags
@@ -0,0 +1 @@
1
+ #child{background:#000000}
@@ -29,8 +29,8 @@ When /^the "([^\"]*)" header should be "([^\"]*)"$/ do |header_key, expected_val
29
29
  end
30
30
 
31
31
  Then /^the response should be from a call back into rack$/ do
32
- last_response.status.should == 404
33
- last_response.body.should include("Sinatra doesn't know this ditty.")
32
+ last_response.status.should == 200
33
+ last_response.body.should include("Hello World!")
34
34
  end
35
35
 
36
36
  When /^javascript combining is disabled$/ do
@@ -51,4 +51,12 @@ end
51
51
 
52
52
  Given /^javascript minifying is enabled$/ do
53
53
  Stylo::Config.options[:js_minifying_enabled] = true
54
- end
54
+ end
55
+
56
+ Given /^css minifying is enabled$/ do
57
+ Stylo::Config.options[:css_minifying_enabled] = true
58
+ end
59
+
60
+ Given /^css minifying is disabled$/ do
61
+ Stylo::Config.options[:css_minifying_enabled] = false
62
+ end
@@ -1,4 +1,6 @@
1
1
  Feature: Stylesheet serving
2
+ Background:
3
+ Given css minifying is disabled
2
4
 
3
5
  Scenario: Simple stylesheet serving
4
6
  Given "child.css" is located at "stylesheets" in the asset location
@@ -51,3 +53,9 @@ Feature: Stylesheet serving
51
53
  """
52
54
  Cannot find referenced asset 'child.css'.
53
55
  """
56
+
57
+ Scenario: Stylesheet minification
58
+ Given css minifying is enabled
59
+ And "child.css" is located at "stylesheets" in the asset location
60
+ When a request is made for "stylesheets/child.css"
61
+ Then the response body should look like "minified_child.css"
@@ -1,12 +1,7 @@
1
1
  require 'rack/test'
2
- require 'sinatra'
3
2
 
4
3
  require File.join(File.dirname(__FILE__), '../../spec/spec_helper')
5
4
 
6
- class MyApp < Sinatra::Application
7
-
8
- end
9
-
10
5
  World do
11
6
  include Rack::Test::Methods
12
7
  include StyloSpecHelpers
@@ -15,7 +10,7 @@ World do
15
10
  def app
16
11
  @app ||= Rack::Builder.new do
17
12
  use Stylo::Rack
18
- run MyApp
13
+ run Proc.new {|env| [200, {"Content-Type" => "text/html"}, "Hello World!"]}
19
14
  end
20
15
  end
21
16
 
data/lib/stylo/config.rb CHANGED
@@ -7,17 +7,19 @@ module Stylo
7
7
 
8
8
  def defaults
9
9
  {
10
- :css_combining_enabled => true,
11
- :js_combining_enabled => true,
12
- :js_minifying_enabled => true
10
+ :css_combining_enabled => true,
11
+ :js_combining_enabled => true,
12
+ :js_minifying_enabled => true,
13
+ :css_minifying_enabled => true
13
14
  }
14
15
  end
15
16
 
16
17
  def pipeline
17
18
  [Stylo::PipelineSteps::Stylesheet.new,
18
- Stylo::PipelineSteps::Javascript.new,
19
- Stylo::PipelineSteps::JavascriptMinifying.new,
20
- Stylo::PipelineSteps::Caching.new]
19
+ Stylo::PipelineSteps::StylesheetMinifying.new,
20
+ Stylo::PipelineSteps::Javascript.new,
21
+ Stylo::PipelineSteps::JavascriptMinifying.new,
22
+ Stylo::PipelineSteps::Caching.new]
21
23
  end
22
24
 
23
25
  def reset_to_default
@@ -0,0 +1,16 @@
1
+ module Stylo
2
+ class CssMinifier
3
+ def self.minify(original)
4
+ result = original.gsub /\s+/, ' '
5
+ result = result.gsub /\/\*.*?\*\//s, ''
6
+ result = result.gsub '; ', ';'
7
+ result = result.gsub ': ', ':'
8
+ result = result.gsub ' {', '{'
9
+ result = result.gsub '{ ', '{'
10
+ result = result.gsub ', ', ','
11
+ result = result.gsub '} ', '}'
12
+ result = result.gsub ';}', '}'
13
+ result.strip
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ module Stylo
2
+ module PipelineSteps
3
+ class StylesheetMinifying
4
+ def call(response)
5
+ if Config.options[:css_minifying_enabled] and response.extension == '.css' and response.has_content?
6
+ minified = CssMinifier.minify(response.body)
7
+ response.set_body minified, :css
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
data/lib/stylo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Stylo
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.5"
3
3
  end
@@ -1,104 +1,44 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Stylo::PipelineSteps::Stylesheet do
4
- let(:step) { Stylo::PipelineSteps::Stylesheet.new }
5
-
6
- describe "when the response has not already been set" do
7
- describe "and the request is not for a stylesheet" do
8
- it "should not set the response" do
9
- response = Stylo::Response.new('javascripts/test.js')
10
- Stylo::AssetLoader.stub(:load_content).with(response.path).and_return('some-content')
11
-
12
- step.call(response)
13
-
14
- response.has_content?.should be_false
15
- end
16
- end
17
-
18
- describe "and the request is for a stylesheet" do
19
- let(:response) { Stylo::Response.new('stylesheets/test.css') }
20
- let(:base_path) { File.dirname(response.path) }
21
-
22
- before(:each) do
23
-
24
- end
25
-
26
- it "should ask the asset loader to load the stylesheet content" do
27
- Stylo::AssetLoader.should_receive(:load_content).with(response.path).and_return(nil)
28
-
29
- step.call(response)
30
- end
31
-
32
- describe "and the asset does not exist" do
33
- it "should not set the response" do
34
- Stylo::AssetLoader.stub(:load_content).and_return(nil)
35
-
36
- step.call(response)
37
-
38
- response.has_content?.should be_false
39
- end
40
- end
41
-
42
- describe "and the asset exists" do
43
- let(:stylesheet_content) { "html { color: $color; }" }
44
- let(:combined_stylesheet_content) { "html { color: red; }" }
45
- let(:combiner) { mock(:combiner) }
46
-
47
- before(:each) do
48
- Stylo::AssetLoader.stub(:load_content).and_return(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)
51
- end
52
-
53
- describe "and combining is enabled" do
54
- before(:each) do
55
- Stylo::Config.options[:css_combining_enabled] = true
56
- end
57
-
58
- it "should tell the combiner to process the stylesheet content" do
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)
3
+ describe Stylo::PipelineSteps::StylesheetMinifying do
4
+ before(:each) do
5
+ Stylo::Config.options[:css_minifying_enabled] = true
6
+ end
61
7
 
62
- step.call(response)
63
- end
8
+ let(:step) { Stylo::PipelineSteps::StylesheetMinifying.new }
64
9
 
65
- it "should set the body of the response to the combined stylesheet content" do
66
- step.call(response)
10
+ describe "when the response body is not a stylesheet" do
11
+ it "should not modify the response body" do
12
+ response = Stylo::Response.new('javascripts/test.js')
13
+ original_body = "alert('hello');"
14
+ response.set_body(original_body, :javascript)
67
15
 
68
- response.body.should == combined_stylesheet_content
69
- end
70
- end
16
+ step.call(response)
71
17
 
72
- describe "and combining is disabled" do
73
- before(:each) do
74
- Stylo::Config.options[:css_combining_enabled] = false
75
- end
18
+ response.body.should == original_body
19
+ end
20
+ end
76
21
 
77
- it "should set the body of the response to the stylesheet content" do
78
- step.call(response)
22
+ describe "when the response body is a stylesheet" do
23
+ let(:response) { Stylo::Response.new('stylesheets/test.css') }
24
+ let(:minified_stylesheet) { 'I am minified!' }
79
25
 
80
- response.body.should == stylesheet_content
81
- end
26
+ before(:each) do
27
+ response.set_body('some stylesheet', :css)
82
28
 
83
- end
29
+ Stylo::CssMinifier.stub(:minify).and_return(minified_stylesheet)
30
+ end
84
31
 
85
- it "should set the content type to text/css" do
86
- step.call(response)
32
+ it "should ask the css minifier to minify the stylesheet" do
33
+ Stylo::CssMinifier.should_receive(:minify).with(response.body)
87
34
 
88
- response.headers['Content-Type'].should == 'text/css'
89
- end
90
- end
35
+ step.call(response)
91
36
  end
92
- end
93
-
94
- describe "when the response has already been set" do
95
- it "should not alter the response" do
96
- response = Stylo::Response.new('stylesheets/test.css')
97
- response.set_body('some-content', :css)
98
37
 
38
+ it "should replace the response body with the minified text" do
99
39
  step.call(response)
100
40
 
101
- response.body.should == 'some-content'
41
+ response.body.should == minified_stylesheet
102
42
  end
103
43
  end
104
44
  end
data/stylo.gemspec CHANGED
@@ -25,5 +25,4 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency('rspec', '>= 2.1.0')
26
26
  s.add_development_dependency('bundler')
27
27
  s.add_development_dependency('rack-test')
28
- s.add_development_dependency('sinatra')
29
28
  end
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: 63
4
+ hash: 53
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 0
10
- version: 0.8.0
9
+ - 5
10
+ version: 0.8.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mike Wagg
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-19 00:00:00 +00:00
18
+ date: 2010-12-07 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -76,20 +76,6 @@ dependencies:
76
76
  version: "0"
77
77
  type: :development
78
78
  version_requirements: *id004
79
- - !ruby/object:Gem::Dependency
80
- name: sinatra
81
- prerelease: false
82
- requirement: &id005 !ruby/object:Gem::Requirement
83
- none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- version: "0"
91
- type: :development
92
- version_requirements: *id005
93
79
  description: |-
94
80
  A rack middleware which does css and javascript combining
95
81
  and minification for sites hosted in readonly filesystem environments
@@ -118,6 +104,7 @@ files:
118
104
  - features/fixtures/grand_parent.js
119
105
  - features/fixtures/grand_parent_with_parent_with_child.css
120
106
  - features/fixtures/grand_parent_with_parent_with_child.js
107
+ - features/fixtures/minified_child.css
121
108
  - features/fixtures/nested_folder_grand_parent.css
122
109
  - features/fixtures/nested_folder_grand_parent_with_parent_with_child.css
123
110
  - features/fixtures/parent.css
@@ -137,10 +124,12 @@ files:
137
124
  - lib/stylo/asset_loader.rb
138
125
  - lib/stylo/combiner.rb
139
126
  - lib/stylo/config.rb
127
+ - lib/stylo/css_minifier.rb
140
128
  - lib/stylo/pipeline_steps/caching.rb
141
129
  - lib/stylo/pipeline_steps/javascript.rb
142
130
  - lib/stylo/pipeline_steps/javascript_minifying.rb
143
131
  - lib/stylo/pipeline_steps/stylesheet.rb
132
+ - lib/stylo/pipeline_steps/stylesheet_minifying.rb
144
133
  - lib/stylo/processor.rb
145
134
  - lib/stylo/rack.rb
146
135
  - lib/stylo/railtie.rb
@@ -199,6 +188,7 @@ test_files:
199
188
  - features/fixtures/grand_parent.js
200
189
  - features/fixtures/grand_parent_with_parent_with_child.css
201
190
  - features/fixtures/grand_parent_with_parent_with_child.js
191
+ - features/fixtures/minified_child.css
202
192
  - features/fixtures/nested_folder_grand_parent.css
203
193
  - features/fixtures/nested_folder_grand_parent_with_parent_with_child.css
204
194
  - features/fixtures/parent.css