Class: Docxer::Word::Contents::Table::TableRow::TableCell

Inherits:
Object
  • Object
show all
Defined in:
lib/docxer/word/contents/table.rb

Defined Under Namespace

Classes: Image

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TableCell

Returns a new instance of TableCell.



93
94
95
96
97
98
99
100
101
102
# File 'lib/docxer/word/contents/table.rb', line 93

def initialize(options={})
  @options = options
  @content = []

  if block_given?
    yield self
  else

  end
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



92
93
94
# File 'lib/docxer/word/contents/table.rb', line 92

def content
  @content
end

#optionsObject

Returns the value of attribute options.



92
93
94
# File 'lib/docxer/word/contents/table.rb', line 92

def options
  @options
end

Instance Method Details

#image(image, options = {}) ⇒ Object



147
148
149
150
151
# File 'lib/docxer/word/contents/table.rb', line 147

def image(image, options={})
  img = Image.new(image, options)
  @content << img
  img
end

#render(xml) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/docxer/word/contents/table.rb', line 104

def render(xml)
  xml['w'].tc do
    xml['w'].tcPr do
      xml['w'].tcW( 'w:w' => ( options[:width].to_i * 14.92 ).to_i, 'w:type' => "dxa" ) if options[:width]
      xml['w'].shd( 'w:val' => "clear", 'w:color' => "auto", 'w:fill' => options[:fill] ) if options[:fill]
      if options[:borders]
        xml['w'].tcBorders do
          options[:borders].each do |k, v|
            if v.nil?
              xml['w'].send(k, 'w:val' => "nil" )
            else
              xml['w'].send(k, 'w:val' => "single", 'w:sz' => v, 'w:space' => "0", 'w:color' => "auto" )
            end
          end
        end
      end
      if options[:merged]
        xml['w'].vMerge
      else
        xml['w'].vAlign( 'w:val' => options[:valign] ) if options[:valign]
        xml['w'].gridSpan( 'w:val' => options[:colspan] ) if options[:colspan]
        xml['w'].vMerge( 'w:val' => "restart" ) if options[:rowspan]
      end
    end
    if options[:merged]
      xml['w'].p
    else
      @content.each do |element|
        element.render(xml)
      end
    end
  end
end

#text(text, options = {}) ⇒ Object



138
139
140
141
142
143
144
145
# File 'lib/docxer/word/contents/table.rb', line 138

def text(text, options={})
  options = @options.merge(options)
  element = Docxer::Word::Contents::Paragraph.new(options) do |p|
    p.text(text)
  end
  @content << element
  element
end