Class: DYI::Formatter::XmlFormatter
- Inherits:
-
Base
- Object
- Base
- DYI::Formatter::XmlFormatter
show all
- Includes:
- XmlChar
- Defined in:
- lib/dyi/formatter/base.rb
Overview
Constant Summary
Constants included
from XmlChar
DYI::Formatter::XmlChar::ATTR_PREDEFINED, DYI::Formatter::XmlChar::CP1252, DYI::Formatter::XmlChar::PREDEFINED, DYI::Formatter::XmlChar::VALID
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#save, #string, #write_canvas, #write_circle, #write_ellipse, #write_group, #write_image, #write_line, #write_path, #write_polygon, #write_polyline, #write_rectangle, #write_text
Constructor Details
#initialize(canvas, options = {}) ⇒ XmlFormatter
Returns a new instance of XmlFormatter.
177
178
179
180
181
182
183
184
|
# File 'lib/dyi/formatter/base.rb', line 177
def initialize(canvas, options={})
@canvas = canvas
@indent = options[:indent] || 0
@level = options[:level] || 0
@inline_mode = options[:inline_mode]
namespace = options[:namespace].to_s
@namespace = namespace.empty? ? nil : namespace
end
|
Instance Attribute Details
#namespace ⇒ Object
175
176
177
|
# File 'lib/dyi/formatter/base.rb', line 175
def namespace
@namespace
end
|
Instance Method Details
#declaration ⇒ Object
224
225
226
|
# File 'lib/dyi/formatter/base.rb', line 224
def declaration
''
end
|
220
221
222
|
# File 'lib/dyi/formatter/base.rb', line 220
def
%Q{<!-- Create with DYI #{DYI::VERSION} (#{DYI::URL}) -->}
end
|
#inline_mode=(boolean) ⇒ Object
192
193
194
|
# File 'lib/dyi/formatter/base.rb', line 192
def inline_mode=(boolean)
@inline_mode = boolean ? true : false
end
|
#inline_mode? ⇒ Boolean
187
188
189
|
# File 'lib/dyi/formatter/base.rb', line 187
def inline_mode?
@inline_mode ? true : false
end
|
#puts(io = $>) ⇒ Object
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
# File 'lib/dyi/formatter/base.rb', line 228
def puts(io=$>)
if @canvas.root_element? && !inline_mode?
puts_line(io) {io << xml_instruction}
@canvas.stylesheets.each do |stylesheet|
if stylesheet.include_external_file?
puts_line(io) {io << stylesheet_instruction(stylesheet)}
end
end
puts_line(io) {io << }
declaration.each_line do |dec|
puts_line(io) {io << dec}
end
end
@canvas.write_as(self, io)
end
|
#stylesheet_instruction(stylesheet) ⇒ Object
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/dyi/formatter/base.rb', line 202
def stylesheet_instruction(stylesheet)
styles = []
styles << '<?xml-stylesheet href="'
styles << stylesheet.href
styles << '" type="'
styles << stylesheet.content_type
if stylesheet.title
styles << '" title="'
styles << stylesheet.title
end
if stylesheet.media
styles << '" media="'
styles << stylesheet.media
end
styles << '"?>'
styles.join
end
|
#xml_instruction ⇒ Object
197
198
199
|
# File 'lib/dyi/formatter/base.rb', line 197
def xml_instruction
%Q{<?xml version="1.0" encoding="UTF-8"?>}
end
|