Sha256: be9652aecb6dfe86f29dbb3c22d52115ad9ab729e94c323676a3cbedca1b525f

Contents?: true

Size: 1.55 KB

Versions: 13

Compression:

Stored size: 1.55 KB

Contents

# encoding: utf-8
module Middleman
  module Presentation
    # Container for helper methods which can be used in presentation slides
    class PresentationHelper
      include Comparable

      private

      attr_reader :helper_container

      public

      def initialize(helper_container)
        fail TypeError, Middleman::Presentation.t('errors.invalid_helper_module') if !helper_container.is_a?(Module) && !helper_container.is_a?(Proc)

        @helper_container = helper_container
      end

      # Return self as module
      def to_module
        if helper_container.is_a? Proc
          mod = Module.new
          mod.module_eval(&helper_container)

          mod
        else
          helper_container
        end
      end

      # Return name for container
      def name
        if helper_container.respond_to?(:name) && !helper_container.name.blank?
          helper_container.name
        else
          '<Anonymous>'
        end
      end

      # Type of helper
      def type
        if helper_container.is_a? Module
          :MODULE
        else
          :PROC
        end
      end

      # Return all available methods
      def available_methods
        instance_methods = to_module.instance_methods - Module.methods
        klass_methods = (to_module.methods - Module.methods).map { |m| "self.#{m}" }

        instance_methods + klass_methods
      end

      # Parse an array
      def self.parse(*modules)
        modules.flatten.map { |m| new(m) }
      end

      # @private
      def <=>(other)
        name <=> other.name
      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/presentation_helper.rb
middleman-presentation-core-0.17.6 lib/middleman-presentation-core/presentation_helper.rb
middleman-presentation-core-0.17.5 lib/middleman-presentation-core/presentation_helper.rb
middleman-presentation-core-0.17.2 lib/middleman-presentation-core/presentation_helper.rb
middleman-presentation-core-0.17.1 lib/middleman-presentation-core/presentation_helper.rb
middleman-presentation-core-0.17.0 lib/middleman-presentation-core/presentation_helper.rb
middleman-presentation-core-0.16.3 lib/middleman-presentation-core/presentation_helper.rb
middleman-presentation-core-0.16.2 lib/middleman-presentation-core/presentation_helper.rb
middleman-presentation-core-0.16.0 lib/middleman-presentation-core/presentation_helper.rb
middleman-presentation-core-0.16.0.rc2 lib/middleman-presentation-core/presentation_helper.rb
middleman-presentation-core-0.16.0.rc1 lib/middleman-presentation-core/presentation_helper.rb
middleman-presentation-core-0.16.0.beta lib/middleman-presentation-core/presentation_helper.rb
middleman-presentation-core-0.16.0.alpha lib/middleman-presentation-core/presentation_helper.rb