Sha256: 3b11454a94bdb7ac29f8e923111077c30ed1c70dccb9264131e5133a347d88e6

Contents?: true

Size: 1.16 KB

Versions: 8

Compression:

Stored size: 1.16 KB

Contents

module ExpressTemplates
  module Macro

      def self.included(base)
        base.class_eval do
          extend ClassMethods
          include InstanceMethods
        end
      end

      module ClassMethods
        def macro_name
          to_s.split('::').last.underscore
        end
      end
      module InstanceMethods
        def macro_name ; self.class.macro_name end

        def initialize(*children_or_options)
          @children = []
          @options = {}.with_indifferent_access
          # expander passes itself as last arg
          @expander = children_or_options.pop if children_or_options.last.kind_of?(ExpressTemplates::Expander)
          _process(*children_or_options)
        end

        private

          def _process(*children_or_options)
            children_or_options.each do |child_or_option|
              case
              when child_or_option.kind_of?(Hash)
                @options.merge!(child_or_option)
              when child_or_option.kind_of?(Symbol)
                @options.merge!(id: child_or_option.to_s)
              else
                @children << child_or_option
              end
            end
          end

      end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
express_templates-0.3.1 lib/express_templates/macro.rb
express_templates-0.3.0 lib/express_templates/macro.rb
express_templates-0.2.7 lib/express_templates/macro.rb
express_templates-0.2.6 lib/express_templates/macro.rb
express_templates-0.2.5 lib/express_templates/macro.rb
express_templates-0.2.4 lib/express_templates/macro.rb
express_templates-0.2.3 lib/express_templates/macro.rb
express_templates-0.2.2 lib/express_templates/macro.rb