documatic 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -17,11 +17,10 @@ Documatic can be installed via Rubygems.
17
17
 
18
18
  == Usage
19
19
 
20
- Documatic is a Ruport extension, so it is loaded like this:
20
+ You can load Documatic as a gem when your program is initialised:
21
21
 
22
22
  require 'rubygems'
23
- require 'ruport'
24
- require 'ruport/extensions'
23
+ require 'documatic'
25
24
 
26
25
  Documatic will then be available as a formatter for your Ruport
27
26
  tables, groups and groupings. Rendering using an OpenDocument text
@@ -43,7 +42,7 @@ tutorials to illustrate how text and spreadsheet rendering works.
43
42
 
44
43
  == Version
45
44
 
46
- 0.1.0, released 02-SEP-2007.
45
+ 0.2.0, released 26-APR-2008.
47
46
 
48
47
 
49
48
  == Licence
@@ -3,12 +3,10 @@ require 'erb'
3
3
  module Documatic
4
4
  class Component
5
5
  include ERB::Util
6
- include Documatic::OpenDocumentText::Helper
7
- include Documatic::OpenDocumentSpreadsheet::Helper
8
-
6
+
9
7
  attr_accessor :erb
10
8
  attr_accessor :erb_text
11
-
9
+
12
10
  def initialize(erb_text)
13
11
  @erb_text = erb_text
14
12
  @erb = ERB.new(erb_text)
@@ -58,15 +56,12 @@ module Documatic
58
56
  # <office:automatic-styles> of this component. This method isn't
59
57
  # intended to be called directly by client applications: it is
60
58
  # called automatically by Documatic::Template after processing.
61
- def merge_partial_styles
62
- cache = Documatic::OpenDocumentText::Partial.cache_by_prefix
63
- if cache.length > 0
64
- styles = self.xml.root.elements['office:automatic-styles']
65
- if styles
66
- cache.each_value do |partial|
67
- partial.styles.each_element do |e|
68
- styles << e
69
- end
59
+ def merge_partial_styles(partials)
60
+ styles = self.xml.root.elements['office:automatic-styles']
61
+ if styles
62
+ partials.each do |partial|
63
+ partial.styles.each_element do |e|
64
+ styles << e
70
65
  end
71
66
  end
72
67
  end
@@ -1,7 +1,8 @@
1
1
  require 'fileutils'
2
2
  require 'ruport'
3
3
 
4
- module Documatic::Formatter
4
+ module Documatic
5
+ module Formatter
5
6
 
6
7
  class OpenDocumentText < Ruport::Formatter
7
8
  class << self
@@ -9,21 +10,24 @@ module Documatic::Formatter
9
10
  end
10
11
 
11
12
  self.processor = Documatic::OpenDocumentText::Template
12
- renders :odt_template, :for => [ Ruport::Renderer::Table, Ruport::Renderer::Group,
13
- Ruport::Renderer::Grouping ]
13
+ renders :odt_template, :for => [ Ruport::Controller::Table,
14
+ Ruport::Controller::Group,
15
+ Ruport::Controller::Grouping ]
14
16
 
15
17
  def build
16
18
  self.class.processor.process_template(:data => data, :options => options)
17
19
  end
18
- alias_method :build_table_body, :build # for Ruport::Renderer::Table
19
- alias_method :build_group_body, :build # for Ruport::Renderer::Group
20
- alias_method :build_grouping_body, :build # for Ruport::Renderer::Grouping
20
+ alias_method :build_table_body, :build # for Ruport::Controller::Table
21
+ alias_method :build_group_body, :build # for Ruport::Controller::Group
22
+ alias_method :build_grouping_body, :build # for Ruport::Controller::Grouping
21
23
  end
22
24
 
23
25
  class OpenDocumentSpreadsheet < OpenDocumentText
24
26
  self.processor = Documatic::OpenDocumentSpreadsheet::Template
25
- renders :ods_template, :for => [ Ruport::Renderer::Table, Ruport::Renderer::Group,
26
- Ruport::Renderer::Grouping ]
27
+ renders :ods_template, :for => [ Ruport::Controller::Table,
28
+ Ruport::Controller::Group,
29
+ Ruport::Controller::Grouping ]
27
30
  end
