Module: Lutaml::Formatter::Graphviz::HtmlBuilder
- Included in:
- Lutaml::Formatter::Graphviz
- Defined in:
- lib/lutaml/lml/formatter/graphviz/html_builder.rb
Constant Summary collapse
- EMPTY_MEMBER_TABLE =
<<~HEREDOC.chomp <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0"> <TR><TD ALIGN="LEFT"></TD></TR> </TABLE> HEREDOC
Instance Method Summary collapse
- #build_member_table(field_rows) ⇒ Object
- #build_name_table(name_parts) ⇒ Object
- #build_table_body(name_html, field_table, method_table) ⇒ Object
- #enum_literal?(node) ⇒ Boolean
- #escape_html_chars(text) ⇒ Object
- #format_enum_member(member) ⇒ Object
- #format_member_rows(members, hide_members, &formatter) ⇒ Object
Instance Method Details
#build_member_table(field_rows) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/lutaml/lml/formatter/graphviz/html_builder.rb', line 41 def build_member_table(field_rows) indented = field_rows.map { |row| (' ' * 10) + row }.join("\n") <<~HEREDOC.chomp <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0"> #{indented} </TABLE> HEREDOC .concat("\n") .concat(' ' * 6) end |
#build_name_table(name_parts) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/lutaml/lml/formatter/graphviz/html_builder.rb', line 52 def build_name_table(name_parts) <<~HEREDOC <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0"> #{name_parts.map { |n| %(<TR><TD ALIGN="CENTER">#{n}</TD></TR>) }.join("\n")} </TABLE> HEREDOC end |
#build_table_body(name_html, field_table, method_table) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/lutaml/lml/formatter/graphviz/html_builder.rb', line 60 def build_table_body(name_html, field_table, method_table) [name_html, field_table, method_table].compact.filter_map do |type| <<~TEXT <TR> <TD>#{type}</TD> </TR> TEXT end.join("\n") end |
#enum_literal?(node) ⇒ Boolean
36 37 38 39 |
# File 'lib/lutaml/lml/formatter/graphviz/html_builder.rb', line 36 def enum_literal?(node) node.is_a?(Lml::TopElementAttribute) && node.type.nil? && node.cardinality.nil? end |
#escape_html_chars(text) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/lutaml/lml/formatter/graphviz/html_builder.rb', line 13 def escape_html_chars(text) text .gsub('&', '&') .gsub('<', '<') .gsub('>', '>') .gsub('[', '[') .gsub(']', ']') end |
#format_enum_member(member) ⇒ Object
32 33 34 |
# File 'lib/lutaml/lml/formatter/graphviz/html_builder.rb', line 32 def format_enum_member(member) enum_literal?(member) ? format_enum_literal(member) : dispatch_format(member) end |
#format_member_rows(members, hide_members, &formatter) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/lutaml/lml/formatter/graphviz/html_builder.rb', line 22 def format_member_rows(members, hide_members, &formatter) return EMPTY_MEMBER_TABLE if hide_members || !members&.any? formatter ||= method(:dispatch_format) field_rows = members.map do |member| %(<TR><TD ALIGN="LEFT">#{formatter.call(member)}</TD></TR>) end build_member_table(field_rows) end |