middleman 2.0.0.beta6 → 2.0.0.rc1

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.
Files changed (36) hide show
  1. data/CHANGELOG +2 -0
  2. data/features/data.feature +7 -0
  3. data/features/front-matter.feature +7 -0
  4. data/features/helpers_page_classes.feature +6 -6
  5. data/fixtures/test-app/config.rb +23 -36
  6. data/fixtures/test-app/data/test.yml +4 -0
  7. data/fixtures/test-app/source/auto-css/auto-css.html.haml +1 -0
  8. data/fixtures/test-app/source/auto-css/index.html.haml +1 -0
  9. data/fixtures/test-app/source/auto-css/sub/auto-css.html.haml +1 -0
  10. data/fixtures/test-app/source/auto-js/auto-js.html.haml +1 -0
  11. data/fixtures/test-app/source/auto-js/index.html.haml +1 -0
  12. data/fixtures/test-app/source/auto-js/sub/auto-js.html.haml +1 -0
  13. data/fixtures/test-app/source/data.html.erb +1 -0
  14. data/fixtures/test-app/source/front-matter.html.slim +6 -0
  15. data/fixtures/test-app/source/sub1/page-classes.html.haml +1 -0
  16. data/fixtures/test-app/source/sub1/sub2/page-classes.html.haml +1 -0
  17. data/lib/middleman.rb +72 -2
  18. data/lib/middleman/core_extensions/assets.rb +57 -0
  19. data/lib/middleman/{features → core_extensions}/data.rb +7 -6
  20. data/lib/middleman/{features → core_extensions}/default_helpers.rb +8 -6
  21. data/lib/middleman/core_extensions/features.rb +96 -0
  22. data/lib/middleman/core_extensions/front_matter.rb +83 -0
  23. data/lib/middleman/core_extensions/rendering.rb +18 -0
  24. data/lib/middleman/core_extensions/routing.rb +62 -0
  25. data/lib/middleman/features/asset_host.rb +5 -5
  26. data/lib/middleman/features/blog.rb +43 -56
  27. data/lib/middleman/features/cache_buster.rb +7 -7
  28. data/lib/middleman/features/relative_assets.rb +4 -4
  29. data/lib/middleman/features/tiny_src.rb +2 -2
  30. data/lib/middleman/server.rb +44 -142
  31. data/lib/middleman/version.rb +1 -1
  32. metadata +35 -9
  33. data/fixtures/test-app/source/front-matter.html.erb +0 -7
  34. data/lib/middleman/assets.rb +0 -33
  35. data/lib/middleman/features.rb +0 -126
  36. data/lib/middleman/features/front_matter.rb +0 -60
