rodf 0.3.7 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +77 -0
  3. data/LICENSE +7 -0
  4. data/README.md +244 -64
  5. data/Rakefile +9 -17
  6. data/lib/rodf/cell.rb +171 -0
  7. data/lib/rodf/column.rb +21 -0
  8. data/lib/rodf/container.rb +18 -0
  9. data/lib/rodf/data_style.rb +46 -0
  10. data/lib/rodf/document.rb +133 -0
  11. data/lib/rodf/hyperlink.rb +33 -0
  12. data/lib/rodf/master_page.rb +11 -0
  13. data/lib/rodf/page_layout.rb +41 -0
  14. data/lib/rodf/paragraph.rb +28 -0
  15. data/lib/rodf/paragraph_container.rb +30 -0
  16. data/lib/rodf/property.rb +138 -0
  17. data/lib/rodf/row.rb +56 -0
  18. data/lib/{odf → rodf}/skeleton/manifest.xml.erb +0 -0
  19. data/lib/{odf → rodf}/skeleton/styles.pxml +0 -0
  20. data/lib/rodf/skeleton.rb +17 -0
  21. data/lib/rodf/span.rb +45 -0
  22. data/lib/rodf/spreadsheet.rb +113 -0
  23. data/lib/rodf/style.rb +77 -0
  24. data/lib/rodf/style_section.rb +33 -0
  25. data/lib/rodf/tab.rb +17 -0
  26. data/lib/rodf/table.rb +95 -0
  27. data/lib/rodf/text.rb +126 -0
  28. data/lib/rodf/version.rb +3 -0
  29. data/lib/rodf.rb +31 -0
  30. metadata +76 -115
  31. data/CHANGELOG +0 -17
  32. data/Gemfile +0 -9
  33. data/LICENSE.LGPL +0 -166
  34. data/Manifest +0 -48
  35. data/lib/odf/cell.rb +0 -104
  36. data/lib/odf/column.rb +0 -33
  37. data/lib/odf/compatibility.rb +0 -25
  38. data/lib/odf/container.rb +0 -57
  39. data/lib/odf/data_style.rb +0 -45
  40. data/lib/odf/document.rb +0 -67
  41. data/lib/odf/hyperlink.rb +0 -51
  42. data/lib/odf/master_page.rb +0 -33
  43. data/lib/odf/page_layout.rb +0 -39
  44. data/lib/odf/paragraph.rb +0 -46
  45. data/lib/odf/paragraph_container.rb +0 -35
  46. data/lib/odf/property.rb +0 -131
  47. data/lib/odf/row.rb +0 -44
  48. data/lib/odf/skeleton.rb +0 -34
  49. data/lib/odf/span.rb +0 -70
  50. data/lib/odf/spreadsheet.rb +0 -64
  51. data/lib/odf/style.rb +0 -65
  52. data/lib/odf/style_section.rb +0 -42
  53. data/lib/odf/tab.rb +0 -38
  54. data/lib/odf/table.rb +0 -50
  55. data/lib/odf/text.rb +0 -66
  56. data/rodf.gemspec +0 -48
  57. data/spec/cell_spec.rb +0 -189
  58. data/spec/data_style_spec.rb +0 -61
  59. data/spec/file_storage_spec.rb +0 -47
  60. data/spec/hyperlink_spec.rb +0 -62
  61. data/spec/master_page_spec.rb +0 -35
  62. data/spec/page_layout_spec.rb +0 -45
  63. data/spec/paragraph_spec.rb +0 -75
  64. data/spec/property_spec.rb +0 -270
  65. data/spec/row_spec.rb +0 -59
  66. data/spec/skeleton_spec.rb +0 -33
  67. data/spec/span_spec.rb +0 -65
  68. data/spec/spec_helper.rb +0 -23
  69. data/spec/spreadsheet_spec.rb +0 -123
  70. data/spec/style_section_spec.rb +0 -42
  71. data/spec/style_spec.rb +0 -109
  72. data/spec/tab_spec.rb +0 -34
  73. data/spec/table_spec.rb +0 -90
  74. data/spec/text_spec.rb +0 -79
