Class: Glimmer::Web::FormattingElementProxy
- Inherits:
-
Object
- Object
- Glimmer::Web::FormattingElementProxy
- 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
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/glimmer/web/formatting_element_proxy.rb', line 24 def format(keyword, *args, &block) content = nil boolean_attributes = [] if block_given? content = block.call.to_s elsif args.any? && !args.first.is_a?(Hash) && !Glimmer::Web::ElementProxy.element_boolean_attribute?(keyword, args.first) content = args.first.to_s args = args[1, args.size - 1] end if args.last.is_a?(Hash) attribute_hash = args.last boolean_attributes = args[0, args.size - 1] else attribute_hash = {} boolean_attributes = args end ElementProxy.render_html(keyword, attributes: attribute_hash, boolean_attributes:, content:) end |
.keyword_supported?(keyword, parent: nil) ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/glimmer/web/formatting_element_proxy.rb', line 11 def keyword_supported?(keyword, parent: nil) # TODO do we need to worry about the parent of the parent being a p tag? keyword = keyword.to_s parent_keyword = parent.is_a?(Component) ? parent.markup_root&.keyword : parent&.keyword parent_keyword == 'p' && ( FORMATTING_ELEMENT_KEYWORDS.include?(keyword) || (keyword == 'span') || (keyword == 'a') ) end |