middleman 0.5.5 → 0.9.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. data/.document +1 -2
  2. data/.gitignore +3 -2
  3. data/LICENSE +0 -0
  4. data/README.rdoc +4 -0
  5. data/Rakefile +28 -36
  6. data/VERSION +1 -1
  7. data/bin/mm-build +7 -113
  8. data/bin/mm-init +11 -5
  9. data/bin/mm-server +56 -3
  10. data/features/asset_host.feature +12 -0
  11. data/features/automatic_image_sizes.feature +14 -0
  12. data/features/cache_buster.feature +22 -0
  13. data/features/generator.feature +8 -0
  14. data/features/minify_css.feature +22 -0
  15. data/features/minify_javascript.feature +12 -0
  16. data/features/page_alias_and_layouts.feature +12 -0
  17. data/features/relative_assets.feature +12 -0
  18. data/features/step_definitions/asset_host_steps.rb +7 -0
  19. data/features/step_definitions/env.rb +3 -0
  20. data/features/step_definitions/generator_steps.rb +24 -0
  21. data/features/step_definitions/middleman_steps.rb +28 -0
  22. data/features/step_definitions/page_layout_steps.rb +13 -0
  23. data/lib/middleman.rb +6 -132
  24. data/lib/middleman/assets.rb +33 -0
  25. data/lib/middleman/base.rb +147 -0
  26. data/lib/middleman/builder.rb +59 -0
  27. data/lib/middleman/config.ru +2 -0
  28. data/lib/middleman/features.rb +39 -0
  29. data/lib/middleman/features/asset_host.rb +21 -0
  30. data/lib/middleman/features/automatic_image_sizes.rb +31 -0
  31. data/lib/middleman/features/automatic_image_sizes/fastimage.rb +282 -0
  32. data/lib/middleman/features/cache_buster.rb +43 -0
  33. data/lib/middleman/features/default_helpers.rb +68 -0
  34. data/lib/middleman/features/livereload.rb +19 -0
  35. data/lib/middleman/features/minify_css.rb +9 -0
  36. data/lib/middleman/features/minify_javascript.rb +20 -0
  37. data/lib/middleman/features/minify_javascript/rack.rb +31 -0
  38. data/lib/middleman/features/relative_assets.rb +35 -0
  39. data/lib/middleman/features/slickmap.rb +118 -0
  40. data/lib/middleman/features/smush_pngs.rb +38 -0
  41. data/lib/middleman/features/ugly_haml.rb +7 -0
  42. data/lib/middleman/renderers.rb +26 -0
  43. data/lib/middleman/renderers/coffee.rb +28 -0
  44. data/lib/middleman/renderers/haml.rb +47 -0
  45. data/lib/middleman/renderers/sass.rb +67 -0
  46. data/lib/middleman/template/init.rbt +57 -0
  47. data/lib/middleman/template/views/index.html.haml +4 -0
  48. data/lib/middleman/template/views/layout.haml +11 -4
  49. data/lib/middleman/template/views/stylesheets/site.css.sass +27 -0
  50. data/lib/middleman/templater+dynamic_renderer.rb +26 -0
  51. data/middleman.gemspec +121 -107
  52. data/spec/builder_spec.rb +17 -16
  53. data/spec/fixtures/sample/init.rb +28 -2
  54. data/spec/fixtures/sample/public/images/blank.gif +0 -0
  55. data/spec/fixtures/sample/public/static.html +0 -0
  56. data/{vendor/sinatra-maruku/examples/public/javascripts/application.js → spec/fixtures/sample/public/stylesheets/auto-css.css} +0 -0
  57. data/spec/fixtures/sample/public/stylesheets/static.css +0 -0
  58. data/{vendor/sinatra-maruku/examples/public/stylesheets/print.css → spec/fixtures/sample/public/stylesheets/sub1/auto-css.css} +0 -0
  59. data/spec/fixtures/sample/public/stylesheets/sub1/sub2/auto-css.css +0 -0
  60. data/spec/fixtures/sample/views/_partial.haml +0 -0
  61. data/spec/fixtures/sample/views/asset_host.html.haml +1 -0
  62. data/spec/fixtures/sample/views/auto-css.html.haml +1 -0
  63. data/spec/fixtures/sample/views/auto-image-sizes.html.haml +1 -0
  64. data/spec/fixtures/sample/views/cache-buster.html.haml +2 -0
  65. data/spec/fixtures/sample/views/{index.haml → custom-layout.html.haml} +0 -0
  66. data/spec/fixtures/sample/views/custom.haml +5 -0
  67. data/spec/fixtures/sample/views/index.html.haml +1 -0
  68. data/spec/fixtures/sample/views/inline-css.html.haml +4 -0
  69. data/spec/fixtures/sample/views/{inline-js.haml → inline-js.html.haml} +0 -0
  70. data/spec/fixtures/sample/views/layout.haml +1 -1
  71. data/spec/fixtures/sample/views/{maruku.maruku → maruku.html.maruku} +0 -0
  72. data/spec/fixtures/sample/views/page-classes.html.haml +1 -0
  73. data/spec/fixtures/sample/views/services/{index.haml → index.html.haml} +0 -0
  74. data/spec/fixtures/sample/views/stylesheets/asset_host.css.sass +3 -0
  75. data/spec/fixtures/sample/views/stylesheets/relative_assets.css.sass +3 -0
  76. data/spec/fixtures/sample/views/stylesheets/site.css.sass +1 -0
  77. data/spec/fixtures/sample/views/stylesheets/site_scss.css.scss +1 -0
  78. data/spec/fixtures/sample/views/stylesheets/test_less.css.less +5 -0
  79. data/spec/helpers_spec.rb +43 -0
  80. data/spec/spec_helper.rb +3 -5
  81. metadata +298 -127
  82. data/lib/middleman/helpers.rb +0 -131
  83. data/lib/middleman/markaby.rb +0 -4
  84. data/lib/middleman/maruku.rb +0 -4
  85. data/lib/middleman/sprockets_ext.rb +0 -29
  86. data/lib/middleman/template/init.rb +0 -22
  87. data/lib/middleman/template/views/index.haml +0 -1
  88. data/lib/middleman/template/views/stylesheets/site.sass +0 -1
  89. data/spec/fixtures/sample/views/markaby.mab +0 -5
  90. data/spec/fixtures/sample/views/stylesheets/site.sass +0 -1
  91. data/spec/generator_spec.rb +0 -34
  92. data/vendor/rack-test/History.txt +0 -64
  93. data/vendor/rack-test/MIT-LICENSE.txt +0 -19
  94. data/vendor/rack-test/README.rdoc +0 -57
  95. data/vendor/rack-test/Rakefile +0 -62
  96. data/vendor/rack-test/lib/rack/mock_session.rb +0 -57
  97. data/vendor/rack-test/lib/rack/test.rb +0 -246
  98. data/vendor/rack-test/lib/rack/test/cookie_jar.rb +0 -169
  99. data/vendor/rack-test/lib/rack/test/methods.rb +0 -73
  100. data/vendor/rack-test/lib/rack/test/mock_digest_request.rb +0 -27
  101. data/vendor/rack-test/lib/rack/test/uploaded_file.rb +0 -36
  102. data/vendor/rack-test/lib/rack/test/utils.rb +0 -75
  103. data/vendor/rack-test/spec/fixtures/config.ru +0 -3
  104. data/vendor/rack-test/spec/fixtures/fake_app.rb +0 -109
  105. data/vendor/rack-test/spec/fixtures/foo.txt +0 -1
  106. data/vendor/rack-test/spec/rack/test/cookie_spec.rb +0 -176
  107. data/vendor/rack-test/spec/rack/test/digest_auth_spec.rb +0 -48
  108. data/vendor/rack-test/spec/rack/test/multipart_spec.rb +0 -85
  109. data/vendor/rack-test/spec/rack/test/utils_spec.rb +0 -44
  110. data/vendor/rack-test/spec/rack/test_spec.rb +0 -363
  111. data/vendor/rack-test/spec/rcov.opts +0 -1
  112. data/vendor/rack-test/spec/spec.opts +0 -1
  113. data/vendor/rack-test/spec/spec_helper.rb +0 -48
  114. data/vendor/sinatra-content-for/LICENSE +0 -22
  115. data/vendor/sinatra-content-for/README.rdoc +0 -49
  116. data/vendor/sinatra-content-for/Rakefile +0 -33
  117. data/vendor/sinatra-content-for/lib/sinatra/content_for.rb +0 -58
  118. data/vendor/sinatra-content-for/sinatra-content-for.gemspec +0 -34
  119. data/vendor/sinatra-content-for/test/content_for_test.rb +0 -156
  120. data/vendor/sinatra-markaby/CHANGES +0 -7
  121. data/vendor/sinatra-markaby/LICENSE +0 -20
  122. data/vendor/sinatra-markaby/README.rdoc +0 -33
  123. data/vendor/sinatra-markaby/Rakefile +0 -45
  124. data/vendor/sinatra-markaby/TODO +0 -3
  125. data/vendor/sinatra-markaby/VERSION.yml +0 -4
  126. data/vendor/sinatra-markaby/lib/sinatra/markaby.rb +0 -31
  127. data/vendor/sinatra-markaby/sinatra-markaby.gemspec +0 -49
  128. data/vendor/sinatra-markaby/test/sinatra_markaby_test.rb +0 -72
  129. data/vendor/sinatra-markaby/test/test_helper.rb +0 -19
  130. data/vendor/sinatra-markaby/test/views/hello.mab +0 -1
  131. data/vendor/sinatra-markaby/test/views/html.mab +0 -4
  132. data/vendor/sinatra-maruku/LICENSE +0 -22
  133. data/vendor/sinatra-maruku/README.markdown +0 -85
  134. data/vendor/sinatra-maruku/Rakefile +0 -34
  135. data/vendor/sinatra-maruku/VERSION.yml +0 -4
  136. data/vendor/sinatra-maruku/examples/app.rb +0 -8
  137. data/vendor/sinatra-maruku/examples/config.ru +0 -4
  138. data/vendor/sinatra-maruku/examples/mapp.rb +0 -15
  139. data/vendor/sinatra-maruku/examples/public/stylesheets/application.css +0 -23
  140. data/vendor/sinatra-maruku/examples/views/index.maruku +0 -32
  141. data/vendor/sinatra-maruku/examples/views/layout.maruku +0 -9
  142. data/vendor/sinatra-maruku/lib/sinatra/maruku.rb +0 -25
  143. data/vendor/sinatra-maruku/sinatra-maruku.gemspec +0 -70
  144. data/vendor/sinatra-maruku/test/sinatra_maruku_test.rb +0 -91
  145. data/vendor/sinatra-maruku/test/test_helper.rb +0 -21
  146. data/vendor/sinatra-maruku/test/views/hello.maruku +0 -1
  147. data/vendor/sinatra-maruku/test/views/layout2.maruku +0 -2
