Class: Middleman::Application

Inherits:
Object
  • Object
show all
Includes:
Hooks, Hooks::InstanceHooks, Configuration::Global, CoreExtensions::Extensions, CoreExtensions::Routing
Defined in:
lib/middleman-core/application.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CoreExtensions::Routing

#page, #with_layout

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

.rootString

Root project directory (overwritten in middleman build/server)

Returns:

  • (String)


59
60
61
# File 'lib/middleman-core/application.rb', line 59

def self.root
  ENV['MM_ROOT'] || Dir.pwd
end

.root_pathObject

Pathname-addressed root



65
66
67
# File 'lib/middleman-core/application.rb', line 65

def self.root_path
  Pathname(root)
end

Instance Method Details

#_hooksObject

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

Returns:

  • (Boolean)

    If we’re in build mode



208
209
210
# File 'lib/middleman-core/application.rb', line 208

def build?
  config[:environment] == :build
end

#build_dirString

Where to build output files

Returns:

  • (String)


116
# File 'lib/middleman-core/application.rb', line 116

config.define_setting :build_dir,   'build', 'Where to build output files'

#css_dirString

Location of stylesheets within source. Used by Compass.

Returns:

  • (String)


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

Returns:

  • (Boolean)

    If we’re in dev mode



202
203
204
# File 'lib/middleman-core/application.rb', line 202

def development?
  config[:environment] == :development
end

#encodingString

Default string encoding for templates and output.

Returns:

  • (String)


128
# File 'lib/middleman-core/application.rb', line 128

config.define_setting :encoding, 'utf-8', 'Default string encoding for templates and output'

#environmentString

Middleman environment. Defaults to :development, set to :build by the build process

Returns:

  • (String)


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_dirString

Location of fonts within source. Used by Compass.

Returns:

  • (String)


104
# File 'lib/middleman-core/application.rb', line 104

config.define_setting :fonts_dir,   'fonts', 'Location of fonts within source'

#http_prefixString

Default prefix for building paths. Used by HTML helpers and Compass.

Returns:

  • (String)


120
# File 'lib/middleman-core/application.rb', line 120

config.define_setting :http_prefix, '/', 'Default prefix for building paths'

#images_dirString

Location of images within source. Used by HTML helpers and Compass.

Returns:

  • (String)


100
# File 'lib/middleman-core/application.rb', line 100

config.define_setting :images_dir,  'images', 'Location of images within source'

#index_fileString

Which file should be used for directory indexes

Returns:

  • (String)


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_dirString

Location of javascripts within source.

Returns:

  • (String)


92
# File 'lib/middleman-core/application.rb', line 92

config.define_setting :js_dir,      'javascripts', 'Location of javascripts within source'

#layoutString, Symbold

Default layout name

Returns:

  • (String, Symbold)


124
# File 'lib/middleman-core/application.rb', line 124

config.define_setting :layout, :_auto_layout, 'Default layout name'

#layouts_dirString

Location of layouts within source. Used by renderers.

Returns:

  • (String)


112
# File 'lib/middleman-core/application.rb', line 112

config.define_setting :layouts_dir, 'layouts', 'Location of layouts within source'

#loggerObject

Reference to Logger singleton



166
167
168
# File 'lib/middleman-core/application.rb', line 166

def logger
  ::Middleman::Logger.singleton
end

#partials_dirString

Location of partials within source. Used by renderers.

Returns:

  • (String)


108
# File 'lib/middleman-core/application.rb', line 108

config.define_setting :partials_dir,   '', 'Location of partials within source'

#protect_from_csrfBoolean

Should Padrino include CRSF tag

Returns:

  • (Boolean)


132
# File 'lib/middleman-core/application.rb', line 132

config.define_setting :protect_from_csrf, false, 'Should Padrino include CRSF tag'

#sourceString

Name of the source directory

Returns:

  • (String)


72
# File 'lib/middleman-core/application.rb', line 72

config.define_setting :source,      'source', 'Name of the source directory'

#source_dirString

The full path to the source directory

Returns:

  • (String)


215
216
217
# File 'lib/middleman-core/application.rb', line 215

def source_dir
  File.join(root, config[:source])
end

#strip_index_fileBoolean

Whether to strip the index file name off links to directory indexes

Returns:

  • (Boolean)


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_sObject 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_slashBoolean

Whether to include a trailing slash when stripping the index file

Returns:

  • (Boolean)


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'