Class: Knartform::Knart

Inherits:
Object
  • Object
show all
Defined in:
lib/knartform/knart.rb

Constant Summary collapse

HTML_OPTIONS =
{}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Knart

Returns a new instance of Knart.



12
13
14
# File 'lib/knartform/knart.rb', line 12

def initialize(file)
        load(file)
end

Instance Attribute Details

#documentObject

Returns the value of attribute document.



8
9
10
# File 'lib/knartform/knart.rb', line 8

def document
  @document
end

#typeObject

Returns the value of attribute type.



9
10
11
# File 'lib/knartform/knart.rb', line 9

def type
  @type
end

Instance Method Details

#dummy_add_buttonObject



56
57
58
59
# File 'lib/knartform/knart.rb', line 56

def dummy_add_button
    path = File.expand_path('../../views/dummy_add_button.slim', __FILE__)
    html = Slim::Template.new(path, pretty: true).render(self)
end

#dummy_drag_controlObject



66
67
68
69
# File 'lib/knartform/knart.rb', line 66

def dummy_drag_control
path = File.expand_path('../../views/dummy_drag_control.slim', __FILE__)
html = Slim::Template.new(path, pretty: true).render(self)
end

#dummy_edit_and_deleteObject



51
52
53
54
# File 'lib/knartform/knart.rb', line 51

def dummy_edit_and_delete
    path = File.expand_path('../../views/dummy_edit_and_delete.slim', __FILE__)
    html = Slim::Template.new(path, pretty: true).render(self)
end

#dummy_edit_buttonObject



61
62
63
64
# File 'lib/knartform/knart.rb', line 61

def dummy_edit_button
  path = File.expand_path('../../views/dummy_edit_button.slim', __FILE__)
  html = Slim::Template.new(path, pretty: true).render(self)
end

#first_attribute(nodes, name) ⇒ Object



47
48
49
# File 'lib/knartform/knart.rb', line 47

def first_attribute(nodes, name)
    nodes.empty? ? '' : nodes.first[name]
end

#load(file) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/knartform/knart.rb', line 16

def load(file)
    self.document = nil
    self.type = nil
    begin
        puts "Loading #{file.path}..."
        self.document = Nokogiri::XML(file) { |config| config.options = Nokogiri::XML::ParseOptions::STRICT }
        self.type = document.xpath('//knart:knowledgeDocument/knart:metadata/knart:artifactType', knart: 'urn:hl7-org:knowledgeartifact:r1').first['value']
        puts "Detected 'artifactType' of '#{type}'."
    rescue Nokogiri::XML::SyntaxError => e
        puts "Issue in KNART document: #{e}"
    end
end

#loaded?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/knartform/knart.rb', line 29

def loaded?
    !document.nil?
end

#to_html(options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/knartform/knart.rb', line 33

def to_html(options = {})
    opts = HTML_OPTIONS.merge(options)
    html = nil
    case type
    when 'Documentation Template'
        path = File.expand_path('../../views/documentation_template.slim', __FILE__)
        html = Slim::Template.new(path, pretty: true, disable_escape: true).render(self)
    else
        path = File.expand_path('../../views/unsupported.slim', __FILE__)
        html = Slim::Template.new(path, pretty: true).render(self)
    end
    html
end