@@ -0,0 +1,12 @@
1
+ Feature: Custom layouts
2
+ In order easily switch between relative and absolute paths
3
+
4
+ Scenario: Using custom :layout attribute
5
+ Given page "/custom-layout.html" has layout "custom"
6
+ When I go to "/custom-layout.html"
7
+ Then I should see "Custom Layout"
8
+
9
+ Scenario: Using with_layout block
10
+ Given "/custom-layout.html" with_layout block has layout "custom"
11
+ When I go to "/custom-layout.html"
12
+ Then I should see "Custom Layout"
@@ -0,0 +1,12 @@
1
+ Feature: Relative Assets
2
+ In order easily switch between relative and absolute paths
3
+
4
+ Scenario: Rendering css with the feature disabled
5
+ Given "relative_assets" feature is "disabled"
6
+ When I go to "/stylesheets/relative_assets.css"
7
+ Then I should not see "url('../"
8
+
9
+ Scenario: Rendering css with the feature enabled
10
+ Given "relative_assets" feature is "enabled"
11
+ When I go to "/stylesheets/relative_assets.css"
12
+ Then I should see "url('../"
@@ -0,0 +1,7 @@
1
+ Given /^I am using an asset host$/ do
2
+ Middleman::Base.enable :asset_host
3
+ Middleman::Base.set :asset_host do |asset|
4
+ "http://assets%d.example.com" % (asset.hash % 4)
5
+ end
6
+ @browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base.new))
7
+ end
@@ -0,0 +1,3 @@
1
+ ENV["MM_DIR"] = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec", "fixtures", "sample")
2
+ require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), 'lib', 'middleman')
3
+ require "rack/test"
@@ -0,0 +1,24 @@
1
+ require 'fileutils'
2
+
3
+ Then /^template files should exist at "([^\"]*)"$/ do |dirname|
4
+ target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec", "fixtures", dirname)
5
+ template_glob = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "lib", "middleman", "template", "*/**/*")
6
+
7
+ Dir[template_glob].each do |f|
8
+ next if File.directory?(f)
9
+ File.exists?("#{target}/#{f.split('template/')[1]}").should be_true
10
+ end
11
+ end
12
+
13
+ Then /^empty directories should exist at "([^\"]*)"$/ do |dirname|
14
+ target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec", "fixtures", dirname)
15
+
16
+ %w(views/stylesheets public/stylesheets public/javascripts public/images).each do |d|
17
+ File.exists?("#{target}/#{d}").should be_true
18
+ end
19
+ end
20
+
21
+ Then /^cleanup at "([^\"]*)"$/ do |dirname|
22
+ target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec", "fixtures", dirname)
23
+ FileUtils.rm_rf(target)
24
+ end
@@ -0,0 +1,28 @@
1
+ Given /^"([^\"]*)" feature is "([^\"]*)"$/ do |feature, state|
2
+ enable_or_disable = (state == "enabled") ? :enable : :disable
3
+ Middleman::Base.send(enable_or_disable, feature.to_sym)
4
+ @browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base.new))
5
+ end
6
+
7
+ Given /^generated directory at "([^\"]*)"$/ do |dirname|
8
+ target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec", "fixtures", dirname)
9
+ init_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "mm-init"))
10
+ `cd #{File.dirname(target)} && #{init_cmd} #{File.basename(target)}`
11
+ end
12
+
13
+ When /^I go to "([^\"]*)"$/ do |url|
14
+ @browser.get(url)
15
+ end
16
+
17
+ Then /^I should see "([^\"]*)"$/ do |expected|
18
+ @browser.last_response.body.should include(expected)
19
+ end
20
+
21
+ Then /^I should not see "([^\"]*)"$/ do |expected|
22
+ @browser.last_response.body.should_not include(expected)
23
+ end
24
+
25
+ Then /^I should see "([^\"]*)" lines$/ do |lines|
26
+ $stderr.puts @browser.last_response.body
27
+ @browser.last_response.body.chomp.split($/).length.should == lines.to_i
28
+ end
@@ -0,0 +1,13 @@
1
+ Given /^page "([^\"]*)" has layout "([^\"]*)"$/ do |url, layout|
2
+ Middleman::Base.set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec", "fixtures", "sample")
3
+ Middleman::Base.page(url, :layout => layout.to_sym)
4
+ @browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base.new))
5
+ end
6
+
7
+ Given /^"([^\"]*)" with_layout block has layout "([^\"]*)"$/ do |url, layout|
8
+ Middleman::Base.set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec", "fixtures", "sample")
9
+ Middleman::Base.with_layout(:layout => layout.to_sym) do
10
+ page(url)
11
+ end
12
+ @browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base.new))
13
+ end
@@ -1,134 +1,8 @@
1
- require 'haml'
2
- require 'compass' #must be loaded before sinatra
3
- require 'sinatra/base'
1
+ libdir = File.dirname(__FILE__)
2
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
4
3
 
