Sha256: 5c1fb83a15d85e4e17a5dff44f355464387ecf6901022fa2ec0c82b7ee733f31

Contents?: true

Size: 1.38 KB

Versions: 6

Compression:

Stored size: 1.38 KB

Contents

require 'padrino-helpers'
require 'rack'
require 'sprockets'
require 'sprockets-helpers'

module Machined
  class Context < Sprockets::Context
    include Helpers::OutputHelpers
    include Padrino::Helpers::OutputHelpers
    include Padrino::Helpers::TagHelpers
    include Padrino::Helpers::AssetTagHelpers
    include Padrino::Helpers::FormHelpers
    include Padrino::Helpers::FormatHelpers
    include Padrino::Helpers::NumberHelpers
    include Padrino::Helpers::TranslationHelpers
    include Helpers::AssetTagHelpers
    include Helpers::LocalsHelpers
    include Helpers::PageHelpers
    include Helpers::RenderHelpers
    
    # Override initialize to add helpers
    # from the Machined environment.
    def initialize(*args) # :nodoc:
      super
      add_machined_helpers
    end
    
    # Returns the main Machined environment instance.
    def machined
      environment.machined
    end
    
    # Returns the configuration of the Machined environment.
    def config
      machined.config
    end
    
    protected
    
    # Loops through the helpers added to the Machined
    # environment and adds them to the Context. Supports
    # blocks and Modules.
    def add_machined_helpers # :nodoc:
      machined.context_helpers.each do |helper|
        case helper
        when Proc
          instance_eval &helper
        when Module
          extend helper
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
machined-1.0.0 lib/machined/context.rb
machined-0.9.3 lib/machined/context.rb
machined-0.9.2 lib/machined/context.rb
machined-0.9.1 lib/machined/context.rb
machined-0.9.0 lib/machined/context.rb
machined-0.8.0 lib/machined/context.rb