Class: YDocx::Document
- Inherits:
-
Object
- Object
- YDocx::Document
- Defined in:
- lib/ydocx/document.rb,
lib/ydocx/templates/patinfo.rb,
lib/ydocx/templates/fachinfo.rb
Instance Attribute Summary collapse
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#images ⇒ Object
readonly
Returns the value of attribute images.
-
#indecies ⇒ Object
readonly
Returns the value of attribute indecies.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #init ⇒ Object
-
#initialize(file, options = {}) ⇒ Document
constructor
A new instance of Document.
- #output_directory ⇒ Object
-
#output_file(ext) ⇒ Object
html.
- #to_html(output = false, options = {}) ⇒ Object
- #to_xml(output = false, options = {}) ⇒ Object
Constructor Details
#initialize(file, options = {}) ⇒ Document
Returns a new instance of Document.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ydocx/document.rb', line 21 def initialize(file, ={}) @parser = nil @builder = nil @contents = nil @indecies = [] @references = [] @images = [] @options = @path = Pathname.new('.') @files = nil @zip = nil init read(file) end |
Instance Attribute Details
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
16 17 18 |
# File 'lib/ydocx/document.rb', line 16 def builder @builder end |
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
16 17 18 |
# File 'lib/ydocx/document.rb', line 16 def contents @contents end |
#images ⇒ Object (readonly)
Returns the value of attribute images.
16 17 18 |
# File 'lib/ydocx/document.rb', line 16 def images @images end |
#indecies ⇒ Object (readonly)
Returns the value of attribute indecies.
16 17 18 |
# File 'lib/ydocx/document.rb', line 16 def indecies @indecies end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
16 17 18 |
# File 'lib/ydocx/document.rb', line 16 def parser @parser end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
16 17 18 |
# File 'lib/ydocx/document.rb', line 16 def path @path end |
Class Method Details
.open(file, options = {}) ⇒ Object
18 19 20 |
# File 'lib/ydocx/document.rb', line 18 def self.open(file, ={}) self.new(file, ) end |
Instance Method Details
#init ⇒ Object
35 36 |
# File 'lib/ydocx/document.rb', line 35 def init end |
#output_directory ⇒ Object
37 38 39 |
# File 'lib/ydocx/document.rb', line 37 def output_directory @files ||= @path.dirname.join(@path.basename('.docx').to_s + '_files') end |
#output_file(ext) ⇒ Object
html
258 259 260 |
# File 'lib/ydocx/templates/fachinfo.rb', line 258 def output_file(ext) @path.sub_ext(".#{ext.to_s}") end |
#to_html(output = false, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ydocx/document.rb', line 43 def to_html(output=false, ={}) html = '' = @options.merge() files = output_directory @builder = Builder.new(@contents) do |builder| builder.title = @path.basename builder.files = files.relative_path_from(files.dirname) builder.style = [:style] if .has_key?(:style) # option builder.indecies = @indecies.dup builder.references = @references.dup html = builder.build_html end if output create_files if has_image? html_file = output_file(:html) File.open(html_file, 'w:utf-8') do |f| f.puts html end end html end |
#to_xml(output = false, options = {}) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ydocx/document.rb', line 66 def to_xml(output=false, ={}) xml = '' = @options.merge() Builder.new(@contents) do |builder| builder.block = .has_key?(:block) ? [:block] : :chapter xml = builder.build_xml end if output xml_file = output_file(:xml) mkdir xml_file.parent File.open(xml_file, 'w:utf-8') do |f| f.puts xml end end xml end |