- //
-
-END
- end
+ compressor = ::YUI::JavaScriptCompressor.new(:munge => true)
+ data = compressor.compress(text)
+ %Q{}
end
end
end
-end
\ No newline at end of file
+end
+
+Middleman::Features.register :minify_javascript, Middleman::Features::MinifyJavascript
\ No newline at end of file
diff --git a/lib/middleman/features/minify_javascript/rack.rb b/lib/middleman/features/minify_javascript/rack.rb
new file mode 100644
index 00000000..c58e5966
--- /dev/null
+++ b/lib/middleman/features/minify_javascript/rack.rb
@@ -0,0 +1,31 @@
+begin
+ require "yui/compressor"
+rescue LoadError
+ puts "YUI-Compressor not available. Install it with: gem install yui-compressor"
+end
+
+module Middleman
+ module Rack
+
+ class MinifyJavascript
+ def initialize(app, options={})
+ @app = app
+ end
+
+ def call(env)
+ status, headers, response = @app.call(env)
+
+ if env["PATH_INFO"].match(/\.js$/)
+ compressor = ::YUI::JavaScriptCompressor.new(:munge => true)
+
+ uncompressed_source = response.is_a?(::Rack::File) ? File.read(response.path) : response
+ response = compressor.compress(uncompressed_source)
+ headers["Content-Length"] = ::Rack::Utils.bytesize(response).to_s
+ end
+
+ [status, headers, response]
+ end
+ end
+
+ end
+end
\ No newline at end of file
diff --git a/lib/middleman/features/relative_assets.rb b/lib/middleman/features/relative_assets.rb
index d931a6bb..f2874a49 100755
--- a/lib/middleman/features/relative_assets.rb
+++ b/lib/middleman/features/relative_assets.rb
@@ -1,46 +1,35 @@
-class Middleman::Base
- after_feature_init do
- ::Compass.configuration do |config|
- config.relative_assets = Proc.new do
- Middleman::Base.enabled?(:relative_assets)
+class Middleman::Features::RelativeAssets
+ def initialize(app)
+ ::Compass.configuration.relative_assets = true
+
+ Middleman::Assets.register :relative_assets do |path, prefix, request|
+ begin
+ prefix = Middleman::Base.images_dir if prefix == Middleman::Base.http_images_path
+ rescue
+ end
+
+ if path.include?("://")
+ Middleman::Assets.before(:relative_assets, path, prefix, request)
+ elsif path[0,1] == "/"
+ path
+ else
+ path = File.join(prefix, path) if prefix.length > 0
+ request_path = request.path_info.dup
+ request_path << Middleman::Base.index_file if path.match(%r{/$})
+ request_path.gsub!(%r{^/}, '')
+ parts = request_path.split('/')
+
+ if parts.length > 1
+ arry = []
+ (parts.length - 1).times { arry << ".." }
+ arry << path
+ File.join(*arry)
+ else
+ path
+ end
end
end
-
- ::Compass.configure_sass_plugin!
end
end
-class << Middleman::Base
- alias_method :pre_relative_asset_url, :asset_url
- def asset_url(path, prefix="", request=nil)
- if !self.enabled?(:relative_assets)
- return pre_relative_asset_url(path, prefix, request)
- end
-
- begin
- prefix = self.images_dir if prefix == self.http_images_path
- rescue
- end
-
- if path.include?("://")
- pre_relative_asset_url(path, prefix, request)
- elsif path[0,1] == "/"
- path
- else
- path = File.join(prefix, path) if prefix.length > 0
- request_path = request.path_info.dup
- request_path << self.index_file if path.match(%r{/$})
- request_path.gsub!(%r{^/}, '')
- parts = request_path.split('/')
-
- if parts.length > 1
- arry = []
- (parts.length - 1).times { arry << ".." }
- arry << path
- File.join(*arry)
- else
- path
- end
- end
- end
-end
\ No newline at end of file
+Middleman::Features.register :relative_assets, Middleman::Features::RelativeAssets
diff --git a/lib/middleman/features/slickmap.rb b/lib/middleman/features/slickmap.rb
index 33b8f71e..e1ee8dfc 100755
--- a/lib/middleman/features/slickmap.rb
+++ b/lib/middleman/features/slickmap.rb
@@ -1,92 +1,91 @@
-begin
- require 'slickmap'
- ::Compass.configure_sass_plugin!
-rescue LoadError
- puts "Slickmap not available. Install it with: gem install compass-slickmap"
-end
-
-if Middleman::Base.environment == "build"
- Middleman::Builder.template :slickmap, "sitemap.html", "sitemap.html"
-end
-
Entry = Struct.new(:dir, :children)
-class Middleman::Base
- def build_sitemap(&block)
- @@utility = []
- [recurse_sitemap(Middleman::Base.views, &block), @@utility]
- end
-
- def recurse_sitemap(path, &block)
- bad_ext = path.split('.html')[1]
- path = path.gsub(bad_ext, '') if bad_ext
- entry = Entry.new(path, [])
+class Middleman::Features::Slickmap
+ def initialize(app)
+ require 'slickmap'
- #no "." or ".." dirs
- Dir[File.join(path, "*")].each do |e|
- next if !File.directory?(e) && !e.include?(".html")
- if File.directory?(e)
- entry.children << recurse_sitemap(e, &block)
- elsif block_given?
- how_to_handle = block.call(e)
- if how_to_handle == :valid
- entry.children << recurse_sitemap(e, &block)
- elsif how_to_handle == :utility
- bad_ext = e.split('.html')[1]
- e = e.gsub(bad_ext, '') if bad_ext
- @@utility << e.gsub(Middleman::Base.views + "/", '')
- end
- end
+ if Middleman::Base.environment == "build"
+ Middleman::Builder.template :slickmap, "sitemap.html", "sitemap.html"
end
- entry
- end
-
- helpers do
- def sitemap_node(n, first=false)
- if n.children.length < 1
- if !first && File.extname(n.dir).length > 0
- haml_tag :li do
- path = n.dir.gsub(self.class.views, '')
- haml_concat link_to(File.basename(path), path)
+ def build_sitemap(&block)
+ @@utility = []
+ [recurse_sitemap(Middleman::Base.views, &block), @@utility]
+ end
+
+ def recurse_sitemap(path, &block)
+ bad_ext = path.split('.html')[1]
+ path = path.gsub(bad_ext, '') if bad_ext
+ entry = Entry.new(path, [])
+
+ #no "." or ".." dirs
+ Dir[File.join(path, "*")].each do |e|
+ next if !File.directory?(e) && !e.include?(".html")
+ if File.directory?(e)
+ entry.children << recurse_sitemap(e, &block)
+ elsif block_given?
+ how_to_handle = block.call(e)
+ if how_to_handle == :valid
+ entry.children << recurse_sitemap(e, &block)
+ elsif how_to_handle == :utility
+ bad_ext = e.split('.html')[1]
+ e = e.gsub(bad_ext, '') if bad_ext
+ @@utility << e.gsub(Middleman::Base.views + "/", '')
end
end
- else
- haml_tag(:li, :id => first ? "home" : nil) do
- if first
- haml_concat link_to("Homepage", "/" + self.class.index_file)
- else
- # we are a dir
- index = n.children.find { |c| c.dir.include?(self.class.index_file) }
- haml_concat link_to(index.dir.gsub(self.class.views + "/", '').gsub("/" + File.basename(index.dir), '').capitalize, index.dir.gsub(self.class.views, ''))
- end
-
- other_children = n.children.select { |c| !c.dir.include?(self.class.index_file) }
- if other_children.length > 0
- if first
- other_children.each { |i| sitemap_node(i) }
- else
- haml_tag :ul do
- other_children.each { |i| sitemap_node(i) }
- end
+ end
+
+ entry
+ end
+
+ Middleman::Base.helpers do
+ def sitemap_node(n, first=false)
+ if n.children.length < 1
+ if !first && File.extname(n.dir).length > 0
+ haml_tag :li do
+ path = n.dir.gsub(self.class.views, '')
+ haml_concat link_to(File.basename(path), path)
end
end
- end
+ else
+ haml_tag(:li, :id => first ? "home" : nil) do
+ if first
+ haml_concat link_to("Homepage", "/" + self.class.index_file)
+ else
+ # we are a dir
+ index = n.children.find { |c| c.dir.include?(self.class.index_file) }
+ haml_concat link_to(index.dir.gsub(self.class.views + "/", '').gsub("/" + File.basename(index.dir), '').capitalize, index.dir.gsub(self.class.views, ''))
+ end
+
+ other_children = n.children.select { |c| !c.dir.include?(self.class.index_file) }
+ if other_children.length > 0
+ if first
+ other_children.each { |i| sitemap_node(i) }
+ else
+ haml_tag :ul do
+ other_children.each { |i| sitemap_node(i) }
+ end
+ end
+ end
+ end
+ end
end
end
- end
-
- get '/sitemap.html' do
- # Return :utility to put it util top menu. False to ignore
- @tree, @utility = build_sitemap do |file_name|
- :valid
- end
- haml :sitemap, :layout => false
- end
- use_in_file_templates!
+ Middleman::Base.get '/sitemap.html' do
+ # Return :utility to put it util top menu. False to ignore
+ @tree, @utility = build_sitemap do |file_name|
+ :valid
+ end
+ haml :sitemap, :layout => false
+ end
+
+ Middleman::Base.use_in_file_templates!
+ end
end
+Middleman::Features.register :slickmap, Middleman::Features::Slickmap
+
__END__
@@ sitemap
@@ -97,7 +96,7 @@ __END__
%title Sitemap
%style{ :type => "text/css" }
:sass
- @import slickmap.sass
+ @import "slickmap"
+slickmap
:javascript
window.onload = function() {
diff --git a/lib/middleman/features/smush_pngs.rb b/lib/middleman/features/smush_pngs.rb
index 294536c6..b3cd7759 100644
--- a/lib/middleman/features/smush_pngs.rb
+++ b/lib/middleman/features/smush_pngs.rb
@@ -1,9 +1,9 @@
-require "middleman/builder"
+class Middleman::Features::SmushPngs
+ def initialize(app)
+ require "middleman/builder"
-module Middleman
- class Builder
- alias_method :pre_smush_after_run, :after_run
- def after_run
+ Middleman::Base.alias_method :pre_smush_after_run, :after_run
+ Middleman::Base.define_method :after_run do
pre_smush_after_run
smush_dir = File.join(Middleman::Base.build_dir, Middleman::Base.images_dir)
@@ -33,4 +33,6 @@ module Middleman
end
end
end
-end
\ No newline at end of file
+end
+
+Middleman::Features.register :smush_pngs, Middleman::Features::SmushPngs
\ No newline at end of file
diff --git a/lib/middleman/features/sprockets.rb b/lib/middleman/features/sprockets.rb
new file mode 100644
index 00000000..c1b50f14
--- /dev/null
+++ b/lib/middleman/features/sprockets.rb
@@ -0,0 +1,13 @@
+class Middleman::Features::Sprockets
+ def initialize(app)
+ require "middleman/features/sprockets/rack"
+ app.use Middleman::Rack::Sprockets,
+ :root => Middleman::Base.root,
+ :load_path => [ File.join("public", Middleman::Base.js_dir),
+ File.join("views", Middleman::Base.js_dir) ]
+ end
+end
+
+Middleman::Features.register :sprockets, Middleman::Features::Sprockets, { :auto_enable => true }
+
+
diff --git a/lib/middleman/features/sprockets/rack.rb b/lib/middleman/features/sprockets/rack.rb
new file mode 100644
index 00000000..c22a8b5e
--- /dev/null
+++ b/lib/middleman/features/sprockets/rack.rb
@@ -0,0 +1,64 @@
+require 'sprockets'
+
+module Middleman
+ module Rack
+
+ class Sprockets
+ def initialize(app, options={})
+ @app = app
+ @options = options
+ end
+
+ def call(env)
+ if env["PATH_INFO"].match(/\.js$/)
+ public_file_path = File.join(Middleman::Base.public, env["PATH_INFO"])
+ view_file_path = File.join(Middleman::Base.views, env["PATH_INFO"])
+
+ source_file = ::Rack::File.new(Middleman::Base.public) if File.exists?(public_file_path)
+ source_file = ::Rack::File.new(Middleman::Base.views) if File.exists?(view_file_path)
+
+ if source_file
+ status, headers, response = source_file.call(env)
+ secretary = ::Sprockets::Secretary.new(@options.merge( :source_files => [ response.path ] ))
+ response = secretary.concatenation.to_s
+ headers["Content-Length"] = ::Rack::Utils.bytesize(response).to_s
+ return [status, headers, response]
+ end
+ end
+
+ @app.call(env)
+ end
+ end
+ end
+end
+
+# Sprockets ruby 1.9 duckpunch
+module Sprockets
+ class SourceFile
+ def source_lines
+ @lines ||= begin
+ lines = []
+
+ comments = []
+ File.open(pathname.absolute_location, 'rb') do |file|
+ file.each do |line|
+ lines << line = SourceLine.new(self, line, file.lineno)
+
+ if line.begins_pdoc_comment? || comments.any?
+ comments << line
+ end
+
+ if line.ends_multiline_comment?
+ if line.ends_pdoc_comment?
+ comments.each { |l| l.comment! }
+ end
+ comments.clear
+ end
+ end
+ end
+
+ lines
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/lib/middleman/features/ugly_haml.rb b/lib/middleman/features/ugly_haml.rb
new file mode 100644
index 00000000..cbc159aa
--- /dev/null
+++ b/lib/middleman/features/ugly_haml.rb
@@ -0,0 +1,7 @@
+class Middleman::Features::UglyHaml
+ def initialize(app)
+ Middleman::Base.set :haml, Middleman::Base.settings.haml.merge({ :ugly_haml => true })
+ end
+end
+
+Middleman::Features.register :ugly_haml, Middleman::Features::UglyHaml
\ No newline at end of file
diff --git a/lib/middleman/rack/minify_css.rb b/lib/middleman/rack/minify_css.rb
deleted file mode 100644
index 1392b4d6..00000000
--- a/lib/middleman/rack/minify_css.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-begin
- require "yui/compressor"
-rescue LoadError
- puts "YUI-Compressor not available. Install it with: gem install yui-compressor"
-end
-
-class Middleman::Rack::MinifyCSS
- def initialize(app, options={})
- @app = app
- end
-
- def call(env)
- status, headers, response = @app.call(env)
-
- if Middleman::Base.enabled?(:minify_css) && env["PATH_INFO"].match(/\.css$/)
- compressor = ::YUI::CssCompressor.new
-
- uncompressed_source = response.is_a?(::Rack::File) ? File.read(response.path) : response
- response = compressor.compress(uncompressed_source)
- headers["Content-Length"] = ::Rack::Utils.bytesize(response).to_s
- end
-
- [status, headers, response]
- end
-end
\ No newline at end of file
diff --git a/lib/middleman/rack/minify_javascript.rb b/lib/middleman/rack/minify_javascript.rb
deleted file mode 100644
index bb5e5b7a..00000000
--- a/lib/middleman/rack/minify_javascript.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-begin
- require "yui/compressor"
-rescue LoadError
- puts "YUI-Compressor not available. Install it with: gem install yui-compressor"
-end
-
-class Middleman::Rack::MinifyJavascript
- def initialize(app, options={})
- @app = app
- end
-
- def call(env)
- status, headers, response = @app.call(env)
-
- if env["PATH_INFO"].match(/\.js$/)
- compressor = ::YUI::JavaScriptCompressor.new(:munge => true)
-
- uncompressed_source = response.is_a?(::Rack::File) ? File.read(response.path) : response
- response = compressor.compress(uncompressed_source)
- headers["Content-Length"] = ::Rack::Utils.bytesize(response).to_s
- end
-
- [status, headers, response]
- end
-end
\ No newline at end of file
diff --git a/lib/middleman/rack/sprockets.rb b/lib/middleman/rack/sprockets.rb
deleted file mode 100644
index add50482..00000000
--- a/lib/middleman/rack/sprockets.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-require 'sprockets'
-
-class Middleman::Rack::Sprockets
- def initialize(app, options={})
- @app = app
- @options = options
- end
-
- def call(env)
- if env["PATH_INFO"].match(/\.js$/)
- public_file_path = File.join(Middleman::Base.public, env["PATH_INFO"])
- view_file_path = File.join(Middleman::Base.views, env["PATH_INFO"])
-
- source_file = Rack::File.new(Middleman::Base.public) if File.exists?(public_file_path)
- source_file = Rack::File.new(Middleman::Base.views) if File.exists?(view_file_path)
-
- if source_file
- status, headers, response = source_file.call(env)
- secretary = ::Sprockets::Secretary.new(@options.merge( :source_files => [ response.path ] ))
- response = secretary.concatenation.to_s
- headers["Content-Length"] = ::Rack::Utils.bytesize(response).to_s
- return [status, headers, response]
- end
- end
-
- @app.call(env)
- end
-end
-
-Middleman::Base.supported_formats << "js"
-
-# Sprockets ruby 1.9 duckpunch
-module Sprockets
- class SourceFile
- def source_lines
- @lines ||= begin
- lines = []
-
- comments = []
- File.open(pathname.absolute_location, 'rb') do |file|
- file.each do |line|
- lines << line = SourceLine.new(self, line, file.lineno)
-
- if line.begins_pdoc_comment? || comments.any?
- comments << line
- end
-
- if line.ends_multiline_comment?
- if line.ends_pdoc_comment?
- comments.each { |l| l.comment! }
- end
- comments.clear
- end
- end
- end
-
- lines
- end
- end
- end
-end
\ No newline at end of file
diff --git a/lib/middleman/renderers.rb b/lib/middleman/renderers.rb
new file mode 100644
index 00000000..e5580e6f
--- /dev/null
+++ b/lib/middleman/renderers.rb
@@ -0,0 +1,26 @@
+module Middleman
+
+ module Renderers
+ @@render_method_for_template_types = {}
+
+ def self.register(method_name, template_type)
+ @@render_method_for_template_types[template_type.to_s] = method_name
+ end
+
+ def self.get_method(template_path)
+ template_type = Tilt[template_path].to_s
+ @@render_method_for_template_types[template_type]
+ end
+
+ end
+end
+
+# Types built into Sinatra
+Middleman::Renderers.register(:less, Tilt::LessTemplate)
+Middleman::Renderers.register(:haml, Tilt::HamlTemplate)
+Middleman::Renderers.register(:builder, Tilt::BuilderTemplate)
+Middleman::Renderers.register(:erb, Tilt::ERBTemplate)
+
+%w(haml
+ sass
+ coffee).each { |renderer| require "middleman/renderers/#{renderer}" }
\ No newline at end of file
diff --git a/lib/middleman/renderers/builder.rb b/lib/middleman/renderers/builder.rb
deleted file mode 100644
index 10091e83..00000000
--- a/lib/middleman/renderers/builder.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require "builder"
-
-module Middleman
- module Renderers
- module Builder
- def self.included(base)
- base.supported_formats << "builder"
- end
-
- def render_path(path, layout)
- if template_exists?(path, :builder)
- builder(path.to_sym, :layout => layout)
- else
- super
- end
- end
- end
- end
-end
-
-class Middleman::Base
- include Middleman::Renderers::Builder
-end
diff --git a/lib/middleman/renderers/coffee.rb b/lib/middleman/renderers/coffee.rb
new file mode 100755
index 00000000..2e2c5a39
--- /dev/null
+++ b/lib/middleman/renderers/coffee.rb
@@ -0,0 +1,28 @@
+class Middleman::Base
+ def coffee(template, options={}, locals={})
+ options[:layout] = false
+ render :coffee, template, options, locals
+ end
+end
+
+unless defined? Tilt::CoffeeTemplate
+ # CoffeeScript info:
+ # http://jashkenas.github.com/coffee-script/
+ class Tilt::CoffeeTemplate < Tilt::Template
+ def initialize_engine
+ return if defined? ::CoffeeScript
+ require_template_library 'coffee-script'
+ end
+
+ def prepare
+ @output = nil
+ end
+
+ def evaluate(scope, locals, &block)
+ @output ||= ::CoffeeScript::compile(data, options)
+ end
+ end
+ Tilt.register 'coffee', Tilt::CoffeeTemplate
+end
+
+Middleman::Renderers.register(:coffee, Tilt::CoffeeTemplate)
\ No newline at end of file
diff --git a/lib/middleman/renderers/erb.rb b/lib/middleman/renderers/erb.rb
deleted file mode 100755
index ac273767..00000000
--- a/lib/middleman/renderers/erb.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require "erb"
-
-module Middleman
- module Renderers
- module ERb
- def self.included(base)
- base.supported_formats << "erb"
- end
-
- def render_path(path, layout)
- if template_exists?(path, :erb)
- layout = false if File.extname(path) == ".xml"
- erb(path.to_sym, :layout => layout)
- else
- super
- end
- end
- end
- end
-end
-
-class Middleman::Base
- include Middleman::Renderers::ERb
-end
diff --git a/lib/middleman/renderers/haml.rb b/lib/middleman/renderers/haml.rb
index 36f3037c..2b315a5a 100755
--- a/lib/middleman/renderers/haml.rb
+++ b/lib/middleman/renderers/haml.rb
@@ -1,30 +1,7 @@
require "haml"
module Middleman
- module Haml
- module Renderer
- def self.included(base)
- base.supported_formats << "haml"
- base.helpers Middleman::Haml::Helpers
- end
-
- def render_path(path, layout)
- if template_exists?(path, :haml)
- result = nil
- begin
- layout = false if File.extname(path) == ".xml"
- result = haml(path.to_sym, :layout => layout, :ugly => Middleman::Base.enabled?(:ugly_haml))
- rescue ::Haml::Error => e
- result = "Haml Error: #{e}"
- result << "Backtrace: #{e.backtrace.join("\n")}
"
- end
- result
- else
- super
- end
- end
- end
-
+ module Haml
module Helpers
def haml_partial(name, options = {})
item_name = name.to_sym
@@ -66,5 +43,5 @@ module Middleman
end
class Middleman::Base
- include Middleman::Haml::Renderer
+ helpers Middleman::Haml::Helpers
end
\ No newline at end of file
diff --git a/lib/middleman/renderers/less.rb b/lib/middleman/renderers/less.rb
deleted file mode 100644
index 1034ee93..00000000
--- a/lib/middleman/renderers/less.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require "less"
-
-module Middleman
- module Renderers
- module Less
- def self.included(base)
- base.supported_formats << "less"
- end
-
- def render_path(path, layout)
- if template_exists?(path, :less)
- less(path.to_sym)
- else
- super
- end
- end
- end
- end
-end
-
-class Middleman::Base
- include Middleman::Renderers::Less
-end
diff --git a/lib/middleman/renderers/sass.rb b/lib/middleman/renderers/sass.rb
index 6f5a9fc1..3fa01427 100644
--- a/lib/middleman/renderers/sass.rb
+++ b/lib/middleman/renderers/sass.rb
@@ -1,93 +1,18 @@
require "sass"
require "compass"
-require "fancy-buttons"
-
-begin
- require "yui/compressor"
-rescue LoadError
- puts "YUI-Compressor not available. Install it with: gem install yui-compressor"
-end
-
-module Middleman::Sass
- def self.included(base)
- base.supported_formats << "sass"
- end
-
- def render_path(path, layout)
- if template_exists?(path, :sass)
- begin
- static_version = settings.public + request.path_info
- send_file(static_version) if File.exists? static_version
-
- location_of_sass_file = settings.environment == "build" ?
- File.join(Dir.pwd, settings.build_dir) :
- settings.public
-
- css_filename = File.join(location_of_sass_file, request.path_info)
- result = sass(path.to_sym, ::Compass.sass_engine_options.merge({ :css_filename => css_filename }))
-
- if enabled?(:minify_css)
- ::YUI::CssCompressor.new.compress(result)
- else
- result
- end
- rescue Exception => e
- sass_exception_string(e)
- end
- else
- super
- end
- end
-
- # Handle Sass errors
- def sass_exception_string(e)
- e_string = "#{e.class}: #{e.message}"
-
- if e.is_a? ::Sass::SyntaxError
- e_string << "\non line #{e.sass_line}"
-
- if e.sass_filename
- e_string << " of #{e.sass_filename}"
-
- if File.exists?(e.sass_filename)
- e_string << "\n\n"
-
- min = [e.sass_line - 5, 0].max
- begin
- File.read(e.sass_filename).rstrip.split("\n")[
- min .. e.sass_line + 5
- ].each_with_index do |line, i|
- e_string << "#{min + i + 1}: #{line}\n"
- end
- rescue
- e_string << "Couldn't read sass file: #{e.sass_filename}"
- end
- end
- end
- end
- < true, :debug_info => true)
-
configure :build do
::Compass.configuration do |config|
config.css_dir = File.join(File.basename(self.build_dir), self.css_dir)
config.images_dir = File.join(File.basename(self.build_dir), self.images_dir)
end
-
- ::Compass.configure_sass_plugin!
- Sass::Plugin.options.update(:line_comments => false, :debug_info => false)
+ end
+ end
+end
+
+class Tilt::SassPlusCSSFilenameTemplate < Tilt::SassTemplate
+ def sass_options
+ location_of_sass_file = Middleman::Base.environment == "build" ?
+ File.join(Middleman::Base.root, Middleman::Base.build_dir) :
+ Middleman::Base.public
+
+ parts = basename.split('.')
+ parts.pop
+ css_filename = File.join(location_of_sass_file, Middleman::Base.css_dir, parts.join("."))
+ super.merge(::Compass.configuration.to_sass_engine_options).merge(:css_filename => css_filename)
+ end
+end
+Tilt.register 'sass', Tilt::SassPlusCSSFilenameTemplate
+Middleman::Renderers.register(:sass, Tilt::SassPlusCSSFilenameTemplate)
+
+class Tilt::ScssPlusCSSFilenameTemplate < Tilt::SassPlusCSSFilenameTemplate
+ def sass_options
+ super.merge(:syntax => :scss)
+ end
+end
+Tilt.register 'scss', Tilt::ScssPlusCSSFilenameTemplate
+Middleman::Renderers.register(:scss, Tilt::ScssPlusCSSFilenameTemplate)
+
+
+module Middleman::Haml
+ module Sass
+ include ::Haml::Filters::Base
+
+ def render(text)
+ ::Sass::Engine.new(text, ::Compass.configuration.to_sass_engine_options).render
end
end
end
\ No newline at end of file
diff --git a/lib/middleman/template/init.rbt b/lib/middleman/template/init.rbt
index efcb876f..f1d50a2a 100755
--- a/lib/middleman/template/init.rbt
+++ b/lib/middleman/template/init.rbt
@@ -1,6 +1,14 @@
-<% if css_dir %>set :css_dir, "<%= css_dir -%>"<% end %>
-<% if js_dir %>set :js_dir, "<%= js_dir -%>"<% end %>
-<% if images_dir %>set :images_dir, "<%= images_dir -%>"<% end %>
+# Automatic sitemaps
+# enable :slickmap
+
+# Automatic image dimension calculations
+# enable :automatic_image_sizes
+
+# Per-page layout changes
+# With no layout
+# page "/path/to/file.html", :layout => false
+# With alternative layout
+# page "/path/to/file.html", :layout => :otherlayout
# Helpers
helpers do
@@ -9,11 +17,26 @@ helpers do
end
end
-# Automatic sitemaps
-# enable :slickmap
+<% if css_dir %>
+set :css_dir, "<%= css_dir -%>"
+<% else %>
+# Change the CSS directory
+# set :css_dir, "alternative_css_directory"
+<% end %>
-# Automatic image dimension calculations
-# enable :automatic_image_sizes
+<% if js_dir %>
+set :js_dir, "<%= js_dir -%>"
+<% else %>
+# Change the JS directory
+# set :js_dir, "alternative_js_directory"
+<% end %>
+
+<% if images_dir %>
+set :images_dir, "<%= images_dir -%>"
+<% else %>
+# Change the images directory
+# set :images_dir, "alternative_image_directory"
+<% end %>
# Build-specific configuration
configure :build do
diff --git a/spec/builder_spec.rb b/spec/builder_spec.rb
index b3311bdc..6d1593b9 100644
--- a/spec/builder_spec.rb
+++ b/spec/builder_spec.rb
@@ -42,6 +42,16 @@ describe "Builder" do
File.read("#{@root_dir}/build/stylesheets/site.css").gsub(/\s/, "").should include("html,body,div,span,applet,object,iframe")
end
+ it "should build less files" do
+ File.exists?("#{@root_dir}/build/stylesheets/test_less.css").should be_true
+ File.read("#{@root_dir}/build/stylesheets/test_less.css").should include("666")
+ end
+
+ it "should build scss files" do
+ File.exists?("#{@root_dir}/build/stylesheets/site_scss.css").should be_true
+ File.read("#{@root_dir}/build/stylesheets/site_scss.css").gsub(/\s/, "").should include("html,body,div,span,applet,object,iframe")
+ end
+
it "should build static css files" do
File.exists?("#{@root_dir}/build/stylesheets/static.css").should be_true
end
diff --git a/spec/fixtures/sample/views/stylesheets/site_scss.css.scss b/spec/fixtures/sample/views/stylesheets/site_scss.css.scss
new file mode 100755
index 00000000..0cc04182
--- /dev/null
+++ b/spec/fixtures/sample/views/stylesheets/site_scss.css.scss
@@ -0,0 +1 @@
+@import "compass/reset";
\ No newline at end of file
diff --git a/spec/fixtures/sample/views/stylesheets/test_less.css.less b/spec/fixtures/sample/views/stylesheets/test_less.css.less
new file mode 100755
index 00000000..a57c304f
--- /dev/null
+++ b/spec/fixtures/sample/views/stylesheets/test_less.css.less
@@ -0,0 +1,5 @@
+@brand_color: #666666;
+
+#header {
+ color: @brand_color;
+}
\ No newline at end of file