Sha256: 53a8a1d5996b4e0fbac6cccee7213f7e605a510e7b39ab5b7b56c05151f7f0a9

Contents?: true

Size: 958 Bytes

Versions: 13

Compression:

Stored size: 958 Bytes

Contents

# encoding: utf-8
module Middleman
  module Presentation
    # Manager for helper modules
    class HelpersManager
      private

      attr_reader :presentation_helpers

      public

      def initialize(_creator: PresentationHelper)
        @presentation_helpers = []
      end

      # Add helpers
      def add(*modules, &block)
        presentation_helpers.concat PresentationHelper.parse(modules)
        presentation_helpers << PresentationHelper.new(block) if block_given?
      end

      # Return available helpers
      def available_helpers
        presentation_helpers.reduce(Module.new) { |a, e| a.include e.to_module }
      end

      # Show helper modules
      def to_s
        data = presentation_helpers.sort.reduce([]) do |a, e|
          a << { name: e.name, type: e.type, available_methods: e.available_methods.to_list }
        end

        List.new(data).to_s(fields: [:name, :type, :available_methods])
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
middleman-presentation-core-0.17.7 lib/middleman-presentation-core/helpers_manager.rb
middleman-presentation-core-0.17.6 lib/middleman-presentation-core/helpers_manager.rb
middleman-presentation-core-0.17.5 lib/middleman-presentation-core/helpers_manager.rb
middleman-presentation-core-0.17.2 lib/middleman-presentation-core/helpers_manager.rb
middleman-presentation-core-0.17.1 lib/middleman-presentation-core/helpers_manager.rb
middleman-presentation-core-0.17.0 lib/middleman-presentation-core/helpers_manager.rb
middleman-presentation-core-0.16.3 lib/middleman-presentation-core/helpers_manager.rb
middleman-presentation-core-0.16.2 lib/middleman-presentation-core/helpers_manager.rb
middleman-presentation-core-0.16.0 lib/middleman-presentation-core/helpers_manager.rb
middleman-presentation-core-0.16.0.rc2 lib/middleman-presentation-core/helpers_manager.rb
middleman-presentation-core-0.16.0.rc1 lib/middleman-presentation-core/helpers_manager.rb
middleman-presentation-core-0.16.0.beta lib/middleman-presentation-core/helpers_manager.rb
middleman-presentation-core-0.16.0.alpha lib/middleman-presentation-core/helpers_manager.rb