Class: Middleman::ConfigContext

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
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.



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

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

  @callbacks = ::Middleman::CallbackManager.new
  @callbacks.install_methods!(self, [: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.



8
9
10
# File 'lib/middleman-core/config_context.rb', line 8

def app
  @app
end

Instance Method Details

#helpers(*helper_modules, &block) ⇒ Object



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

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



25
26
27
# File 'lib/middleman-core/config_context.rb', line 25

def include(mod)
  self.extend(mod)
end

#include_environment(name) ⇒ Object



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

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

  return unless File.exist? other_config

  instance_eval File.read(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



62
63
64
65
# File 'lib/middleman-core/config_context.rb', line 62

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



52
53
54
55
# File 'lib/middleman-core/config_context.rb', line 52

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