rodf 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,34 +1,35 @@
1
- require_relative 'data_style'
2
- require_relative 'document'
3
- require_relative 'hyperlink'
4
- require_relative 'span'
5
- require_relative 'table'
6
-
7
1
  module RODF
8
2
  class Spreadsheet < Document
9
- contains :tables, :data_styles
10
-
11
3
  def xml
12
- b = Builder::XmlMarkup.new
13
-
14
- b.instruct! :xml, version: '1.0', encoding: 'UTF-8'
15
- b.tag! 'office:document-content',
16
- 'xmlns:office' => "urn:oasis:names:tc:opendocument:xmlns:office:1.0",
17
- 'xmlns:table' => "urn:oasis:names:tc:opendocument:xmlns:table:1.0",
18
- 'xmlns:text' => "urn:oasis:names:tc:opendocument:xmlns:text:1.0",
19
- 'xmlns:oooc' => "http://openoffice.org/2004/calc",
20
- 'xmlns:style' => "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
21
- 'xmlns:fo' => "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0",
22
- 'xmlns:number' => "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0",
23
- 'xmlns:xlink' => "http://www.w3.org/1999/xlink" do
24
- |xml|
25
- xml.tag! 'office:styles' do
26
- xml << default_styles_xml
27
- end unless default_styles.empty?
28
- xml.tag! 'office:automatic-styles' do
29
- xml << styles_xml
30
- xml << data_styles_xml
31
- end unless styles.empty? && data_styles.empty?
4
+ builder = Builder::XmlMarkup.new
5
+
6
+ builder.instruct!(:xml, version: '1.0', encoding: 'UTF-8')
7
+
8
+ attrs = {
9
+ 'xmlns:office' => "urn:oasis:names:tc:opendocument:xmlns:office:1.0",
10
+ 'xmlns:table' => "urn:oasis:names:tc:opendocument:xmlns:table:1.0",
11
+ 'xmlns:text' => "urn:oasis:names:tc:opendocument:xmlns:text:1.0",
12
+ 'xmlns:oooc' => "http://openoffice.org/2004/calc",
13
+ 'xmlns:style' => "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
14
+ 'xmlns:fo' => "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0",
15
+ 'xmlns:number' => "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0",
16
+ 'xmlns:xlink' => "http://www.w3.org/1999/xlink",
17
+ }
18
+
19
+ builder.tag!('office:document-content', attrs) do |xml|
20
+ if !default_styles.empty?
21
+ xml.tag! 'office:styles' do
22
+ xml << default_styles_xml
23
+ end
24
+ end
25
+
26
+ if !styles.empty? || !data_styles.empty?
27
+ xml.tag! 'office:automatic-styles' do
28
+ xml << styles_xml
29
+ xml << data_styles_xml
30
+ end
31
+ end
32
+
32
33
  xml.office:body do
33
34
  xml.office:spreadsheet do
34
35
  xml << tables_xml
@@ -36,6 +37,76 @@ module RODF
36
37
  end
37
38
  end
38
39
  end
40
+
41
+ def set_column_widths(table:, column_widths:)
42
+ table.instance_variable_set(:@columns, []) ### Reset completely
43
+
44
+ column_widths.each_with_index do |width, i|
45
+ name = "col-width-#{i}"
46
+
47
+ self.style(name, family: :column) do
48
+ property(:column, {'column-width' => width})
49
+ end
50
+
51
+ table.columns << RODF::Column.new(style: name)
52
+ end
53
+ end
54
+
55
+ def tables
56
+ @tables ||= []
57
+ end
58
+
59
+ def table(*args, column_widths: nil, &block)
60
+ x = Table.new(*args, &block)
61
+
62
+ tables << x
63
+
64
+ if column_widths
65
+ set_column_widths(table: x, column_widths: column_widths)
66
+ end
67
+
68
+ return x
69
+ end
70
+
71
+ def tables_xml
72
+ tables.map(&:xml).join
73
+ end
74
+
75
+ def add_tables(*elements)
76
+ if elements.first.is_a?(Array)
77
+ elements = elements.first
78
+ end
79
+
80
+ elements.each do |element|
81
+ table(element)
82
+ end
83
+ end
84
+
85
+ def data_styles
86
+ @data_styles ||= []
87
+ end
88
+
89
+ def data_style(*args, &block)
90
+ x = DataStyle.new(*args, &block)
91
+
92
+ data_styles << x
93
+
94
+ return x
95
+ end
96
+
97
+ def data_styles_xml
98
+ data_styles.map(&:xml).join
99
+ end
100
+
101
+ def add_data_styles(*elements)
102
+ if elements.first.is_a?(Array)
103
+ elements = elements.first
104
+ end
105
+
106
+ elements.each do |element|
107
+ data_style(element)
108
+ end
109
+ end
39
110
  end
