Class: DrawioDsl::Formatters::InterfaceFormatter
- Inherits:
-
BaseFormatter
- Object
- BaseFormatter
- DrawioDsl::Formatters::InterfaceFormatter
- Defined in:
- lib/drawio_dsl/formatters/interface_formatter.rb
Overview
Format the HTML to display an interface on a class diagram
Instance Attribute Summary
Attributes inherited from BaseFormatter
Instance Method Summary collapse
- #as_html(new_line: false) ⇒ Object
- #field(name, type: nil) ⇒ Object
- #header(name, description: nil, namespace: nil, interface_type: 'Interface', **args) ⇒ Object
-
#initialize ⇒ InterfaceFormatter
constructor
A new instance of InterfaceFormatter.
- #method(name, type: nil) ⇒ Object
Methods inherited from BaseFormatter
#b, #empty?, #h1, #h2, #h3, #h4, #h5, #h6, #hr, #li, #p, #to_h, #ul_e, #ul_s
Constructor Details
#initialize ⇒ InterfaceFormatter
Returns a new instance of InterfaceFormatter.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/drawio_dsl/formatters/interface_formatter.rb', line 9 def initialize super( { p: { margin: '0px', margin_left: '4px', margin_bottom: "#{p_margin_bottom}px" }, b: { margin: '0px', margin_left: '4px', margin_bottom: "#{b_margin_bottom}px" }, h1: { margin: '0px', margin_left: '4px', margin_bottom: "#{h1_margin_bottom}px" }, h2: { margin: '0px', margin_left: '4px', margin_bottom: "#{h2_margin_bottom}px" }, h3: { margin: '0px', margin_left: '4px', margin_bottom: "#{h3_margin_bottom}px" }, h4: { margin: '0px', margin_left: '4px', margin_bottom: "#{h4_margin_bottom}px" }, h5: { margin: '0px', margin_left: '4px', margin_bottom: "#{h5_margin_bottom}px" }, h6: { margin: '0px', margin_left: '4px', margin_bottom: "#{h6_margin_bottom}px" }, li: { margin: '0px', margin_left: '4px', margin_bottom: "#{li_margin_bottom}px" } } ) end |
Instance Method Details
#as_html(new_line: false) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/drawio_dsl/formatters/interface_formatter.rb', line 78 def as_html(new_line: false) html.add_placeholder(:fields) html.add_placeholder(:methods) html.group(:fields).hr if html.group(:fields).exist? && html.group(:methods).exist? html.as_html(new_line: new_line) end |
#field(name, type: nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/drawio_dsl/formatters/interface_formatter.rb', line 44 def field(name, type: nil) value = if type "#{name}: #{type}" else name end html.group(:fields).p(value) items << { type: :field, name: name, return_type: type } self end |
#header(name, description: nil, namespace: nil, interface_type: 'Interface', **args) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/drawio_dsl/formatters/interface_formatter.rb', line 25 def header(name, description: nil, namespace: nil, interface_type: 'Interface', **args) html.p("<i><< #{interface_type} >></i>", text_align: :center) html.p("<b>#{name}</b>", text_align: :center) html.hr html.group(:description).p(description) if description items << { type: :interface, name: name, description: description, namespace: namespace, interface_type: interface_type, **args } self end |
#method(name, type: nil) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/drawio_dsl/formatters/interface_formatter.rb', line 61 def method(name, type: nil) value = if type "#{name}() : #{type}" else "#{name}()" end html.group(:methods).p(value) items << { type: :method, name: name, return_type: type } self end |