Class: Archsight::Web::Editor::FormBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/archsight/web/editor/form_builder.rb

Overview

FormBuilder generates form field metadata from annotation definitions

Defined Under Namespace

Classes: Field

Class Method Summary collapse

Class Method Details

.determine_input_type(annotation) ⇒ Symbol

Determine input type based on annotation properties

Parameters:

Returns:

  • (Symbol)


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/archsight/web/editor/form_builder.rb', line 68

def self.determine_input_type(annotation)
  return :select if annotation.enum

  case annotation.type.to_s
  when "Integer", "Float"
    :number
  when "URI"
    :url
  else
    return :markdown if annotation.markdown?
    return :textarea if annotation.multiline?
    return :code if annotation.code?
    return :list if annotation.list?

    :text
  end
end

.determine_step(annotation) ⇒ String?

Determine step attribute for number inputs

Parameters:

Returns:

  • (String, nil)


89
90
91
92
93
94
95
96
# File 'lib/archsight/web/editor/form_builder.rb', line 89

def self.determine_step(annotation)
  case annotation.type.to_s
  when "Integer"
    "1"
  when "Float"
    "0.01"
  end
end

.fields_for(kind) ⇒ Array<Field>

Build form fields for a resource kind

Parameters:

  • kind (String)

    Resource kind

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/archsight/web/editor/form_builder.rb', line 48

def self.fields_for(kind)
  annotations = Archsight::Editor.editable_annotations(kind)

  annotations.map do |ann|
    Field.new(
      key: ann.key,
      title: ann.title,
      description: ann.description,
      input_type: determine_input_type(ann),
      options: ann.enum,
      step: determine_step(ann),
      required: false,
      code_language: ann.code_language
    )
  end
end