28
-
29
- end # module Documatic::Formatter
31
+
32
+ end # module Formatter
33
+ end # module Documatic
@@ -1,4 +1,2 @@
1
- class RuportDocumaticLoader < GemPlugin::Plugin "/ruport/documatic"
2
- require 'documatic'
3
- require 'documatic/formatter/open_document'
4
- end
1
+ require 'documatic'
2
+
@@ -0,0 +1,5 @@
1
+ module Documatic::OpenDocumentSpreadsheet
2
+ class Component < Documatic::Component
3
+ include Documatic::OpenDocumentSpreadsheet::Helper
4
+ end
5
+ end
@@ -26,28 +26,15 @@ module Documatic::OpenDocumentSpreadsheet
26
26
  TYPE = 2
27
27
  ERB_CODE = 3
28
28
  ROW_END = 4
29
-
30
- class << self
31
-
32
- # Includes the number and text helpers from Rails' ActionPack.
33
- # Requires that the Rails gems be installed.
34
- def include_rails_helpers
35
- require 'action_pack'
36
- require 'action_controller'
37
- require 'action_view'
38
-
39
- require 'action_view/helpers/number_helper'
40
- require 'action_view/helpers/text_helper'
41
-
42
- self.class_eval do
43
- include ActionView::Helpers::NumberHelper
44
- include ActionView::Helpers::TextHelper
45
- end
46
29
 
47
- end
30
+ # Abbrevs
31
+ DSC = Documatic::OpenDocumentSpreadsheet::Component
32
+
33
+ class << self
48
34
 
49
35
  def process_template(args, &block)
50
- if args[:options] && args[:options].template_file && args[:options].output_file
36
+ if args[:options] && args[:options].template_file &&
37
+ args[:options].output_file
51
38
  output_dir = File.dirname(args[:options].output_file)
52
39
  File.directory?(output_dir) || FileUtils.mkdir_p(output_dir)
53
40
  FileUtils.cp(args[:options].template_file, args[:options].output_file)
@@ -60,7 +47,8 @@ module Documatic::OpenDocumentSpreadsheet
60
47
  end
61
48
  template.close
62
49
  else
63
- raise ArgumentError, 'Need to specify both :template_file and :output_file in options'
50
+ raise ArgumentError,
51
+ 'Need to specify both :template_file and :output_file in options'
64
52
  end
65
53
  end
66
54
 
@@ -76,14 +64,13 @@ module Documatic::OpenDocumentSpreadsheet
76
64
  # Compile this template, if not compiled already.
77
65
  self.jar.find_entry('documatic/master') || self.compile
78
66
  # Process the main (body) content.
79
- @content = Documatic::Component.new( self.jar.read('documatic/master/content.erb') )
67
+ @content = DSC.new( self.jar.read('documatic/master/content.erb') )
80
68
  @content.process(local_assigns)
81
- @content.merge_partial_styles
82
69
  end
83
70
 
84
71
  def save
85
- # Gather all the styles from the partials, add them to the master's styles.
86
- # Put the body into the document.
72
+ # Gather all the styles from the partials, add them to the
73
+ # master's styles. Put the body into the document.
87
74
  self.jar.get_output_stream('content.xml') do |f|
88
75
  f.write self.content.to_s
89
76
  end
@@ -99,7 +86,8 @@ module Documatic::OpenDocumentSpreadsheet
99
86
  @content_erb = self.erbify(@content_raw)
100
87
 
101
88
  # Create 'documatic/master/' in zip file
102
- self.jar.find_entry('documatic/master') || self.jar.mkdir('documatic/master')
89
+ self.jar.find_entry('documatic/master') ||
90
+ self.jar.mkdir('documatic/master')
103
91
 
104
92
  self.jar.get_output_stream('documatic/master/content.erb') do |f|
105
93
  f.write @content_erb
@@ -109,7 +97,8 @@ module Documatic::OpenDocumentSpreadsheet
109
97
 
