hassle3 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2009, Pedro Belo, Nick Quaranto
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,115 @@
1
+ h1. Hassle
2
+
3
+ Making "SASS":http://sass-lang.com/ less of a hassle on read only filesystems. (like "Heroku":http://heroku.com)
4
+
5
+ IMPORTANT: This is for rails 3. If you want hassle for rails 2, then you should use "the original one":http://github.com/pedro/hassle
6
+
7
+ h2. Install
8
+
9
+ Get it from "Gemcutter.":http://gemcutter.org
10
+
11
+ <pre>
12
+ gem install hassle -s http://gemcutter.org
13
+ </pre>
14
+
15
+ h2. Usage
16
+
17
+ By default, SASS compiles CSS into the @public/@ directory. On platforms like Heroku, "this won't work.":http://docs.heroku.com/constraints#read-only-filesystem Instead, Hassle compiles the SASS for you into @tmp/@ and serves it up via a @Rack::Static@ middleware.
18
+
19
+ Hassle assumes a few basic things about your setup: There's going to be a @tmp/@ directory where it can write to, and @public/@ is where you store your css. A simple example:
20
+
21
+ <pre>
22
+ $ tree
23
+ .
24
+ |-- config.ru
25
+ |-- public
26
+ | `-- stylesheets
27
+ | `-- sass
28
+ | `-- application.sass
29
+ `-- tmp
30
+ `-- hassle
31
+ `-- stylesheets
32
+ `-- application.css
33
+ </pre>
34
+
35
+ With a basic SASS file in @public/stylesheets/sass/application.sass@, you can include it in your views with:
36
+
37
+ <pre>
38
+ <link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
39
+ </pre>
40
+
41
+ Hassle will look at the default sass directory (@public/stylesheets/sass@) and other input directories given in @Sass::Plugin.options[:template_location]@. CSS files are then compiled into @tmp/@ one directory higher than where you specified. Here's a small example of customization:
42
+
43
+ <pre>
44
+ Sass::Plugin.options[:template_location] = "./public/css/templates"
45
+ </pre>
46
+
47
+ And after Hassle runs...
48
+
49
+ <pre>
50
+ $ tree
51
+ .
52
+ |-- config.ru
53
+ |-- public
54
+ | `-- css
55
+ | `-- templates
56
+ | `-- screen.sass
57
+ `-- tmp
58
+ `-- hassle
59
+ `-- css
60
+ `-- screen.css
61
+ </pre>
62
+
63
+ Include this in your views with:
64
+
65
+ <pre>
66
+ <link href="/css/screen.css" media="screen" rel="stylesheet" type="text/css" />
67
+ </pre>
68
+
69
+ h2. Integration
70
+
71
+ Here's how to integrate it with your favorite web framework:
72
+
73
+ h3. Rails
74
+
75
+ For Rails: @script/plugin install git://github.com/Papipo/hassle@. Done. Once you're in production mode, Hassle will kick in and prepare your SASS for all to enjoy.
76
+
77
+ h3. Sinatra
78
+
79
+ Here's a sample config.ru that's "up and running.":http://hassle-sinatra.heroku.com
80
+
81
+ <pre>
82
+ require 'sinatra'
83
+ require 'hassle'
84
+ require 'haml'
85
+
86
+ get '/' do
87
+ haml <<EOF
88
+ %html
89
+ %head
90
+ %link{:rel => 'stylesheet', :href => "stylesheets/application.css"}
91
+ %body
92
+ %h1 Hassle!
93
+ EOF
94
+ end
95
+
96
+ use Hassle
97
+ run Sinatra::Application
98
+ </pre>
99
+
100
+ And its wonderful SASS file:
101
+
102
+ <pre>
103
+ $ cat public/stylesheets/sass/application.sass
104
+ h1
105
+ font-size: 11em
106
+ color: purple
107
+ </pre>
108
+
109
+ h2. Bugs
110
+
111
+ Found some problems? Post 'em in "Issues":http://github.com/pedro/hassle/issues.
112
+
113
+ h2. License
114
+
115
+ Hassle uses the MIT license. Please check the LICENSE file for more details.
data/TODO ADDED
@@ -0,0 +1 @@
1
+ Make features pass
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'hassle'
data/lib/hassle.rb ADDED
@@ -0,0 +1,2 @@
1
+ require File.dirname(__FILE__) + '/hassle/hassle'
2
+ require File.dirname(__FILE__) + '/hassle/railtie'
data/spec/base.rb ADDED
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'rack/test'
4
+ require 'active_support'
5
+ require 'active_support/core_ext/numeric/time'
6
+ require 'sass'
7
+ require 'sass/plugin'
8
+ require File.dirname(__FILE__) + '/../lib/hassle'
9
+ puts 1.hour
10
+ SASS_OPTIONS = Sass::Plugin.options.dup
11
+
12
+ def write_sass(location, css_file = "screen")
13
+ FileUtils.mkdir_p(location)
14
+ sass_path = File.join(location, "#{css_file}.sass")
15
+
16
+ File.open(sass_path, "w") do |f|
17
+ f.write <<EOF
18
+ %h1 {
19
+ font-size: 42em
20
+ }
21
+ EOF
22
+ end
23
+
24
+ File.join(@hassle.css_location(location), "#{css_file}.css") if @hassle
25
+ end
26
+
27
+ def be_compiled
28
+ simple_matcher("exist") { |given| File.exists?(given) }
29
+ simple_matcher("contain compiled sass") { |given| File.read(given) =~ /h1 \{/ }
30
+ end
31
+
32
+ def have_tmp_dir_removed(*stylesheets)
33
+ simple_matcher("remove tmp dir") do |given|
34
+ given == stylesheets.map { |css| css.gsub(File.join(Dir.pwd, "tmp", "hassle"), "") }
35
+ end
36
+ end
37
+
38
+ def have_served_sass
39
+ simple_matcher("return success") { |given| given.status == 200 }
40
+ simple_matcher("compiled sass") { |given| given.body.should =~ /h1 \{/ }
41
+ end
42
+
43
+ def reset
44
+ Sass::Plugin.options.clear
45
+ Sass::Plugin.options = SASS_OPTIONS
46
+ FileUtils.rm_rf([File.join(Dir.pwd, "public"), File.join(Dir.pwd, "tmp")])
47
+ end
@@ -0,0 +1,152 @@
1
+ require File.join(File.dirname(__FILE__), "base")
2
+
3
+ describe Hassle::Compiler do
4
+ before do
5
+ reset
6
+ @hassle = Hassle::Compiler.new
7
+ end
8
+
9
+ it "dumps css into separate folders" do
10
+ @hassle.css_location("./public/stylesheets/sass").should ==
11
+ File.join(Dir.pwd, "tmp", "hassle", "stylesheets")
12
+
13
+ @hassle.css_location("./public/css/compiled").should ==
14
+ File.join(Dir.pwd, "tmp", "hassle", "css", "compiled")
15
+
16
+ @hassle.css_location("./public/styles/posts/sass").should ==
17
+ File.join(Dir.pwd, "tmp", "hassle", "styles", "posts")
18
+ end
19
+
20
+ describe "compiling sass" do
21
+ before do
22
+ @default_location = Sass::Plugin.options[:css_location]
23
+ end
24
+
25
+ it "moves css into tmp directory with default settings" do
26
+ sass = write_sass(File.join(@default_location, "sass"))
27
+
28
+ @hassle.compile
29
+
30
+ sass.should be_compiled
31
+ @hassle.stylesheets.should have_tmp_dir_removed(sass)
32
+ end
33
+
34
+ it "should not create sass cache" do
35
+ write_sass(File.join(@default_location, "sass"))
36
+ Sass::Plugin.options[:cache] = true
37
+
38
+ @hassle.compile
39
+
40
+ File.exists?(".sass-cache").should be_false
41
+ end
42
+
43
+ it "should compile sass even if disabled with never_update" do
44
+ sass = write_sass(File.join(@default_location, "sass"))
45
+ Sass::Plugin.options[:never_update] = true
46
+
47
+ @hassle.compile
48
+
49
+ sass.should be_compiled
50
+ end
51
+
52
+ it "should compile sass if template location is not specified" do
53
+ template_directory = "public/stylesheets/sass"
54
+ output_directory = "public/stylesheets"
55
+ Sass::Plugin.options[:template_location] = nil
56
+ sass_template = write_sass(template_directory)
57
+ template_name = File.basename(sass_template)
58
+
59
+ @hassle.compile
60
+
61
+ css_location = @hassle.css_location(template_directory)
62
+ css_file = @hassle.css_location(File.join(output_directory, File.basename(sass_template)))
63
+ css_file.should be_compiled
64
+ end
65
+
66
+ it "should compile sass if template location is a hash" do
67
+ template_directory = "public/css/sass"
68
+ output_directory = "public/css"
69
+ Sass::Plugin.options[:template_location] = {template_directory => output_directory}
70
+ sass_template = write_sass(template_directory)
71
+ template_name = File.basename(sass_template)
72
+
73
+ @hassle.compile
74
+
75
+ css_location = @hassle.css_location(template_directory)
76
+ css_file = @hassle.css_location(File.join(output_directory, File.basename(sass_template)))
77
+ css_file.should be_compiled
78
+ end
79
+
80
+ it "should compile sass if template location is a hash with multiple locations" do
81
+ template_directory_one = "public/css/sass"
82
+ output_directory_one = 'public/css'
83
+ template_directory_two = "public/stylesheets/sass"
84
+ output_directory_two = 'public/css'
85
+ Sass::Plugin.options[:template_location] = {template_directory_one => output_directory_one, template_directory_two => output_directory_two}
86
+ sass_one = write_sass(template_directory_one, "one")
87
+ sass_two = write_sass(template_directory_two, "two")
88
+
89
+ @hassle.compile
90
+
91
+ css_location = @hassle.css_location(template_directory_one)
92
+ css_file = @hassle.css_location(File.join(output_directory_one, File.basename(sass_one)))
93
+ css_file.should be_compiled
94
+
95
+ css_location = @hassle.css_location(template_directory_two)
96
+ css_file = @hassle.css_location(File.join(output_directory_two, File.basename(sass_two)))
97
+ css_file.should be_compiled
98
+
99
+ @hassle.stylesheets.each do |s|
100
+ ["/css/one.css", "/css/two.css"].should include(s)
101
+ end
102
+ end
103
+
104
+ it "should compile sass if template location is an array with multiple locations" do
105
+ template_directory_one = "public/css/sass"
106
+ output_directory_one = 'public/css'
107
+ template_directory_two = "public/stylesheets/sass"
108
+ output_directory_two = 'public/css'
109
+ Sass::Plugin.options[:template_location] = [[template_directory_one, output_directory_one], [template_directory_two, output_directory_two]]
110
+ sass_one = write_sass(template_directory_one, "one")
111
+ sass_two = write_sass(template_directory_two, "two")
112
+
113
+ @hassle.compile
114
+
115
+ css_location = @hassle.css_location(template_directory_one)
116
+ css_file = @hassle.css_location(File.join(output_directory_one, File.basename(sass_one)))
117
+ css_file.should be_compiled
118
+
119
+ css_location = @hassle.css_location(template_directory_two)
120
+ css_file = @hassle.css_location(File.join(output_directory_two, File.basename(sass_two)))
121
+ css_file.should be_compiled
122
+
123
+ @hassle.stylesheets.each do |s|
124
+ ["/css/one.css", "/css/two.css"].should include(s)
125
+ end
126
+ end
127
+
128
+ it "should not overwrite similarly name files in different directories" do
129
+ template_directory_one = "public/css/sass"
130
+ output_directory_one = 'public/css'
131
+ template_directory_two = "public/stylesheets/sass"
132
+ output_directory_two = 'public/css'
133
+ Sass::Plugin.options[:template_location] = [[template_directory_one, output_directory_one], [template_directory_two, output_directory_two]]
134
+ sass_one = write_sass(template_directory_one, "screen")
135
+ sass_two = write_sass(template_directory_two, "screen")
136
+
137
+ @hassle.compile
138
+
139
+ css_location = @hassle.css_location(template_directory_one)
140
+ css_file = @hassle.css_location(File.join(output_directory_one, File.basename(sass_one)))
141
+ css_file.should be_compiled
142
+
143
+ css_location = @hassle.css_location(template_directory_two)
144
+ css_file = @hassle.css_location(File.join(output_directory_two, File.basename(sass_two)))
145
+ css_file.should be_compiled
146
+
147
+ @hassle.stylesheets.each do |s|
148
+ ["/css/screen.css", "/css/screen.css"].should include(s)
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,55 @@
1
+ require File.dirname(__FILE__) + '/base'
2
+ require 'active_support'
3
+
4
+ describe Hassle do
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ Rack::Builder.new do
9
+ use Hassle
10
+ run Proc.new {|env| [200, {"Content-Type" => "text/html"}, "hello!"]}
11
+ end
12
+ end
13
+
14
+ before do
15
+ reset
16
+ end
17
+
18
+ it "sends through basic responses" do
19
+ get '/'
20
+ last_response.status.should == 200
21
+ last_response.body.should =~ /hello!/
22
+ end
23
+
24
+ describe "a basic setup" do
25
+ before do
26
+ write_sass("./public/stylesheets/sass")
27
+ end
28
+
29
+ it "serves up some sass" do
30
+ get '/stylesheets/screen.css'
31
+ last_response.should have_served_sass
32
+ end
33
+ end
34
+
35
+ describe "a slightly more complex setup" do
36
+ before do
37
+ @location_one = "./public/css/sass"
38
+ @location_two = "./public/stylesheets/sass"
39
+ Sass::Plugin.options[:template_location] = { @location_one => "public/css",
40
+ @location_two => "public/stylesheets"}
41
+ write_sass(@location_one, "style")
42
+ write_sass(@location_two, "application")
43
+ end
44
+
45
+ it "serves up some sass from the normal location" do
46
+ get '/stylesheets/application.css'
47
+ last_response.should have_served_sass
48
+ end
49
+
50
+ it "serves up some sass from a different location" do
51
+ get '/css/style.css'
52
+ last_response.should have_served_sass
53
+ end
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hassle3
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Pedro Belo
14
+ - Nick Quaranto
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-01-06 00:00:00 -08:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: rack
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: haml
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rspec
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ type: :development
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: cucumber
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :development
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: rack-test
80
+ prerelease: false
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :development
91
+ version_requirements: *id005
92
+ description: Makes SASS less of a hassle on read-only filesystems by compiling and serving it up for you.
93
+ email:
94
+ executables: []
95
+
96
+ extensions: []
97
+
98
+ extra_rdoc_files:
99
+ - LICENSE
100
+ - README.textile
101
+ - TODO
102
+ files:
103
+ - LICENSE
104
+ - README.textile
105
+ - init.rb
106
+ - lib/hassle.rb
107
+ - TODO
108
+ - spec/base.rb
109
+ - spec/hassle_compiler_spec.rb
110
+ - spec/hassle_spec.rb
111
+ has_rdoc: true
112
+ homepage: http://github.com/pedro/hassle
113
+ licenses: []
114
+
115
+ post_install_message:
116
+ rdoc_options: []
117
+
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: 17
135
+ segments:
136
+ - 1
137
+ - 3
138
+ - 5
139
+ version: 1.3.5
140
+ requirements: []
141
+
142
+ rubyforge_project:
143
+ rubygems_version: 1.3.7
144
+ signing_key:
145
+ specification_version: 3
146
+ summary: Make SASS less of a hassle.
147
+ test_files:
148
+ - spec/base.rb
149
+ - spec/hassle_compiler_spec.rb
150
+ - spec/hassle_spec.rb