40
111
 
41
112
  SpreadSheet = Spreadsheet
data/lib/rodf/style.rb CHANGED
@@ -1,18 +1,16 @@
1
- require 'builder'
2
-
3
- require_relative 'container'
4
- require_relative 'property'
5
-
6
1
  module RODF
7
2
  class Style < Container
8
- contains :properties
9
-
10
- FAMILIES = {cell: 'table-cell', column: 'table-column', row: 'table-row'}
3
+ FAMILIES = {
4
+ "cell" => 'table-cell',
5
+ "column" => 'table-column',
6
+ "row" => 'table-row',
7
+ }
11
8
 
12
9
  def initialize(name='', opts={}, node_tag='style:style')
13
10
  super
14
11
 
15
12
  @name, @node_tag = name, node_tag
13
+
16
14
  @elem_attrs = make_element_attributes(@name, opts)
17
15
  end
18
16
 
@@ -25,16 +23,47 @@ module RODF
25
23
  def make_element_attributes(name, opts)
26
24
  attrs = {
27
25
  'style:name' => name,
28
- 'style:family' => (FAMILIES[opts[:family]] || opts[:family])}
26
+ 'style:family' => (FAMILIES[opts[:family].to_s] || opts[:family]),
27
+ }
28
+
29
29
  attrs['style:data-style-name'] = opts[:data_style] unless opts[:data_style].nil?
30
+
30
31
  attrs['style:parent-style-name'] = opts[:parent].to_s unless opts[:parent].nil?
32
+
31
33
  attrs['style:master-page-name'] = opts[:master_page] unless opts[:master_page].nil?
34
+
32
35
  attrs
33
36
  end
34
37
 
35
38
  def to_s
36
39
  @name
37
40
  end
41
+
42
+ def properties
43
+ @properties ||= []
44
+ end
45
+
46
+ def property(*args, &block)
47
+ x = Property.new(*args, &block)
48
+
49
+ properties << x
50
+
51
+ return x
52
+ end
53
+
54
+ def properties_xml
55
+ properties.map(&:xml).join
56
+ end
57
+
58
+ def add_properties(*elements)
59
+ if elements.first.is_a?(Array)
60
+ elements = elements.first
61
+ end
62
+
63
+ elements.each do |element|
64
+ property(element)
65
+ end
66
+ end
38
67
  end
39
68
 
40
69
  class OfficeStyle < Style
@@ -1,9 +1,8 @@
1
- require 'builder'
2
-
3
1
  module RODF
4
2
  class StyleSection
5
3
  def initialize(type, second = {})
6
4
  @type = type
5
+
7
6
  if second.instance_of?(Hash)
8
7
  @elem_attrs = make_element_attributes(second)
9
8
  else
@@ -19,9 +18,13 @@ module RODF
19
18
  attrs = {}
20
19
 
21
20
  attrs['number:decimal-places'] = opts[:decimal_places] unless opts[:decimal_places].nil?
21
+
22
22
  attrs['number:grouping'] = opts[:grouping] unless opts[:grouping].nil?
