lib/giblish/docinfo.rb in giblish-0.7.6 vs lib/giblish/docinfo.rb in giblish-0.8.0

- old
+ new

@@ -2,57 +2,31 @@ module Giblish # Container class for bundling together the data we cache for # each asciidoc file we come across class DocInfo - # Cache git info + # History info from git class DocHistory - attr_accessor :date - attr_accessor :author - attr_accessor :message + attr_accessor :date, :author, :message end - attr_accessor :converted - attr_accessor :doc_id - attr_accessor :purpose_str - attr_accessor :status - attr_accessor :history - attr_accessor :error_msg - attr_accessor :stderr + attr_accessor :converted, :doc_id, :purpose_str, :status, :history, :error_msg, :stderr + attr_reader :title, :rel_path, :src_file # these members can have encoding issues when # running in a mixed Windows/Linux setting. # that is why we explicitly encodes them when # writing to them - def title - @title - end + def title=(rhs) @title = rhs.nil? ? nil : rhs.encode("utf-8") end - def rel_path - @rel_path - end - # attr_accessor :rel_path - def src_file - @src_file - end + def src_file=(rhs) @src_file = rhs.nil? ? nil : rhs.encode("utf-8") end - # attr_accessor :src_file - # def relPath_utf8 - # return nil if @rel_path.nil? - # @rel_path.to_s.encode("utf-8") - # end - # - # def srcFile_utf8 - # return nil if @src_file.nil? - # @src_file.to_s.encode("utf-8") - # end - def initialize(adoc: nil, dst_root_abs: nil, adoc_stderr: "") @src_file = nil @history = [] @converted = true @stderr = adoc_stderr @@ -61,18 +35,18 @@ # Get the purpose info if it exists @purpose_str = get_purpose_info adoc # fill in doc meta data d_attr = adoc.attributes - self.src_file=(d_attr["docfile"]) - self.title=(adoc.doctitle) + self.src_file = (d_attr["docfile"]) + self.title = (adoc.doctitle) @doc_id = d_attr["docid"] return if dst_root_abs.nil? # Get the relative path beneath the root dir to the doc @rel_path = Pathname.new( - "#{d_attr['outdir']}/#{d_attr['docname']}#{d_attr['docfilesuffix']}".encode("utf-8") + "#{d_attr['outdir']}/#{d_attr['docname']}#{d_attr['docfilesuffix']}".encode("utf-8") ).relative_path_from(dst_root_abs) end def to_s "DocInfo: title: #{@title} src_file: #{@src_file}" @@ -80,21 +54,22 @@ private def get_purpose_info(adoc) # Get the 'Purpose' section if it exists - purpose_str = "" + purpose_str = String.new("") adoc.blocks.each do |section| next unless section.is_a?(Asciidoctor::Section) && - (section.level == 1) && - (section.name =~ /^Purpose$/) + (section.level == 1) && + (section.name =~ /^Purpose$/) # filter out 'odd' text, such as lists etc... section.blocks.each do |bb| next unless bb.is_a?(Asciidoctor::Block) + purpose_str << "#{bb.source}\n+\n" end end purpose_str end end -end \ No newline at end of file +end