middleman 0.5.5 → 0.9.0.pre
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/.document +1 -2
- data/.gitignore +3 -2
- data/LICENSE +0 -0
- data/README.rdoc +4 -0
- data/Rakefile +28 -36
- data/VERSION +1 -1
- data/bin/mm-build +7 -113
- data/bin/mm-init +11 -5
- data/bin/mm-server +56 -3
- data/features/asset_host.feature +12 -0
- data/features/automatic_image_sizes.feature +14 -0
- data/features/cache_buster.feature +22 -0
- data/features/generator.feature +8 -0
- data/features/minify_css.feature +22 -0
- data/features/minify_javascript.feature +12 -0
- data/features/page_alias_and_layouts.feature +12 -0
- data/features/relative_assets.feature +12 -0
- data/features/step_definitions/asset_host_steps.rb +7 -0
- data/features/step_definitions/env.rb +3 -0
- data/features/step_definitions/generator_steps.rb +24 -0
- data/features/step_definitions/middleman_steps.rb +28 -0
- data/features/step_definitions/page_layout_steps.rb +13 -0
- data/lib/middleman.rb +6 -132
- data/lib/middleman/assets.rb +33 -0
- data/lib/middleman/base.rb +147 -0
- data/lib/middleman/builder.rb +59 -0
- data/lib/middleman/config.ru +2 -0
- data/lib/middleman/features.rb +39 -0
- data/lib/middleman/features/asset_host.rb +21 -0
- data/lib/middleman/features/automatic_image_sizes.rb +31 -0
- data/lib/middleman/features/automatic_image_sizes/fastimage.rb +282 -0
- data/lib/middleman/features/cache_buster.rb +43 -0
- data/lib/middleman/features/default_helpers.rb +68 -0
- data/lib/middleman/features/livereload.rb +19 -0
- data/lib/middleman/features/minify_css.rb +9 -0
- data/lib/middleman/features/minify_javascript.rb +20 -0
- data/lib/middleman/features/minify_javascript/rack.rb +31 -0
- data/lib/middleman/features/relative_assets.rb +35 -0
- data/lib/middleman/features/slickmap.rb +118 -0
- data/lib/middleman/features/smush_pngs.rb +38 -0
- data/lib/middleman/features/ugly_haml.rb +7 -0
- data/lib/middleman/renderers.rb +26 -0
- data/lib/middleman/renderers/coffee.rb +28 -0
- data/lib/middleman/renderers/haml.rb +47 -0
- data/lib/middleman/renderers/sass.rb +67 -0
- data/lib/middleman/template/init.rbt +57 -0
- data/lib/middleman/template/views/index.html.haml +4 -0
- data/lib/middleman/template/views/layout.haml +11 -4
- data/lib/middleman/template/views/stylesheets/site.css.sass +27 -0
- data/lib/middleman/templater+dynamic_renderer.rb +26 -0
- data/middleman.gemspec +121 -107
- data/spec/builder_spec.rb +17 -16
- data/spec/fixtures/sample/init.rb +28 -2
- data/spec/fixtures/sample/public/images/blank.gif +0 -0
- data/spec/fixtures/sample/public/static.html +0 -0
- data/{vendor/sinatra-maruku/examples/public/javascripts/application.js → spec/fixtures/sample/public/stylesheets/auto-css.css} +0 -0
- data/spec/fixtures/sample/public/stylesheets/static.css +0 -0
- data/{vendor/sinatra-maruku/examples/public/stylesheets/print.css → spec/fixtures/sample/public/stylesheets/sub1/auto-css.css} +0 -0
- data/spec/fixtures/sample/public/stylesheets/sub1/sub2/auto-css.css +0 -0
- data/spec/fixtures/sample/views/_partial.haml +0 -0
- data/spec/fixtures/sample/views/asset_host.html.haml +1 -0
- data/spec/fixtures/sample/views/auto-css.html.haml +1 -0
- data/spec/fixtures/sample/views/auto-image-sizes.html.haml +1 -0
- data/spec/fixtures/sample/views/cache-buster.html.haml +2 -0
- data/spec/fixtures/sample/views/{index.haml → custom-layout.html.haml} +0 -0
- data/spec/fixtures/sample/views/custom.haml +5 -0
- data/spec/fixtures/sample/views/index.html.haml +1 -0
- data/spec/fixtures/sample/views/inline-css.html.haml +4 -0
- data/spec/fixtures/sample/views/{inline-js.haml → inline-js.html.haml} +0 -0
- data/spec/fixtures/sample/views/layout.haml +1 -1
- data/spec/fixtures/sample/views/{maruku.maruku → maruku.html.maruku} +0 -0
- data/spec/fixtures/sample/views/page-classes.html.haml +1 -0
- data/spec/fixtures/sample/views/services/{index.haml → index.html.haml} +0 -0
- data/spec/fixtures/sample/views/stylesheets/asset_host.css.sass +3 -0
- data/spec/fixtures/sample/views/stylesheets/relative_assets.css.sass +3 -0
- data/spec/fixtures/sample/views/stylesheets/site.css.sass +1 -0
- data/spec/fixtures/sample/views/stylesheets/site_scss.css.scss +1 -0
- data/spec/fixtures/sample/views/stylesheets/test_less.css.less +5 -0
- data/spec/helpers_spec.rb +43 -0
- data/spec/spec_helper.rb +3 -5
- metadata +298 -127
- data/lib/middleman/helpers.rb +0 -131
- data/lib/middleman/markaby.rb +0 -4
- data/lib/middleman/maruku.rb +0 -4
- data/lib/middleman/sprockets_ext.rb +0 -29
- data/lib/middleman/template/init.rb +0 -22
- data/lib/middleman/template/views/index.haml +0 -1
- data/lib/middleman/template/views/stylesheets/site.sass +0 -1
- data/spec/fixtures/sample/views/markaby.mab +0 -5
- data/spec/fixtures/sample/views/stylesheets/site.sass +0 -1
- data/spec/generator_spec.rb +0 -34
- data/vendor/rack-test/History.txt +0 -64
- data/vendor/rack-test/MIT-LICENSE.txt +0 -19
- data/vendor/rack-test/README.rdoc +0 -57
- data/vendor/rack-test/Rakefile +0 -62
- data/vendor/rack-test/lib/rack/mock_session.rb +0 -57
- data/vendor/rack-test/lib/rack/test.rb +0 -246
- data/vendor/rack-test/lib/rack/test/cookie_jar.rb +0 -169
- data/vendor/rack-test/lib/rack/test/methods.rb +0 -73
- data/vendor/rack-test/lib/rack/test/mock_digest_request.rb +0 -27
- data/vendor/rack-test/lib/rack/test/uploaded_file.rb +0 -36
- data/vendor/rack-test/lib/rack/test/utils.rb +0 -75
- data/vendor/rack-test/spec/fixtures/config.ru +0 -3
- data/vendor/rack-test/spec/fixtures/fake_app.rb +0 -109
- data/vendor/rack-test/spec/fixtures/foo.txt +0 -1
- data/vendor/rack-test/spec/rack/test/cookie_spec.rb +0 -176
- data/vendor/rack-test/spec/rack/test/digest_auth_spec.rb +0 -48
- data/vendor/rack-test/spec/rack/test/multipart_spec.rb +0 -85
- data/vendor/rack-test/spec/rack/test/utils_spec.rb +0 -44
- data/vendor/rack-test/spec/rack/test_spec.rb +0 -363
- data/vendor/rack-test/spec/rcov.opts +0 -1
- data/vendor/rack-test/spec/spec.opts +0 -1
- data/vendor/rack-test/spec/spec_helper.rb +0 -48
- data/vendor/sinatra-content-for/LICENSE +0 -22
- data/vendor/sinatra-content-for/README.rdoc +0 -49
- data/vendor/sinatra-content-for/Rakefile +0 -33
- data/vendor/sinatra-content-for/lib/sinatra/content_for.rb +0 -58
- data/vendor/sinatra-content-for/sinatra-content-for.gemspec +0 -34
- data/vendor/sinatra-content-for/test/content_for_test.rb +0 -156
- data/vendor/sinatra-markaby/CHANGES +0 -7
- data/vendor/sinatra-markaby/LICENSE +0 -20
- data/vendor/sinatra-markaby/README.rdoc +0 -33
- data/vendor/sinatra-markaby/Rakefile +0 -45
- data/vendor/sinatra-markaby/TODO +0 -3
- data/vendor/sinatra-markaby/VERSION.yml +0 -4
- data/vendor/sinatra-markaby/lib/sinatra/markaby.rb +0 -31
- data/vendor/sinatra-markaby/sinatra-markaby.gemspec +0 -49
- data/vendor/sinatra-markaby/test/sinatra_markaby_test.rb +0 -72
- data/vendor/sinatra-markaby/test/test_helper.rb +0 -19
- data/vendor/sinatra-markaby/test/views/hello.mab +0 -1
- data/vendor/sinatra-markaby/test/views/html.mab +0 -4
- data/vendor/sinatra-maruku/LICENSE +0 -22
- data/vendor/sinatra-maruku/README.markdown +0 -85
- data/vendor/sinatra-maruku/Rakefile +0 -34
- data/vendor/sinatra-maruku/VERSION.yml +0 -4
- data/vendor/sinatra-maruku/examples/app.rb +0 -8
- data/vendor/sinatra-maruku/examples/config.ru +0 -4
- data/vendor/sinatra-maruku/examples/mapp.rb +0 -15
- data/vendor/sinatra-maruku/examples/public/stylesheets/application.css +0 -23
- data/vendor/sinatra-maruku/examples/views/index.maruku +0 -32
- data/vendor/sinatra-maruku/examples/views/layout.maruku +0 -9
- data/vendor/sinatra-maruku/lib/sinatra/maruku.rb +0 -25
- data/vendor/sinatra-maruku/sinatra-maruku.gemspec +0 -70
- data/vendor/sinatra-maruku/test/sinatra_maruku_test.rb +0 -91
- data/vendor/sinatra-maruku/test/test_helper.rb +0 -21
- data/vendor/sinatra-maruku/test/views/hello.maruku +0 -1
- data/vendor/sinatra-maruku/test/views/layout2.maruku +0 -2
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class Middleman::Features::LiveReload
|
|
2
|
+
def initialize(app)
|
|
3
|
+
return unless Middleman::Base.environment == :development
|
|
4
|
+
|
|
5
|
+
begin
|
|
6
|
+
require 'livereload'
|
|
7
|
+
rescue LoadError
|
|
8
|
+
puts "Livereload not available. Install it with: gem install livereload"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
new_config = ::LiveReload::Config.new do |config|
|
|
12
|
+
config.exts = %w(haml sass scss coffee less builder)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
::LiveReload.run [Middleman::Base.public, Middleman::Base.views], new_config
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
Middleman::Features.register :livereload, Middleman::Features::LiveReload
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class Middleman::Features::MinifyJavascript
|
|
2
|
+
def initialize(app)
|
|
3
|
+
Haml::Javascript.send :include, ::Haml::Filters::Base
|
|
4
|
+
|
|
5
|
+
require "middleman/features/minify_javascript/rack"
|
|
6
|
+
app.use Middleman::Rack::MinifyJavascript
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module Haml
|
|
10
|
+
module Javascript
|
|
11
|
+
def render_with_options(text, options)
|
|
12
|
+
compressor = ::YUI::JavaScriptCompressor.new(:munge => true)
|
|
13
|
+
data = compressor.compress(text)
|
|
14
|
+
%Q{<script type=#{options[:attr_wrapper]}text/javascript#{options[:attr_wrapper]}>#{data.chomp}</script>}
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
Middleman::Features.register :minify_javascript, Middleman::Features::MinifyJavascript
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require "yui/compressor"
|
|
3
|
+
rescue LoadError
|
|
4
|
+
puts "YUI-Compressor not available. Install it with: gem install yui-compressor"
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
module Middleman
|
|
8
|
+
module Rack
|
|
9
|
+
|
|
10
|
+
class MinifyJavascript
|
|
11
|
+
def initialize(app, options={})
|
|
12
|
+
@app = app
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def call(env)
|
|
16
|
+
status, headers, response = @app.call(env)
|
|
17
|
+
|
|
18
|
+
if env["PATH_INFO"].match(/\.js$/)
|
|
19
|
+
compressor = ::YUI::JavaScriptCompressor.new(:munge => true)
|
|
20
|
+
|
|
21
|
+
uncompressed_source = response.is_a?(::Rack::File) ? File.read(response.path) : response
|
|
22
|
+
response = compressor.compress(uncompressed_source)
|
|
23
|
+
headers["Content-Length"] = ::Rack::Utils.bytesize(response).to_s
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
[status, headers, response]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
class Middleman::Features::RelativeAssets
|
|
2
|
+
def initialize(app)
|
|
3
|
+
::Compass.configuration.relative_assets = true
|
|
4
|
+
|
|
5
|
+
Middleman::Assets.register :relative_assets do |path, prefix, request|
|
|
6
|
+
begin
|
|
7
|
+
prefix = Middleman::Base.images_dir if prefix == Middleman::Base.http_images_path
|
|
8
|
+
rescue
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
if path.include?("://")
|
|
12
|
+
Middleman::Assets.before(:relative_assets, path, prefix, request)
|
|
13
|
+
elsif path[0,1] == "/"
|
|
14
|
+
path
|
|
15
|
+
else
|
|
16
|
+
path = File.join(prefix, path) if prefix.length > 0
|
|
17
|
+
request_path = request.path_info.dup
|
|
18
|
+
request_path << Middleman::Base.index_file if path.match(%r{/$})
|
|
19
|
+
request_path.gsub!(%r{^/}, '')
|
|
20
|
+
parts = request_path.split('/')
|
|
21
|
+
|
|
22
|
+
if parts.length > 1
|
|
23
|
+
arry = []
|
|
24
|
+
(parts.length - 1).times { arry << ".." }
|
|
25
|
+
arry << path
|
|
26
|
+
File.join(*arry)
|
|
27
|
+
else
|
|
28
|
+
path
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
Middleman::Features.register :relative_assets, Middleman::Features::RelativeAssets
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
Entry = Struct.new(:dir, :children)
|
|
2
|
+
|
|
3
|
+
class Middleman::Features::Slickmap
|
|
4
|
+
def initialize(app)
|
|
5
|
+
require 'slickmap'
|
|
6
|
+
|
|
7
|
+
if Middleman::Base.environment == "build"
|
|
8
|
+
Middleman::Builder.template :slickmap, "sitemap.html", "sitemap.html"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def build_sitemap(&block)
|
|
12
|
+
@@utility = []
|
|
13
|
+
[recurse_sitemap(Middleman::Base.views, &block), @@utility]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def recurse_sitemap(path, &block)
|
|
17
|
+
bad_ext = path.split('.html')[1]
|
|
18
|
+
path = path.gsub(bad_ext, '') if bad_ext
|
|
19
|
+
entry = Entry.new(path, [])
|
|
20
|
+
|
|
21
|
+
#no "." or ".." dirs
|
|
22
|
+
Dir[File.join(path, "*")].each do |e|
|
|
23
|
+
next if !File.directory?(e) && !e.include?(".html")
|
|
24
|
+
if File.directory?(e)
|
|
25
|
+
entry.children << recurse_sitemap(e, &block)
|
|
26
|
+
elsif block_given?
|
|
27
|
+
how_to_handle = block.call(e)
|
|
28
|
+
if how_to_handle == :valid
|
|
29
|
+
entry.children << recurse_sitemap(e, &block)
|
|
30
|
+
elsif how_to_handle == :utility
|
|
31
|
+
bad_ext = e.split('.html')[1]
|
|
32
|
+
e = e.gsub(bad_ext, '') if bad_ext
|
|
33
|
+
@@utility << e.gsub(Middleman::Base.views + "/", '')
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
entry
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
Middleman::Base.helpers do
|
|
42
|
+
def sitemap_node(n, first=false)
|
|
43
|
+
if n.children.length < 1
|
|
44
|
+
if !first && File.extname(n.dir).length > 0
|
|
45
|
+
haml_tag :li do
|
|
46
|
+
path = n.dir.gsub(self.class.views, '')
|
|
47
|
+
haml_concat link_to(File.basename(path), path)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
else
|
|
51
|
+
haml_tag(:li, :id => first ? "home" : nil) do
|
|
52
|
+
if first
|
|
53
|
+
haml_concat link_to("Homepage", "/" + self.class.index_file)
|
|
54
|
+
else
|
|
55
|
+
# we are a dir
|
|
56
|
+
index = n.children.find { |c| c.dir.include?(self.class.index_file) }
|
|
57
|
+
haml_concat link_to(index.dir.gsub(self.class.views + "/", '').gsub("/" + File.basename(index.dir), '').capitalize, index.dir.gsub(self.class.views, ''))
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
other_children = n.children.select { |c| !c.dir.include?(self.class.index_file) }
|
|
61
|
+
if other_children.length > 0
|
|
62
|
+
if first
|
|
63
|
+
other_children.each { |i| sitemap_node(i) }
|
|
64
|
+
else
|
|
65
|
+
haml_tag :ul do
|
|
66
|
+
other_children.each { |i| sitemap_node(i) }
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
Middleman::Base.get '/sitemap.html' do
|
|
76
|
+
# Return :utility to put it util top menu. False to ignore
|
|
77
|
+
@tree, @utility = build_sitemap do |file_name|
|
|
78
|
+
:valid
|
|
79
|
+
end
|
|
80
|
+
haml :sitemap, :layout => false
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
Middleman::Base.use_in_file_templates!
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
Middleman::Features.register :slickmap, Middleman::Features::Slickmap
|
|
88
|
+
|
|
89
|
+
__END__
|
|
90
|
+
|
|
91
|
+
@@ sitemap
|
|
92
|
+
!!!
|
|
93
|
+
%html{ :xmlns => "http://www.w3.org/1999/xhtml" }
|
|
94
|
+
%head
|
|
95
|
+
%meta{ :content => "text/html; charset=utf-8", "http-equiv" => "Content-type" }
|
|
96
|
+
%title Sitemap
|
|
97
|
+
%style{ :type => "text/css" }
|
|
98
|
+
:sass
|
|
99
|
+
@import "slickmap"
|
|
100
|
+
+slickmap
|
|
101
|
+
:javascript
|
|
102
|
+
window.onload = function() {
|
|
103
|
+
document.getElementById('primaryNav').className = "col" + document.querySelectorAll("#primaryNav > li:not(#home)").length;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
%body
|
|
107
|
+
.logo
|
|
108
|
+
%h1= @project_name || "Sitemap"
|
|
109
|
+
- if @project_subtitle
|
|
110
|
+
%h2= @project_subtitle
|
|
111
|
+
|
|
112
|
+
- if @utility.length > 0
|
|
113
|
+
%ul#utilityNav
|
|
114
|
+
- @utility.each do |u|
|
|
115
|
+
%li= link_to u, u
|
|
116
|
+
|
|
117
|
+
%ul#primaryNav
|
|
118
|
+
- sitemap_node(@tree, true)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
class Middleman::Features::SmushPngs
|
|
2
|
+
def initialize(app)
|
|
3
|
+
require "middleman/builder"
|
|
4
|
+
|
|
5
|
+
Middleman::Base.alias_method :pre_smush_after_run, :after_run
|
|
6
|
+
Middleman::Base.define_method :after_run do
|
|
7
|
+
pre_smush_after_run
|
|
8
|
+
smush_dir = File.join(Middleman::Base.build_dir, Middleman::Base.images_dir)
|
|
9
|
+
|
|
10
|
+
# Read cache
|
|
11
|
+
cache_file = File.join(Middleman::Base.root, ".smush-cache")
|
|
12
|
+
cache_data = if File.exists?(cache_file)
|
|
13
|
+
Marshal.restore(File.read(cache_file))
|
|
14
|
+
else
|
|
15
|
+
{}
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
require "smusher"
|
|
19
|
+
require "json/pure"
|
|
20
|
+
::Smusher.class_eval do
|
|
21
|
+
images_in_folder(smush_dir).each do |file|
|
|
22
|
+
original_file_size = size(file)
|
|
23
|
+
return if original_file_size.zero?
|
|
24
|
+
return if cache_data[file] && cache_data[file] == original_file_size
|
|
25
|
+
|
|
26
|
+
with_logging(file, true) do
|
|
27
|
+
write_optimized_data(file)
|
|
28
|
+
cache_data[file] = size(file) # Add or update cache
|
|
29
|
+
File.open(cache_file, "w") { |f| f.write Marshal.dump(cache_data) } # Write cache
|
|
30
|
+
say "<%= color('#{"[SMUSHED]".rjust(12)}', :yellow) %> " + file.gsub(Middleman::Base.build_dir+"/", '')
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
Middleman::Features.register :smush_pngs, Middleman::Features::SmushPngs
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Middleman
|
|
2
|
+
|
|
3
|
+
module Renderers
|
|
4
|
+
@@render_method_for_template_types = {}
|
|
5
|
+
|
|
6
|
+
def self.register(method_name, template_type)
|
|
7
|
+
@@render_method_for_template_types[template_type.to_s] = method_name
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.get_method(template_path)
|
|
11
|
+
template_type = Tilt[template_path].to_s
|
|
12
|
+
@@render_method_for_template_types[template_type]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Types built into Sinatra
|
|
19
|
+
Middleman::Renderers.register(:less, Tilt::LessTemplate)
|
|
20
|
+
Middleman::Renderers.register(:haml, Tilt::HamlTemplate)
|
|
21
|
+
Middleman::Renderers.register(:builder, Tilt::BuilderTemplate)
|
|
22
|
+
Middleman::Renderers.register(:erb, Tilt::ERBTemplate)
|
|
23
|
+
|
|
24
|
+
%w(haml
|
|
25
|
+
sass
|
|
26
|
+
coffee).each { |renderer| require "middleman/renderers/#{renderer}" }
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class Middleman::Base
|
|
2
|
+
def coffee(template, options={}, locals={})
|
|
3
|
+
options[:layout] = false
|
|
4
|
+
render :coffee, template, options, locals
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
unless defined? Tilt::CoffeeTemplate
|
|
9
|
+
# CoffeeScript info:
|
|
10
|
+
# http://jashkenas.github.com/coffee-script/
|
|
11
|
+
class Tilt::CoffeeTemplate < Tilt::Template
|
|
12
|
+
def initialize_engine
|
|
13
|
+
return if defined? ::CoffeeScript
|
|
14
|
+
require_template_library 'coffee-script'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def prepare
|
|
18
|
+
@output = nil
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def evaluate(scope, locals, &block)
|
|
22
|
+
@output ||= ::CoffeeScript::compile(data, options)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
Tilt.register 'coffee', Tilt::CoffeeTemplate
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
Middleman::Renderers.register(:coffee, Tilt::CoffeeTemplate)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require "haml"
|
|
2
|
+
|
|
3
|
+
module Middleman
|
|
4
|
+
module Haml
|
|
5
|
+
module Helpers
|
|
6
|
+
def haml_partial(name, options = {})
|
|
7
|
+
item_name = name.to_sym
|
|
8
|
+
counter_name = "#{name}_counter".to_sym
|
|
9
|
+
if collection = options.delete(:collection)
|
|
10
|
+
collection.enum_for(:each_with_index).collect do |item,index|
|
|
11
|
+
haml_partial name, options.merge(:locals => {item_name => item, counter_name => index+1})
|
|
12
|
+
end.join
|
|
13
|
+
elsif object = options.delete(:object)
|
|
14
|
+
haml_partial name, options.merge(:locals => {item_name => object, counter_name => nil})
|
|
15
|
+
else
|
|
16
|
+
haml "_#{name}".to_sym, options.merge(:layout => false)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
module Table
|
|
22
|
+
include ::Haml::Filters::Base
|
|
23
|
+
|
|
24
|
+
def render(text)
|
|
25
|
+
output = '<div class="table"><table cellspacing="0" cellpadding="0">'
|
|
26
|
+
line_num = 0
|
|
27
|
+
text.each_line do |line|
|
|
28
|
+
line_num += 1
|
|
29
|
+
next if line.strip.empty?
|
|
30
|
+
output << %Q{<tr class="#{(line_num % 2 == 0) ? "even" : "odd" }#{(line_num == 1) ? " first" : "" }">}
|
|
31
|
+
|
|
32
|
+
columns = line.split("|").map { |p| p.strip }
|
|
33
|
+
columns.each_with_index do |col, i|
|
|
34
|
+
output << %Q{<td class="col#{i+1}">#{col}</td>}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
output << "</tr>"
|
|
38
|
+
end
|
|
39
|
+
output + "</table></div>"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
class Middleman::Base
|
|
46
|
+
helpers Middleman::Haml::Helpers
|
|
47
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require "sass"
|
|
2
|
+
require "compass"
|
|
3
|
+
|
|
4
|
+
class Middleman::Base
|
|
5
|
+
def scss(template, options={}, locals={})
|
|
6
|
+
options[:layout] = false
|
|
7
|
+
render :scss, template, options, locals
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
after_feature_init do
|
|
11
|
+
::Compass.configuration do |config|
|
|
12
|
+
config.cache_path = File.join(self.root, ".sass-cache") # For sassc files
|
|
13
|
+
config.project_path = self.root
|
|
14
|
+
config.sass_dir = File.join(File.basename(self.views), self.css_dir)
|
|
15
|
+
config.output_style = :nested
|
|
16
|
+
config.fonts_dir = File.join(File.basename(self.public), self.fonts_dir)
|
|
17
|
+
config.css_dir = File.join(File.basename(self.public), self.css_dir)
|
|
18
|
+
config.images_dir = File.join(File.basename(self.public), self.images_dir)
|
|
19
|
+
config.http_images_path = self.http_images_path rescue File.join(self.http_prefix || "/", self.images_dir)
|
|
20
|
+
config.http_stylesheets_path = self.http_css_path rescue File.join(self.http_prefix || "/", self.css_dir)
|
|
21
|
+
config.asset_cache_buster { false }
|
|
22
|
+
|
|
23
|
+
config.add_import_path(config.sass_dir)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
configure :build do
|
|
27
|
+
::Compass.configuration do |config|
|
|
28
|
+
config.css_dir = File.join(File.basename(self.build_dir), self.css_dir)
|
|
29
|
+
config.images_dir = File.join(File.basename(self.build_dir), self.images_dir)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class Tilt::SassPlusCSSFilenameTemplate < Tilt::SassTemplate
|
|
36
|
+
def sass_options
|
|
37
|
+
location_of_sass_file = Middleman::Base.environment == "build" ?
|
|
38
|
+
File.join(Middleman::Base.root, Middleman::Base.build_dir) :
|
|
39
|
+
Middleman::Base.public
|
|
40
|
+
|
|
41
|
+
parts = basename.split('.')
|
|
42
|
+
parts.pop
|
|
43
|
+
css_filename = File.join(location_of_sass_file, Middleman::Base.css_dir, parts.join("."))
|
|
44
|
+
super.merge(::Compass.configuration.to_sass_engine_options).merge(:css_filename => css_filename)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
Tilt.register 'sass', Tilt::SassPlusCSSFilenameTemplate
|
|
48
|
+
Middleman::Renderers.register(:sass, Tilt::SassPlusCSSFilenameTemplate)
|
|
49
|
+
|
|
50
|
+
class Tilt::ScssPlusCSSFilenameTemplate < Tilt::SassPlusCSSFilenameTemplate
|
|
51
|
+
def sass_options
|
|
52
|
+
super.merge(:syntax => :scss)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
Tilt.register 'scss', Tilt::ScssPlusCSSFilenameTemplate
|
|
56
|
+
Middleman::Renderers.register(:scss, Tilt::ScssPlusCSSFilenameTemplate)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
module Middleman::Haml
|
|
60
|
+
module Sass
|
|
61
|
+
include ::Haml::Filters::Base
|
|
62
|
+
|
|
63
|
+
def render(text)
|
|
64
|
+
::Sass::Engine.new(text, ::Compass.configuration.to_sass_engine_options).render
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|