sandrods-odf-report 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -66,9 +66,14 @@ end
66
66
  and considering you have a table like this in your template
67
67
 
68
68
  <pre>
69
- ----------------------------
70
- | [ITEM_ID] | [DESCRIPTON] |
71
- ----------------------------
69
+ ---------------------------------
70
+ | [ITEM_ID] | [DESCRIPTION] |
71
+ ---------------------------------
72
+
73
+ * this is my lame attempt to draw a table.
74
+ you don't suppose to type this.
75
+ you have to use an actual table.
76
+ i don't know... just thought I'd mention it ;-)
72
77
  </pre>
73
78
 
74
79
  and a collection @list_of_itens, it will be created one row for each item in the collection, and the replacement will take place accordingly.
@@ -88,6 +93,8 @@ In a controller, you can have a code like this:
88
93
  <pre>
89
94
  def print
90
95
 
96
+ @ticket = Ticket.find(params[:id])
97
+
91
98
  report = ODFReport.new("#{RAILS_ROOT}/app/reports/ticket.odt") do |r|
92
99
 
93
100
  r.add_field(:id, @ticket.id.to_s)
@@ -148,3 +155,10 @@ h3. REQUIREMENTS
148
155
  *rubyzip*: for manipulating the contents of the odt file, since it's actually a zip file.
149
156
 
150
157
 
158
+ <hr/>
159
+
160
+ h3. THE FUTURE
161
+
162
+ Well, this is my first attempt. This gem was extracted from an actual project we developed internally, to fulfill our specific needs.
163
+
164
+ That said, I would really appreciate any input you can come up with. Critics, suggestions, bug reports are welcome and will be thoroughly examined.
data/lib/odf-report.rb CHANGED
@@ -154,7 +154,7 @@ private
154
154
 
155
155
  def hash_gsub!(_text, hash_of_values)
156
156
  hash_of_values.each do |key, val|
157
- _text.gsub!("[#{key.to_s.upcase}]", val.to_s) unless val.nil?
157
+ _text.gsub!("[#{key.to_s.upcase}]", html_escape(val)) unless val.nil?
158
158
  end
159
159
  end
160
160
 
@@ -171,4 +171,11 @@ private
171
171
  nil
172
172
  end
173
173
 
174
+ HTML_ESCAPE = { '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;' }
175
+
176
+ def html_escape(s)
177
+ return "" unless s
178
+ s.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] }
179
+ end
180
+
174
181
  end
data/odf-report.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{odf-report}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sandro Duarte"]
data/test/test.rb CHANGED
@@ -1,21 +1,21 @@
1
1
  require '../lib/odf-report'
2
2
 
3
3
  col1 = []
4
- col1 << {:nome=>"Campo zero um", :id=>"Campo dois", :ender=>"tres tres"}
5
- col1 << {:nome=>"zero um", :id=>"dois", :ender=>"tres"}
6
- col1 << {:nome=>"Campo um", :id=>"Campo erthe dois", :ender=>"tres tres tres"}
4
+ col1 << {:nome=>"name 01", :id=>"01", :ender=>"this is address 01"}
5
+ col1 << {:nome=>"name 03", :id=>"03", :ender=>"this is address 03"}
6
+ col1 << {:nome=>"name 02", :id=>"02", :ender=>"this is address 02"}
7
7
 
8
8
  col2 = []
9
- col2 << {:nome=>"Campo zero um", :id=>"Campo dois", :ender=>"tres tres", :fone=>99025668, :cep=>"90420-002"}
10
- col2 << {:nome=>"sandro", :id=>"45", :ender=>"minha casa", :fone=>88774451, :cep=>"90490-002"}
11
- col2 << {:nome=>"ellen bicca", :id=>"77", :ender=>"casa dela", :fone=>77025668, :cep=>"94420-002"}
9
+ col2 << {:nome=>"josh harnet", :id=>"02", :ender=>"testing <&> ", :fone=>99025668, :cep=>"90420-002"}
10
+ col2 << {:nome=>"sandro", :id=>"45", :ender=>"address with &", :fone=>88774451, :cep=>"90490-002"}
11
+ col2 << {:nome=>"ellen bicca", :id=>"77", :ender=>"<address with escaped html>", :fone=>77025668, :cep=>"94420-002"}
12
12
 
13
13
  report = ODFReport.new("test.odt") do |r|
14
14
 
15
- r.add_field("CAMPO_CAB", "Este campo estava no cabecalho")
15
+ r.add_field("CAMPO_CAB", "This field was in the HEADER")
16
16
 
17
- r.add_field("TAG_01", "Nova tag")
18
- r.add_field("TAG_02", "TAG-2 -> Nova tag")
17
+ r.add_field("TAG_01", "New tag")
18
+ r.add_field("TAG_02", "TAG-2 -> New tag")
19
19
 
20
20
  r.add_table("TABELA_01", col1) do |row, item|
21
21
  row["CAMPO_01"] = item[:id]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sandrods-odf-report
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Duarte
@@ -44,7 +44,6 @@ files:
44
44
  - Manifest
45
45
  has_rdoc: true
46
46
  homepage: ""
47
- licenses:
48
47
  post_install_message:
49
48
  rdoc_options:
50
49
  - --line-numbers
@@ -70,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
69
  requirements: []
71
70
 
72
71
  rubyforge_project: odf-report
73
- rubygems_version: 1.3.5
72
+ rubygems_version: 1.2.0
74
73
  signing_key:
75
74
  specification_version: 2
76
75
  summary: Generates ODF files, given a template (.odt) and data, replacing tags