Class: ODF::Style

Inherits:
Container show all
Defined in:
lib/odf/style.rb

Direct Known Subclasses

DefaultStyle, OfficeStyle

Constant Summary collapse

FAMILIES =
{:cell => 'table-cell', :column => 'table-column', :row => 'table-row'}

Instance Method Summary collapse

Methods inherited from Container

contains, create

Constructor Details

#initialize(name = '', opts = {}, node_tag = 'style:style') ⇒ Style

Returns a new instance of Style.



30
31
32
33
# File 'lib/odf/style.rb', line 30

def initialize(name='', opts={}, node_tag='style:style')
  @name, @node_tag = name, node_tag
  @elem_attrs = make_element_attributes(@name, opts)
end

Instance Method Details

#make_element_attributes(name, opts) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/odf/style.rb', line 41

def make_element_attributes(name, opts)
  attrs = {
    'style:name' => name,
    'style:family' => (FAMILIES[opts[:family]] || opts[:family])}
  attrs['style:data-style-name'] = opts[:data_style] unless opts[:data_style].nil?
  attrs['style:parent-style-name'] = opts[:parent].to_s unless opts[:parent].nil?
  attrs['style:master-page-name'] = opts[:master_page] unless opts[:master_page].nil?
  attrs
end

#to_sObject



51
52
53
# File 'lib/odf/style.rb', line 51

def to_s
  @name
end

#xmlObject



35
36
37
38
39
# File 'lib/odf/style.rb', line 35

def xml
  Builder::XmlMarkup.new.tag!(@node_tag, @elem_attrs) do |xml|
    xml << properties_xml
  end
end