Module: Xampl::XamplWithSimpleContent

Defined in:
lib/xamplr/mixins.rb

Instance Method Summary collapse

Instance Method Details

#<<(other) ⇒ Object



159
160
161
162
163
164
165
166
# File 'lib/xamplr/mixins.rb', line 159

def <<(other)
  if (other.respond_to?("append_to"))
    raise XamplException.new("simple content only")
  else
    add_content(other)
  end
  return self
end

#_contentObject Also known as: content



86
87
88
89
# File 'lib/xamplr/mixins.rb', line 86

def _content
  accessed
  @_content
end

#_content=(v) ⇒ Object Also known as: content=



91
92
93
94
95
96
97
# File 'lib/xamplr/mixins.rb', line 91

def _content=(v)
  accessed
  v = v.to_s if (v.kind_of? Symbol) and !Xampl.xampl_extends_symbols
  v.extend(XamplExtensionsToRubyObjects) unless v.kind_of? Symbol
  @_content = v
  changed
end

#add_content(new_content, tokenise = false) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/xamplr/mixins.rb', line 102

def add_content(new_content, tokenise=false)
  return if nil == new_content
  accessed

  if (nil == @_content) then
    @_content = new_content.to_s
    @_content.extend(XamplExtensionsToRubyObjects)
  else
    @_content << new_content.to_s
  end

  FromXML.tokenise_string(@_content, false) if tokenise
  @_content = nil if 0 == @_content.size

  changed
end

#after_visit_by_element_kind(visitor) ⇒ Object



82
83
84
# File 'lib/xamplr/mixins.rb', line 82

def after_visit_by_element_kind(visitor)
  visitor.after_visit_simple_content(self)
end

#before_visit_by_element_kind(visitor) ⇒ Object



74
75
76
# File 'lib/xamplr/mixins.rb', line 74

def before_visit_by_element_kind(visitor)
  visitor.before_visit_simple_content(self)
end

#childrenObject



119
120
121
# File 'lib/xamplr/mixins.rb', line 119

def children
  return []
end

#has_mixed_contentObject



70
71
72
# File 'lib/xamplr/mixins.rb', line 70

def has_mixed_content
  false
end

#initializeObject



65
66
67
68
# File 'lib/xamplr/mixins.rb', line 65

def initialize
  super
  @_content = nil unless defined? @_content
end

#test_to_xml(out = "", rules = nil) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/xamplr/mixins.rb', line 123

def test_to_xml(out="", rules=nil)
  accessed
  rules = XMLPrinter.new(out) if nil == rules

  rules.attribute(self)
  if (nil == self._content)
    rules.start_root_element(tag, ns, true)
    rules.end_root_element(tag, ns, true)
  else
    rules.start_root_element(tag, ns, false)
    rules._content(content)
    rules.end_root_element(tag, ns, false)
  end

  return rules.done
end

#test_to_xml_internal(rules) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/xamplr/mixins.rb', line 140

def test_to_xml_internal(rules)
  if rules.persisting && self.persist_required then
    rules.persist_attribute(self)
    rules.persisted_element(tag, ns)
    return
  end

  rules.attribute(self)
  if (nil == self._content)
    rules.start_element(tag, ns, true)
    rules._content(content)
    rules.end_element(tag, ns, true)
  else
    rules.start_element(tag, ns, false)
    rules._content(content)
    rules.end_element(tag, ns, false)
  end
end

#visit_by_element_kind(visitor) ⇒ Object



78
79
80
# File 'lib/xamplr/mixins.rb', line 78

def visit_by_element_kind(visitor)
  visitor.visit_simple_content(self)
end