Class: DxSectionX

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, domain: nil, xsl_url: nil) ⇒ DxSectionX

Returns a new instance of DxSectionX.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dxsectionx.rb', line 14

def initialize(x, domain: nil, xsl_url: nil)

  @domain, @xsl_url = domain, xsl_url
  
  if x.is_a? Rexle then
    @doc = x
    transform()
  else
    
    dx = Dynarex.new
    dx.import x
    @doc = dx.to_doc
    transform()

  end

end

Instance Attribute Details

#domain=(value) ⇒ Object (writeonly)

Sets the attribute domain

Parameters:

  • value

    the value to set the attribute domain to.



11
12
13
# File 'lib/dxsectionx.rb', line 11

def domain=(value)
  @domain = value
end

#xsl_url=(value) ⇒ Object (writeonly)

Sets the attribute xsl_url

Parameters:

  • value

    the value to set the attribute xsl_url to.



11
12
13
# File 'lib/dxsectionx.rb', line 11

def xsl_url=(value)
  @xsl_url = value
end

Instance Method Details

#to_docObject



32
33
34
# File 'lib/dxsectionx.rb', line 32

def to_doc()
  @doc
end

#transformObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/dxsectionx.rb', line 36

def transform

  @doc.root.xpath('records/section/x') do |x|

    s = "=%s\n%s\n=" % [x.text.lines.first[/#\w+$/], x.text.unescape]

    html = Martile.new(s, ignore_domainlabel: @domain).to_html

    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

  if @xsl_url then

    @doc.instructions << [
      'xml-stylesheet',
      "title='XSL_formatting' type='text/xsl' href='#{@xsl_url}'"
    ]

  end
  
  return @doc

end