110
98
  protected
111
99
 
112
- # Change OpenDocument line breaks and tabs in the ERb code to regular characters.
100
+ # Change OpenDocument line breaks and tabs in the ERb code to
101
+ # regular characters.
113
102
  def unnormalize(code)
114
103
  code = code.gsub(/<text:line-break\/>/, "\n")
115
104
  code = code.gsub(/<text:tab\/>/, "\t")
@@ -120,7 +109,8 @@ module Documatic::OpenDocumentSpreadsheet
120
109
  def erbify(code)
121
110
  # First gather all the ERb-related derived styles
122
111
  remaining = code
123
- styles = {'Ruby_20_Code' => 'Code', 'Ruby_20_Value' => 'Value', 'Ruby_20_Literal' => 'Literal'}
112
+ styles = {'Ruby_20_Code' => 'Code', 'Ruby_20_Value' => 'Value',
113
+ 'Ruby_20_Literal' => 'Literal'}
124
114
  re_styles = /<style:style style:name="([^"]+)" style:parent-style-name="Ruby_20_(Code|Value|Literal)" style:family="table-cell">/
125
115
 
126
116
  while remaining.length > 0
@@ -147,9 +137,6 @@ module Documatic::OpenDocumentSpreadsheet
147
137
  # "?": optional, might not occur every time
148
138
  re_erb = /(<table:table-row[^>]*>)?<table:table-cell [^>]*table:style-name="(#{styles.keys.join '|'})"[^>]*><text:p>([^<]*)<\/text:p><\/table:table-cell>(((<table:covered-table-cell[^\/>]*\/>)|(<table:table-cell[^\/>]*\/>))*<\/table:table-row>)?/
149
139
 
150
- # The text one:
151
- # re_erb = /(<table:table-row[^>]*>)?<table:table-cell [^>]+>)?(<text:list-item>)?(<text:p [^>]+>)?(<\/text:span>)?<text:span text:style-name="(#{styles.keys.join '|'})">(([^<]*|<text:line-break\/>|<text:tab\/>)+)<\/text:span>(<text:span [^>]+>)?(<\/text:p>)?(<\/text:list-item>)?(<\/table:table-cell>(<table:covered-table-cell\/>)*<\/table:table-row>)?/
152
-
153
140
  # Then search for all text using those styles
154
141
  while remaining.length > 0
155
142
 
@@ -215,13 +202,15 @@ module Documatic::OpenDocumentSpreadsheet
215
202
  def regularise_styles(content_raw)
216
203
  doc = REXML::Document.new(content_raw)
217
204
 
218
- # Get the default column types from all the sheets (tables) in the workbook
205
+ # Get the default column types from all the sheets (tables) in
206
+ # the workbook
219
207
  num_tables = doc.root.elements.to_a('//office:body/*/table:table').length
220
208
  (1 .. num_tables).to_a.each do |tnum|
221
209
  col_types = []
222
210
  cols = doc.root.elements.to_a("//table:table[#{tnum}]/table:table-column")
223
211
  cols.each do |col|
224
- (0 ... (col.attributes['table:number-columns-repeated'] || 1).to_i).to_a.each do
212
+ (0 ... (col.attributes['table:number-columns-repeated'] ||
213
+ 1).to_i).to_a.each do
225
214
  col_types << col.attributes['table:default-cell-style-name']
226
215
  end
227
216
  end # each column
@@ -231,20 +220,24 @@ module Documatic::OpenDocumentSpreadsheet
231
220
 
232
221
  # Go through each row and process its cells
233
222
  (1 .. num_rows).to_a.each do |rnum|
234
- # The cells are both <table:table-cell> and <table:covered-table-cell>
223
+ # The cells are both <table:table-cell> and
224
+ # <table:covered-table-cell>
235
225
  cells = doc.root.elements.to_a(<<-END
236
226
  //table:table[#{tnum}]/table:table-row[#{rnum}]/(table:table-cell | table:covered-table-cell)
237
227
  END
238
228
  )
