Class: Middleman::Server
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Middleman::Server
- Defined in:
- lib/middleman/server.rb,
lib/middleman/server.rb
Overview
The Rack App
Constant Summary collapse
- @@run_after_features =
An array of callback procs to run after all features have been setup
[]
Class Method Summary collapse
-
.after_feature_init(&block) ⇒ Object
Add a block/proc to be run after features have been setup.
- .current_layout ⇒ Object
-
.mime(ext, type) ⇒ Object
Rack helper for adding mime-types during local preview.
- .new(*args, &block) ⇒ Object
-
.page(url, options = {}, &block) ⇒ Object
The page method allows the layout to be set on a specific path page “/about.html”, :layout => false page “/”, :layout => :homepage_layout.
-
.set(option, value = self, &block) ⇒ Object
Override Sinatra’s set to accept a block.
-
.with_layout(layout_name, &block) ⇒ Object
Takes a block which allows many pages to have the same layout with_layout :admin do page “/admin/” page “/admin/login.html” end.
Class Method Details
.after_feature_init(&block) ⇒ Object
Add a block/proc to be run after features have been setup
59 60 61 |
# File 'lib/middleman/server.rb', line 59 def self.after_feature_init(&block) @@run_after_features << block end |
.current_layout ⇒ Object
76 77 78 |
# File 'lib/middleman/server.rb', line 76 def self.current_layout @layout end |
.mime(ext, type) ⇒ Object
Rack helper for adding mime-types during local preview
68 69 70 71 |
# File 'lib/middleman/server.rb', line 68 def self.mime(ext, type) ext = ".#{ext}" unless ext.to_s[0] == ?. ::Rack::Mime::MIME_TYPES[ext.to_s] = type end |
.new(*args, &block) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/middleman/server.rb', line 143 def self.new(*args, &block) # If the old init.rb exists, use it, but issue warning old_config = File.join(self.root, "init.rb") if File.exists? old_config $stderr.puts "== Warning: The init.rb file has been renamed to config.rb" local_config = old_config end # Check for and evaluate local configuration local_config ||= File.join(self.root, "config.rb") if File.exists? local_config $stderr.puts "== Reading: Local config" if logging? Middleman::Server.class_eval File.read(local_config) set :app_file, File.(local_config) end use ::Rack::ConditionalGet if environment == :development @@run_after_features.each { |block| class_eval(&block) } super end |
.page(url, options = {}, &block) ⇒ Object
The page method allows the layout to be set on a specific path page “/about.html”, :layout => false page “/”, :layout => :homepage_layout
97 98 99 100 101 102 103 104 105 |
# File 'lib/middleman/server.rb', line 97 def self.page(url, ={}, &block) url << settings.index_file if url.match(%r{/$}) [:layout] ||= current_layout get(url) do return yield if block_given? process_request() end end |
.set(option, value = self, &block) ⇒ Object
Override Sinatra’s set to accept a block
47 48 49 50 51 52 53 |
# File 'lib/middleman/server.rb', line 47 def self.set(option, value=self, &block) if block_given? value = Proc.new { block } end super(option, value, &nil) end |
.with_layout(layout_name, &block) ⇒ Object
Takes a block which allows many pages to have the same layout with_layout :admin do
page "/admin/"
page "/admin/login.html"
end
85 86 87 88 89 90 91 92 |
# File 'lib/middleman/server.rb', line 85 def self.with_layout(layout_name, &block) old_layout = current_layout layout(layout_name) class_eval(&block) if block_given? ensure layout(old_layout) end |