Module: ManipulateNode

Extended by:
ActiveSupport::Concern
Included in:
ApplicationController, FacetFilter, NoteRenderer, Record, Tree
Defined in:
public/app/controllers/concerns/manipulate_node.rb

Instance Method Summary collapse

Instance Method Details

#inheritance(struct = nil) ⇒ Object

provides inheritance information, with markup!



68
69
70
71
72
73
74
75
# File 'public/app/controllers/concerns/manipulate_node.rb', line 68

def inheritance(struct = nil)
  text = ''
  unless struct.blank? || struct['level'].blank? || struct['direct']
    level = I18n.t("inherit.#{struct['level'].downcase}", :default => struct['level'])
    text = '<span class="inherit">' + I18n.t('inherit.inherited', :level => level) + '</span>'
  end
  text
end

#process_mixed_content(in_txt, opts = {}) ⇒ Object

the beginning of processing mixed content nodes for titles, notes, etc. TODO: look at replacing these gsubs with syntax like: @xml.xpath(“//item”).each do |item| item.name = “li” end



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'public/app/controllers/concerns/manipulate_node.rb', line 13

def process_mixed_content(in_txt, opts = {})
  return if !in_txt

  # Don't fire up nokogiri if there's no mixed content to parse
  needs_nokogiri = in_txt.include?("<")

  txt = in_txt.strip.encode(
    Encoding.find('utf-8'), { invalid: :replace, undef: :replace, replace: '' }
  )

  txt = txt.gsub("chronlist>", "ul>")
    .gsub("chronitem>", "li>")
  txt = txt.gsub("list>", "ul>")
    .gsub("item>", "li>")

  unless opts[:preserve_newlines]
    txt = txt.gsub(/\n\n/, "<br /><br />")
            .gsub(/\r\n\r\n/, "<br /><br />")
  end

  txt = txt.gsub(/&(?![A-Za-z]+;|#[0-9]+;)/, '&amp;')

  txt = txt.gsub("xlink\:type=\"simple\"", "")

  unless needs_nokogiri
    return txt
  end

  @frag = Nokogiri::XML.fragment(txt)
  move_list_heads
  @frag.traverse { |el|
    # we don't do anything at the top level of the fragment or if it's text
    node_check(el) if el.parent && !el.text?
    el.content = el.text.gsub("\"", "&quot;") if el.text?
  }
  # replace the inline quotes with &quot;
  @frag.to_xml(encoding: 'utf-8').to_s.gsub("&amp;quot;", "&quot;")
end

#strip_mixed_content(in_text) ⇒ Object

strips all xml markup; used for things like titles.



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'public/app/controllers/concerns/manipulate_node.rb', line 53

def strip_mixed_content(in_text)
  return if !in_text

  # Don't fire up nokogiri if there's no mixed content to parse
  unless in_text.include?("<")
    return in_text
  end

  in_text = in_text.gsub(/ & /, ' &amp; ')
  @frag = Nokogiri::XML.fragment(in_text)

  @frag.content
end