239
- # Keep track of the column number, for formatting purposes (c.f. col_types)
229
+ # Keep track of the column number, for formatting purposes
230
+ # (c.f. col_types)
240
231
  col_num = 0
241
232
  cells.each do |cell|
242
233
  # Only need to explicitly format the <table:table-cell>s
243
234
  if cell.name == 'table-cell'
244
235
  cell.attributes['table:style-name'] ||= col_types[col_num]
245
236
  end
246
- # Advance the column number, based on the columns spanned by the cell
247
- col_num += (cell.attributes['table:number-columns-repeated'] || 1).to_i
237
+ # Advance the column number, based on the columns spanned
238
+ # by the cell
239
+ col_num += (cell.attributes['table:number-columns-repeated'] ||
240
+ 1).to_i
248
241
  end
249
242
 
250
243
  end # each row
@@ -253,6 +246,5 @@ END
253
246
  return doc.to_s
254
247
  end
255
248
 
256
-
257
249
  end
258
250
  end
@@ -0,0 +1,5 @@
1
+ module Documatic::OpenDocumentText
2
+ class Component < Documatic::Component
3
+ include Documatic::OpenDocumentText::Helper
4
+ end
5
+ end
@@ -51,16 +51,31 @@ module Documatic
51
51
  # This method will add the provided partial to the
52
52
  # Documatic::Partial cache if it hasn't yet been loaded; or if it
53
53
  # has been loaded then the existing partial will be re-used.
54
- def partial(filename, *assigns)
55
- if Documatic::OpenDocumentText::Partial.cache.has_key?(filename)
56
- p = Documatic::OpenDocumentText::Partial.cache[filename]
54
+ def partial(filename, assigns = {})
55
+ if template.partials.has_key?(filename)
56
+ p = template.partials[filename]
57
57
  else
58
58
  p = Documatic::OpenDocumentText::Partial.new(filename)
59
- Documatic::OpenDocumentText::Partial.add_partial(filename, p)
59
+ template.add_partial(filename, p)
60
60
  end
61
- p.process(*assigns)
61
+ assigns.merge!(:template => template, :master => master)
62
+ p.process(assigns)
62
63
  end
63
64
 
65
+ # Insert a reference to an image file with the minimal set of options
66
+ # (:width and :height in centimetres).
67
+ def image(full_path, opts = {})
68
+ image_name = template.add_image(full_path)
69
+ output = '<draw:frame text:anchor-type="as-char" '
70
+ opts[:width] && output << %Q(svg:width="#{opts[:width]}cm" )
71
+ opts[:height] && output << %Q(svg:height="#{opts[:height]}cm")
72
+ output << '>'
73
+ output << %Q(<draw:image xlink:href="Pictures/#{image_name}" )
74
+ output <<
75
+ 'xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>'
76
+ output << '</draw:frame>'
77
+ end
78
+
64
79
  end
65
80
  end
66
81
  end
@@ -36,7 +36,7 @@ module Documatic::OpenDocumentText
36
36
 
37
37
  def process(local_assigns = {})
38
38
  self.jar.find_entry('documatic/partial') || self.compile
39
- @content = Documatic::Component.new( self.content_erb )
39
+ @content = Documatic::OpenDocumentText::Component.new( self.content_erb )
40
40
  @content.process(local_assigns)
41
41
  end
42
42
 
@@ -50,7 +50,8 @@ module Documatic::OpenDocumentText
50
50
  attr && style_names[attr.value] = attr
51
51
  end
52
52
 
53
- # Replace all auto styles in the document's attributes with the prefixed form.
53
+ # Replace all auto styles in the document's attributes with the
54
+ # prefixed form.
54
55
  doc.each_element('//*') do |e|
55
56
  e.attributes.each_attribute do |attr|
56
57
  if style_names.has_key? attr.value
@@ -60,7 +61,8 @@ module Documatic::OpenDocumentText
60
61
  end
61
62
 
62
63
  # Create 'documatic/partial/' in zip file
63
- self.jar.find_entry('documatic/partial') || self.jar.mkdir('documatic/partial')
64
+ self.jar.find_entry('documatic/partial') ||
65
+ self.jar.mkdir('documatic/partial')
64
66
 
