Sha256: 45ada4ca57b30417a6a9491f359bc0f747ebd701a384ba68bb76ab33356ab582

Contents?: true

Size: 1.4 KB

Versions: 4

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

# Work with HTML formatters to DrawIO shapes
module DrawioDsl
  # HTML formatters can be used on shapes to render HTML using a DSL
  module Formatters
    # Create an instance of a HTML formatter on the shape
    class InterfaceFormatter < BaseFormatter
      def initialize
        super({ p: { margin: '0px', margin_left: '4px', margin_top: '4px' } })
      end

      def header(name, description: nil, interface_type: 'Interface')
        html.p("<i>&lt;&lt; #{interface_type} &gt;&gt;</i>", text_align: :center)
        html.p("<b>#{name}</b>", text_align: :center)
        html.hr

        html.group(:description).p(description) if description

        self
      end

      def field(name, type: nil)
        value = if type
                  "#{name}: #{type}"
                else
                  name
                end
        html.group(:fields).p(value)

        self
      end

      def method(name, type: nil)
        value = if type
                  "#{name}() : #{type}"
                else
                  "#{name}()"
                end
        html.group(:methods).p(value)

        self
      end

      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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
drawio_dsl-0.8.4 lib/drawio_dsl/formatters/interface_formatter.rb
drawio_dsl-0.8.3 lib/drawio_dsl/formatters/interface_formatter.rb
drawio_dsl-0.8.2 lib/drawio_dsl/formatters/interface_formatter.rb
drawio_dsl-0.8.1 lib/drawio_dsl/formatters/interface_formatter.rb