Class: DxSectionX
- Inherits:
-
Object
- Object
- DxSectionX
- Defined in:
- lib/dxsectionx.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
writeonly
Sets the attribute domain.
-
#dx ⇒ Object
readonly
Returns the value of attribute dx.
-
#xsl_url ⇒ Object
writeonly
Sets the attribute xsl_url.
Instance Method Summary collapse
- #create(h) ⇒ Object
-
#initialize(x, domain: nil, xsl_url: nil, debug: false, autosave: false) ⇒ DxSectionX
constructor
A new instance of DxSectionX.
- #save(filename) ⇒ Object
- #to_doc ⇒ Object
- #to_s ⇒ Object
- #transform ⇒ Object
Constructor Details
#initialize(x, domain: nil, xsl_url: nil, debug: false, autosave: false) ⇒ DxSectionX
Returns a new instance of DxSectionX.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dxsectionx.rb', line 16 def initialize(x, domain: nil, xsl_url: nil, debug: false, autosave: false) @domain, @xsl_url, @debug = domain, xsl_url, debug if x.is_a? Rexle then @doc = x transform() else @dx = Dynarex.new autosave: autosave, debug: debug @dx.import x puts '@dx.to_s : ' + @dx.to_s if @debug transform() end end |
Instance Attribute Details
#domain=(value) ⇒ Object (writeonly)
Sets the attribute domain
13 14 15 |
# File 'lib/dxsectionx.rb', line 13 def domain=(value) @domain = value end |
#dx ⇒ Object (readonly)
Returns the value of attribute dx.
12 13 14 |
# File 'lib/dxsectionx.rb', line 12 def dx @dx end |
#xsl_url=(value) ⇒ Object (writeonly)
Sets the attribute xsl_url
13 14 15 |
# File 'lib/dxsectionx.rb', line 13 def xsl_url=(value) @xsl_url = value end |
Instance Method Details
#create(h) ⇒ Object
35 36 37 38 |
# File 'lib/dxsectionx.rb', line 35 def create(h) puts 'inside dxsection#create' if @debug @dx.create h end |
#save(filename) ⇒ Object
40 41 42 43 |
# File 'lib/dxsectionx.rb', line 40 def save(filename) puts 'inside dxsection save ' + filename.inspect if @debug @dx.save filename end |
#to_doc ⇒ Object
45 46 47 48 |
# File 'lib/dxsectionx.rb', line 45 def to_doc() transform() @doc end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/dxsectionx.rb', line 50 def to_s() @dx.to_s end |
#transform ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/dxsectionx.rb', line 54 def transform doc = @dx.doc.clone doc.root.xpath('records/section/x') do |x| s = "=%s\n%s\n=" % [x.text.lines.first[/#\w+$/], x.text.unescape] html = Kramdown::Document\ .new(Martile.new(s, ignore_domainlabel: @domain).to_s).to_html puts 'html: ' + html.inspect if @debug e = x.parent e.attributes.merge x.attributes x.delete doc2 = Rexle.new(html) h1 = doc2.root.element('h1') details = Rexle::Element.new('details') details.attributes[:open] = 'open' summary = Rexle::Element.new('summary') summary.add h1 details.add summary doc2.root.xpath('*').each {|x| details.add x } doc2.root.add details doc2.root.elements.each {|e2| e.add e2 } end @doc = doc if @xsl_url then @doc.instructions << [ 'xml-stylesheet', "title='XSL_formatting' type='text/xsl' href='#{@xsl_url}'" ] end return @doc end |