65
67
  # Save the prefix in documatic/partial.txt
66
68
  self.jar.get_output_stream('documatic/partial/partial.txt') do |f|
@@ -73,18 +75,22 @@ module Documatic::OpenDocumentText
73
75
  f.write @styles.to_s
74
76
  end
75
77
 
76
- # Get body text, erbify it, keep it in @content and save it in documatic/content.erb
78
+ # Get body text, erbify it, keep it in @content and save it in
79
+ # documatic/content.erb
77
80
  body_text = doc.root.elements['office:body/office:text']
78
81
  body_text.elements.delete('text:sequence-decls')
79
82
  body_text.elements.delete('office:forms')
80
- @content_erb = self.erbify( (body_text.elements.to_a.collect do |e| e.to_s ; end ).join("\n") )
83
+ @content_erb = self.erbify( (body_text.elements.to_a.collect do |e|
84
+ e.to_s ;
85
+ end ).join("\n") )
81
86
  self.jar.get_output_stream('documatic/partial/content.erb') do |f|
82
87
  f.write @content_erb
83
88
  end
84
89
 
85
90
  end
86
91
 
87
- # Partials aren't saved in the same way that templates are: this is a no-op.
92
+ # Partials aren't saved in the same way that templates are: this
93
+ # is a no-op.
88
94
  def save ; end
89
95
 
90
96
  def prefix
@@ -92,7 +98,8 @@ module Documatic::OpenDocumentText
92
98
  if self.jar.find_entry('documatic/partial/partial.txt')
93
99
  @prefix = self.jar.read('documatic/partial/partial.txt')
94
100
  else
95
- @prefix = File.basename(self.filename, '.odt').gsub(/[^A-Za-z0-9_]/, '_')
101
+ @prefix = File.basename(self.filename, '.odt').gsub(/[^A-Za-z0-9_]/,
102
+ '_')
96
103
  end
97
104
  end
98
105
  return @prefix
@@ -1,4 +1,3 @@
1
- #require 'rexml/text'
2
1
  require 'rexml/document'
3
2
  require 'rexml/attribute'
4
3
  require 'zip/zip'
@@ -8,9 +7,16 @@ require 'fileutils'
8
7
  module Documatic::OpenDocumentText
9
8
  class Template
10
9
  include ERB::Util
11
-
10
+
11
+ # The template's content component. This is an instance of
12
+ # Documatic::Component, instantiated from the compiled (embedded
13
+ # Ruby) version of 'content.xml'.
12
14
  attr_accessor :content
15
+ # The template's styles component. This is an instance of
16
+ # Documatic::Component, instantiated from the compiled (embedded
17
+ # Ruby) version of 'styles.xml'.
13
18
  attr_accessor :styles
19
+ # The template's JAR file (i.e. an instance of Zip::ZipFile)
14
20
  attr_accessor :jar
15
21
  # The raw contents of 'content.xml'.
16
22
  attr_accessor :content_raw
@@ -47,33 +53,35 @@ module Documatic::OpenDocumentText
47
53
  INLINE_CODE = 3
48
54
  VALUE = 4
49
55
 
56
+ # Abbrevs
57
+ DTC = Documatic::OpenDocumentText::Component
58
+
50
59
  class << self
51
-
52
- # Includes the number and text helpers from Rails' ActionPack.
53
- # Requires that the Rails gems be installed.
54
- def include_rails_helpers
55
- require 'action_pack'
56
- require 'action_controller'
57
- require 'action_view'
58
-
59
- require 'action_view/helpers/number_helper'
60
- require 'action_view/helpers/text_helper'
61
-
62
- [self, Documatic::OpenDocumentText::Partial].each do |klass|
63
- klass.class_eval do
64
- include ActionView::Helpers::NumberHelper
65
- include ActionView::Helpers::TextHelper
66
- end
67
- end
68
- end
69
-
60
+ # Process a template and save it to an output file.
61
+ #
62
+ # The argument is a hash with the keys :options and :data.
63
+ # :options should contain an object that responds to
64
+ # #template_file and #output_file. #template_file is the path
65
+ # and filename to the OpenDocument template to be used;
66
+ # #output_file is where the processed results will be stored.
67
+ # The #template_file must exist, and the #output_file path must
68
+ # either exist or the current process must be able to create it.
69
+ #
70
+ # An optional block can be provided to this method. The block
71
+ # will be passed the template currently being processed (i.e. an
72
+ # instance of Documatic::OpenDocumentText::Template). The block
73
+ # can peform manipulation of the template directly by
74
+ # e.g. accessing the template's JAR or the content or styles
75
+ # components. The template will be saved after the block exits.
70
76
  def process_template(args, &block)