5
- # Sprockets ruby 1.9 hack
6
- require 'sprockets'
7
- require File.join(File.dirname(__FILE__), 'middleman', 'sprockets_ext')
4
+ require 'rubygems'
8
5
 
9
- require "yui/compressor"
10
-
11
- # Include content_for support
12
- require File.join(File.dirname(__FILE__), '..', 'vendor', 'sinatra-content-for', 'lib', 'sinatra', 'content_for')
13
-
14
- class Middleman < Sinatra::Base
15
- set :app_file, __FILE__
16
- set :static, true
17
- set :root, Dir.pwd
18
- set :environment, defined?(MIDDLEMAN_BUILDER) ? :build : :development
19
- set :default_ext, 'html'
20
- set :supported_formats, %w(haml erb builder)
21
-
22
- helpers Sinatra::ContentFor
23
-
24
- def self.run!(options={}, &block)
25
- set options
26
- handler = detect_rack_handler
27
- handler_name = handler.name.gsub(/.*::/, '')
28
- puts "== The Middleman is standing watch on port #{port}"
29
- handler.run self, :Host => host, :Port => port do |server|
30
- trap(:INT) do
31
- ## Use thins' hard #stop! if available, otherwise just #stop
32
- server.respond_to?(:stop!) ? server.stop! : server.stop
33
- puts "\n== The Middleman has ended his patrol"
34
- end
35
-
36
- if block_given?
37
- block.call
38
- ## Use thins' hard #stop! if available, otherwise just #stop
39
- server.respond_to?(:stop!) ? server.stop! : server.stop
40
- end
41
- end
42
- rescue Errno::EADDRINUSE => e
43
- puts "== The Middleman is already standing watch on port #{port}!"
44
- end
45
-
46
- configure do
47
- Compass.configuration do |config|
48
- config.project_path = Dir.pwd
49
- config.sass_dir = File.join(File.basename(self.views), "stylesheets")
50
- config.output_style = :nested
51
- config.css_dir = File.join(File.basename(self.public), "stylesheets")
52
- config.images_dir = File.join(File.basename(self.public), "images")
53
- config.http_images_path = "/images"
54
- config.http_stylesheets_path = "/stylesheets"
55
- config.add_import_path(config.sass_dir)
56
- end
57
- end
58
-
59
- # include helpers
60
- class_eval File.read(File.join(File.dirname(__FILE__), 'middleman', 'helpers.rb'))
61
-
62
- # Check for local config
63
- local_config = File.join(self.root, "init.rb")
64
- if File.exists? local_config
65
- puts "== Local config at: #{local_config}"
66
- class_eval File.read(local_config)
67
- end
68
-
69
- configure do
70
- Compass.configure_sass_plugin!
71
- end
72
-
73
- configure :build do
74
- Compass.configuration do |config|
75
- config.output_style = :compressed
76
- end
77
-
78
- module Minified
79
- module Javascript
80
- include ::Haml::Filters::Base
81
- def render_with_options(text, options)
82
- compressor = ::YUI::JavaScriptCompressor.new(:munge => true)
83
- data = compressor.compress(text.rstrip.gsub("\n", "\n "))
84
- %Q{<script type=#{options[:attr_wrapper]}text/javascript#{options[:attr_wrapper]}>#{data.chomp}</script>}
85
- end
86
- end
87
- end
88
- end
89
-
90
- # CSS files
91
- get %r{/(.*).css} do |path|
92
- content_type 'text/css', :charset => 'utf-8'
93
- begin
94
- static_version = File.join(Dir.pwd, 'public') + request.path_info
95
- send_file(static_version) if File.exists? static_version
96
-
97
- location_of_sass_file = defined?(MIDDLEMAN_BUILDER) ? "build" : "views"
98
- css_filename = File.join(Dir.pwd, location_of_sass_file) + request.path_info
99
- sass(path.to_sym, Compass.sass_engine_options.merge({ :css_filename => css_filename }))
100
- rescue Exception => e
101
- sass_exception_string(e)
102
- end
103
- end
104
-
105
- # All other files
106
- get /(.*)/ do |path|
107
- path << "index.#{options.default_ext}" if path.match(%r{/$})
108
- path.gsub!(%r{^/}, '')
109
- path_without_ext = path.gsub(File.extname(path), '')
110
-
111
- result = nil
112
- begin
113
- options.supported_formats.detect do |renderer|
114
- if File.exists?(File.join(options.views, "#{path}.#{renderer}"))
115
- result = send(renderer.to_sym, path.to_sym)
116
- elsif File.exists?(File.join(options.views, "#{path_without_ext}.#{renderer}"))
117
- result = send(renderer.to_sym, path_without_ext.to_sym)
118
- else
119
- false
120
- end
121
- end
122
- rescue Haml::Error => e
123
- result = "Haml Error: #{e}"
124
- result << "<pre>Backtrace: #{e.backtrace.join("\n")}</pre>"
125
- end
126
-
127
- result || pass
128
- end
129
-
130
- get %r{/(.*\.xml)} do |path|
131
- content_type 'text/xml', :charset => 'utf-8'
132
- haml(path.to_sym, :layout => false)
133
- end
134
- end
6
+ module Middleman
7
+ autoload :Base, "middleman/base"
8
+ end
@@ -0,0 +1,33 @@
1
+ module Middleman
2
+ module Assets
3
+ @@asset_handler_map = []
4
+ @@asset_handler_stack = []
5
+
6
+ def self.register(handler_name, &block)
7
+ if block_given?
8
+ @@asset_handler_stack << block
9
+ @@asset_handler_map << handler_name
10
+ end
11
+ end
12
+
13
+ def self.get_url(path, prefix="", request=nil)
14
+ @@asset_handler_stack.last.call(path, prefix, request)
15
+ end
16
+
17
+ def self.before(position, *args)
18
+ current_index = @@asset_handler_map.index(position)
19
+ return nil unless current_index
20
+
21
+ previous = current_index - 1
22
+ if (previous >= 0) && (previous < @@asset_handler_map.length)
23
+ @@asset_handler_stack[previous].call(*args)
24
+ else
25
+ nil
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ Middleman::Assets.register :base do |path, prefix, request|
32
+ path.include?("://") ? path : File.join(Middleman::Base.http_prefix || "/", prefix, path)
33
+ end
@@ -0,0 +1,147 @@
1
+ # We're riding on Sinatra, so let's include it
2
+ require "sinatra/base"
3
+ require "sinatra/content_for"
4
+
5
+ class Sinatra::Request
6
+ attr_accessor :layout
7
+ end
8
+
9
+ module Middleman
10
+ class Base < Sinatra::Base
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'] || :development
17
+ set :index_file, "index.html"
18
+ set :js_dir, "javascripts"
19
+ set :css_dir, "stylesheets"
20
+ set :images_dir, "images"
21
+ set :fonts_dir, "fonts"
22
+ set :build_dir, "build"
23
+ set :http_prefix, nil
24
+
25
+ helpers Sinatra::ContentFor
26
+
27
+ set :features, []
28
+ def self.enable(*opts)
29
+ set :features, (self.features << opts).flatten
30
+ super
31
+ end
32
+
33
+ def self.disable(*opts)
34
+ current = self.features
35
+ current -= opts.flatten
36
+ set :features, current
37
+ super
38
+ end
39
+
40
+ def self.set(option, value=self, &block)
41
+ if block_given?
42
+ value = Proc.new { block }
43
+ end
44
+
45
+ super(option, value, &nil)
46
+ end
47
+
48
+ @@afters = []
49
+ def self.after_feature_init(&block)
50
+ @@afters << block
51
+ end
52
+
53
+ # Rack helper for adding mime-types during local preview
54
+ def self.mime(ext, type)
55
+ ext = ".#{ext}" unless ext.to_s[0] == ?.
56
+ ::Rack::Mime::MIME_TYPES[ext.to_s] = type
57
+ end
58
+
59
+ @@layout = nil
60
+ def self.page(url, options={}, &block)
61
+ layout = @@layout
62
+ layout = options[:layout] if !options[:layout].nil?
63
+
64
+ get(url) do
65
+ return yield if block_given?
66
+ process_request(layout)
67
+ end
68
+ end
69
+
70
+ def self.with_layout(layout, &block)
71
+ @@layout = layout
72
+ class_eval(&block) if block_given?
73
+ ensure
74
+ @@layout = nil
75
+ end
76
+
77
+ def self.enabled?(name)
78
+ name = (name.to_s << "?").to_sym
79
+ self.respond_to?(name) && self.send(name)
80
+ end
81
+
82
+ def enabled?(name)
83
+ self.class.enabled?(name)
84
+ end
85
+
86
+ # This will match all requests not overridden in the project's init.rb
87
+ not_found do
88
+ process_request
89
+ end
90
+
91
+ private
92
+ def process_request(layout = :layout)
93
+ # Normalize the path and add index if we're looking at a directory
94
+ path = request.path
95
+ path << settings.index_file if path.match(%r{/$})
96
+ path.gsub!(%r{^/}, '')
97
+
98
+ template_path = locate_template_file(path)
99
+ if template_path
100
+ content_type mime_type(File.extname(path)), :charset => 'utf-8'
101
+
102
+ renderer = Middleman::Renderers.get_method(template_path)
103
+ if respond_to? renderer
104
+ status 200
105
+ return send(renderer, path.to_sym, { :layout => layout })
106
+ end
107
+ end
108
+
109
+ status 404
110
+ end
111
+
112
+ def locate_template_file(path)
113
+ template_path = File.join(settings.views, "#{path}.*")
114
+ Dir.glob(template_path).first
115
+ end
116
+ end
117
+ end
118
+
119
+ require "middleman/assets"
120
+ require "middleman/renderers"
121
+ require "middleman/features"
122
+
123
+ # The Rack App
124
+ class Middleman::Base
125
+ def self.new(*args, &block)
126
+ # Check for and evaluate local configuration
127
+ local_config = File.join(self.root, "init.rb")
128
+ if File.exists? local_config
129
+ puts "== Reading: Local config" if logging?
130
+ Middleman::Base.class_eval File.read(local_config)
131
+ set :app_file, File.expand_path(local_config)
132
+ end
133
+
134
+ # loop over enabled feature
135
+ features.flatten.each do |feature_name|
136
+ next unless send(:"#{feature_name}?")
137
+ $stderr.puts "== Enabling: #{feature_name.to_s.capitalize}" if logging?
138
+ Middleman::Features.run(feature_name, self)
139
+ end
140
+
141
+ use ::Rack::ConditionalGet if environment == :development
142
+
143
+ @@afters.each { |block| class_eval(&block) }
144
+
145
+ super
146
+ end
147
+ end
@@ -0,0 +1,59 @@
1
+ require 'middleman/base'
2
+ require 'templater'
3
+ require 'middleman/templater+dynamic_renderer.rb'
4
+
5
+ # Placeholder for any methods the builder needs to abstract to allow feature integration
6
+ module Middleman
7
+ class Builder < ::Templater::Generator
8
+
9
+ @@template_extensions = ::Tilt.mappings.keys << "js"
10
+
11
+ # Define source and desintation
12
+ def self.source_root; Dir.pwd; end
13
+ def destination_root; File.join(Dir.pwd, Middleman::Base.build_dir); end
14
+
15
+ # Override template to ask middleman for the correct extension to output
16
+ def self.template(name, *args, &block)
17
+ return if args[0].include?('layout')
18
+
19
+ args.first.split('/').each do |part|
20
+ return if part[0,1] == '_'
21
+ end
22
+
23
+ if (args[0] === args[1])
24
+ args[1] = args[0].gsub("#{File.basename(Middleman::Base.views)}/", "").gsub("#{File.basename(Middleman::Base.public)}/", "")
25
+ if File.extname(args[1]) != ".js"
26
+ args[1] = args[1].gsub!(File.extname(args[1]), "") if File.basename(args[1]).split('.').length > 2
27
+ end
28
+ end
29
+
30
+ super(name, *args, &block)
31
+ end
32
+
33
+ def self.file(name, *args, &block)
34
+ file_ext = File.extname(args[0])
35
+
36
+ return unless ::Tilt[file_ext].nil?
37
+
38
+ if (args[0] === args[1])
39
+ args[1] = args[0].gsub("#{File.basename(Middleman::Base.views)}/", "").gsub("#{File.basename(Middleman::Base.public)}/", "")
40
+ end
41
+ super(name, *args, &block)
42
+ end
43
+
44
+ def self.init!
45
+ glob! File.basename(Middleman::Base.public), @@template_extensions
46
+ glob! File.basename(Middleman::Base.views), @@template_extensions
47
+ end
48
+
49
+ def after_run
50
+ end
51
+ end
52
+
53
+ module Generators
54
+ extend ::Templater::Manifold
55
+ desc "Build a static site"
56
+
57
+ add :build, ::Middleman::Builder
58
+ end
59
+ end