@@ -0,0 +1,83 @@
1
+ require "yaml"
2
+ require "tilt"
3
+
4
+ module Middleman::CoreExtensions::FrontMatter
5
+ class << self
6
+ def registered(app)
7
+ app.extend ClassMethods
8
+
9
+ ::Tilt::register RDiscountTemplate, 'markdown', 'mkd', 'md'
10
+ ::Tilt::register RedClothTemplate, 'textile'
11
+ ::Tilt::register ERBTemplate, 'erb', 'rhtml'
12
+ ::Tilt::register SlimTemplate, 'slim'
13
+ ::Tilt::register HamlTemplate, 'haml'
14
+
15
+ app.before do
16
+ result = resolve_template(request.path_info, :raise_exceptions => false)
17
+
18
+ if result && Tilt.mappings.has_key?(result[1].to_s)
19
+ extensionless_path, template_engine = result
20
+ full_file_path = "#{extensionless_path}.#{template_engine}"
21
+ system_path = File.join(settings.views, full_file_path)
22
+ data, content = app.parse_front_matter(File.read(system_path))
23
+
24
+ request['custom_options'] = {}
25
+ %w(layout layout_engine).each do |opt|
26
+ if data.has_key?(opt)
27
+ request['custom_options'][opt.to_sym] = data.delete(opt)
28
+ end
29
+ end
30
+
31
+ # Forward remaining data to helpers
32
+ app.data_content("page", data)
33
+ end
34
+ end
35
+ end
36
+ alias :included :registered
37
+ end
38
+
39
+ module ClassMethods
40
+ def parse_front_matter(content)
41
+ yaml_regex = /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
42
+ if content =~ yaml_regex
43
+ begin
44
+ data = YAML.load($1)
45
+ rescue => e
46
+ puts "YAML Exception: #{e.message}"
47
+ end
48
+
49
+ content = content.split(yaml_regex).last
50
+ end
51
+
52
+ data ||= {}
53
+ [data, content]
54
+ end
55
+ end
56
+
57
+ module YamlAware
58
+ def prepare
59
+ options, @data = Middleman::Server.parse_front_matter(@data)
60
+ super
61
+ end
62
+ end
63
+
64
+ class RDiscountTemplate < ::Tilt::RDiscountTemplate
65
+ include Middleman::CoreExtensions::FrontMatter::YamlAware
66
+ end
67
+
68
+ class RedClothTemplate < ::Tilt::RedClothTemplate
69
+ include Middleman::CoreExtensions::FrontMatter::YamlAware
70
+ end
71
+
72
+ class ERBTemplate < ::Tilt::ERBTemplate
73
+ include Middleman::CoreExtensions::FrontMatter::YamlAware
74
+ end
75
+
76
+ class HamlTemplate < ::Tilt::HamlTemplate
77
+ include Middleman::CoreExtensions::FrontMatter::YamlAware
78
+ end
79
+
80
+ class SlimTemplate < ::Slim::Template
81
+ include Middleman::CoreExtensions::FrontMatter::YamlAware
82
+ end
83
+ end
@@ -0,0 +1,18 @@
1
+ require "padrino-core/application/rendering"
2
+
3
+ module Middleman::CoreExtensions::Rendering
4
+ class << self
5
+ def registered(app)
6
+ # Tilt-aware renderer
7
+ app.register Padrino::Rendering
8
+
9
+ # Activate custom renderers
10
+ app.register Middleman::Renderers::Slim
11
+ app.register Middleman::Renderers::Haml
12
+ app.register Middleman::Renderers::Sass
13
+ app.register Middleman::Renderers::Markdown
14
+ app.register Middleman::Renderers::CoffeeScript
15
+ end
16
+ alias :included :registered
17
+ end
18
+ end
@@ -0,0 +1,62 @@
1
+ module Middleman::CoreExtensions::Routing
2
+ class << self
3
+ def registered(app)
4
+ app.extend ClassMethods
5
+
6
+ # Normalize the path and add index if we're looking at a directory
7
+ app.before do
8
+ request.path_info = self.class.path_to_index(request.path)
9
+ end
10
+ end
11
+ alias :included :registered
12
+ end
13
+
14
+ module ClassMethods
15
+ def current_layout
16
+ @layout
17
+ end
18
+
19
+ def path_to_index(path)
20
+ parts = path ? path.split('/') : []
21
+ if parts.last.nil? || parts.last.split('.').length == 1
22
+ path = File.join(path, settings.index_file)
23
+ end
24
+ path.gsub(%r{^/}, '')
25
+ end
26
+
27
+ # Takes a block which allows many pages to have the same layout
28
+ # with_layout :admin do
29
+ # page "/admin/"
30
+ # page "/admin/login.html"
31
+ # end
32
+ def with_layout(layout_name, &block)
33
+ old_layout = current_layout
34
+
35
+ layout(layout_name)
36
+ class_eval(&block) if block_given?
37
+ ensure
38
+ layout(old_layout)
39
+ end
40
+
41
+ # The page method allows the layout to be set on a specific path
42
+ # page "/about.html", :layout => false
43
+ # page "/", :layout => :homepage_layout
44
+ def page(url, options={}, &block)
45
+ url = url.gsub(%r{#{settings.index_file}$}, "")
46
+ url = url.gsub(%r{(\/)$}, "") if url.length > 1
47
+
48
+ paths = [url]
49
+ paths << "#{url}/" if url.length > 1 && url.split("/").last.split('.').length <= 1
50
+ paths << "#{path_to_index(url)}"
51
+
52
+ options[:layout] = current_layout if options[:layout].nil?
53
+
54
+ paths.each do |p|
55
+ get(p) do
56
+ return yield if block_given?
57
+ process_request(options)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -2,17 +2,17 @@ module Middleman::Features::AssetHost
2
2
  class << self
3
3
  def registered(app)
4
4
  app.after_feature_init do
5
- if Middleman::Server.asset_host.is_a?(Proc)
6
- ::Compass.configuration.asset_host(&Middleman::Server.asset_host)
5
+ if app.asset_host.is_a?(Proc)
6
+ ::Compass.configuration.asset_host(&app.asset_host)
7
7
  end
8
8
  end
9
9
 
10
- Middleman::Assets.register :asset_host do |path, prefix, request|
11
- original_output = Middleman::Assets.before(:asset_host, path, prefix, request)
10
+ app.register_asset_handler :asset_host do |path, prefix, request|
11
+ original_output = app.before_asset_handler(:asset_host, path, prefix, request)
12
12
 
13
13
  valid_extensions = %w(.png .gif .jpg .jpeg .js .css)
14
14
 
15
- asset_prefix = Middleman::Server.asset_host.call(original_output)
15
+ asset_prefix = app.asset_host.call(original_output)
16
16
 
17
17
  File.join(asset_prefix, original_output)
18
18
  end
@@ -10,11 +10,11 @@ module Middleman
10
10
 
11
11
  app.after_feature_init do
12
12
  if !app.settings.respond_to? :blog_permalink
13
- app.set :blog_permalink, "/:year/:month/:day/:title.html"
13
+ app.set :blog_permalink, ":year/:month/:day/:title.html"
14
14
  end
15
15
 
16
16
  if !app.settings.respond_to? :blog_taglink
17
- app.set :blog_taglink, "/tags/:tag.html"
17
+ app.set :blog_taglink, "tags/:tag.html"
18
18
  end
19
19
 
20
20
  if !app.settings.respond_to? :blog_layout
@@ -43,71 +43,58 @@ module Middleman
43
43
 
44
44
  $stderr.puts "== Blog: #{app.settings.blog_permalink}"
45
45
 
46
- articles_glob = File.join(app.views, app.settings.blog_permalink.gsub(/(:\w+)/, "*") + ".*")
46
+ app.before do
47
+ articles_glob = File.join(app.views, app.settings.blog_permalink.gsub(/(:\w+)/, "*") + ".*")
47
48
 
48
- articles = Dir[articles_glob].map do |article|
49
- template_content = File.read(article)
50
- data, content = parse_front_matter(template_content)
51
- data["date"] = Date.parse(data["date"])
49
+ articles = Dir[articles_glob].map do |article|
50
+ template_content = File.read(article)
51
+ data, content = app.parse_front_matter(template_content)
52
+ data["date"] = Date.parse(data["date"])
52
53
 
53
- yaml_regex = /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
54
- data["raw"] = template_content.split(yaml_regex).last
55
- data["url"] = article.gsub(app.views, "").split(".html").first + ".html"
54
+ data["raw"] = content
55
+ data["url"] = article.gsub(app.views, "").split(".html").first + ".html"
56
56
 
57
- all_content = Tilt.new(article).render
58
- data["body"] = all_content.gsub!(app.settings.blog_summary_separator, "")
57
+ all_content = Tilt.new(article).render
58
+ data["body"] = all_content.gsub!(app.settings.blog_summary_separator, "")
59
59
 
60
- sum = if data["raw"] =~ app.settings.blog_summary_separator
61
- data["raw"].split(app.settings.blog_summary_separator).first
62
- else
63
- data["raw"].match(/(.{1,#{app.settings.blog_summary_length}}.*?)(\n|\Z)/m).to_s
64
- end
60
+ sum = if data["raw"] =~ app.settings.blog_summary_separator
61
+ data["raw"].split(app.settings.blog_summary_separator).first
62
+ else
63
+ data["raw"].match(/(.{1,#{app.settings.blog_summary_length}}.*?)(\n|\Z)/m).to_s
64
+ end
65
65
 
66
- engine = RDiscount.new(sum)
67
- data["summary"] = engine.to_html
68
- data
69
- end.sort { |a, b| b["date"] <=> a["date"] }
70
-
71
- tags = {}
72
- articles.each do |article|
73
- article["tags"] ||= ""
74
- if !article["tags"].empty?
75
- tags_array = article["tags"].split(',').map{|t| t.strip}
76
- tags_array.each do |tag_title|
77
- tag_key = tag_title.parameterize
78
- tag_path = blog_taglink.gsub(/(:\w+)/, tag_key)
79
- (tags[tag_path] ||= {})["title"] = tag_title
80
- tags[tag_path]["ident"] = tag_key
81
- (tags[tag_path]["pages"] ||= {})[article["title"]] = article["url"]
66
+ engine = RDiscount.new(sum)
67
+ data["summary"] = engine.to_html
68
+ data
69
+ end.sort { |a, b| b["date"] <=> a["date"] }
70
+
71
+ tags = {}
72
+ articles.each do |article|
73
+ article["tags"] ||= ""
74
+ if !article["tags"].empty?
75
+ tags_array = article["tags"].split(',').map{|t| t.strip}
76
+ tags_array.each do |tag_title|
77
+ tag_key = tag_title.parameterize
78
+ tag_path = blog_taglink.gsub(/(:\w+)/, tag_key)
79
+ (tags[tag_path] ||= {})["title"] = tag_title
80
+ tags[tag_path]["ident"] = tag_key
81
+ (tags[tag_path]["pages"] ||= {})[article["title"]] = article["url"]
82
+ end
82
83
  end
83
84
  end
84
- end
85
-
86
- app.data_content("blog", { :articles => articles, :tags => tags })
87
85
 
86
+ app.data_content("blog", { :articles => articles, :tags => tags })
87
+ end
88
+
88
89
  app.get(app.settings.blog_permalink) do
89
- options = {}
90
- options[:layout] = settings.blog_layout
91
- options[:layout_engine] = settings.blog_layout_engine
92
-
93
- extensionless_path, template_engine = resolve_template(request.path)
94
-
95
- full_file_path = "#{extensionless_path}.#{template_engine}"
96
- system_path = File.join(settings.views, full_file_path)
97
- data, content = self.class.parse_front_matter(File.read(system_path))
98
-
99
- # Forward remaining data to helpers
100
- self.class.data_content("page", data)
101
-
102
- output = render(request.path, options)
103
-
90
+ process_request({
91
+ :layout => settings.blog_layout,
92
+ :layout_engine => settings.blog_layout_engine
93
+ })
94
+
104
95
  # No need for separator on permalink page
105
- output.gsub!(settings.blog_summary_separator, "")
106
-
107
- status 200
108
- output
96
+ body body.gsub!(settings.blog_summary_separator, "")
109
97
  end
110
-
111
98
  end
112
99
  end
113
100
  alias :included :registered
@@ -1,23 +1,23 @@
1
1
  module Middleman::Features::CacheBuster
2
2
  class << self
3
3
  def registered(app)
4
- Middleman::Assets.register :cache_buster do |path, prefix, request|
5
- http_path = Middleman::Assets.before(:cache_buster, path, prefix, request)
4
+ app.register_asset_handler :cache_buster do |path, prefix, request|
5
+ http_path = app.before_asset_handler(:cache_buster, path, prefix, request)
6
6
 
7
7
  if http_path.include?("://") || !%w(.css .png .jpg .js .gif).include?(File.extname(http_path))
8
8
  http_path
9
9
  else
10
10
  begin
11
- prefix = Middleman::Server.images_dir if prefix == Middleman::Server.http_images_path
11
+ prefix = app.images_dir if prefix == app.http_images_path
12
12
  rescue
13
13
  end
14
14
 
15
- real_path_static = File.join(Middleman::Server.views, prefix, path)
15
+ real_path_static = File.join(app.views, prefix, path)
16
16
 
17
17
  if File.readable?(real_path_static)
18
18
  http_path << "?" + File.mtime(real_path_static).strftime("%s")
19
- elsif Middleman::Server.environment == :build
20
- real_path_dynamic = File.join(Middleman::Server.root, Middleman::Server.build_dir, prefix, path)
19
+ elsif app.environment == :build
20
+ real_path_dynamic = File.join(app.root, app.build_dir, prefix, path)
21
21
  http_path << "?" + File.mtime(real_path_dynamic).strftime("%s") if File.readable?(real_path_dynamic)
22
22
  end
23
23
 
@@ -29,7 +29,7 @@ module Middleman::Features::CacheBuster
29
29
  ::Compass.configuration do |config|
30
30
  config.asset_cache_buster do |path, real_path|
31
31
  real_path = real_path.path if real_path.is_a? File
32
- real_path = real_path.gsub(File.join(Middleman::Server.root, Middleman::Server.build_dir), Middleman::Server.views)
32
+ real_path = real_path.gsub(File.join(app.root, app.build_dir), app.views)
33
33
  if File.readable?(real_path)
34
34
  File.mtime(real_path).strftime("%s")
35
35
  else
@@ -3,20 +3,20 @@ module Middleman::Features::RelativeAssets
3
3
  def registered(app)
4
4
  ::Compass.configuration.relative_assets = true
5
5
 
6
- Middleman::Assets.register :relative_assets do |path, prefix, request|
6
+ app.register_asset_handler :relative_assets do |path, prefix, request|
7
7
  begin
8
- prefix = Middleman::Server.images_dir if prefix == Middleman::Server.http_images_path
8
+ prefix = app.images_dir if prefix == app.http_images_path
9
9
  rescue
10
10
  end
11
11
 
12
12
  if path.include?("://")
13
- Middleman::Assets.before(:relative_assets, path, prefix, request)
13
+ app.before_asset_handler(:relative_assets, path, prefix, request)
14
14
  elsif path[0,1] == "/"
15
15
  path
16
16
  else
17
17
  path = File.join(prefix, path) if prefix.length > 0
18
18
  request_path = request.path_info.dup
19
- request_path << Middleman::Server.index_file if path.match(%r{/$})
19
+ request_path << app.index_file if path.match(%r{/$})
20
20
  request_path.gsub!(%r{^/}, '')
21
21
  parts = request_path.split('/')
22
22
 
@@ -1,8 +1,8 @@
1
1
  module Middleman::Features::TinySrc
2
2
  class << self
3
3
  def registered(app)
4
- Middleman::Assets.register :tiny_src do |path, prefix, request|
5
- original_output = Middleman::Assets.before(:tiny_src, path, prefix, request)
4
+ app.register_asset_handler :tiny_src do |path, prefix, request|
5
+ original_output = app.before_asset_handler(:tiny_src, path, prefix, request)
6
6
  "http://i.tinysrc.mobi/#{original_output}"
7
7
  end
8
8
  end
@@ -1,16 +1,11 @@
1
1
  # We're riding on Sinatra, so let's include it.
2
2
  require "sinatra/base"
3
3
 
4
- # Use the padrino project's helpers
5
- require "padrino-core/application/rendering"
6
- require "padrino-helpers"
7
-
8
4
  module Middleman
9
5
  class Server < Sinatra::Base
10
6
  # Basic Sinatra config
11
7
  set :app_file, __FILE__
12
8
  set :root, ENV["MM_DIR"] || Dir.pwd
13
- set :reload, false
14
9
  set :sessions, false
15
10
  set :logging, false
16
11
  set :environment, (ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development
@@ -28,36 +23,38 @@ module Middleman
28
23
  set :build_dir, "build" # Which folder are builds output to
29
24
  set :http_prefix, nil # During build, add a prefix for absolute paths
30
25
 
26
+ # Pass all request to Middleman, even "static" files
31
27
  set :static, false
28
+
32
29
  set :views, "source"
33
30
 
34
- # Disable Padrino cache buster until explicitly enabled
35
- set :asset_stamp, false
31
+ # Activate custom features
32
+ register Middleman::CoreExtensions::Features
36
33
 
37
- # Use Padrino Helpers
38
- register Padrino::Helpers
34
+ # Setup custom rendering
35
+ register Middleman::CoreExtensions::Rendering
39
36
 
40
- # Activate custom features
41
- register Middleman::Features
37
+ # Setup asset path pipeline
38
+ register Middleman::CoreExtensions::Assets
42
39
 
43
40
  # Activate built-in helpers
44
- register Middleman::Features::DefaultHelpers
41
+ register Middleman::CoreExtensions::DefaultHelpers
45
42
 
46
43
  # Activate Yaml Data package
47
- register Middleman::Features::Data
48
-
49
- # Activate Webservices Proxy package
50
- # register Middleman::Features::Proxy
44
+ register Middleman::CoreExtensions::Data
51
45
 
52
- register Middleman::Features::FrontMatter
46
+ # with_layout and page routing
47
+ register Middleman::CoreExtensions::Routing
53
48
 
54
- # Activate Lorem helpers
55
- register Middleman::Features::Lorem
49
+ # Parse YAML from templates
50
+ register Middleman::CoreExtensions::FrontMatter
56
51
 
57
- # Tilt-aware renderer
58
- register Padrino::Rendering
52
+ set :default_extensions, [
53
+ :lorem
54
+ ]
59
55
 
60
56
  # Override Sinatra's set to accept a block
57
+ # Specifically for the asset_host feature
61
58
  def self.set(option, value=self, &block)
62
59
  if block_given?
63
60
  value = Proc.new { block }
@@ -66,153 +63,58 @@ module Middleman
66
63
  super(option, value, &nil)
67
64
  end
68
65
 
69
- # An array of callback procs to run after all features have been setup
70
- @@run_after_features = []
71
-
72
- # Add a block/proc to be run after features have been setup
73
- def self.after_feature_init(&block)
74
- @@run_after_features << block
75
- end
76
-
77
- # Activate custom renderers
78
- register Middleman::Renderers::Slim
79
- register Middleman::Renderers::Haml
80
- register Middleman::Renderers::Sass
81
- register Middleman::Renderers::Markdown
82
- register Middleman::Renderers::CoffeeScript
83
-
84
- # Rack helper for adding mime-types during local preview
85
- def self.mime(ext, type)
86
- ext = ".#{ext}" unless ext.to_s[0] == ?.
87
- ::Rack::Mime::MIME_TYPES[ext.to_s] = type
88
- end
89
-
90
66
  # Default layout name
91
67
  layout :layout
92
-
93
- def self.current_layout
94
- @layout
95
- end
96
-
97
- # Takes a block which allows many pages to have the same layout
98
- # with_layout :admin do
99
- # page "/admin/"
100
- # page "/admin/login.html"
101
- # end
102
- def self.with_layout(layout_name, &block)
103
- old_layout = current_layout
104
-
105
- layout(layout_name)
106
- class_eval(&block) if block_given?
107
- ensure
108
- layout(old_layout)
109
- end
110
-
111
- # The page method allows the layout to be set on a specific path
112
- # page "/about.html", :layout => false
113
- # page "/", :layout => :homepage_layout
114
- def self.page(url, options={}, &block)
115
- url = url.gsub(%r{#{settings.index_file}$}, "")
116
- url = url.gsub(%r{(\/)$}, "") if url.length > 1
117
-
118
- paths = [url]
119
- paths << "#{url}/" if url.length > 1 && url.split("/").last.split('.').length <= 1
120
- paths << "/#{path_to_index(url)}"
121
-
122
- options[:layout] = current_layout if options[:layout].nil?
123
-
124
- paths.each do |p|
125
- get(p) do
126
- return yield if block_given?
127
- process_request(options)
128
- end
129
- end
130
- end
131
68
 
132
69
  # This will match all requests not overridden in the project's config.rb
133
70
  not_found do
134
71
  process_request
135
72
  end
136
73
 
137
- private
138
- def self.path_to_index(path)
139
- parts = path ? path.split('/') : []
140
- if parts.last.nil? || parts.last.split('.').length == 1
141
- path = File.join(path, settings.index_file)
74
+ # See if Tilt cannot handle this file
75
+ before do
76
+ result = resolve_template(request.path_info, :raise_exceptions => false)
77
+ if result
78
+ extensionless_path, template_engine = result
79
+
80
+ # Return static files
81
+ if !::Tilt.mappings.has_key?(template_engine.to_s)
82
+ content_type mime_type(File.extname(request.path_info)), :charset => 'utf-8'
83
+ status 200
84
+ send_file File.join(Middleman::Server.views, request.path_info)
85
+ request["already_sent"] = true
86
+ end
87
+ else
88
+ $stderr.puts "File not found: #{request.path_info}"
89
+ status 404
90
+ request["already_sent"] = true
142
91
  end
143
- path.gsub(%r{^/}, '')
144
92
  end
145
-
93
+
94
+ private
146
95
  # Internal method to look for templates and evaluate them if found
147
96
  def process_request(options={})
148
- # Normalize the path and add index if we're looking at a directory
149
- path = self.class.path_to_index(request.path)
150
-
151
- extensionless_path, template_engine = resolve_template(path)
152
-
153
- if !::Tilt.mappings.has_key?(template_engine.to_s)
154
- content_type mime_type(File.extname(path)), :charset => 'utf-8'
155
- status 200
156
- send_file File.join(Middleman::Server.views, path)
157
- return
158
- end
159
-
160
- full_file_path = "#{extensionless_path}.#{template_engine}"
161
- system_path = File.join(settings.views, full_file_path)
162
- data, content = self.class.parse_front_matter(File.read(system_path))
97
+ return if request["already_sent"]
163
98
 
164
- %w(layout layout_engine).each do |opt|
165
- if data.has_key?(opt)
166
- options[opt.to_sym] = data.delete(opt)
167
- end
168
- end
169
-
170
- # Forward remaining data to helpers
171
- self.class.data_content("page", data)
99
+ options.merge!(request['custom_options'] || {})
172
100
 
173
101
  old_layout = settings.current_layout
174
102
  settings.layout(options[:layout]) if !options[:layout].nil?
175
103
  layout = settings.fetch_layout_path.to_sym
176
- layout = false if options[:layout] == false or path =~ /\.(css|js)$/
104
+ layout = false if options[:layout] == false or request.path_info =~ /\.(css|js)$/
177
105
 
178
106
  render_options = { :layout => layout }
179
107
  render_options[:layout_engine] = options[:layout_engine] if options.has_key? :layout_engine
180
- result = render(path, render_options)
108
+ result = render(request.path_info, render_options)
181
109
  settings.layout(old_layout)
182
110
 
183
111
  if result
184
- content_type mime_type(File.extname(path)), :charset => 'utf-8'
112
+ content_type mime_type(File.extname(request.path_info)), :charset => 'utf-8'
185
113
  status 200
186
- return result
187
- end
188
-
189
- status 404
190
- rescue Padrino::Rendering::TemplateNotFound
191
- if settings.environment == :development
192
- raise $!
114
+ body result
193
115
  else
194
- $stderr.puts "File not found: #{request.path}"
195
116
  status 404
196
117
  end
197
118
  end
198
119
  end
199
- end
200
-
201
- require "middleman/assets"
202
-
203
- # The Rack App
204
- class Middleman::Server
205
- def self.new(*args, &block)
206
- # Check for and evaluate local configuration
207
- local_config = File.join(self.root, "config.rb")
208
- if File.exists? local_config
209
- $stderr.puts "== Reading: Local config" if logging?
210
- Middleman::Server.class_eval File.read(local_config)
211
- set :app_file, File.expand_path(local_config)
212
- end
213
-
214
- @@run_after_features.each { |block| class_eval(&block) }
215
-
216
- super
217
- end
218
- end
120
+ end