stylo 0.5 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -16,8 +16,9 @@ begin
16
16
  gem.add_development_dependency "cucumber", ">= 0"
17
17
  gem.add_development_dependency "rack-test", ">= 0"
18
18
  gem.add_development_dependency "sinatra", ">= 0"
19
+ gem.add_development_dependency "rails", ">= 3.0.0"
19
20
  gem.add_runtime_dependency "haml", ">= 3.0.21"
20
- gem.version = "0.5"
21
+ gem.version = "0.5.1"
21
22
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
22
23
  end
23
24
  Jeweler::GemcutterTasks.new
@@ -5,6 +5,13 @@ Feature: Javascript serving
5
5
  When a request is made for "javascripts/child.js"
6
6
  Then the response body should look like "child.js"
7
7
 
8
+ Scenario: Simple javascript combining
9
+ Given "parent.js" is located at "javascripts" in the asset location
10
+ And "child.js" is located at "javascripts" in the asset location
11
+ And javascript combining is disabled
12
+ When a request is made for "javascripts/parent.js"
13
+ Then the response body should look like "parent.js"
14
+
8
15
  Scenario: Simple javascript combining
9
16
  Given "parent.js" is located at "javascripts" in the asset location
10
17
  And "child.js" is located at "javascripts" in the asset location
@@ -21,4 +21,12 @@ end
21
21
  Then /^the response should be from a call back into rack$/ do
22
22
  last_response.status.should == 404
23
23
  last_response.body.should include("Sinatra doesn't know this ditty.")
24
+ end
25
+
26
+ When /^javascript combining is disabled$/ do
27
+ Stylo::Config.javascript_combining_enabled = false
28
+ end
29
+
30
+ When /^css combining is disabled$/ do
31
+ Stylo::Config.css_combining_enabled = false
24
32
  end
@@ -5,6 +5,13 @@ Feature: Stylesheet serving
5
5
  When a request is made for "stylesheets/child.css"
6
6
  Then the response body should look like "child.css"
7
7
 
8
+ Scenario: Combining does not take place when it is disabled
9
+ Given "parent.css" is located at "stylesheets" in the asset location
10
+ And "child.css" is located at "stylesheets" in the asset location
11
+ And css combining is disabled
12
+ When a request is made for "stylesheets/parent.css"
13
+ Then the response body should look like "parent.css"
14
+
8
15
  Scenario: Simple stylesheet combining
9
16
  Given "parent.css" is located at "stylesheets" in the asset location
10
17
  And "child.css" is located at "stylesheets" in the asset location
@@ -22,3 +22,7 @@ World do
22
22
  reset_paths
23
23
  end
24
24
 
25
+ Before do
26
+ Stylo::Config.reset_to_default
27
+ end
28
+
data/lib/stylo/config.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Stylo
2
2
  class Config
3
3
  class << self
4
- attr_accessor :asset_location
4
+ attr_accessor :asset_location, :css_combining_enabled, :javascript_combining_enabled
5
5
 
6
6
  def pipeline
7
7
  [Stylo::PipelineSteps::Stylesheet.new,
@@ -9,6 +9,13 @@ module Stylo
9
9
  Stylo::PipelineSteps::Sass.new,
10
10
  Stylo::PipelineSteps::Caching.new]
11
11
  end
12
+
13
+ def reset_to_default
14
+ self.css_combining_enabled = true
15
+ self.javascript_combining_enabled = true
16
+ end
12
17
  end
18
+
19
+ reset_to_default
13
20
  end
14
21
  end
@@ -6,9 +6,12 @@ module Stylo
6
6
  def call(response)
7
7
  return if response.has_content? || response.extension != '.js'
8
8
  return unless content = AssetLoader.load_content(response.path)
9
- combined_content = Combiner.new(File.dirname(response.path), REQUIRE_PATTERN).process(content)
10
9
 
11
- response.set_body combined_content, :javascript
10
+ if Config.javascript_combining_enabled
11
+ content = Combiner.new(File.dirname(response.path), REQUIRE_PATTERN).process(content)
12
+ end
13
+
14
+ response.set_body content, :javascript
12
15
  end
13
16
  end
14
17
  end
@@ -6,9 +6,12 @@ module Stylo
6
6
  def call(response)
7
7
  return if response.has_content? || response.extension != '.css'
8
8
  return unless content = AssetLoader.load_content(response.path)
9
- combined_content = Combiner.new(File.dirname(response.path), REQUIRE_PATTERN).process(content)
10
9
 
11
- response.set_body combined_content, :css
10
+ if Config.css_combining_enabled
11
+ content = Combiner.new(File.dirname(response.path), REQUIRE_PATTERN).process(content)
12
+ end
13
+
14
+ response.set_body content, :css
12
15
  end
13
16
  end
14
17
  end
@@ -49,17 +49,35 @@ describe Stylo::PipelineSteps::Javascript do
49
49
  combiner.stub(:process).with(javascript_content).and_return(combined_javascript_content)
50
50
  end
51
51
 
52
- it "should tell the combiner to process the javascript content" do
53
- Stylo::Combiner.should_receive(:new).with('javascripts', /\/\/\/require "(.*)";/).and_return(combiner)
54
- combiner.should_receive(:process).with(javascript_content).and_return(combined_javascript_content)
52
+ describe "and combining is enabled" do
53
+ before(:each) do
54
+ Stylo::Config.javascript_combining_enabled = true
55
+ end
55
56
 
