beans-middleman 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +15 -0
- data/Rakefile +9 -0
- data/bin/mm-build +15 -0
- data/bin/mm-init +37 -0
- data/bin/mm-preview +12 -0
- data/bin/mm-server +67 -0
- data/features/builder.feature +16 -0
- data/features/coffee-script.feature +7 -0
- data/features/generator.feature +8 -0
- data/features/helpers_auto_stylesheet_link_tag.feature +17 -0
- data/features/helpers_page_classes.feature +17 -0
- data/features/less-css.feature +7 -0
- data/features/minify_css.feature +22 -0
- data/features/minify_javascript.feature +12 -0
- data/features/padrino_helpers.feature +10 -0
- data/features/page_alias_and_layouts.feature +12 -0
- data/features/scss-support.feature +7 -0
- data/features/step_definitions/asset_host_steps.rb +7 -0
- data/features/step_definitions/builder_steps.rb +23 -0
- data/features/step_definitions/env.rb +3 -0
- data/features/step_definitions/generator_steps.rb +30 -0
- data/features/step_definitions/middleman_steps.rb +29 -0
- data/features/step_definitions/page_layout_steps.rb +13 -0
- data/features/w_asset_host.feature +12 -0
- data/features/x_automatic_image_sizes.feature +14 -0
- data/features/y_cache_buster.feature +22 -0
- data/features/z_relative_assets.feature +12 -0
- data/fixtures/test-app/config.rb +28 -0
- data/fixtures/test-app/public/images/blank.gif +0 -0
- data/fixtures/test-app/public/static.html +1 -0
- data/fixtures/test-app/public/stylesheets/auto-css.css +0 -0
- data/fixtures/test-app/public/stylesheets/static.css +2 -0
- data/fixtures/test-app/public/stylesheets/sub1/auto-css.css +0 -0
- data/fixtures/test-app/public/stylesheets/sub1/sub2/auto-css.css +0 -0
- data/fixtures/test-app/views/_partial.haml +1 -0
- data/fixtures/test-app/views/asset_host.html.haml +1 -0
- data/fixtures/test-app/views/auto-css.html.haml +1 -0
- data/fixtures/test-app/views/auto-image-sizes.html.haml +1 -0
- data/fixtures/test-app/views/cache-buster.html.haml +2 -0
- data/fixtures/test-app/views/custom-layout.html.haml +1 -0
- data/fixtures/test-app/views/index.html.haml +1 -0
- data/fixtures/test-app/views/inline-css.html.haml +4 -0
- data/fixtures/test-app/views/inline-js.html.haml +7 -0
- data/fixtures/test-app/views/javascripts/coffee_test.js.coffee +3 -0
- data/fixtures/test-app/views/layout.haml +6 -0
- data/fixtures/test-app/views/layouts/custom.haml +5 -0
- data/fixtures/test-app/views/padrino_test.html.haml +5 -0
- data/fixtures/test-app/views/page-classes.html.haml +1 -0
- data/fixtures/test-app/views/services/index.html.haml +1 -0
- data/fixtures/test-app/views/stylesheets/asset_host.css.sass +3 -0
- data/fixtures/test-app/views/stylesheets/relative_assets.css.sass +3 -0
- data/fixtures/test-app/views/stylesheets/site.css.sass +1 -0
- data/fixtures/test-app/views/stylesheets/site_scss.css.scss +1 -0
- data/fixtures/test-app/views/stylesheets/test_less.css.less +5 -0
- data/lib/middleman/assets.rb +33 -0
- data/lib/middleman/builder.rb +60 -0
- data/lib/middleman/config.ru +2 -0
- data/lib/middleman/features/asset_host.rb +22 -0
- data/lib/middleman/features/automatic_image_sizes/fastimage.rb +287 -0
- data/lib/middleman/features/automatic_image_sizes.rb +33 -0
- data/lib/middleman/features/cache_buster.rb +44 -0
- data/lib/middleman/features/code_ray.rb +12 -0
- data/lib/middleman/features/default_helpers.rb +61 -0
- data/lib/middleman/features/live_reload.rb +21 -0
- data/lib/middleman/features/minify_css.rb +10 -0
- data/lib/middleman/features/minify_javascript/rack.rb +31 -0
- data/lib/middleman/features/minify_javascript.rb +21 -0
- data/lib/middleman/features/partials.rb +15 -0
- data/lib/middleman/features/relative_assets.rb +36 -0
- data/lib/middleman/features/slickmap/template.html.haml +27 -0
- data/lib/middleman/features/slickmap.rb +89 -0
- data/lib/middleman/features/smush_pngs.rb +38 -0
- data/lib/middleman/features/ugly_haml.rb +8 -0
- data/lib/middleman/features.rb +37 -0
- data/lib/middleman/renderers/haml.rb +42 -0
- data/lib/middleman/renderers/sass.rb +70 -0
- data/lib/middleman/server.rb +165 -0
- data/lib/middleman/template/config.rbt +64 -0
- data/lib/middleman/template/views/index.html.haml +4 -0
- data/lib/middleman/template/views/layout.haml +13 -0
- data/lib/middleman/template/views/stylesheets/site.css.sass +27 -0
- data/lib/middleman/templater+dynamic_renderer.rb +26 -0
- data/lib/middleman.rb +15 -0
- metadata +452 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
module Middleman::Features::RelativeAssets
|
2
|
+
class << self
|
3
|
+
def registered(app)
|
4
|
+
::Compass.configuration.relative_assets = true
|
5
|
+
|
6
|
+
Middleman::Assets.register :relative_assets do |path, prefix, request|
|
7
|
+
begin
|
8
|
+
prefix = Middleman::Server.images_dir if prefix == Middleman::Server.http_images_path
|
9
|
+
rescue
|
10
|
+
end
|
11
|
+
|
12
|
+
if path.include?("://")
|
13
|
+
Middleman::Assets.before(:relative_assets, path, prefix, request)
|
14
|
+
elsif path[0,1] == "/"
|
15
|
+
path
|
16
|
+
else
|
17
|
+
path = File.join(prefix, path) if prefix.length > 0
|
18
|
+
request_path = request.path_info.dup
|
19
|
+
request_path << Middleman::Server.index_file if path.match(%r{/$})
|
20
|
+
request_path.gsub!(%r{^/}, '')
|
21
|
+
parts = request_path.split('/')
|
22
|
+
|
23
|
+
if parts.length > 1
|
24
|
+
arry = []
|
25
|
+
(parts.length - 1).times { arry << ".." }
|
26
|
+
arry << path
|
27
|
+
File.join(*arry)
|
28
|
+
else
|
29
|
+
path
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
alias :included :registered
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
!!!
|
2
|
+
%html{ :xmlns => "http://www.w3.org/1999/xhtml" }
|
3
|
+
%head
|
4
|
+
%meta{ :content => "text/html; charset=utf-8", "http-equiv" => "Content-type" }
|
5
|
+
%title Sitemap
|
6
|
+
%style{ :type => "text/css" }
|
7
|
+
:sass
|
8
|
+
@import "slickmap"
|
9
|
+
+slickmap
|
10
|
+
:javascript
|
11
|
+
window.onload = function() {
|
12
|
+
document.getElementById('primaryNav').className = "col" + document.querySelectorAll("#primaryNav > li:not(#home)").length;
|
13
|
+
};
|
14
|
+
|
15
|
+
%body
|
16
|
+
.logo
|
17
|
+
%h1= @project_name || "Sitemap"
|
18
|
+
- if @project_subtitle
|
19
|
+
%h2= @project_subtitle
|
20
|
+
|
21
|
+
- if @utility.length > 0
|
22
|
+
%ul#utilityNav
|
23
|
+
- @utility.each do |u|
|
24
|
+
%li= link_to u, u
|
25
|
+
|
26
|
+
%ul#primaryNav
|
27
|
+
- sitemap_node(@tree, true)
|
@@ -0,0 +1,89 @@
|
|
1
|
+
Entry = Struct.new(:dir, :children)
|
2
|
+
|
3
|
+
module Middleman::Features::Slickmap
|
4
|
+
class << self
|
5
|
+
def registered(app)
|
6
|
+
require 'slickmap'
|
7
|
+
|
8
|
+
@sitemap_url = config[:url] || "sitemap.html"
|
9
|
+
|
10
|
+
if Middleman::Server.environment == :build
|
11
|
+
Middleman::Builder.template :slickmap, @sitemap_url, @sitemap_url
|
12
|
+
end
|
13
|
+
|
14
|
+
Middleman::Server.helpers do
|
15
|
+
def sitemap_node(n, first=false)
|
16
|
+
if n.children.length < 1
|
17
|
+
if !first && File.extname(n.dir).length > 0
|
18
|
+
haml_tag :li do
|
19
|
+
path = n.dir.gsub(self.class.views, '')
|
20
|
+
haml_concat link_to(File.basename(path), path)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
else
|
24
|
+
haml_tag(:li, :id => first ? "home" : nil) do
|
25
|
+
if first
|
26
|
+
haml_concat link_to("Homepage", "/" + self.class.index_file)
|
27
|
+
else
|
28
|
+
# we are a dir
|
29
|
+
index = n.children.find { |c| c.dir.include?(self.class.index_file) }
|
30
|
+
haml_concat link_to(index.dir.gsub(self.class.views + "/", '').gsub("/" + File.basename(index.dir), '').capitalize, index.dir.gsub(self.class.views, ''))
|
31
|
+
end
|
32
|
+
|
33
|
+
other_children = n.children.select { |c| !c.dir.include?(self.class.index_file) }
|
34
|
+
if other_children.length > 0
|
35
|
+
if first
|
36
|
+
other_children.each { |i| sitemap_node(i) }
|
37
|
+
else
|
38
|
+
haml_tag :ul do
|
39
|
+
other_children.each { |i| sitemap_node(i) }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
Middleman::Server.get "/#{@sitemap_url}" do
|
49
|
+
# Return :utility to put it util top menu. False to ignore
|
50
|
+
@tree, @utility = Middleman::Features::Slickmap.build_sitemap do |file_name|
|
51
|
+
:valid
|
52
|
+
end
|
53
|
+
|
54
|
+
haml "template.html".to_sym, :layout => false, :views => File.expand_path(File.join(File.dirname(__FILE__), "slickmap"))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
alias :included :registered
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.build_sitemap(&block)
|
61
|
+
@@utility = []
|
62
|
+
[recurse_sitemap(Middleman::Server.views, &block), @@utility]
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.recurse_sitemap(path, &block)
|
66
|
+
bad_ext = path.split('.html')[1]
|
67
|
+
path = path.gsub(bad_ext, '') if bad_ext
|
68
|
+
entry = Entry.new(path, [])
|
69
|
+
|
70
|
+
#no "." or ".." dirs
|
71
|
+
Dir[File.join(path, "*")].each do |e|
|
72
|
+
next if !File.directory?(e) && !e.include?(".html")
|
73
|
+
if File.directory?(e)
|
74
|
+
entry.children << recurse_sitemap(e, &block)
|
75
|
+
elsif block_given?
|
76
|
+
how_to_handle = block.call(e)
|
77
|
+
if how_to_handle == :valid
|
78
|
+
entry.children << recurse_sitemap(e, &block)
|
79
|
+
elsif how_to_handle == :utility
|
80
|
+
bad_ext = e.split('.html')[1]
|
81
|
+
e = e.gsub(bad_ext, '') if bad_ext
|
82
|
+
@@utility << e.gsub(Middleman::Server.views + "/", '')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
entry
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Middleman::Features::SmushPNGs
|
2
|
+
class << self
|
3
|
+
def registered(app)
|
4
|
+
require "middleman/builder"
|
5
|
+
|
6
|
+
app.alias_method :pre_smush_after_run, :after_run
|
7
|
+
app.define_method :after_run do
|
8
|
+
pre_smush_after_run
|
9
|
+
smush_dir = File.join(Middleman::Server.build_dir, Middleman::Server.images_dir)
|
10
|
+
|
11
|
+
# Read cache
|
12
|
+
cache_file = File.join(Middleman::Server.root, ".smush-cache")
|
13
|
+
cache_data = if File.exists?(cache_file)
|
14
|
+
Marshal.restore(File.read(cache_file))
|
15
|
+
else
|
16
|
+
{}
|
17
|
+
end
|
18
|
+
|
19
|
+
require "smusher"
|
20
|
+
require "json/pure"
|
21
|
+
::Smusher.class_eval do
|
22
|
+
images_in_folder(smush_dir).each do |file|
|
23
|
+
original_file_size = size(file)
|
24
|
+
return if original_file_size.zero?
|
25
|
+
return if cache_data[file] && cache_data[file] == original_file_size
|
26
|
+
|
27
|
+
with_logging(file, true) do
|
28
|
+
write_optimized_data(file)
|
29
|
+
cache_data[file] = size(file) # Add or update cache
|
30
|
+
File.open(cache_file, "w") { |f| f.write Marshal.dump(cache_data) } # Write cache
|
31
|
+
say "<%= color('#{"[SMUSHED]".rjust(12)}', :yellow) %> " + file.gsub(Middleman::Server.build_dir+"/", '')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Middleman::Features
|
2
|
+
autoload :RelativeAssets, "middleman/features/relative_assets"
|
3
|
+
autoload :AssetHost, "middleman/features/asset_host"
|
4
|
+
autoload :CacheBuster, "middleman/features/cache_buster"
|
5
|
+
autoload :DefaultHelpers, "middleman/features/default_helpers"
|
6
|
+
autoload :AutomaticImageSizes, "middleman/features/automatic_image_sizes"
|
7
|
+
autoload :UglyHaml, "middleman/features/ugly_haml"
|
8
|
+
autoload :MinifyCss, "middleman/features/minify_css"
|
9
|
+
autoload :MinifyJavascript, "middleman/features/minify_javascript"
|
10
|
+
autoload :Slickmap, "middleman/features/slickmap"
|
11
|
+
autoload :SmushPNGs, "middleman/features/smush_pngs"
|
12
|
+
autoload :CodeRay, "middleman/features/code_ray"
|
13
|
+
autoload :Partials, "middleman/features/partials"
|
14
|
+
# autoload :LiveReload, "middleman/features/live_reload"
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def registered(app)
|
18
|
+
app.extend ClassMethods
|
19
|
+
end
|
20
|
+
alias :included :registered
|
21
|
+
end
|
22
|
+
|
23
|
+
module ClassMethods
|
24
|
+
def activate(feature_name)
|
25
|
+
mod_name = feature_name.to_s.camelize
|
26
|
+
if Middleman::Features.const_defined?(mod_name)
|
27
|
+
register Middleman::Features.const_get(mod_name)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def enable(feature_name)
|
32
|
+
$stderr.puts "Warning: Feature activation has been renamed from enable to activate"
|
33
|
+
activate(feature_name)
|
34
|
+
super(feature_name)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "haml"
|
2
|
+
|
3
|
+
module Middleman
|
4
|
+
module Renderers
|
5
|
+
module Haml
|
6
|
+
class << self
|
7
|
+
def registered(app)
|
8
|
+
app.helpers Middleman::Renderers::Haml::Helpers
|
9
|
+
end
|
10
|
+
alias :included :registered
|
11
|
+
end
|
12
|
+
|
13
|
+
module Helpers
|
14
|
+
def haml_partial(name, options = {})
|
15
|
+
partial(name, options)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module Table
|
20
|
+
include ::Haml::Filters::Base
|
21
|
+
|
22
|
+
def render(text)
|
23
|
+
output = '<div class="table"><table cellspacing="0" cellpadding="0">'
|
24
|
+
line_num = 0
|
25
|
+
text.each_line do |line|
|
26
|
+
line_num += 1
|
27
|
+
next if line.strip.empty?
|
28
|
+
output << %Q{<tr class="#{(line_num % 2 == 0) ? "even" : "odd" }#{(line_num == 1) ? " first" : "" }">}
|
29
|
+
|
30
|
+
columns = line.split("|").map { |p| p.strip }
|
31
|
+
columns.each_with_index do |col, i|
|
32
|
+
output << %Q{<td class="col#{i+1}">#{col}</td>}
|
33
|
+
end
|
34
|
+
|
35
|
+
output << "</tr>"
|
36
|
+
end
|
37
|
+
output + "</table></div>"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "sass"
|
2
|
+
require "compass"
|
3
|
+
require "lemonade"
|
4
|
+
|
5
|
+
module Middleman
|
6
|
+
module Renderers
|
7
|
+
module Sass
|
8
|
+
class << self
|
9
|
+
def registered(app)
|
10
|
+
app.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
|
+
alias :included :registered
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Tilt::SassPlusCSSFilenameTemplate < Tilt::SassTemplate
|
41
|
+
def sass_options
|
42
|
+
location_of_sass_file = Middleman::Server.environment == :build ?
|
43
|
+
File.join(Middleman::Server.root, Middleman::Server.build_dir) :
|
44
|
+
Middleman::Server.public
|
45
|
+
|
46
|
+
parts = basename.split('.')
|
47
|
+
parts.pop
|
48
|
+
css_filename = File.join(location_of_sass_file, Middleman::Server.css_dir, parts.join("."))
|
49
|
+
super.merge(::Compass.configuration.to_sass_engine_options).merge(:css_filename => css_filename)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
Tilt.register 'sass', Tilt::SassPlusCSSFilenameTemplate
|
53
|
+
|
54
|
+
class Tilt::ScssPlusCSSFilenameTemplate < Tilt::SassPlusCSSFilenameTemplate
|
55
|
+
def sass_options
|
56
|
+
super.merge(:syntax => :scss)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
Tilt.register 'scss', Tilt::ScssPlusCSSFilenameTemplate
|
60
|
+
|
61
|
+
|
62
|
+
module Middleman::Renderers::Haml
|
63
|
+
module Sass
|
64
|
+
include ::Haml::Filters::Base
|
65
|
+
|
66
|
+
def render(text)
|
67
|
+
::Sass::Engine.new(text, ::Compass.configuration.to_sass_engine_options).render
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
# We're riding on Sinatra, so let's include it.
|
2
|
+
require "sinatra/base"
|
3
|
+
|
4
|
+
# Use the padrino project's helpers
|
5
|
+
require "padrino-core/application/rendering"
|
6
|
+
require "padrino-helpers"
|
7
|
+
|
8
|
+
module Middleman
|
9
|
+
class Server < Sinatra::Base
|
10
|
+
# Basic Sinatra config
|
11
|
+
set :app_file, __FILE__
|
12
|
+
set :root, ENV["MM_DIR"] || Dir.pwd
|
13
|
+
set :reload, false
|
14
|
+
set :sessions, false
|
15
|
+
set :logging, false
|
16
|
+
set :environment, (ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development
|
17
|
+
|
18
|
+
# Import padrino helper methods
|
19
|
+
|
20
|
+
# Middleman-specific options
|
21
|
+
set :index_file, "index.html" # What file responds to folder requests
|
22
|
+
# Such as the homepage (/) or subfolders (/about/)
|
23
|
+
|
24
|
+
# These directories are passed directly to Compass
|
25
|
+
set :js_dir, "javascripts" # Where to look for javascript files
|
26
|
+
set :css_dir, "stylesheets" # Where to look for CSS files
|
27
|
+
set :images_dir, "images" # Where to look for images
|
28
|
+
set :fonts_dir, "fonts" # Where to look for fonts
|
29
|
+
|
30
|
+
set :build_dir, ENV['MM_ENV'] || 'build' # Which folder are builds output to
|
31
|
+
set :http_prefix, nil # During build, add a prefix for absolute paths
|
32
|
+
|
33
|
+
# Use Padrino Helpers
|
34
|
+
register Padrino::Helpers
|
35
|
+
set :asset_stamp, false # Disable Padrino cache buster until explicitly enabled
|
36
|
+
|
37
|
+
# Activate custom features
|
38
|
+
register Middleman::Features
|
39
|
+
|
40
|
+
# Activate built-in helpers
|
41
|
+
register Middleman::Features::DefaultHelpers
|
42
|
+
|
43
|
+
# Tilt-aware renderer
|
44
|
+
register Padrino::Rendering
|
45
|
+
|
46
|
+
# Override Sinatra's set to accept a block
|
47
|
+
def self.set(option, value=self, &block)
|
48
|
+
if block_given?
|
49
|
+
value = Proc.new { block }
|
50
|
+
end
|
51
|
+
|
52
|
+
super(option, value, &nil)
|
53
|
+
end
|
54
|
+
|
55
|
+
# An array of callback procs to run after all features have been setup
|
56
|
+
@@run_after_features = []
|
57
|
+
|
58
|
+
# Add a block/proc to be run after features have been setup
|
59
|
+
def self.after_feature_init(&block)
|
60
|
+
@@run_after_features << block
|
61
|
+
end
|
62
|
+
|
63
|
+
# Activate custom renderers
|
64
|
+
register Middleman::Renderers::Haml
|
65
|
+
register Middleman::Renderers::Sass
|
66
|
+
|
67
|
+
# Rack helper for adding mime-types during local preview
|
68
|
+
def self.mime(ext, type)
|
69
|
+
ext = ".#{ext}" unless ext.to_s[0] == ?.
|
70
|
+
::Rack::Mime::MIME_TYPES[ext.to_s] = type
|
71
|
+
end
|
72
|
+
|
73
|
+
# Default layout name
|
74
|
+
layout :layout
|
75
|
+
|
76
|
+
def self.current_layout
|
77
|
+
@layout
|
78
|
+
end
|
79
|
+
|
80
|
+
# Takes a block which allows many pages to have the same layout
|
81
|
+
# with_layout :admin do
|
82
|
+
# page "/admin/"
|
83
|
+
# page "/admin/login.html"
|
84
|
+
# end
|
85
|
+
def self.with_layout(layout_name, &block)
|
86
|
+
old_layout = current_layout
|
87
|
+
|
88
|
+
layout(layout_name)
|
89
|
+
class_eval(&block) if block_given?
|
90
|
+
ensure
|
91
|
+
layout(old_layout)
|
92
|
+
end
|
93
|
+
|
94
|
+
# The page method allows the layout to be set on a specific path
|
95
|
+
# page "/about.html", :layout => false
|
96
|
+
# page "/", :layout => :homepage_layout
|
97
|
+
def self.page(url, options={}, &block)
|
98
|
+
url << settings.index_file if url.match(%r{/$})
|
99
|
+
|
100
|
+
options[:layout] ||= current_layout
|
101
|
+
get(url) do
|
102
|
+
return yield if block_given?
|
103
|
+
process_request(options)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# This will match all requests not overridden in the project's config.rb
|
108
|
+
not_found do
|
109
|
+
process_request
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
# Internal method to look for templates and evaluate them if found
|
114
|
+
def process_request(options={})
|
115
|
+
# Normalize the path and add index if we're looking at a directory
|
116
|
+
path = request.path
|
117
|
+
path << settings.index_file if path.match(%r{/$})
|
118
|
+
path.gsub!(%r{^/}, '')
|
119
|
+
|
120
|
+
old_layout = settings.current_layout
|
121
|
+
settings.layout(options[:layout]) if !options[:layout].nil?
|
122
|
+
result = render(path, :layout => settings.fetch_layout_path.to_sym)
|
123
|
+
settings.layout(old_layout)
|
124
|
+
|
125
|
+
if result
|
126
|
+
content_type mime_type(File.extname(path)), :charset => 'utf-8'
|
127
|
+
status 200
|
128
|
+
return result
|
129
|
+
end
|
130
|
+
|
131
|
+
status 404
|
132
|
+
rescue Padrino::Rendering::TemplateNotFound
|
133
|
+
$stderr.puts "File not found: #{request.path}"
|
134
|
+
status 404
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
require "middleman/assets"
|
140
|
+
|
141
|
+
# The Rack App
|
142
|
+
class Middleman::Server
|
143
|
+
def self.new(*args, &block)
|
144
|
+
# If the old init.rb exists, use it, but issue warning
|
145
|
+
old_config = File.join(self.root, "init.rb")
|
146
|
+
if File.exists? old_config
|
147
|
+
$stderr.puts "== Warning: The init.rb file has been renamed to config.rb"
|
148
|
+
local_config = old_config
|
149
|
+
end
|
150
|
+
|
151
|
+
# Check for and evaluate local configuration
|
152
|
+
local_config ||= File.join(self.root, "config.rb")
|
153
|
+
if File.exists? local_config
|
154
|
+
$stderr.puts "== Reading: Local config" if logging?
|
155
|
+
Middleman::Server.class_eval File.read(local_config)
|
156
|
+
set :app_file, File.expand_path(local_config)
|
157
|
+
end
|
158
|
+
|
159
|
+
use ::Rack::ConditionalGet if environment == :development
|
160
|
+
|
161
|
+
@@run_after_features.each { |block| class_eval(&block) }
|
162
|
+
|
163
|
+
super
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Automatic sitemaps
|
2
|
+
# activate :slickmap
|
3
|
+
|
4
|
+
# CodeRay syntax highlighting in Haml
|
5
|
+
# activate :code_ray
|
6
|
+
|
7
|
+
# Automatic image dimension calculations
|
8
|
+
# activate :automatic_image_sizes
|
9
|
+
|
10
|
+
# Per-page layout changes
|
11
|
+
# With no layout
|
12
|
+
# page "/path/to/file.html", :layout => false
|
13
|
+
# With alternative layout
|
14
|
+
# page "/path/to/file.html", :layout => :otherlayout
|
15
|
+
|
16
|
+
# Helpers
|
17
|
+
helpers do
|
18
|
+
def some_helper(*args)
|
19
|
+
"Helping"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
<% if css_dir %>
|
24
|
+
set :css_dir, "<%= css_dir -%>"
|
25
|
+
<% else %>
|
26
|
+
# Change the CSS directory
|
27
|
+
# set :css_dir, "alternative_css_directory"
|
28
|
+
<% end %>
|
29
|
+
|
30
|
+
<% if js_dir %>
|
31
|
+
set :js_dir, "<%= js_dir -%>"
|
32
|
+
<% else %>
|
33
|
+
# Change the JS directory
|
34
|
+
# set :js_dir, "alternative_js_directory"
|
35
|
+
<% end %>
|
36
|
+
|
37
|
+
<% if images_dir %>
|
38
|
+
set :images_dir, "<%= images_dir -%>"
|
39
|
+
<% else %>
|
40
|
+
# Change the images directory
|
41
|
+
# set :images_dir, "alternative_image_directory"
|
42
|
+
<% end %>
|
43
|
+
|
44
|
+
# Build-specific configuration
|
45
|
+
configure :build do
|
46
|
+
# For example, change the Compass output style for deployment
|
47
|
+
# activate :minify_css
|
48
|
+
|
49
|
+
# Minify Javascript on build
|
50
|
+
# activate :minify_javascript
|
51
|
+
|
52
|
+
# Shrink/smush PNG/JPEGs on build
|
53
|
+
# activate :smush_pngs
|
54
|
+
|
55
|
+
# Enable cache buster
|
56
|
+
# activate :cache_buster
|
57
|
+
|
58
|
+
# Generate ugly/obfuscated HTML from Haml
|
59
|
+
# activate :ugly_haml
|
60
|
+
|
61
|
+
|
62
|
+
# Or use a different image path
|
63
|
+
# set :http_path, "/Content/images/"
|
64
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
!!! Strict
|
2
|
+
%html{ :xmlns => "http://www.w3.org/1999/xhtml", "xml:lang" => "en", :lang => "en" }
|
3
|
+
%head
|
4
|
+
%meta{ :content => "text/html; charset=utf-8", "http-equiv" => "Content-Type" }
|
5
|
+
/ Comment in layout
|
6
|
+
= stylesheet_link_tag "site.css"
|
7
|
+
:javascript
|
8
|
+
// Comment in javascript
|
9
|
+
= yield_content :head
|
10
|
+
|
11
|
+
%body{ :class => page_classes }
|
12
|
+
#frame
|
13
|
+
= yield
|
@@ -0,0 +1,27 @@
|
|
1
|
+
@import "compass"
|
2
|
+
@import "blueprint"
|
3
|
+
|
4
|
+
$font-color: #2a2a2a
|
5
|
+
$link-color: #0388a6
|
6
|
+
$link-hover-color: #009ce0
|
7
|
+
$link-focus-color: $link-color
|
8
|
+
$link-active-color: $link-color
|
9
|
+
$link-visited-color: $link-color
|
10
|
+
|
11
|
+
$blueprint-font-family: 'Century Gothic', 'Apple Gothic', 'Helvetica Neue', arial, sans-serif
|
12
|
+
$blueprint-font-size: 13px
|
13
|
+
$blueprint-grid-columns: 12
|
14
|
+
$blueprint-grid-width: 60px
|
15
|
+
$blueprint-grid-margin: 20px
|
16
|
+
|
17
|
+
+global-reset
|
18
|
+
|
19
|
+
+blueprint-typography
|
20
|
+
|
21
|
+
a
|
22
|
+
+link-colors($link-color, $link-hover-color, $link-focus-color, $link-active-color, $link-visited-color)
|
23
|
+
|
24
|
+
#frame
|
25
|
+
padding: 50px
|
26
|
+
text-align: center
|
27
|
+
+container
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rack/test' # Use Rack::Test to access Sinatra without starting up a full server
|
2
|
+
|
3
|
+
# Monkey-patch to use a dynamic renderer
|
4
|
+
class Templater::Actions::File
|
5
|
+
def identical?
|
6
|
+
if exists?
|
7
|
+
return true if File.mtime(source) < File.mtime(destination)
|
8
|
+
FileUtils.identical?(source, destination)
|
9
|
+
else
|
10
|
+
false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Templater::Actions::Template
|
16
|
+
def render
|
17
|
+
@@rack_test ||= Rack::Test::Session.new(Rack::MockSession.new(Middleman::Server))
|
18
|
+
|
19
|
+
@render_cache ||= begin
|
20
|
+
# The default render just requests the page over Rack and writes the response
|
21
|
+
request_path = destination.gsub(File.join(Dir.pwd, Middleman::Server.build_dir), "")
|
22
|
+
@@rack_test.get(request_path)
|
23
|
+
@@rack_test.last_response.body
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/middleman.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
libdir = File.dirname(__FILE__)
|
2
|
+
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
|
6
|
+
module Middleman
|
7
|
+
autoload :Server, "middleman/server"
|
8
|
+
|
9
|
+
module Renderers
|
10
|
+
autoload :Haml, "middleman/renderers/haml"
|
11
|
+
autoload :Sass, "middleman/renderers/sass"
|
12
|
+
end
|
13
|
+
|
14
|
+
autoload :Features, "middleman/features"
|
15
|
+
end
|