Sha256: 6fa9d56e5ebf5280d57d1d5de47ac9fa4999ded1dd40f316200a51f13bf5c6be

Contents?: true

Size: 1.75 KB

Versions: 15

Compression:

Stored size: 1.75 KB

Contents

# backtick_javascript: true

module Preact::HtmlElements
  # https://html.spec.whatwg.org/multipage/indices.html#elements-3
  SUPPORTED_HTML_ELEMENTS = %w[
    a abbr address area article aside audio
    b base bdi bdo blockquote body br button
    canvas caption cite code col colgroup
    data datalist dd del details dfn dialog div dl dt
    em embed
    fieldset figcaption figure footer form
    h1 h2 h3 h4 h5 h6 head header hgroup hr html
    i iframe img input ins
    kbd
    label legend li link
    main map mark math menu meta meter
    nav noscript
    object ol optgroup option output
    p picture pre progress
    q
    rp rt ruby
    s samp script section select slot small source span strong style sub summary sup svg
    table tbody td template textarea tfoot th thead time title tr track
    u ul
    var video
    wbr
  ]

  if RUBY_ENGINE == 'opal'
    %x{
      const $op = Opal.Preact;
    }

    SUPPORTED_HTML_ELEMENTS.each do |element|
      define_method(element.underscore.JS.toUpperCase()) do |props = nil, &block|
        %x{
          if (typeof block === 'function') $op.$_render_element.$$p = block;
          $op.$_render_element(element, props, block)
        }
      end
    end
  else
    SUPPORTED_HTML_ELEMENTS.each do |element|
      define_method(element.to_s.underscore.upcase.to_sym) do |props = nil, &block|
        ::Preact._render_element(element, props, &block)
      end
    end
  end

  # Get Preact Element from render buffer
  def GPE(arg, &block)
    if block_given?
      el = block.call
      return el if el
    end
    ::Preact.render_buffer.last.pop
  end

  # Render Preact Element to render buffer
  def RPE(el)
    ::Preact.render_buffer.last << el
    nil
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
isomorfeus-preact-23.9.0.rc12 lib/preact/html_elements.rb
isomorfeus-preact-23.9.0.rc11 lib/preact/html_elements.rb
isomorfeus-preact-23.9.0.rc10 lib/preact/html_elements.rb
isomorfeus-preact-23.9.0.rc9 lib/preact/html_elements.rb
isomorfeus-preact-23.9.0.rc8 lib/preact/html_elements.rb
isomorfeus-preact-23.9.0.rc7 lib/preact/html_elements.rb
isomorfeus-preact-23.9.0.rc6 lib/preact/html_elements.rb
isomorfeus-preact-23.9.0.rc5 lib/preact/html_elements.rb
isomorfeus-preact-23.9.0.rc4 lib/preact/html_elements.rb
isomorfeus-preact-23.9.0.rc3 lib/preact/html_elements.rb
isomorfeus-preact-23.9.0.rc2 lib/preact/html_elements.rb
isomorfeus-preact-23.9.0.rc1 lib/preact/html_elements.rb
isomorfeus-preact-23.8.0.rc3 lib/preact/html_elements.rb
isomorfeus-preact-23.8.0.rc2 lib/preact/html_elements.rb
isomorfeus-preact-23.8.0.rc1 lib/preact/html_elements.rb