56
- step.call(response)
57
+ it "should tell the combiner to process the javascript content" do
58
+ Stylo::Combiner.should_receive(:new).with('javascripts', /\/\/\/require "(.*)";/).and_return(combiner)
59
+ combiner.should_receive(:process).with(javascript_content).and_return(combined_javascript_content)
60
+
61
+ step.call(response)
62
+ end
63
+
64
+ it "should set the body of the response to the combined javascript content" do
65
+ step.call(response)
66
+
67
+ response.body.should == combined_javascript_content
68
+ end
57
69
  end
58
70
 
59
- it "should set the body of the response to the combined javascript content" do
60
- step.call(response)
71
+ describe "and combining is disabled" do
72
+ before(:each) do
73
+ Stylo::Config.javascript_combining_enabled = false
74
+ end
75
+
76
+ it "should set the body of the response to the javascript content" do
77
+ step.call(response)
61
78
 
62
- response.body.should == combined_javascript_content
79
+ response.body.should == javascript_content
80
+ end
63
81
  end
64
82
 
65
83
  it "should set the content type to text/javascript" do
@@ -49,17 +49,36 @@ describe Stylo::PipelineSteps::Stylesheet do
49
49
  combiner.stub(:process).with(stylesheet_content).and_return(combined_stylesheet_content)
50
50
  end
51
51
 
52
- it "should tell the combiner to process the stylesheet content" do
53
- Stylo::Combiner.should_receive(:new).with('stylesheets', /@import "(.*)";/).and_return(combiner)
54
- combiner.should_receive(:process).with(stylesheet_content).and_return(combined_stylesheet_content)
52
+ describe "and combining is enabled" do
53
+ before(:each) do
54
+ Stylo::Config.css_combining_enabled = true
55
+ end
55
56
 
56
- step.call(response)
57
+ it "should tell the combiner to process the stylesheet content" do
58
+ Stylo::Combiner.should_receive(:new).with('stylesheets', /@import "(.*)";/).and_return(combiner)
59
+ combiner.should_receive(:process).with(stylesheet_content).and_return(combined_stylesheet_content)
60
+
61
+ step.call(response)
62
+ end
63
+
64
+ it "should set the body of the response to the combined stylesheet content" do
65
+ step.call(response)
66
+
67
+ response.body.should == combined_stylesheet_content
68
+ end
57
69
  end
58
70
 
59
- it "should set the body of the response to the combined stylesheet content" do
60
- step.call(response)
71
+ describe "and combining is disabled" do
72
+ before(:each) do
73
+ Stylo::Config.css_combining_enabled = false
74
+ end
75
+
76
+ it "should set the body of the response to the stylesheet content" do
77
+ step.call(response)
78
+
79
+ response.body.should == stylesheet_content
80
+ end
61
81
 
62
- response.body.should == combined_stylesheet_content
63
82
  end
64
83
 
65
84
  it "should set the content type to text/css" do
data/spec/spec_helper.rb CHANGED
@@ -12,6 +12,7 @@ RSpec.configure do |config|
12
12
 
13
13
  config.before(:each) do
14
14
  reset_paths
15
+ Stylo::Config.reset_to_default
15
16
  end
16
17
  end
17
18
 
data/stylo.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{stylo}
8
- s.version = "0.5"
8
+ s.version = "0.5.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["mwagg"]
@@ -97,12 +97,14 @@ Gem::Specification.new do |s|
97
97
  s.add_development_dependency(%q<cucumber>, [">= 0"])
98
98
  s.add_development_dependency(%q<rack-test>, [">= 0"])
99
99
  s.add_development_dependency(%q<sinatra>, [">= 0"])
100
+ s.add_development_dependency(%q<rails>, [">= 3.0.0"])
100
101
  s.add_runtime_dependency(%q<haml>, [">= 3.0.21"])
101
102
  else
102
103
  s.add_dependency(%q<rspec>, [">= 0"])
103
104
  s.add_dependency(%q<cucumber>, [">= 0"])
104
105
  s.add_dependency(%q<rack-test>, [">= 0"])
105
106
  s.add_dependency(%q<sinatra>, [">= 0"])
107
+ s.add_dependency(%q<rails>, [">= 3.0.0"])
106
108
  s.add_dependency(%q<haml>, [">= 3.0.21"])
107
109
  end
108
110
  else
@@ -110,6 +112,7 @@ Gem::Specification.new do |s|
110
112
  s.add_dependency(%q<cucumber>, [">= 0"])
111
113
  s.add_dependency(%q<rack-test>, [">= 0"])
112
114
  s.add_dependency(%q<sinatra>, [">= 0"])
115
+ s.add_dependency(%q<rails>, [">= 3.0.0"])
113
116
  s.add_dependency(%q<haml>, [">= 3.0.21"])
114
117
  end
115
118
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stylo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- version: "0.5"
9
+ - 1
10
+ version: 0.5.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - mwagg
@@ -74,9 +75,25 @@ dependencies:
74
75
  type: :development
75
76
  version_requirements: *id004
76
77
  - !ruby/object:Gem::Dependency
77
- name: haml
78
+ name: rails
78
79
  prerelease: false
79
80
  requirement: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 7
86
+ segments:
87
+ - 3
88
+ - 0
89
+ - 0
90
+ version: 3.0.0
91
+ type: :development
92
+ version_requirements: *id005
93
+ - !ruby/object:Gem::Dependency
94
+ name: haml
95
+ prerelease: false
96
+ requirement: &id006 !ruby/object:Gem::Requirement
80
97
  none: false
81
98
  requirements:
82
99
  - - ">="
@@ -88,7 +105,7 @@ dependencies:
88
105
  - 21
89
106
  version: 3.0.21
90
107
  type: :runtime
91
- version_requirements: *id005
108
+ version_requirements: *id006
92
109
  description: Server side stylesheet combining for readonly hosting environments
93
110
  email: michael@guerillatactics.co.uk
94
111
  executables: []