hassless 0.0.1
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/LICENSE +22 -0
- data/README.textile +113 -0
- data/lib/hassless.rb +2 -0
- data/lib/hassless/compiler.rb +65 -0
- data/lib/hassless/middleware.rb +30 -0
- data/rails/init.rb +1 -0
- metadata +91 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2010, Mateusz Drożdżyński
|
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,113 @@
|
|
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
|
+
h2. Install
|
6
|
+
|
7
|
+
Get it from "Gemcutter.":http://gemcutter.org
|
8
|
+
|
9
|
+
<pre>
|
10
|
+
gem install hassle -s http://gemcutter.org
|
11
|
+
</pre>
|
12
|
+
|
13
|
+
h2. Usage
|
14
|
+
|
15
|
+
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.
|
16
|
+
|
17
|
+
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:
|
18
|
+
|
19
|
+
<pre>
|
20
|
+
$ tree
|
21
|
+
.
|
22
|
+
|-- config.ru
|
23
|
+
|-- public
|
24
|
+
| `-- stylesheets
|
25
|
+
| `-- sass
|
26
|
+
| `-- application.sass
|
27
|
+
`-- tmp
|
28
|
+
`-- hassle
|
29
|
+
`-- stylesheets
|
30
|
+
`-- application.css
|
31
|
+
</pre>
|
32
|
+
|
33
|
+
With a basic SASS file in @public/stylesheets/sass/application.sass@, you can include it in your views with:
|
34
|
+
|
35
|
+
<pre>
|
36
|
+
<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
|
37
|
+
</pre>
|
38
|
+
|
39
|
+
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:
|
40
|
+
|
41
|
+
<pre>
|
42
|
+
Sass::Plugin.options[:template_location] = "./public/css/templates"
|
43
|
+
</pre>
|
44
|
+
|
45
|
+
And after Hassle runs...
|
46
|
+
|
47
|
+
<pre>
|
48
|
+
$ tree
|
49
|
+
.
|
50
|
+
|-- config.ru
|
51
|
+
|-- public
|
52
|
+
| `-- css
|
53
|
+
| `-- templates
|
54
|
+
| `-- screen.sass
|
55
|
+
`-- tmp
|
56
|
+
`-- hassle
|
57
|
+
`-- css
|
58
|
+
`-- screen.css
|
59
|
+
</pre>
|
60
|
+
|
61
|
+
Include this in your views with:
|
62
|
+
|
63
|
+
<pre>
|
64
|
+
<link href="/css/screen.css" media="screen" rel="stylesheet" type="text/css" />
|
65
|
+
</pre>
|
66
|
+
|
67
|
+
h2. Integration
|
68
|
+
|
69
|
+
Here's how to integrate it with your favorite web framework:
|
70
|
+
|
71
|
+
h3. Rails
|
72
|
+
|
73
|
+
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.
|
74
|
+
|
75
|
+
h3. Sinatra
|
76
|
+
|
77
|
+
Here's a sample config.ru that's "up and running.":http://hassle-sinatra.heroku.com
|
78
|
+
|
79
|
+
<pre>
|
80
|
+
require 'sinatra'
|
81
|
+
require 'hassle'
|
82
|
+
require 'haml'
|
83
|
+
|
84
|
+
get '/' do
|
85
|
+
haml <<EOF
|
86
|
+
%html
|
87
|
+
%head
|
88
|
+
%link{:rel => 'stylesheet', :href => "stylesheets/application.css"}
|
89
|
+
%body
|
90
|
+
%h1 Hassle!
|
91
|
+
EOF
|
92
|
+
end
|
93
|
+
|
94
|
+
use Hassle
|
95
|
+
run Sinatra::Application
|
96
|
+
</pre>
|
97
|
+
|
98
|
+
And its wonderful SASS file:
|
99
|
+
|
100
|
+
<pre>
|
101
|
+
$ cat public/stylesheets/sass/application.sass
|
102
|
+
h1
|
103
|
+
font-size: 11em
|
104
|
+
color: purple
|
105
|
+
</pre>
|
106
|
+
|
107
|
+
h2. Bugs
|
108
|
+
|
109
|
+
Found some problems? Post 'em in "Issues":http://github.com/pedro/hassle/issues.
|
110
|
+
|
111
|
+
h2. License
|
112
|
+
|
113
|
+
Hassle uses the MIT license. Please check the LICENSE file for more details.
|
data/lib/hassless.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require "less"
|
2
|
+
|
3
|
+
module Hassless
|
4
|
+
class Compiler
|
5
|
+
def source(path = "")
|
6
|
+
@source ||= File.join("app", "stylesheets")
|
7
|
+
File.join(@source, path)
|
8
|
+
end
|
9
|
+
|
10
|
+
def destination(path = "")
|
11
|
+
@destination ||= File.join("tmp", "hassless", "stylesheets")
|
12
|
+
File.join(@destination, path.sub(/(le?|c)ss$/, "css"))
|
13
|
+
end
|
14
|
+
|
15
|
+
def stylesheets
|
16
|
+
Dir[File.join(destination, "**", "*.css")].map { |css| "/stylesheets/" + css.gsub(destination, "") }
|
17
|
+
end
|
18
|
+
|
19
|
+
def generate(template)
|
20
|
+
source = source(template)
|
21
|
+
destination = destination(template)
|
22
|
+
|
23
|
+
if mtime(destination) < mtime(source, :imports => true)
|
24
|
+
FileUtils.mkdir_p File.dirname(destination)
|
25
|
+
File.open(destination, "w"){|f| f.write compile(source) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def run
|
30
|
+
Dir[File.join(Rails.root, source, "**", "*.{css,less,lss}")].reject { |path| File.basename(path) =~ /^_/ }.each do |path|
|
31
|
+
generate(path.sub(File.join(Rails.root, source), ""))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def compile(file)
|
38
|
+
File.open(file){ |f| Less::Engine.new(f) }.to_css
|
39
|
+
rescue Exception => e
|
40
|
+
e.message << "\nFrom #{file}"
|
41
|
+
raise e
|
42
|
+
end
|
43
|
+
|
44
|
+
def mtime(file, options = {:imports => false})
|
45
|
+
return 0 unless File.file?(file)
|
46
|
+
|
47
|
+
mtimes = [File.mtime(file).to_i]
|
48
|
+
|
49
|
+
if options[:imports]
|
50
|
+
File.readlines(file).each do |line|
|
51
|
+
if line =~ /^\s*@import ['"]([^'"]+)/
|
52
|
+
imported = File.join(File.dirname(file), $1)
|
53
|
+
mtimes << if imported =~ /\.le?ss$/ # complete path given?
|
54
|
+
mtime(imported)
|
55
|
+
else # we need to add .less or .lss
|
56
|
+
[mtime("#{imported}.less"), mtime("#{imported}.lss")].max
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
mtimes.max
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
gem 'rack'
|
2
|
+
|
3
|
+
module Hassless
|
4
|
+
class Middleware
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
run if Rails.env == "production"
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
run if Rails.env == "development"
|
12
|
+
static.call(env)
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def compiler
|
18
|
+
@compiler ||= Hassless::Compiler.new
|
19
|
+
@compiler
|
20
|
+
end
|
21
|
+
|
22
|
+
def static
|
23
|
+
Rack::Static.new(@app, :urls => compiler.stylesheets, :root => File.join(compiler.destination, ".."))
|
24
|
+
end
|
25
|
+
|
26
|
+
def run
|
27
|
+
compiler.run
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Rails.configuration.middleware.use Hassless::Middleware
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hassless
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- "Mateusz Dro\xC5\xBCd\xC5\xBCy\xC5\x84ski"
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-12 00:00:00 +00:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rack
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: less
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :runtime
|
43
|
+
version_requirements: *id002
|
44
|
+
description: Makes LESS less of a hassle on read-only filesystems by compiling and serving it up for you.
|
45
|
+
email: gems@objectreload.com
|
46
|
+
executables: []
|
47
|
+
|
48
|
+
extensions: []
|
49
|
+
|
50
|
+
extra_rdoc_files:
|
51
|
+
- LICENSE
|
52
|
+
- README.textile
|
53
|
+
files:
|
54
|
+
- LICENSE
|
55
|
+
- README.textile
|
56
|
+
- lib/hassless.rb
|
57
|
+
- lib/hassless/compiler.rb
|
58
|
+
- lib/hassless/middleware.rb
|
59
|
+
- rails/init.rb
|
60
|
+
has_rdoc: true
|
61
|
+
homepage: http://github.com/objectreload/hassless
|
62
|
+
licenses: []
|
63
|
+
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options:
|
66
|
+
- --charset=UTF-8
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.3.6
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Make LESS less of a hassle.
|
90
|
+
test_files: []
|
91
|
+
|