Skip to content
Browse files

Trying to get hassle working :(

  • Loading branch information...
1 parent 769d2ba commit ba69011421e1387c845c63871478821126ccc1fd @metaskills committed Jan 21, 2010
View
2 .gems
@@ -1 +1 @@
-haml --version '2.2.6'
+haml --version '2.2.6'
View
2 app/views/layouts/application.html.haml
@@ -5,7 +5,7 @@
%head
%meta{"http-equiv" => "Content-Type", :content => "text/html; charset=utf-8"}
%title= params[:page] ? "757 Studio - #{params[:page].titleize}" : '757 Studio'
- = stylesheet_link_tag :all, :recursive => true
+ = stylesheet_link_tag 'webkit','utility','sass/site'
= javascript_include_tag 'prototype', 'effects', 'builder', 'application'
= javascript_tag 'Builder.dump();'
View
5 config/initializers/haml_sass.rb
@@ -1,5 +0,0 @@
-
-Sass::Plugin.options.merge!(
- :template_location => RAILS_ROOT + '/app/stylesheets'
-)
-
View
0 app/stylesheets/site.sass → public/stylesheets/sass/site.sass
File renamed without changes.
View
22 vendor/plugins/hassle/LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2009, Pedro Belo, Nick Quaranto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
View
113 vendor/plugins/hassle/README.textile
@@ -0,0 +1,113 @@
+h1. Hassle
+
+Making "SASS":http://sass-lang.com/ less of a hassle on read only filesystems. (like "Heroku":http://heroku.com)
+
+h2. Install
+
+Get it from "Gemcutter.":http://gemcutter.org
+
+<pre>
+gem install hassle -s http://gemcutter.org
+</pre>
+
+h2. Usage
+
+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.
+
+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:
+
+<pre>
+$ tree
+.
+|-- config.ru
+|-- public
+| `-- stylesheets
+| `-- sass
+| `-- application.sass
+`-- tmp
+ `-- hassle
+ `-- stylesheets
+ `-- application.css
+</pre>
+
+With a basic SASS file in @public/stylesheets/sass/application.sass@, you can include it in your views with:
+
+<pre>
+<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
+</pre>
+
+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:
+
+<pre>
+Sass::Plugin.options[:template_location] = "./public/css/templates"
+</pre>
+
+And after Hassle runs...
+
+<pre>
+$ tree
+.
+|-- config.ru
+|-- public
+| `-- css
+| `-- templates
+| `-- screen.sass
+`-- tmp
+ `-- hassle
+ `-- css
+ `-- screen.css
+</pre>
+
+Include this in your views with:
+
+<pre>
+<link href="/css/screen.css" media="screen" rel="stylesheet" type="text/css" />
+</pre>
+
+h2. Integration
+
+Here's how to integrate it with your favorite web framework:
+
+h3. Rails
+
+For Rails: @script/plugin install git://github.com/pedro/hassle@. Done. Once you're in production mode, Hassle will kick in and prepare your SASS for all to enjoy.
+
+h3. Sinatra
+
+Here's a sample config.ru that's "up and running.":http://hassle-sinatra.heroku.com
+
+<pre>
+require 'sinatra'
+require 'hassle'
+require 'haml'
+
+get '/' do
+ haml <<EOF
+%html
+ %head
+ %link{:rel => 'stylesheet', :href => "stylesheets/application.css"}
+ %body
+ %h1 Hassle!
+EOF
+end
+
+use Hassle
+run Sinatra::Application
+</pre>
+
+And its wonderful SASS file:
+
+<pre>
+$ cat public/stylesheets/sass/application.sass
+h1
+ font-size: 11em
+ color: purple
+</pre>
+
+h2. Bugs
+
+Found some problems? Post 'em in "Issues":http://github.com/pedro/hassle/issues.
+
+h2. License
+
+Hassle uses the MIT license. Please check the LICENSE file for more details.
View
44 vendor/plugins/hassle/Rakefile
@@ -0,0 +1,44 @@
+require 'rake'
+require 'spec/rake/spectask'
+
+desc "Run all specs"
+Spec::Rake::SpecTask.new('spec') do |t|
+ t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
+ t.spec_files = FileList['spec/*_spec.rb']
+end
+
+begin
+ require 'cucumber/rake/task'
+
+ Cucumber::Rake::Task.new(:cucumber) do |t|
+ t.cucumber_opts = "--format pretty"
+ end
+rescue LoadError
+ desc 'Cucumber rake task not available'
+ task :features do
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
+ end
+end
+
+task :default => [:spec, :cucumber]
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = "hassle"
+ gem.summary = "Make SASS less of a hassle."
+ gem.description = "Makes SASS less of a hassle on read-only filesystems by compiling and serving it up for you."
+ gem.homepage = "http://github.com/pedro/hassle"
+ gem.authors = ["Pedro Belo", "Nick Quaranto"]
+ gem.files = FileList["LICENSE", "README.textile", "lib/hassle.rb", "init.rb"]
+ gem.add_dependency('rack')
+ gem.add_dependency('haml')
+ gem.add_development_dependency('rspec')
+ gem.add_development_dependency('cucumber')
+ gem.add_development_dependency('rack-test')
+ gem.required_rubygems_version = Gem::Requirement.new(">= 1.3.5") if gem.respond_to? :required_rubygems_version=
+ end
+ Jeweler::RubyforgeTasks.new
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
+end
View
1 vendor/plugins/hassle/VERSION
@@ -0,0 +1 @@
+0.0.1
View
30 vendor/plugins/hassle/features/rails_integration.feature
@@ -0,0 +1,30 @@
+Feature: Integration into Rails Apps
+ As someone who loves syntactically awesome stylesheets
+ I want to be able to use sass when on (mostly) read only file systems and using Rails
+ In order to make css less of a hassle
+
+ Scenario: Use hassle with Rails in production mode
+ Given I have a Rails app
+ And I have a file "public/stylesheets/sass/hassle.sass" with:
+ """
+ h1
+ :font-size 42em
+ """
+ When Hassle is installed as a plugin
+ And the Rails app is initialized in "production" mode
+ Then I should see the following in "tmp/hassle/stylesheets/hassle.css":
+ """
+ h1 {
+ font-size: 42em; }
+ """
+
+ Scenario: Use hassle with Rails in development mode
+ Given I have a Rails app
+ And I have a file "public/stylesheets/sass/hassle.sass" with:
+ """
+ h1
+ :font-size 42em
+ """
+ When Hassle is installed as a plugin
+ And the Rails app is initialized in "development" mode
+ Then the file "tmp/hassle/stylesheets/hassle.css" should not exist
View
27 vendor/plugins/hassle/features/step_definitions/hassle_steps.rb
@@ -0,0 +1,27 @@
+Given /^I have a Rails app$/ do
+ `rails #{TEST_DIR}`
+end
+
+And /^I have a file "(.*)" with:$/ do |path, content|
+ FileUtils.mkdir_p(File.join(TEST_DIR, File.dirname(path)))
+ File.open(File.join(TEST_DIR, path), "w") do |f|
+ f.write content
+ end
+end
+
+Then /^I should see the following in "(.*)":$/ do |path, content|
+ content.strip.should == File.read(File.join(TEST_DIR, path)).strip
+end
+
+When /^Hassle is installed as a plugin$/ do
+ FileUtils.cp_r(ORIGINAL_DIR, File.join(TEST_DIR, "vendor", "plugins", "hassle"))
+end
+
+When /^the Rails app is initialized in "(.*)" mode$/ do |environment|
+ ENV["RAILS_ENV"] = environment
+ require File.expand_path('./config/environment')
+end
+
+Then /^the file "([^\"]*)" should not exist$/ do |path|
+ File.exists?(path).should be_false
+end
View
15 vendor/plugins/hassle/features/support/env.rb
@@ -0,0 +1,15 @@
+require 'fileutils'
+
+ORIGINAL_DIR = Dir.pwd
+TEST_DIR = File.join('/', 'tmp', 'hassle')
+
+Before do
+ FileUtils.mkdir(TEST_DIR)
+ Dir.chdir(TEST_DIR)
+end
+
+After do
+ Dir.chdir(TEST_DIR)
+ FileUtils.rm_rf(TEST_DIR)
+end
+
View
59 vendor/plugins/hassle/hassle.gemspec
@@ -0,0 +1,59 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE
+# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{hassle}
+ s.version = "0.0.1"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.3.5") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Pedro Belo", "Nick Quaranto"]
+ s.date = %q{2009-10-16}
+ s.description = %q{Makes SASS less of a hassle on read-only filesystems by compiling and serving it up for you}
+ s.extra_rdoc_files = [
+ "LICENSE",
+ "README.textile"
+ ]
+ s.files = [
+ "LICENSE",
+ "README.textile",
+ "init.rb",
+ "lib/hassle.rb"
+ ]
+ s.homepage = %q{http://github.com/pedro/hassle}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.5}
+ s.summary = %q{Make SASS less of a hassle}
+ s.test_files = [
+ "spec/base.rb",
+ "spec/hassle_compiler_spec.rb",
+ "spec/hassle_spec.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<rack>, [">= 0"])
+ s.add_runtime_dependency(%q<haml>, [">= 0"])
+ s.add_development_dependency(%q<rspec>, [">= 0"])
+ s.add_development_dependency(%q<cucumber>, [">= 0"])
+ s.add_development_dependency(%q<rack-test>, [">= 0"])
+ else
+ s.add_dependency(%q<rack>, [">= 0"])
+ s.add_dependency(%q<haml>, [">= 0"])
+ s.add_dependency(%q<rspec>, [">= 0"])
+ s.add_dependency(%q<cucumber>, [">= 0"])
+ s.add_dependency(%q<rack-test>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<rack>, [">= 0"])
+ s.add_dependency(%q<haml>, [">= 0"])
+ s.add_dependency(%q<rspec>, [">= 0"])
+ s.add_dependency(%q<cucumber>, [">= 0"])
+ s.add_dependency(%q<rack-test>, [">= 0"])
+ end
+end
View
3 vendor/plugins/hassle/init.rb
@@ -0,0 +1,3 @@
+if RAILS_ENV == 'production'
+ ActionController::Dispatcher.middleware.use Hassle
+end
View
68 vendor/plugins/hassle/lib/hassle.rb
@@ -0,0 +1,68 @@
+require 'rack'
+require 'sass'
+require 'sass/plugin'
+
+class Hassle
+ def initialize(app)
+ compiler = Hassle::Compiler.new
+ compiler.compile
+ @static = Rack::Static.new(app,
+ :urls => compiler.stylesheets,
+ :root => compiler.compile_location)
+ end
+
+ def call(env)
+ @static.call(env)
+ end
+end
+
+class Hassle::Compiler
+ def options
+ Sass::Plugin.options
+ end
+
+ def css_location(path)
+ expanded = File.expand_path(path)
+ public_dir = File.join(File.expand_path(Dir.pwd), "public")
+
+ File.expand_path(compile_location(expanded.gsub(public_dir, ''), '..'))
+ end
+
+ def compile_location(*subdirs)
+ File.join(Dir.pwd, "tmp", "hassle", subdirs)
+ end
+
+ def normalize
+ template_location = options[:template_location]
+
+ if template_location.is_a?(Hash) || template_location.is_a?(Array)
+ options[:template_location] = template_location.to_a.map do |input, output|
+ [input, css_location(input)]
+ end
+ else
+ default_location = File.join(options[:css_location], "sass")
+ options[:template_location] = {default_location => css_location(default_location)}
+ end
+ end
+
+ def prepare
+ options.merge!(:cache => false,
+ :never_update => false)
+
+ options[:template_location].to_a.each do |location|
+ FileUtils.mkdir_p(location.last)
+ end
+ end
+
+ def stylesheets
+ options[:template_location].to_a.map do |location|
+ Dir[File.join(location.last, "**", "*.css")].map { |css| css.gsub(compile_location, "/") }
+ end.flatten.sort
+ end
+
+ def compile
+ normalize
+ prepare
+ Sass::Plugin.update_stylesheets
+ end
+end
View
42 vendor/plugins/hassle/spec/base.rb
@@ -0,0 +1,42 @@
+require 'rubygems'
+require 'spec'
+require 'rack/test'
+
+require File.dirname(__FILE__) + '/../lib/hassle'
+
+SASS_OPTIONS = Sass::Plugin.options.dup
+
+def write_sass(location, css_file = "screen")
+ FileUtils.mkdir_p(location)
+ sass_path = File.join(location, "#{css_file}.sass")
+ File.open(sass_path, "w") do |f|
+ f.write <<EOF
+%h1
+ font-size: 42em
+EOF
+ end
+
+ File.join(@hassle.css_location(location), "#{css_file}.css") if @hassle
+end
+
+def be_compiled
+ simple_matcher("exist") { |given| File.exists?(given) }
+ simple_matcher("contain compiled sass") { |given| File.read(given) =~ /h1 \{/ }
+end
+
+def have_tmp_dir_removed(*stylesheets)
+ simple_matcher("remove tmp dir") do |given|
+ given == stylesheets.map { |css| css.gsub(File.join(Dir.pwd, "tmp", "hassle"), "") }
+ end
+end
+
+def have_served_sass
+ simple_matcher("return success") { |given| given.status == 200 }
+ simple_matcher("compiled sass") { |given| given.body.should =~ /h1 \{/ }
+end
+
+def reset
+ Sass::Plugin.options.clear
+ Sass::Plugin.options = SASS_OPTIONS
+ FileUtils.rm_rf([File.join(Dir.pwd, "public"), File.join(Dir.pwd, "tmp")])
+end
View
104 vendor/plugins/hassle/spec/hassle_compiler_spec.rb
@@ -0,0 +1,104 @@
+require File.join(File.dirname(__FILE__), "base")
+
+describe Hassle::Compiler do
+ before do
+ reset
+ @hassle = Hassle::Compiler.new
+ end
+
+ it "dumps css into separate folders" do
+ @hassle.css_location("./public/stylesheets/sass").should ==
+ File.join(Dir.pwd, "tmp", "hassle", "stylesheets")
+
+ @hassle.css_location("./public/css/compiled").should ==
+ File.join(Dir.pwd, "tmp", "hassle", "css")
+
+ @hassle.css_location("./public/styles/posts/sass").should ==
+ File.join(Dir.pwd, "tmp", "hassle", "styles", "posts")
+ end
+
+ describe "compiling sass" do
+ before do
+ @default_location = Sass::Plugin.options[:css_location]
+ end
+
+ it "moves css into tmp directory with default settings" do
+ sass = write_sass(File.join(@default_location, "sass"))
+
+ @hassle.compile
+
+ sass.should be_compiled
+ @hassle.stylesheets.should have_tmp_dir_removed(sass)
+ end
+
+ it "should not create sass cache" do
+ write_sass(File.join(@default_location, "sass"))
+ Sass::Plugin.options[:cache] = true
+
+ @hassle.compile
+
+ File.exists?(".sass-cache").should be_false
+ end
+
+ it "should compile sass even if disabled with never_update" do
+ sass = write_sass(File.join(@default_location, "sass"))
+ Sass::Plugin.options[:never_update] = true
+
+ @hassle.compile
+
+ sass.should be_compiled
+ end
+
+ it "should compile sass if template location is a hash" do
+ new_location = "public/css/sass"
+ Sass::Plugin.options[:template_location] = {new_location => "public/css"}
+ sass = write_sass(new_location)
+
+ @hassle.compile
+
+ sass.should be_compiled
+ end
+
+ it "should compile sass if template location is a hash with multiple locations" do
+ location_one = "public/css/sass"
+ location_two = "public/stylesheets/sass"
+ Sass::Plugin.options[:template_location] = {location_one => "public/css", location_two => "public/css"}
+ sass_one = write_sass(location_one, "one")
+ sass_two = write_sass(location_two, "two")
+
+ @hassle.compile
+
+ sass_one.should be_compiled
+ sass_two.should be_compiled
+ @hassle.stylesheets.should have_tmp_dir_removed(sass_one, sass_two)
+ end
+
+ it "should compile sass if template location is an array with multiple locations" do
+ location_one = "public/css/sass"
+ location_two = "public/stylesheets/sass"
+ Sass::Plugin.options[:template_location] = [[location_one, "public/css"], [location_two, "public/css"]]
+ sass_one = write_sass(location_one, "one")
+ sass_two = write_sass(location_two, "two")
+
+ @hassle.compile
+
+ sass_one.should be_compiled
+ sass_two.should be_compiled
+ @hassle.stylesheets.should have_tmp_dir_removed(sass_one, sass_two)
+ end
+
+ it "should not overwrite similarly name files in different directories" do
+ location_one = "public/css/sass"
+ location_two = "public/stylesheets/sass"
+ Sass::Plugin.options[:template_location] = {location_one => "public/css", location_two => "public/css"}
+ sass_one = write_sass(location_one, "screen")
+ sass_two = write_sass(location_two, "screen")
+
+ @hassle.compile
+
+ sass_one.should be_compiled
+ sass_two.should be_compiled
+ @hassle.stylesheets.should have_tmp_dir_removed(sass_one, sass_two)
+ end
+ end
+end
View
54 vendor/plugins/hassle/spec/hassle_spec.rb
@@ -0,0 +1,54 @@
+require File.dirname(__FILE__) + '/base'
+
+describe Hassle do
+ include Rack::Test::Methods
+
+ def app
+ Rack::Builder.new do
+ use Hassle
+ run Proc.new {|env| [200, {"Content-Type" => "text/html"}, "hello!"]}
+ end
+ end
+
+ before do
+ reset
+ end
+
+ it "sends through basic responses" do
+ get '/'
+ last_response.status.should == 200
+ last_response.body.should =~ /hello!/
+ end
+
+ describe "a basic setup" do
+ before do
+ write_sass("./public/stylesheets/sass")
+ end
+
+ it "serves up some sass" do
+ get '/stylesheets/screen.css'
+ last_response.should have_served_sass
+ end
+ end
+
+ describe "a slightly more complex setup" do
+ before do
+ @location_one = "./public/css/sass"
+ @location_two = "./public/stylesheets/sass"
+ Sass::Plugin.options[:template_location] = { @location_one => "public/css",
+ @location_two => "public/css"}
+ write_sass(@location_one, "style")
+ write_sass(@location_two, "application")
+ end
+
+ it "serves up some sass from the normal location" do
+ get '/stylesheets/application.css'
+ last_response.should have_served_sass
+ end
+
+ it "serves up some sass from a different location" do
+ get '/css/style.css'
+ last_response.should have_served_sass
+ end
+ end
+end

0 comments on commit ba69011

Please sign in to comment.
Something went wrong with that request. Please try again.