Class: RubyDocx::Html
- Inherits:
-
Object
- Object
- RubyDocx::Html
- Defined in:
- lib/ruby_docx/html.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
attr_reader :xml, :doc, :zip, :styles, :styles_xml, :rels.
-
#html_str ⇒ Object
readonly
attr_reader :xml, :doc, :zip, :styles, :styles_xml, :rels.
-
#xml ⇒ Object
readonly
attr_reader :xml, :doc, :zip, :styles, :styles_xml, :rels.
-
#xml_doc ⇒ Object
readonly
attr_reader :xml, :doc, :zip, :styles, :styles_xml, :rels.
-
#zip ⇒ Object
readonly
attr_reader :xml, :doc, :zip, :styles, :styles_xml, :rels.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(html_str) ⇒ Html
constructor
A new instance of Html.
- #save(path) ⇒ Object
Constructor Details
#initialize(html_str) ⇒ Html
Returns a new instance of Html.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ruby_docx/html.rb', line 21 def initialize(html_str) @html_str = html_str @doc = Nokogiri::HTML(@html_str) @zip = Zip::File.open("template.docx") @xml = @zip.read('word/document.xml') @xml_doc = Nokogiri::XML(@xml) # @path = path # @zip = Zip::File.open(path) # rels_xml = @zip.read('word/_rels/document.xml.rels') # @rels = Nokogiri::XML(rels_xml) # @rels.remove_namespaces! # @doc = Nokogiri::XML(@xml) # @styles_xml = @zip.read('word/styles.xml') # @styles = Nokogiri::XML(@styles_xml) end |
Instance Attribute Details
#doc ⇒ Object (readonly)
attr_reader :xml, :doc, :zip, :styles, :styles_xml, :rels
11 12 13 |
# File 'lib/ruby_docx/html.rb', line 11 def doc @doc end |
#html_str ⇒ Object (readonly)
attr_reader :xml, :doc, :zip, :styles, :styles_xml, :rels
11 12 13 |
# File 'lib/ruby_docx/html.rb', line 11 def html_str @html_str end |
#xml ⇒ Object (readonly)
attr_reader :xml, :doc, :zip, :styles, :styles_xml, :rels
11 12 13 |
# File 'lib/ruby_docx/html.rb', line 11 def xml @xml end |
#xml_doc ⇒ Object (readonly)
attr_reader :xml, :doc, :zip, :styles, :styles_xml, :rels
11 12 13 |
# File 'lib/ruby_docx/html.rb', line 11 def xml_doc @xml_doc end |
#zip ⇒ Object (readonly)
attr_reader :xml, :doc, :zip, :styles, :styles_xml, :rels
11 12 13 |
# File 'lib/ruby_docx/html.rb', line 11 def zip @zip end |
Class Method Details
.open_path(path) ⇒ Object
13 14 15 |
# File 'lib/ruby_docx/html.rb', line 13 def self.open_path(path) self.new(File.read(path)) end |
.parse(html_str) ⇒ Object
17 18 19 |
# File 'lib/ruby_docx/html.rb', line 17 def self.parse(html_str) self.new(html_str) end |
Instance Method Details
#save(path) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ruby_docx/html.rb', line 41 def save(path) Zip::OutputStream.open(path) do |out| @zip.each do |entry| out.put_next_entry(entry.name) unless entry.name =~ /\/$/ out.write(@zip.read(entry.name)) end end end end |