Sha256: b794160921769786274a0769d6fc035de8af5dddc0a6679301b6216a01afc94e

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

require "padrino-helpers"
require "rack"
require "sprockets"

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::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

2 entries across 2 versions & 1 rubygems

Version Path
machined-0.1.1 lib/machined/context.rb
machined-0.1.0 lib/machined/context.rb