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.
-
.defaults ⇒ Hash
Access class-wide defaults.
-
.helpers(*extensions, &block) ⇒ void
Mix-in helper methods.
-
.set(key, value = nil, &block) ⇒ void
Set class-wide defaults.
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.
-
#root ⇒ String
Root project directory (overwritten in middleman build/server).
-
#root_path ⇒ Object
Pathname-addressed root.
-
#set(key, value = nil, &block) ⇒ void
Set attributes (global variables).
-
#settings ⇒ Middleman::Application
Backwards compatibilty with old Sinatra template interface.
-
#show_exceptions ⇒ Boolean
Whether to catch and display exceptions.
-
#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
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::RubyEncoding
Methods included from CoreExtensions::Extensions
Methods included from Hooks
Constructor Details
#initialize(&block) ⇒ Application
Initialize the Middleman project
176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/middleman-core/application.rb', line 176 def initialize(&block) # Clear the static class cache cache.clear # Setup the default values from calls to set before initialization self.class.superclass.defaults.each { |k,v| set(k,v) } # Evaluate a passed block if given instance_exec(&block) if block_given? set :source, ENV["MM_SOURCE"] if ENV["MM_SOURCE"] super end |
Class Method Details
.cache ⇒ Middleman::Util::Cache
Shared cache instance
195 196 197 |
# File 'lib/middleman-core/application.rb', line 195 def self.cache @_cache ||= ::Middleman::Util::Cache.new end |
.defaults ⇒ Hash
Access class-wide defaults
42 43 44 |
# File 'lib/middleman-core/application.rb', line 42 def defaults @defaults ||= {} 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
33 34 35 36 |
# File 'lib/middleman-core/application.rb', line 33 def helpers(*extensions, &block) class_eval(&block) if block_given? include(*extensions) if extensions.any? end |
.set(key, value = nil, &block) ⇒ void
This method returns an undefined value.
Set class-wide defaults
51 52 53 54 55 56 |
# File 'lib/middleman-core/application.rb', line 51 def set(key, value=nil, &block) @defaults ||= {} @defaults[key] = value @inst.set(key, value, &block) if @inst end |
Instance Method Details
#build? ⇒ Boolean
Whether we’re in build mode
206 |
# File 'lib/middleman-core/application.rb', line 206 def build?; environment == :build; end |
#build_dir ⇒ String
Where to build output files
120 |
# File 'lib/middleman-core/application.rb', line 120 set :build_dir, "build" |
#css_dir ⇒ String
Location of stylesheets within source. Used by Compass.
108 |
# File 'lib/middleman-core/application.rb', line 108 set :css_dir, "stylesheets" |
#development? ⇒ Boolean
Whether we’re in development mode
202 |
# File 'lib/middleman-core/application.rb', line 202 def development?; environment == :development; end |
#encoding ⇒ String
Default string encoding for templates and output.
128 |
# File 'lib/middleman-core/application.rb', line 128 set :encoding, "utf-8" |
#environment ⇒ String
Middleman environment. Defaults to :development, set to :build by the build process
88 |
# File 'lib/middleman-core/application.rb', line 88 set :environment, (ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development |
#fonts_dir ⇒ String
Location of fonts within source. Used by Compass.
116 |
# File 'lib/middleman-core/application.rb', line 116 set :fonts_dir, "fonts" |
#full_path(path) ⇒ String
Expand a path to include the index file if it’s a directory
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/middleman-core/application.rb', line 237 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{/$}, ''), 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.
124 |
# File 'lib/middleman-core/application.rb', line 124 set :http_prefix, "/" |
#images_dir ⇒ String
Location of images within source. Used by HTML helpers and Compass.
112 |
# File 'lib/middleman-core/application.rb', line 112 set :images_dir, "images" |
#index_file ⇒ String
Which file should be used for directory indexes
92 |
# File 'lib/middleman-core/application.rb', line 92 set :index_file, "index.html" |
#js_dir ⇒ String
Location of javascripts within source.
104 |
# File 'lib/middleman-core/application.rb', line 104 set :js_dir, "javascripts" |
#layout ⇒ String, Symbold
Default layout name
136 |
# File 'lib/middleman-core/application.rb', line 136 set :layout, :_auto_layout |
#root ⇒ String
Root project directory (overwritten in middleman build/server)
75 |
# File 'lib/middleman-core/application.rb', line 75 set :root, ENV["MM_ROOT"] || Dir.pwd |
#root_path ⇒ Object
Pathname-addressed root
78 79 80 |
# File 'lib/middleman-core/application.rb', line 78 def root_path @_root_path ||= Pathname.new(root) end |
#set(key, value = nil, &block) ⇒ void
This method returns an undefined value.
Set attributes (global variables)
66 67 68 69 70 71 |
# File 'lib/middleman-core/application.rb', line 66 def set(key, value=nil, &block) setter = "#{key}=".to_sym self.class.send(:attr_accessor, key) if !respond_to?(setter) value = block if block_given? send(setter, value) end |
#settings ⇒ Middleman::Application
Backwards compatibilty with old Sinatra template interface
211 212 213 |
# File 'lib/middleman-core/application.rb', line 211 def settings self end |
#show_exceptions ⇒ Boolean
Whether to catch and display exceptions
132 |
# File 'lib/middleman-core/application.rb', line 132 set :show_exceptions, true |
#source ⇒ String
Name of the source directory
84 |
# File 'lib/middleman-core/application.rb', line 84 set :source, "source" |
#source_dir ⇒ String
The full path to the source directory
218 219 220 |
# File 'lib/middleman-core/application.rb', line 218 def source_dir File.join(root, source) end |
#strip_index_file ⇒ Boolean
Whether to strip the index file name off links to directory indexes
96 |
# File 'lib/middleman-core/application.rb', line 96 set :strip_index_file, true |
#to_s ⇒ Object
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.
228 229 230 |
# File 'lib/middleman-core/application.rb', line 228 def to_s "#<Middleman::Application:0x#{object_id}>" end |
#trailing_slash ⇒ Boolean
Whether to include a trailing slash when stripping the index file
100 |
# File 'lib/middleman-core/application.rb', line 100 set :trailing_slash, true |