Sha256: 77e0f7bc0699281e08e7421e6e71987076f867980c81adff40f31037169b5120

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

require 'hyperstack/ext/component/string'
# see hyperstack/component/haml for this is to be included.
module Hyperstack
  module Internal
    module Component
      module HAMLTagInstanceMethods
        def self.included(base)
          base.const_get('HTML_TAGS').each do |tag|
            if tag == 'p'
              base.define_method(tag) do |*params, &children|
                if children || params.count == 0 || (params.count == 1 && params.first.is_a?(Hash))
                  RenderingContext.render(tag, *params, &children)
                else
                  Kernel.p(*params)
                end
              end
            else
              base.alias_method tag, tag.upcase
            end
          end
        end
      end

      module HAMLElementInstanceMethods
        def method_missing(class_name, args = {}, &new_block)
          return dup.render.method_missing(class_name, args, &new_block) unless rendered?
          Hyperstack::Internal::Component::RenderingContext.replace(
            self,
            Hyperstack::Internal::Component::RenderingContext.build do
              Hyperstack::Internal::Component::RenderingContext.render(
                type, @properties, args, class: haml_class_name(class_name), &new_block
              )
            end
          )
        end

        def rendered?
          Hyperstack::Internal::Component::RenderingContext.rendered? self
        end

        def haml_class_name(class_name)
          class_name.gsub(/__|_/, '__' => '_', '_' => '-')
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hyper-component-1.0.alpha1.5 lib/hyperstack/internal/component/haml.rb
hyper-component-1.0.alpha1.4 lib/hyperstack/internal/component/haml.rb