Class: Middleman::Application
- Inherits:
-
Object
- Object
- Middleman::Application
- Includes:
- Hooks, Hooks::InstanceHooks, Configuration::Global, CoreExtensions::Extensions, CoreExtensions::Routing
- Defined in:
- lib/middleman-core/application.rb
Class Method Summary collapse
-
.helpers(*extensions, &block)
Mix-in helper methods.
-
.root ⇒ String
Root project directory (overwritten in middleman build/server).
-
.root_path ⇒ Object
Pathname-addressed root.
Instance Method Summary collapse
-
#_hooks ⇒ Object
Hooks clones _hooks from the class to the instance.
-
#bind_address ⇒ NilClass, String
Which bind address the preview server should use.
-
#build? ⇒ Boolean
Whether we’re in build mode.
-
#build_dir ⇒ String
Where to build output files.
-
#css_dir ⇒ String
Location of stylesheets within source.
-
#development? ⇒ Boolean
Whether we’re in development mode.
-
#encoding ⇒ String
Default string encoding for templates and output.
-
#environment ⇒ String
Middleman environment.
-
#fonts_dir ⇒ String
Location of fonts within source.
-
#http_prefix ⇒ String
Default prefix for building paths.
-
#https ⇒ Boolean
Whether to serve the preview server over HTTPS.
-
#images_dir ⇒ String
Location of images within source.
-
#index_file ⇒ String
Which file should be used for directory indexes.
-
#initialize(&block) ⇒ Application
constructor
Initialize the Middleman project.
-
#js_dir ⇒ String
Location of javascripts within source.
-
#layout ⇒ String, Symbold
Default layout name.
-
#layouts_dir ⇒ String
Location of layouts within source.
-
#logger ⇒ Object
Reference to Logger singleton.
-
#partials_dir ⇒ String
Location of partials within source.
-
#port ⇒ Fixnum
Which port preview should start on.
-
#protect_from_csrf ⇒ Boolean
Should Padrino include CRSF tag.
-
#server_name ⇒ NilClass, String
Which server name should be used.
-
#source ⇒ String
Name of the source directory.
-
#source_dir ⇒ String
The full path to the source directory.
-
#ssl_certificate ⇒ String
The (optional) path to the SSL cert to use for the preview server.
-
#ssl_private_key ⇒ String
The (optional) private key for the certificate in :ssl_certificate.
-
#strip_index_file ⇒ Boolean
Whether to strip the index file name off links to directory indexes.
-
#to_s ⇒ Object
(also: #inspect)
Work around this bug: bugs.ruby-lang.org/issues/4521 where Ruby will call to_s/inspect while printing exception messages, which can take a long time (minutes at full CPU) if the object is huge or has cyclic references, like this.
-
#trailing_slash ⇒ Boolean
Whether to include a trailing slash when stripping the index file.
Methods included from CoreExtensions::Routing
Methods included from Configuration::Global
#config, #method_missing, #respond_to?, #set
Constructor Details
#initialize(&block) ⇒ Application
Initialize the Middleman project
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/middleman-core/application.rb', line 196 def initialize(&block) # Clear the static class cache cache.clear # Setup the default values from calls to set before initialization self.class.config.load_settings(self.class.superclass.config.all_settings) if Object.const_defined?(:Encoding) Encoding.default_internal = config[:encoding] Encoding.default_external = config[:encoding] end # Evaluate a passed block if given instance_exec(&block) if block_given? config[:source] = ENV['MM_SOURCE'] if ENV['MM_SOURCE'] super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Middleman::Configuration::Global
Class Method Details
.helpers(*extensions, &block)
This method returns an undefined value.
Mix-in helper methods. Accepts either a list of Modules and/or a block to be evaluated
50 51 52 53 |
# File 'lib/middleman-core/application.rb', line 50 def self.helpers(*extensions, &block) class_eval(&block) if block_given? include(*extensions) if extensions.any? end |
.root ⇒ String
Root project directory (overwritten in middleman build/server)
58 59 60 61 62 |
# File 'lib/middleman-core/application.rb', line 58 def self.root r = ENV['MM_ROOT'] ? ENV['MM_ROOT'].dup : ::Middleman::Util.current_directory r.encode!('UTF-8', 'UTF-8-MAC') if RUBY_PLATFORM =~ /darwin/ r end |
.root_path ⇒ Object
Pathname-addressed root
66 67 68 |
# File 'lib/middleman-core/application.rb', line 66 def self.root_path Pathname(root) end |
Instance Method Details
#_hooks ⇒ Object
Hooks clones _hooks from the class to the instance. github.com/apotonick/hooks/blob/master/lib/hooks/instance_hooks.rb#L10 Middleman expects the same list of hooks for class and instance hooks:
258 259 260 |
# File 'lib/middleman-core/application.rb', line 258 def _hooks self.class._hooks end |
#bind_address ⇒ NilClass, String
Which bind address the preview server should use
81 |
# File 'lib/middleman-core/application.rb', line 81 config.define_setting :bind_address, nil, 'The bind address of the preview server' |
#build? ⇒ Boolean
Whether we’re in build mode
233 234 235 |
# File 'lib/middleman-core/application.rb', line 233 def build? config[:environment] == :build end |
#build_dir ⇒ String
Where to build output files
141 |
# File 'lib/middleman-core/application.rb', line 141 config.define_setting :build_dir, 'build', 'Where to build output files' |
#css_dir ⇒ String
Location of stylesheets within source. Used by Compass.
121 |
# File 'lib/middleman-core/application.rb', line 121 config.define_setting :css_dir, 'stylesheets', 'Location of stylesheets within source' |
#development? ⇒ Boolean
Whether we’re in development mode
227 228 229 |
# File 'lib/middleman-core/application.rb', line 227 def development? config[:environment] == :development end |
#encoding ⇒ String
Default string encoding for templates and output.
153 |
# File 'lib/middleman-core/application.rb', line 153 config.define_setting :encoding, 'utf-8', 'Default string encoding for templates and output' |
#environment ⇒ String
Middleman environment. Defaults to :development, set to :build by the build process
101 |
# File 'lib/middleman-core/application.rb', line 101 config.define_setting :environment, ((ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development), 'Middleman environment. Defaults to :development, set to :build by the build process' |
#fonts_dir ⇒ String
Location of fonts within source. Used by Compass.
129 |
# File 'lib/middleman-core/application.rb', line 129 config.define_setting :fonts_dir, 'fonts', 'Location of fonts within source' |
#http_prefix ⇒ String
Default prefix for building paths. Used by HTML helpers and Compass.
145 |
# File 'lib/middleman-core/application.rb', line 145 config.define_setting :http_prefix, '/', 'Default prefix for building paths' |
#https ⇒ Boolean
Whether to serve the preview server over HTTPS.
85 |
# File 'lib/middleman-core/application.rb', line 85 config.define_setting :https, false, 'Serve the preview server over SSL/TLS' |
#images_dir ⇒ String
Location of images within source. Used by HTML helpers and Compass.
125 |
# File 'lib/middleman-core/application.rb', line 125 config.define_setting :images_dir, 'images', 'Location of images within source' |
#index_file ⇒ String
Which file should be used for directory indexes
105 |
# File 'lib/middleman-core/application.rb', line 105 config.define_setting :index_file, 'index.html', 'Which file should be used for directory indexes' |
#js_dir ⇒ String
Location of javascripts within source.
117 |
# File 'lib/middleman-core/application.rb', line 117 config.define_setting :js_dir, 'javascripts', 'Location of javascripts within source' |
#layout ⇒ String, Symbold
Default layout name
149 |
# File 'lib/middleman-core/application.rb', line 149 config.define_setting :layout, :_auto_layout, 'Default layout name' |
#layouts_dir ⇒ String
Location of layouts within source. Used by renderers.
137 |
# File 'lib/middleman-core/application.rb', line 137 config.define_setting :layouts_dir, 'layouts', 'Location of layouts within source' |
#logger ⇒ Object
Reference to Logger singleton
191 192 193 |
# File 'lib/middleman-core/application.rb', line 191 def logger ::Middleman::Logger.singleton end |
#partials_dir ⇒ String
Location of partials within source. Used by renderers.
133 |
# File 'lib/middleman-core/application.rb', line 133 config.define_setting :partials_dir, '', 'Location of partials within source' |
#port ⇒ Fixnum
Which port preview should start on.
73 |
# File 'lib/middleman-core/application.rb', line 73 config.define_setting :port, 4567, 'The preview server port' |
#protect_from_csrf ⇒ Boolean
Should Padrino include CRSF tag
157 |
# File 'lib/middleman-core/application.rb', line 157 config.define_setting :protect_from_csrf, false, 'Should Padrino include CRSF tag' |
#server_name ⇒ NilClass, String
Which server name should be used
77 |
# File 'lib/middleman-core/application.rb', line 77 config.define_setting :server_name, nil, 'The server name of preview server' |
#source ⇒ String
Name of the source directory
97 |
# File 'lib/middleman-core/application.rb', line 97 config.define_setting :source, 'source', 'Name of the source directory' |
#source_dir ⇒ String
The full path to the source directory
240 241 242 |
# File 'lib/middleman-core/application.rb', line 240 def source_dir File.join(root, config[:source]) end |
#ssl_certificate ⇒ String
The (optional) path to the SSL cert to use for the preview server.
89 |
# File 'lib/middleman-core/application.rb', line 89 config.define_setting :ssl_certificate, nil, 'Path to an X.509 certificate to use for the preview server' |
#ssl_private_key ⇒ String
The (optional) private key for the certificate in :ssl_certificate.
93 |
# File 'lib/middleman-core/application.rb', line 93 config.define_setting :ssl_private_key, nil, "Path to an RSA private key for the preview server's certificate" |
#strip_index_file ⇒ Boolean
Whether to strip the index file name off links to directory indexes
109 |
# File 'lib/middleman-core/application.rb', line 109 config.define_setting :strip_index_file, true, 'Whether to strip the index file name off links to directory indexes' |
#to_s ⇒ Object Also known as: inspect
Work around this bug: bugs.ruby-lang.org/issues/4521 where Ruby will call to_s/inspect while printing exception messages, which can take a long time (minutes at full CPU) if the object is huge or has cyclic references, like this.
250 251 252 |
# File 'lib/middleman-core/application.rb', line 250 def to_s "#<Middleman::Application:0x#{object_id}>" end |
#trailing_slash ⇒ Boolean
Whether to include a trailing slash when stripping the index file
113 |
# File 'lib/middleman-core/application.rb', line 113 config.define_setting :trailing_slash, true, 'Whether to include a trailing slash when stripping the index file' |