Class: Middleman::ConfigContext

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
middleman-core/lib/middleman-core/config_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, template_context_class) ⇒ ConfigContext

Returns a new instance of ConfigContext.


16
17
18
19
20
21
22
23
24
25
# File 'middleman-core/lib/middleman-core/config_context.rb', line 16

def initialize(app, template_context_class)
  @app = app
  @template_context_class = template_context_class

  @callbacks = ::Middleman::CallbackManager.new
  @callbacks.install_methods!(self, %i[before_build after_build configure after_configuration ready])

  # Trigger internal callbacks when app level are executed.
  app.subscribe_to_callbacks(&method(:execute_callbacks))
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.


10
11
12
# File 'middleman-core/lib/middleman-core/config_context.rb', line 10

def app
  @app
end

Instance Method Details

#helpers(*helper_modules, &block) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'middleman-core/lib/middleman-core/config_context.rb', line 31

def helpers(*helper_modules, &block)
  helper_modules ||= []

  if block_given?
    block_module = Module.new
    block_module.module_eval(&block)
    helper_modules << block_module
  end

  helper_modules.each do |mod|
    @template_context_class.send :include, mod
  end
end

#include(mod) ⇒ Object


27
28
29
# File 'middleman-core/lib/middleman-core/config_context.rb', line 27

def include(mod)
  extend(mod)
end

#include_environment(name) ⇒ Object


45
46
47
48
49
50
51
52
# File 'middleman-core/lib/middleman-core/config_context.rb', line 45

def include_environment(name)
  path = File.dirname(__FILE__)
  other_config = File.join(path, name.to_s)

  return unless File.exist? other_config

  instance_eval ::Middleman::Util.read_file(other_config), other_config, 1
end

#mime_type(type, value)

This method returns an undefined value.

Add a new mime-type for a specific extension

Parameters:

  • type (Symbol)

    File extension

  • value (String)

    Mime type


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

def mime_type(type, value)
  type = ".#{type}" unless type.to_s[0] == '.'
  ::Rack::Mime::MIME_TYPES[type] = value
end

#set(key, default = nil, &block) ⇒ Object


54
55
56
57
# File 'middleman-core/lib/middleman-core/config_context.rb', line 54

def set(key, default = nil, &block)
  config.define_setting(key, default) unless config.defines_setting?(key)
  @app.config[key] = block_given? ? block : default
end