Class: Middleman::Application
- Inherits:
-
Object
- Object
- Middleman::Application
- Defined in:
- lib/middleman-core/application.rb
Constant Summary
Constants included from Hooks
Class Method Summary collapse
-
.cache ⇒ Middleman::Util::Cache
Shared cache instance.
-
.helpers(*extensions, &block) ⇒ void
Mix-in helper methods.
-
.root ⇒ String
Root project directory (overwritten in middleman build/server).
-
.root_path ⇒ Object
Pathname-addressed root.
Instance Method Summary collapse
-
#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.
-
#full_path(path) ⇒ String
Expand a path to include the index file if it’s a directory.
-
#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.
-
#partials_dir ⇒ String
Location of partials within source.
-
#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 CoreExtensions::Extensions
Methods included from Hooks
Methods included from Configuration::Global
#config, included, #method_missing, #respond_to?, #set
Constructor Details
#initialize(&block) ⇒ Application
Initialize the Middleman project
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/middleman-core/application.rb', line 152 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
.cache ⇒ Middleman::Util::Cache
Shared cache instance
176 177 178 |
# File 'lib/middleman-core/application.rb', line 176 def self.cache @_cache ||= ::Tilt::Cache.new end |
.helpers(*extensions, &block) ⇒ void
This method returns an undefined value.
Mix-in helper methods. Accepts either a list of Modules and/or a block to be evaluated
41 42 43 44 |
# File 'lib/middleman-core/application.rb', line 41 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)
49 50 51 |
# File 'lib/middleman-core/application.rb', line 49 def self.root ENV["MM_ROOT"] || Dir.pwd end |
.root_path ⇒ Object
Pathname-addressed root
55 56 57 |
# File 'lib/middleman-core/application.rb', line 55 def self.root_path Pathname(root) end |
Instance Method Details
#build? ⇒ Boolean
Whether we’re in build mode
187 |
# File 'lib/middleman-core/application.rb', line 187 def build?; config[:environment] == :build; end |
#build_dir ⇒ String
Where to build output files
106 |
# File 'lib/middleman-core/application.rb', line 106 config.define_setting :build_dir, "build", 'Where to build output files' |
#css_dir ⇒ String
Location of stylesheets within source. Used by Compass.
86 |
# File 'lib/middleman-core/application.rb', line 86 config.define_setting :css_dir, "stylesheets", 'Location of stylesheets within source' |
#development? ⇒ Boolean
Whether we’re in development mode
183 |
# File 'lib/middleman-core/application.rb', line 183 def development?; config[:environment] == :development; end |
#encoding ⇒ String
Default string encoding for templates and output.
118 |
# File 'lib/middleman-core/application.rb', line 118 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
66 |
# File 'lib/middleman-core/application.rb', line 66 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.
94 |
# File 'lib/middleman-core/application.rb', line 94 config.define_setting :fonts_dir, "fonts", 'Location of fonts within source' |
#full_path(path) ⇒ String
Expand a path to include the index file if it’s a directory
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/middleman-core/application.rb', line 212 def full_path(path) resource = sitemap.find_resource_by_destination_path(path) if !resource # Try it with /index.html at the end indexed_path = File.join(path.sub(%r{/$}, ''), config[:index_file]) resource = sitemap.find_resource_by_destination_path(indexed_path) end if resource '/' + resource.destination_path else '/' + Middleman::Util.normalize_path(path) end end |
#http_prefix ⇒ String
Default prefix for building paths. Used by HTML helpers and Compass.
110 |
# File 'lib/middleman-core/application.rb', line 110 config.define_setting :http_prefix, "/", 'Default prefix for building paths' |
#images_dir ⇒ String
Location of images within source. Used by HTML helpers and Compass.
90 |
# File 'lib/middleman-core/application.rb', line 90 config.define_setting :images_dir, "images", 'Location of images within source' |
#index_file ⇒ String
Which file should be used for directory indexes
70 |
# File 'lib/middleman-core/application.rb', line 70 config.define_setting :index_file, "index.html", 'Which file should be used for directory indexes' |
#js_dir ⇒ String
Location of javascripts within source.
82 |
# File 'lib/middleman-core/application.rb', line 82 config.define_setting :js_dir, "javascripts", 'Location of javascripts within source' |
#layout ⇒ String, Symbold
Default layout name
114 |
# File 'lib/middleman-core/application.rb', line 114 config.define_setting :layout, :_auto_layout, 'Default layout name' |
#layouts_dir ⇒ String
Location of layouts within source. Used by renderers.
102 |
# File 'lib/middleman-core/application.rb', line 102 config.define_setting :layouts_dir, "layouts", 'Location of layouts within source' |
#partials_dir ⇒ String
Location of partials within source. Used by renderers.
98 |
# File 'lib/middleman-core/application.rb', line 98 config.define_setting :partials_dir, "", 'Location of partials within source' |
#source ⇒ String
Name of the source directory
62 |
# File 'lib/middleman-core/application.rb', line 62 config.define_setting :source, "source", 'Name of the source directory' |
#source_dir ⇒ String
The full path to the source directory
192 193 194 |
# File 'lib/middleman-core/application.rb', line 192 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
74 |
# File 'lib/middleman-core/application.rb', line 74 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.
202 203 204 |
# File 'lib/middleman-core/application.rb', line 202 def to_s "#<Middleman::Application:0x#{object_id}>" end |
#trailing_slash ⇒ Boolean
Whether to include a trailing slash when stripping the index file
78 |
# File 'lib/middleman-core/application.rb', line 78 config.define_setting :trailing_slash, true, 'Whether to include a trailing slash when stripping the index file' |