class Knartform::Knart

Constants

HTML_OPTIONS

Attributes

document[RW]
type[RW]

Public Class Methods

new(file) click to toggle source
# File lib/knartform/knart.rb, line 12
    def initialize(file)
        load(file)
end

Public Instance Methods

dummy_add_button() click to toggle source
# 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_control() click to toggle source
# 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_delete() click to toggle source
# 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_button() click to toggle source
# 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) click to toggle source
# File lib/knartform/knart.rb, line 47
def first_attribute(nodes, name)
    nodes.empty? ? '' : nodes.first[name]
end
load(file) click to toggle source
# 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?() click to toggle source
# File lib/knartform/knart.rb, line 29
def loaded?
    !document.nil?
end
to_html(options = {}) click to toggle source
# 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