23
+
23
24
  attrs['number:min-integer-digits'] = opts[:min_integer_digits] unless opts[:min_integer_digits].nil?
25
+
24
26
  attrs['number:style'] = opts[:style] unless opts[:style].nil?
27
+
25
28
  attrs['number:textual'] = opts[:textual] unless opts[:textual].nil?
26
29
 
27
30
  attrs
data/lib/rodf/tab.rb CHANGED
@@ -1,7 +1,3 @@
1
- require 'builder'
2
-
3
- require_relative 'paragraph_container'
4
-
5
1
  module RODF
6
2
  class Tab
7
3
  def xml
@@ -12,7 +8,9 @@ module RODF
12
8
  class ParagraphContainer < Container
13
9
  def tab(*args)
14
10
  t = Tab.new
11
+
15
12
  content_parts << t
13
+
16
14
  t
17
15
  end
18
16
  end
data/lib/rodf/table.rb CHANGED
@@ -1,21 +1,43 @@
1
- require 'builder'
2
-
3
- require_relative 'column'
4
- require_relative 'container'
5
- require_relative 'row'
6
-
7
1
  module RODF
8
2
  class Table < Container
9
- contains :rows, :columns
10
-
11
- def initialize(title = nil)
3
+ def initialize(title = nil, opts ={})
12
4
  @title = title
5
+
13
6
  @last_row = 0
14
7
 
8
+ @elem_attrs = {}
9
+
10
+ @elem_attrs['table:style-name'] = opts[:style] unless opts[:style].nil?
11
+
12
+ @elem_attrs['table:name'] = @title
13
+
14
+ if opts[:attributes]
15
+ @elem_attrs.merge!(opts[:attributes])
16
+ end
17
+
15
18
  super
16
19
  end
17
20
 
18
- alias create_row row
21
+ def style=(style_name)
22
+ @elem_attrs['table:style-name'] = style_name
23
+ end
24
+
25
+ def rows
26
+ @rows ||= []
27
+ end
28
+
29
+ def create_row(*args, &block)
30
+ x = Row.new(*args, &block)
31
+
32
+ rows << x
33
+
34
+ return x
35
+ end
36
+
37
+ def rows_xml
38
+ rows.map(&:xml).join
39
+ end
40
+
19
41
  def row(options = {}, &contents)
20
42
  create_row(next_row, options) do |row|
21
43
  if contents
@@ -29,22 +51,45 @@ module RODF
29
51
  end
30
52
 
31
53
  def add_rows(*rows)
32
- rows = rows.first if rows.first.first.is_a?(Array)
54
+ if rows.first.first.is_a?(Array)
55
+ rows = rows.first
56
+ end
57
+
33
58
  rows.each do |row|
34
- created = self.row
35
- created.add_cells row
59
+ new_row = self.row
60
+
61
+ new_row.add_cells(row)
36
62
  end
37
63
  end
38
64
 
65
+ def columns
66
+ @columns ||= []
67
+ end
68
+
69
+ def column(options = {})
70
+ x = Column.new(options)
71
+
72
+ columns << x
73
+
74
+ return x
75
+ end
76
+
77
+ def columns_xml
78
+ columns.map(&:xml).join
79
+ end
80
+
39
81
  def xml
40
- Builder::XmlMarkup.new.table:table, 'table:name' => @title do |xml|
82
+ Builder::XmlMarkup.new.table :table, @elem_attrs do |xml|
41
83
  xml << columns_xml
42
84
  xml << rows_xml
43
85
  end
44
86
  end
45
- private
87
+
88
+ private
89
+
46
90
  def next_row
47
91
  @last_row += 1
48
92
  end
93
+
49
94
  end
50
95
  end
data/lib/rodf/text.rb CHANGED
@@ -1,40 +1,40 @@
1
- require 'builder'
2
-
3
- require_relative 'document'
4
- require_relative 'master_page'
5
- require_relative 'page_layout'
6
- require_relative 'paragraph'
7
- require_relative 'span'
8
- require_relative 'hyperlink'
9
-
10
1
  module RODF
11
2
  class Text < Document
12
- contains :paragraphs, :page_layouts, :master_pages
13
-
14
- alias :p :paragraph
15
-
16
3
  def xml
17
4
  b = Builder::XmlMarkup.new
18
5
 
19
6
  b.instruct! :xml, version: '1.0', encoding: 'UTF-8'
20
- b.tag! 'office:document-content', 'xmlns:office' => "urn:oasis:names:tc:opendocument:xmlns:office:1.0",
21
- 'xmlns:table' => "urn:oasis:names:tc:opendocument:xmlns:table:1.0",
22
- 'xmlns:text' => "urn:oasis:names:tc:opendocument:xmlns:text:1.0",
23
- 'xmlns:oooc' => "http://openoffice.org/2004/calc",
24
- 'xmlns:style' => "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
25
- 'xmlns:fo' => "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0",
26
- 'xmlns:xlink' => "http://www.w3.org/1999/xlink" do
27
- |xml|
28
- xml.tag! 'office:styles' do
29
- xml << default_styles_xml
30
- end unless default_styles.empty?
31
- xml.tag! 'office:automatic-styles' do
32
- xml << styles_xml
33
- xml << page_layouts_xml
34
- end unless styles.empty? && page_layouts.empty?
35
- xml.tag! 'office:master-styles' do
36
- xml << master_pages_xml
37
- end unless master_pages.empty?
7
+
8
+ attrs = {
9
+ 'xmlns:office' => "urn:oasis:names:tc:opendocument:xmlns:office:1.0",
10
+ 'xmlns:table' => "urn:oasis:names:tc:opendocument:xmlns:table:1.0",
11
+ 'xmlns:text' => "urn:oasis:names:tc:opendocument:xmlns:text:1.0",
12
+ 'xmlns:oooc' => "http://openoffice.org/2004/calc",
13
+ 'xmlns:style' => "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
14
+ 'xmlns:fo' => "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0",
15
+ 'xmlns:xlink' => "http://www.w3.org/1999/xlink",
16
+ }
17
+
18
+ b.tag! 'office:document-content', attrs do |xml|
19
+ unless default_styles.empty?
20
+ xml.tag! 'office:styles' do
21
+ xml << default_styles_xml
22
+ end
23
+ end
24
+
25
+ unless styles.empty? && page_layouts.empty?
26
+ xml.tag! 'office:automatic-styles' do
27
+ xml << styles_xml
28
+ xml << page_layouts_xml
29
+ end
30
+ end
31
+
32
+ unless master_pages.empty?
33
+ xml.tag! 'office:master-styles' do
34
+ xml << master_pages_xml
35
+ end
36
+ end
37
+
38
38
  xml.office:body do
39
39
  xml.office:text do
40
40
  xml << paragraphs_xml
@@ -42,5 +42,85 @@ module RODF
42
42
  end
43
43
  end
44
44
  end
45
+
46
+ def paragraphs
47
+ @paragraphs ||= []
48
+ end
49
+
50
+ def paragraph(*args, &block)
51
+ x = Paragraph.new(*args, &block)
52
+
53
+ paragraphs << x
54
+
55
+ return x
56
+ end
57
+ alias p paragraph
58
+
59
+ def paragraphs_xml
60
+ paragraphs.map(&:xml).join
61
+ end
62
+
63
+ def add_paragraphs(*elements)
64
+ if elements.first.is_a?(Array)
65
+ elements = elements.first
66
+ end
67
+
68
+ elements.each do |element|
69
+ paragraph(element)
70
+ end
71
+ end
72
+
73
+ def page_layouts
74
+ @page_layouts ||= []
75
+ end
76
+
77
+ def page_layout(*args, &block)
78
+ x = PageLayout.new(*args, &block)
79
+
80
+ page_layouts << x
81
+
82
+ return x
83
+ end
84
+
85
+ def page_layouts_xml
86
+ page_layouts.map(&:xml).join
87
+ end
88
+
89
+ def add_page_layouts(*elements)
90
+ if elements.first.is_a?(Array)
91
+ elements = elements.first
92
+ end
93
+
94
+ elements.each do |element|
95
+ page_layout(element)
96
+ end
97
+ end
98
+
99
+ def master_pages
100
+ @master_pages ||= []
101
+ end
102
+
103
+ def master_page(*args, &block)
104
+ x = MasterPage.new(*args, &block)
105
+
106
+ master_pages << x
107
+
108
+ return x
109
+ end
110
+
111
+ def master_pages_xml
112
+ master_pages.map(&:xml).join
113
+ end
114
+
115
+ def add_master_pages(*elements)
116
+ if elements.first.is_a?(Array)
117
+ elements = elements.first
118
+ end
119
+
120
+ elements.each do |element|
121
+ master_pages(element)
122
+ end
123
+ end
124
+
45
125
  end
