Class: OpenRosa::XForm

Inherits:
Object
  • Object
show all
Defined in:
lib/open_rosa/xform.rb

Overview

Generates XForm XML from Form definitions rubocop:disable Metrics/ClassLength

Constant Summary collapse

XFORMS_NS =
"http://www.w3.org/2002/xforms"
XHTML_NS =
"http://www.w3.org/1999/xhtml"

Instance Method Summary collapse

Constructor Details

#initialize(form_class) ⇒ XForm

Returns a new instance of XForm.



12
13
14
15
16
17
18
# File 'lib/open_rosa/xform.rb', line 12

def initialize(form_class)
  @form_class = form_class
  @form_id = form_class.form_id
  @version = form_class.version
  @name = form_class.name || form_class.form_id
  @fields = form_class.fields
end

Instance Method Details

#to_xmlObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/open_rosa/xform.rb', line 20

def to_xml
  builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
    xml.html(xform_namespaces) do
      generate_head(xml)
      generate_body(xml)
    end
  end

  builder.to_xml
end

#xform_namespacesObject



31
32
33
34
35
36
37
38
39
# File 'lib/open_rosa/xform.rb', line 31

def xform_namespaces
  {
    "xmlns" => XFORMS_NS,
    "xmlns:h" => XHTML_NS,
    "xmlns:ev" => "http://www.w3.org/2001/xml-events",
    "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema",
    "xmlns:jr" => "http://openrosa.org/javarosa"
  }
end