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.
-
#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.
-
#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.
-
#protect_from_csrf ⇒ Boolean
Should Padrino include CRSF tag.
-
#source ⇒ String
Name of the source directory.
-
#source_dir ⇒ String
The full path to the source directory.
-
#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
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/middleman-core/application.rb', line 171 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
51 52 53 54 |
# File 'lib/middleman-core/application.rb', line 51 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)
59 60 61 |
# File 'lib/middleman-core/application.rb', line 59 def self.root ENV['MM_ROOT'] || Dir.pwd end |
.root_path ⇒ Object
Pathname-addressed root
65 66 67 |
# File 'lib/middleman-core/application.rb', line 65 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:
233 234 235 |
# File 'lib/middleman-core/application.rb', line 233 def _hooks self.class._hooks end |
#build? ⇒ Boolean
Whether we’re in build mode
208 209 210 |
# File 'lib/middleman-core/application.rb', line 208 def build? config[:environment] == :build end |
#build_dir ⇒ String
Where to build output files
116 |
# File 'lib/middleman-core/application.rb', line 116 config.define_setting :build_dir, 'build', 'Where to build output files' |
#css_dir ⇒ String
Location of stylesheets within source. Used by Compass.
96 |
# File 'lib/middleman-core/application.rb', line 96 config.define_setting :css_dir, 'stylesheets', 'Location of stylesheets within source' |
#development? ⇒ Boolean
Whether we’re in development mode
202 203 204 |
# File 'lib/middleman-core/application.rb', line 202 def development? config[:environment] == :development end |
#encoding ⇒ String
Default string encoding for templates and output.
128 |
# File 'lib/middleman-core/application.rb', line 128 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
76 |
# File 'lib/middleman-core/application.rb', line 76 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.
104 |
# File 'lib/middleman-core/application.rb', line 104 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.
120 |
# File 'lib/middleman-core/application.rb', line 120 config.define_setting :http_prefix, '/', 'Default prefix for building paths' |
#images_dir ⇒ String
Location of images within source. Used by HTML helpers and Compass.
100 |
# File 'lib/middleman-core/application.rb', line 100 config.define_setting :images_dir, 'images', 'Location of images within source' |
#index_file ⇒ String
Which file should be used for directory indexes
80 |
# File 'lib/middleman-core/application.rb', line 80 config.define_setting :index_file, 'index.html', 'Which file should be used for directory indexes' |
#js_dir ⇒ String
Location of javascripts within source.
92 |
# File 'lib/middleman-core/application.rb', line 92 config.define_setting :js_dir, 'javascripts', 'Location of javascripts within source' |
#layout ⇒ String, Symbold
Default layout name
124 |
# File 'lib/middleman-core/application.rb', line 124 config.define_setting :layout, :_auto_layout, 'Default layout name' |
#layouts_dir ⇒ String
Location of layouts within source. Used by renderers.
112 |
# File 'lib/middleman-core/application.rb', line 112 config.define_setting :layouts_dir, 'layouts', 'Location of layouts within source' |
#logger ⇒ Object
Reference to Logger singleton
166 167 168 |
# File 'lib/middleman-core/application.rb', line 166 def logger ::Middleman::Logger.singleton end |
#partials_dir ⇒ String
Location of partials within source. Used by renderers.
108 |
# File 'lib/middleman-core/application.rb', line 108 config.define_setting :partials_dir, '', 'Location of partials within source' |
#protect_from_csrf ⇒ Boolean
Should Padrino include CRSF tag
132 |
# File 'lib/middleman-core/application.rb', line 132 config.define_setting :protect_from_csrf, false, 'Should Padrino include CRSF tag' |
#source ⇒ String
Name of the source directory
72 |
# File 'lib/middleman-core/application.rb', line 72 config.define_setting :source, 'source', 'Name of the source directory' |
#source_dir ⇒ String
The full path to the source directory
215 216 217 |
# File 'lib/middleman-core/application.rb', line 215 def source_dir File.join(root, config[:source]) end |
#strip_index_file ⇒ Boolean
Whether to strip the index file name off links to directory indexes
84 |
# File 'lib/middleman-core/application.rb', line 84 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.
225 226 227 |
# File 'lib/middleman-core/application.rb', line 225 def to_s "#<Middleman::Application:0x#{object_id}>" end |
#trailing_slash ⇒ Boolean
Whether to include a trailing slash when stripping the index file
88 |
# File 'lib/middleman-core/application.rb', line 88 config.define_setting :trailing_slash, true, 'Whether to include a trailing slash when stripping the index file' |