Sha256: 6434d1b40b079e350495076dce8bc77f66197958f3a07bd4afff5102db1f68df

Contents?: true

Size: 1.2 KB

Versions: 10

Compression:

Stored size: 1.2 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)
              when child_or_option.nil?
              else
                @children << child_or_option
              end
            end
          end

      end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
express_admin-1.2.1 vendor/gems/express_templates/lib/express_templates/macro.rb
express_admin-1.2.0 vendor/gems/express_templates/lib/express_templates/macro.rb
express_templates-0.5.0 lib/express_templates/macro.rb
express_templates-0.4.2 lib/express_templates/macro.rb
express_templates-0.4.1 lib/express_templates/macro.rb
express_templates-0.4.0 lib/express_templates/macro.rb
express_templates-0.3.6 lib/express_templates/macro.rb
express_templates-0.3.5 lib/express_templates/macro.rb
express_templates-0.3.4 lib/express_templates/macro.rb
express_templates-0.3.2 lib/express_templates/macro.rb