class Docxer::Word::Document
Attributes
effects[RW]
endnotes[RW]
fonts[RW]
footnotes[RW]
headers[RW]
numbering[RW]
options[RW]
relationships[RW]
setings[RW]
styles[RW]
themes[RW]
web_settings[RW]
Public Class Methods
new(options)
click to toggle source
# File lib/docxer/word/document.rb, line 9 def initialize(options) @options = options @content = [] end
Public Instance Methods
add_header(header, options={})
click to toggle source
# File lib/docxer/word/document.rb, line 29 def add_header(header, options={}) header.id = headers.sequence rel = relationships.add(header.content_type, header.target) header.sequence = rel.id headers.add(header) @header = header end
add_media(file, options={})
click to toggle source
# File lib/docxer/word/document.rb, line 14 def add_media(file, options={}) media = Medias::Media.new(medias.sequence, file, options) rel = relationships.add(media.content_type, media.target) media.set_sequence(rel.id) medias.add(media) end
medias()
click to toggle source
# File lib/docxer/word/document.rb, line 65 def medias @medias ||= Medias.new end
render(zip)
click to toggle source
# File lib/docxer/word/document.rb, line 89 def render(zip) zip.put_next_entry('word/document.xml') zip.write(Docxer.to_xml(document)) fonts.render(zip) settings.render(zip) styles.render(zip) effects.render(zip) numbering.render(zip) web_settings.render(zip) themes.render(zip) footnotes.render(zip) endnotes.render(zip) headers.render(zip) footers.render(zip) medias.render(zip) relationships.render(zip) end
settings()
click to toggle source
# File lib/docxer/word/document.rb, line 41 def settings @settings ||= Settings.new end
Private Instance Methods
content()
click to toggle source
# File lib/docxer/word/document.rb, line 138 def content @content end
document()
click to toggle source
# File lib/docxer/word/document.rb, line 109 def document Nokogiri::XML::Builder.with(Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>')) do |xml| xml.document('xmlns:wpc' => "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas", 'xmlns:mc' => "http://schemas.openxmlformats.org/markup-compatibility/2006", 'xmlns:o' => "urn:schemas-microsoft-com:office:office", 'xmlns:r' => "http://schemas.openxmlformats.org/officeDocument/2006/relationships", 'xmlns:m' => "http://schemas.openxmlformats.org/officeDocument/2006/math", 'xmlns:v' => "urn:schemas-microsoft-com:vml", 'xmlns:wp14' => "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing", 'xmlns:wp' => "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", 'xmlns:w10' => "urn:schemas-microsoft-com:office:word", 'xmlns:w' => "http://schemas.openxmlformats.org/wordprocessingml/2006/main", 'xmlns:w14' => "http://schemas.microsoft.com/office/word/2010/wordml", 'xmlns:wpg' => "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup", 'xmlns:wpi' => "http://schemas.microsoft.com/office/word/2010/wordprocessingInk", 'xmlns:wne' => "http://schemas.microsoft.com/office/word/2006/wordml", 'xmlns:wps' => "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", 'mc:Ignorable' => "w14 wp14") do xml.parent.namespace = xml.parent.namespace_definitions.find{|ns| ns.prefix == "w" } xml['w'].body do content.each do |element| element.render(xml) end xml['w'].p do xml['w'].bookmarkStart( 'w:id' => "0", 'w:name' => "_GoBack") xml['w'].bookmarkEnd('w:id' => "0") end xml['w'].sectPr do xml['w'].footerReference( 'w:type' => "default", 'r:id' => @footer.sequence ) if @footer xml['w'].headerReference( 'w:type' => "default", 'r:id' => @header.sequence ) if @header xml['w'].titlePg xml['w'].pgSz( 'w:w' => 12240, 'w:h' => 15840 ) xml['w'].pgMar( 'w:top' => 800, 'w:right' => 940, 'w:bottom' => 1000, 'w:left' => 940, 'w:header' => 190, 'w:footer' => 200, 'w:gutter' => 0) xml['w'].cols( 'w:space' => 720) xml['w'].docGrid( 'w:linePitch' => "360") end end end end end