Class: Knartform::Knart
- Inherits:
-
Object
- Object
- Knartform::Knart
- Defined in:
- lib/knartform/knart.rb
Constant Summary collapse
- HTML_OPTIONS =
{}.freeze
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #dummy_add_button ⇒ Object
- #dummy_drag_control ⇒ Object
- #dummy_edit_and_delete ⇒ Object
- #dummy_edit_button ⇒ Object
- #first_attribute(nodes, name) ⇒ Object
-
#initialize(file) ⇒ Knart
constructor
A new instance of Knart.
- #load(file) ⇒ Object
- #loaded? ⇒ Boolean
- #to_html(options = {}) ⇒ Object
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
#document ⇒ Object
Returns the value of attribute document.
8 9 10 |
# File 'lib/knartform/knart.rb', line 8 def document @document end |
#type ⇒ Object
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_button ⇒ Object
56 57 58 59 |
# File 'lib/knartform/knart.rb', line 56 def path = File.('../../views/dummy_add_button.slim', __FILE__) html = Slim::Template.new(path, pretty: true).render(self) end |
#dummy_drag_control ⇒ Object
66 67 68 69 |
# File 'lib/knartform/knart.rb', line 66 def dummy_drag_control path = File.('../../views/dummy_drag_control.slim', __FILE__) html = Slim::Template.new(path, pretty: true).render(self) end |
#dummy_edit_and_delete ⇒ Object
51 52 53 54 |
# File 'lib/knartform/knart.rb', line 51 def dummy_edit_and_delete path = File.('../../views/dummy_edit_and_delete.slim', __FILE__) html = Slim::Template.new(path, pretty: true).render(self) end |
#dummy_edit_button ⇒ Object
61 62 63 64 |
# File 'lib/knartform/knart.rb', line 61 def path = File.('../../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. = 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
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( = {}) opts = HTML_OPTIONS.merge() html = nil case type when 'Documentation Template' path = File.('../../views/documentation_template.slim', __FILE__) html = Slim::Template.new(path, pretty: true, disable_escape: true).render(self) else path = File.('../../views/unsupported.slim', __FILE__) html = Slim::Template.new(path, pretty: true).render(self) end html end |