71
- if args[:options] && args[:options].template_file && args[:options].output_file
77
+ if args[:options] && args[:options].template_file &&
78
+ args[:options].output_file
72
79
  output_dir = File.dirname(args[:options].output_file)
73
80
  File.directory?(output_dir) || FileUtils.mkdir_p(output_dir)
74
81
  FileUtils.cp(args[:options].template_file, args[:options].output_file)
75
82
  template = self.new(args[:options].output_file)
76
- template.process :data => args[:data], :options => args[:options]
83
+ template.process :data => args[:data], :options => args[:options],
84
+ :template => template, :master => template
77
85
  template.save
78
86
  if block
79
87
  block.call(template)
@@ -98,12 +106,23 @@ module Documatic::OpenDocumentText
98
106
  self.jar.find_entry('documatic/master') || self.compile
99
107
  # Process the styles (incl. headers and footers).
100
108
  # This is conditional because partials don't need styles.erb.
101
- @styles = Documatic::Component.new( self.jar.read('documatic/master/styles.erb') )
109
+ @styles = DTC.new(self.jar.read('documatic/master/styles.erb') )
102
110
  @styles.process(local_assigns)
103
111
  # Process the main (body) content.
104
- @content = Documatic::Component.new( self.jar.read('documatic/master/content.erb') )
112
+ @content = DTC.new( self.jar.read('documatic/master/content.erb') )
105
113
  @content.process(local_assigns)
106
- @content.merge_partial_styles
114
+ # Merge styles from any partials into the main template
115
+ if self.partials.keys.length > 0
116
+ @content.merge_partial_styles(self.partials.values)
117
+ end
118
+ # Copy any images into this jar
119
+ if images.length > 0
120
+ self.jar.find_entry('Pictures') || self.jar.mkdir('Pictures')
121
+ images.keys.each do |filename|
122
+ path = images.delete(filename)
123
+ self.jar.add("Pictures/#{filename}", path)
124
+ end
125
+ end
107
126
  end
108
127
 
109
128
  def save
@@ -143,7 +162,39 @@ module Documatic::OpenDocumentText
143
162
  end
144
163
  end
145
164
 
165
+ # Returns a hash of images added during the processing of the
166
+ # current template. (This method is not intended to be called
167
+ # directly by application developers: it is used indirectly by
168
+ # the #image helper to add images from within an OpenDocument
169
+ # template.)
170
+ def images
171
+ @images ||= Hash.new
172
+ end
173
+
174
+ # Add an image to the current template. The argument is the
175
+ # path and filename of the image to be added to the template.
176
+ # This can be an absolute path or a relative path to the current
177
+ # directory. Returns the basename of file if it exists;
178
+ # otherwise an ArgumentError exception is raised.
179
+ def add_image(full_path)
180
+ if File.exists?(full_path)
181
+ image = File.basename(full_path)
182
+ self.images[image] = full_path
183
+ return image
184
+ else
185
+ raise ArgumentError, 'Attempted to add non-existent image to template'
186
+ end
187
+ end
146
188
 
189
+ def partials
190
+ @partials ||= Hash.new
191
+ end
192
+
193
+ def add_partial(full_path, partial)
194
+ self.partials[full_path] = partial
195
+ end
196
+
197
+
147
198
  protected
148
199
 
149
200
  def pretty_xml(filename)
