Sha256: d9257241ef4cdc5569e7561d6da8a570e625e6d246c84cd525c00593e169f1ac

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

module Rocx
  module Parts
    class Styles < BasePart
      attr_reader :styles

      def initialize
        @styles = []
      end

      def <<(style)
        @styles << style
      end

      def to_xml
        build_standalone_xml do |xml|
          xml.styles(root_namespaces) {
            xml.parent.namespace = xml.parent.namespace_definitions.find { |ns| ns.prefix == "w" }
            add_default_styles(xml)
            styles.each { |style| style.build_xml(xml) }
          }
        end
      end

    private

      def add_default_styles(xml)
        xml["w"].docDefaults {
          xml["w"].rPrDefault {
            xml["w"].rPr {
              xml["w"].lang("w:bidi" => "ar-SA", "w:eastAsia" => "en-US", "w:val" => "en-US")
            }
          }
          xml["w"].pPrDefault {
            xml["w"].pPr {
              xml["w"].spacing("w:after" => "0", "w:line" => "240", "w:lineRule" => "auto")
            }
          }
        }
      end

      def root_namespaces
        { "xmlns:r" => "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
          "xmlns:w" => "http://schemas.openxmlformats.org/wordprocessingml/2006/main" }
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rocx-0.7.0 lib/rocx/parts/styles.rb
rocx-0.6.0 lib/rocx/parts/styles.rb
rocx-0.5.8 lib/rocx/parts/styles.rb
rocx-0.5.7 lib/rocx/parts/styles.rb