Class: Docxi::Word::Contents::Table::TableRow::TableCell

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

Defined Under Namespace

Classes: Image, PageNumbers

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TableCell

Returns a new instance of TableCell.



110
111
112
113
114
115
116
117
118
119
# File 'lib/docxi/word/contents/table.rb', line 110

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

  if block_given?
    yield self
  else

  end
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



109
110
111
# File 'lib/docxi/word/contents/table.rb', line 109

def content
  @content
end

#optionsObject

Returns the value of attribute options.



109
110
111
# File 'lib/docxi/word/contents/table.rb', line 109

def options
  @options
end

Instance Method Details

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



167
168
169
170
171
# File 'lib/docxi/word/contents/table.rb', line 167

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

#p(options = {}, &block) ⇒ Object



179
180
181
182
183
# File 'lib/docxi/word/contents/table.rb', line 179

def p(options={}, &block)
  element = Docxi::Word::Contents::Paragraph.new(options, &block)
  @content << element
  element
end

#page_numbersObject



173
174
175
176
177
# File 'lib/docxi/word/contents/table.rb', line 173

def page_numbers
  numbers = PageNumbers.new
  @content << numbers
  numbers
end

#render(xml) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/docxi/word/contents/table.rb', line 121

def render(xml)
  if options[:fill].blank?
    options[:fill] = 'FFFFFF'
  end
  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



158
159
160
161
162
163
164
165
# File 'lib/docxi/word/contents/table.rb', line 158

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