class Libera::Tei
Public Class Methods
xml_template()
click to toggle source
# File lib/libera/tei.rb, line 35 def self.xml_template builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml| xml.TEI("xmlns"=>"http://www.tei-c.org/ns/1.0") { xml.teiHeader{ xml.fileDesc{ xml.titleStmt{ xml.title } xml.publicationStmt{ xml.p_ } xml.sourceDesc{ xml.p_ } } } xml.text_{ xml.body{ xml.ab } } } end return builder.doc end
Public Instance Methods
add_anon_block(text)
click to toggle source
# File lib/libera/tei.rb, line 106 def add_anon_block(text) if self.find_by_terms(:text, :body, :page_break).blank? # Raise error, page break required raise "Page Break not found, unable to add anon block" end if self.find_by_terms(:text, :body, :page_break).count == 1 self.template_registry.add_next_sibling(self.find_by_terms(:text, :body, :page_break => 0).first, :anon_block, text) else self.template_registry.add_next_sibling(self.find_by_terms(:text, :body, :page_break).last, :anon_block, text) end end
add_body()
click to toggle source
# File lib/libera/tei.rb, line 70 def add_body begin self.template_registry.add_child(self.find_by_terms(:text => 0), :body) rescue NoMethodError raise "Unable to add XML node to base template" end end
add_page_break(page_img)
click to toggle source
# File lib/libera/tei.rb, line 78 def add_page_break(page_img) # any text? if self.find_by_terms(:text => 0).blank? self.add_text end # any body? if self.find_by_terms(:text, :body => 0).blank? self.add_body end # any anon breaks? ab_count = self.find_by_terms(:text, :body, :anon_block).count if ab_count == 1 && self.find_by_terms(:text, :body, :anon_block).first.text.blank? self.find_by_terms(:text, :body, :anon_block).first.remove ab_count = 0 end if !(ab_count > 0) # if not add to child of body self.template_registry.add_child(self.find_by_terms(:text, :body => 0), :page_break, page_img) else # else add as sibling self.template_registry.add_next_sibling(self.find_by_terms(:text, :body, :anon_block).last, :page_break, page_img) end end
add_text()
click to toggle source
# File lib/libera/tei.rb, line 62 def add_text begin self.template_registry.add_child(self.ng_xml.root, :text) rescue NoMethodError raise "Unable to add XML node to base template" end end