@@ -0,0 +1,113 @@
1
+ module RODF
2
+ class Spreadsheet < Document
3
+ def xml
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
+
33
+ xml.office:body do
34
+ xml.office:spreadsheet do
35
+ xml << tables_xml
36
+ end
37
+ end
38
+ end
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
110
+ end
111
+
112
+ SpreadSheet = Spreadsheet
113
+ end
data/lib/rodf/style.rb ADDED
@@ -0,0 +1,77 @@
1
+ module RODF
2
+ class Style < Container
3
+ FAMILIES = {
4
+ "cell" => 'table-cell',
5
+ "column" => 'table-column',
6
+ "row" => 'table-row',
7
+ }
8
+
9
+ def initialize(name='', opts={}, node_tag='style:style')
10
+ super
11
+
12
+ @name, @node_tag = name, node_tag
13
+
14
+ @elem_attrs = make_element_attributes(@name, opts)
15
+ end
16
+
17
+ def xml
18
+ Builder::XmlMarkup.new.tag!(@node_tag, @elem_attrs) do |xml|
19
+ xml << properties_xml
20
+ end
21
+ end
22
+
23
+ def make_element_attributes(name, opts)
24
+ attrs = {
25
+ 'style:name' => name,
26
+ 'style:family' => (FAMILIES[opts[:family].to_s] || opts[:family]),
27
+ }
28
+
29
+ attrs['style:data-style-name'] = opts[:data_style] unless opts[:data_style].nil?
30
+
31
+ attrs['style:parent-style-name'] = opts[:parent].to_s unless opts[:parent].nil?
32
+
33
+ attrs['style:master-page-name'] = opts[:master_page] unless opts[:master_page].nil?
34
+
35
+ attrs
36
+ end
37
+
38
+ def to_s
39
+ @name
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
67
+ end
68
+
69
+ class OfficeStyle < Style
70
+ end
71
+
72
+ class DefaultStyle < Style
73
+ def initialize(opts={})
74
+ super(nil, opts, 'style:default-style')
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,33 @@
1
+ module RODF
2
+ class StyleSection
3
+ def initialize(type, second = {})
4
+ @type = type
5
+
6
+ if second.instance_of?(Hash)
7
+ @elem_attrs = make_element_attributes(second)
8
+ else
9
+ @content, @elem_attrs = second, {}
10
+ end
11
+ end
12
+
13
+ def xml
14
+ Builder::XmlMarkup.new.number @type, @content, @elem_attrs
15
+ end
16
+
17
+ def make_element_attributes(opts)
18
+ attrs = {}
19
+
20
+ attrs['number:decimal-places'] = opts[:decimal_places] unless opts[:decimal_places].nil?
21
+
22
+ attrs['number:grouping'] = opts[:grouping] unless opts[:grouping].nil?
23
+
24
+ attrs['number:min-integer-digits'] = opts[:min_integer_digits] unless opts[:min_integer_digits].nil?
25
+
26
+ attrs['number:style'] = opts[:style] unless opts[:style].nil?
27
+
28
+ attrs['number:textual'] = opts[:textual] unless opts[:textual].nil?
29
+
30
+ attrs
31
+ end
32
+ end
33
+ end
data/lib/rodf/tab.rb ADDED
@@ -0,0 +1,17 @@
1
+ module RODF
2
+ class Tab
3
+ def xml
4
+ Builder::XmlMarkup.new.text:tab
5
+ end
6
+ end
7
+
8
+ class ParagraphContainer < Container
9
+ def tab(*args)
10
+ t = Tab.new
11
+
12
+ content_parts << t
13
+
14
+ t
15
+ end
16
+ end
17
+ end
data/lib/rodf/table.rb ADDED
@@ -0,0 +1,95 @@
1
+ module RODF
2
+ class Table < Container
3
+ def initialize(title = nil, opts ={})
4
+ @title = title
5
+
6
+ @last_row = 0
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
+
18
+ super
19
+ end
20
+
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
+
41
+ def row(options = {}, &contents)
42
+ create_row(next_row, options) do |row|
43
+ if contents
44
+ if contents.arity.zero?
45
+ row.instance_exec(row, &contents)
46
+ else
47
+ yield(row)
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ def add_rows(*rows)
54
+ if rows.first.first.is_a?(Array)
55
+ rows = rows.first
56
+ end
57
+
58
+ rows.each do |row|
59
+ new_row = self.row
60
+
61
+ new_row.add_cells(row)
62
+ end
63
+ end
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
+
81
+ def xml
82
+ Builder::XmlMarkup.new.table :table, @elem_attrs do |xml|
83
+ xml << columns_xml
84
+ xml << rows_xml
85
+ end
86
+ end
87
+
88
+ private
89
+
90
+ def next_row
91
+ @last_row += 1
92
+ end
93
+
94
+ end
95
+ end
data/lib/rodf/text.rb ADDED
@@ -0,0 +1,126 @@
1
+ module RODF
2
+ class Text < Document
3
+ def xml
4
+ b = Builder::XmlMarkup.new
5
+
6
+ b.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: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
+ xml.office:body do
39
+ xml.office:text do
40
+ xml << paragraphs_xml
41
+ end
42
+ end
43
+ end
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
+
125
+ end
126
+ end
@@ -0,0 +1,3 @@
1
+ module RODF
2
+ VERSION = '1.2.0'
3
+ end
data/lib/rodf.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'builder'
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'
28
+
29
+ module RODF
30
+
31
+ end