Class: Glimmer::Web::FormattingElementProxy

Inherits:
Object
  • Object
show all
Extended by:
Glimmer
Defined in:
lib/glimmer/web/formatting_element_proxy.rb

Constant Summary collapse

FORMATTING_ELEMENT_KEYWORDS =
%w[b i strong em sub sup del ins small mark br]

Class Method Summary collapse

Class Method Details

.format(keyword, *args, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/glimmer/web/formatting_element_proxy.rb', line 41

def format(keyword, *args, &block)
  content = nil
  if block_given?
    content = block.call.to_s
  elsif args.any? && !args.first.is_a?(Hash)
    content = args.first.to_s
  end
  attribute_hash = args.last.is_a?(Hash) ? args.last : {}
  ElementProxy.render_html(keyword, attribute_hash, content)
end

.keyword_supported?(keyword, parent: nil) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
# File 'lib/glimmer/web/formatting_element_proxy.rb', line 32

def keyword_supported?(keyword, parent: nil)
  keyword = keyword.to_s
  (
    FORMATTING_ELEMENT_KEYWORDS.include?(keyword) ||
    (keyword == 'span' && parent&.keyword == 'p') ||
    (keyword == 'a' && parent&.keyword == 'p')
  )
end