46
126
  end
data/lib/rodf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RODF
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2.0'
3
3
  end
data/lib/rodf.rb CHANGED
@@ -1,5 +1,30 @@
1
1
  require 'builder'
2
- require_relative 'rodf/spreadsheet'
2
+ require 'zip'
3
+ require 'erb'
4
+
5
+ require 'rodf/version'
6
+
7
+ require 'rodf/container'
8
+ require 'rodf/document'
9
+ require 'rodf/paragraph_container'
10
+
11
+ require 'rodf/cell'
12
+ require 'rodf/column'
13
+ require 'rodf/data_style'
14
+ require 'rodf/hyperlink'
15
+ require 'rodf/master_page'
16
+ require 'rodf/page_layout'
17
+ require 'rodf/paragraph'
18
+ require 'rodf/property'
19
+ require 'rodf/row'
20
+ require 'rodf/skeleton'
21
+ require 'rodf/span'
22
+ require 'rodf/spreadsheet'
23
+ require 'rodf/style'
24
+ require 'rodf/style_section'
25
+ require 'rodf/table'
26
+ require 'rodf/tab'
27
+ require 'rodf/text'
3
28
 
4
29
  module RODF
5
30
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Weston Ganger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-01-31 00:00:00.000000000 Z
12
+ date: 2021-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder
@@ -25,20 +25,6 @@ dependencies:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '3.0'
28
- - !ruby/object:Gem::Dependency
29
- name: dry-inflector
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: '0.1'
35
- type: :runtime
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: '0.1'
42
28
  - !ruby/object:Gem::Dependency
43
29
  name: rubyzip
44
30
  requirement: !ruby/object:Gem::Requirement
@@ -138,7 +124,6 @@ files:
138
124
  - lib/rodf.rb
139
125
  - lib/rodf/cell.rb
140
126
  - lib/rodf/column.rb
141
- - lib/rodf/compatibility.rb
142
127
  - lib/rodf/container.rb
143
128
  - lib/rodf/data_style.rb
144
129
  - lib/rodf/document.rb
@@ -161,7 +146,8 @@ files:
161
146
  - lib/rodf/text.rb
162
147
  - lib/rodf/version.rb
163
148
  homepage: https://github.com/thiagoarrais/rodf
164
- licenses: []
149
+ licenses:
150
+ - MIT
165
151
  metadata: {}
166
152
  post_install_message:
167
153
  rdoc_options: []
@@ -178,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
164
  - !ruby/object:Gem::Version
179
165
  version: '0'
180
166
  requirements: []
181
- rubygems_version: 3.0.3
167
+ rubygems_version: 3.1.4
182
168
  signing_key:
183
169
  specification_version: 4
184
170
  summary: This is a library for writing to ODF output from Ruby. It mainly focuses
@@ -1,9 +0,0 @@
1
- require 'builder'
2
-
3
- if !String.method_defined? :to_xs
4
- class String
5
- def to_xs
6
- Builder::XChar.encode(self)
7
- end
8
- end
9
- end