data/lib/documatic.rb CHANGED
@@ -1,9 +1,14 @@
1
+ require 'ruport'
2
+
3
+ require 'documatic/component'
1
4
  require 'documatic/open_document_text/helper'
5
+ require 'documatic/open_document_text/component'
2
6
  require 'documatic/open_document_text/template'
3
- require 'documatic/open_document_spreadsheet/template'
4
- require 'documatic/open_document_spreadsheet/helper'
5
- require 'documatic/component'
6
7
  require 'documatic/open_document_text/partial'
8
+ require 'documatic/open_document_spreadsheet/helper'
9
+ require 'documatic/open_document_spreadsheet/component'
10
+ require 'documatic/open_document_spreadsheet/template'
11
+ require 'documatic/formatter/open_document'
7
12
 
8
13
  # The module "Documatic" is the namespace for the other modules and
9
14
  # classes in this project. It also contains some convenience methods.
@@ -11,17 +16,30 @@ module Documatic
11
16
  class << self
12
17
 
13
18
  # Short-cut method for including a helper in
14
- # Documatic::Component (the ERb processor).
19
+ # Documatic::OpenDocumentText::Component (the ERb processor).
20
+ # This is the 'old' method that pre-dates the spreadsheet
21
+ # component -- that's why it only adds the helper to the text
22
+ # component.
15
23
  def add_helper(helper_module)
16
- Documatic::Component.class_eval do
17
- include helper_module
18
- end
24
+ Documatic::OpenDocumentText::Component.send(:include, helper_module)
25
+ end
26
+
27
+ # Short-cut method for including a helper in
28
+ # Documatic::OpenDocumentText::Component.
29
+ def text_helper(helper_module)
30
+ add_helper helper_module
31
+ end
32
+
33
+ # Short-cut method for including a helper in
34
+ # Documatic::OpenDocumentSpreadsheet::Component.
35
+ def spreadsheet_helper(helper_module)
36
+ Documatic::OpenDocumentSpreadsheet::Component.send(:include,
37
+ helper_module)
19
38
  end
20
39
 
21
40
  end # class << self
22
41
  end
23
42
 
24
-
25
43
  # Force REXML to use double-quotes (consistent with OOo).
26
44
  REXML::Attribute.class_eval do
27
45
  def to_string
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: documatic
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2007-09-02 00:00:00 +10:00
6
+ version: 0.2.0
7
+ date: 2008-04-26 00:00:00 +10:00
8
8
  summary: Documatic is an OpenDocument extension for Ruby Reports (Ruport). It is a template-driven formatter that can be used to produce attractive printable documents such as database reports, invoices, letters, faxes and more.
9
9
  require_paths:
10
10
  - lib
@@ -37,9 +37,11 @@ files:
37
37
  - lib/documatic/formatter/open_document.rb
38
38
  - lib/documatic/init.rb
39
39
  - lib/documatic/open_document_spreadsheet/
40
+ - lib/documatic/open_document_spreadsheet/component.rb
40
41
  - lib/documatic/open_document_spreadsheet/helper.rb
41
42
  - lib/documatic/open_document_spreadsheet/template.rb
42
43
  - lib/documatic/open_document_text/
44
+ - lib/documatic/open_document_text/component.rb
43
45
  - lib/documatic/open_document_text/helper.rb
44
46
  - lib/documatic/open_document_text/partial.rb
45
47
  - lib/documatic/open_document_text/template.rb
@@ -69,15 +71,6 @@ dependencies:
69
71
  - !ruby/object:Gem::Version
70
72
  version: 0.9.1
71
73
  version:
72
- - !ruby/object:Gem::Dependency
73
- name: gem_plugin
74
- version_requirement:
75
- version_requirements: !ruby/object:Gem::Version::Requirement
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: 0.2.2
80
- version:
81
74
  - !ruby/object:Gem::Dependency
82
75
  name: ruport
83
76
  version_requirement:
@@ -85,5 +78,5 @@ dependencies:
85
78
  requirements:
86
79
  - - ">="
87
80
  - !ruby/object:Gem::Version
88
- version: 1.2.0
81
+ version: 1.6.0
89
82
  version: