to_spreadsheet 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c7bb1fac67822b9d246906d3969e7edd895cf312
4
+ data.tar.gz: 7d4ff08a4596f79467489561eb82c18547e7e87b
5
+ SHA512:
6
+ metadata.gz: 15cdd95363abc3f088e80fac952e5d6485772cf622c7f479a22f10503328b95a148d43a50ef823b727714f9b8d10e9dedda04c6ac226c4109d934d866460472f
7
+ data.tar.gz: 050ad9400c2843ae6cd023dc2530a02747d510b04b3e5f06647cbf0f9a6f4a224a44f249692a2980f575e4d1347811a24d6c1701ffaa871b913c3ebeda3f034a
data/README.textile CHANGED
@@ -1,4 +1,4 @@
1
- to_spreadsheet is a gem that lets you render xls from your existing haml/erb views from Rails (>= 3.0). !https://secure.travis-ci.org/glebm/to_spreadsheet.png?branch=master(Build Status)!:http://travis-ci.org/glebm/to_spreadsheet
1
+ to_spreadsheet is a gem that lets you render xls from your existing slim/haml/erb/etc views from Rails (>= 3.0). !https://secure.travis-ci.org/glebm/to_spreadsheet.png?branch=master(Build Status)!:http://travis-ci.org/glebm/to_spreadsheet
2
2
 
3
3
  h2. Installation
4
4
 
@@ -74,6 +74,24 @@ bc. format_xls 'table.my-table' do
74
74
  For the full list of supported properties head here: http://rubydoc.info/github/randym/axlsx/Axlsx/Styles#add_style-instance_method
75
75
  In addition, for column formats, Axlsx columnInfo properties are also supported
76
76
 
77
+ h3. Advanced formatting
78
+
79
+ to_spreadsheet "associates":https://github.com/glebm/to_spreadsheet/blob/master/lib/to_spreadsheet/renderer.rb#L33 HTML nodes with Axlsx objects as follows:
80
+
81
+ |_. HTML tag |_. Axlsx object |
82
+ | table | worksheet |
83
+ | tr | row |
84
+ | td, th | cell |
85
+
86
+ For example, to directly manipulate a worksheet:
87
+
88
+ bc. format_xls do
89
+ format 'table' do |worksheet|
90
+ worksheet.add_chart ...
91
+ # to get the associated Nokogiri node:
92
+ el = context.to_xml_node(worksheet)
93
+
94
+
77
95
  h3. Themes
78
96
 
79
97
  You can define "themes" - blocks of formatting code:
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  require 'rubygems'
3
- require 'bundler/setup'
3
+ require 'bundler/gem_tasks'
4
4
 
5
5
  require 'rake'
6
6
  require 'rdoc/task'
@@ -20,4 +20,4 @@ task :write_test_xlsx => :env do
20
20
  html = Haml::Engine.new(File.read('spec/support/table.html.haml')).render
21
21
  ToSpreadsheet::Renderer.to_package(html).serialize(path)
22
22
  puts "Written to #{path}"
23
- end
23
+ end
@@ -68,8 +68,14 @@ module ToSpreadsheet
68
68
  # format 'A1:C30', b: true
69
69
  # Accepted properties: http://rubydoc.info/github/randym/axlsx/Axlsx/Cell
70
70
  # column format also accepts Axlsx columnInfo settings
71
- def format(selector = nil, options)
72
- options = options.dup
71
+ def format(selector = nil, options, &block)
72
+ if !selector && options.is_a?(String)
73
+ selector = options
74
+ options = nil
75
+ else
76
+ options = options.dup
77
+ end
78
+ options ||= block
73
79
  selector = selector_query(selector, options)
74
80
  add_rule :format, *selector, options
75
81
  end
@@ -127,4 +133,4 @@ module ToSpreadsheet
127
133
  [nil, nil]
128
134
  end
129
135
  end
130
- end
136
+ end
@@ -54,4 +54,4 @@ module ToSpreadsheet
54
54
  end
55
55
  end
56
56
  end
57
- end
57
+ end
@@ -57,7 +57,9 @@ module ToSpreadsheet
57
57
  end
58
58
 
59
59
  def css_match(css_selector, xml_node, &block)
60
- xml_node.css(css_selector).each(&block)
60
+ result = xml_node.css(css_selector)
61
+ block.call(xml_node) if xml_node.matches?(css_selector)
62
+ result.each(&block)
61
63
  end
62
64
 
63
65
  def css_match?(css_selector, xml_document, xml_node)
@@ -86,4 +88,4 @@ module ToSpreadsheet
86
88
  pos[0] >= top_left[0] && pos[0] <= bot_right[0] && pos[1] >= top_left[1] && pos[1] <= bot_right[1]
87
89
  end
88
90
  end
89
- end
91
+ end
@@ -1,3 +1,3 @@
1
1
  module ToSpreadsheet
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
data/spec/format_spec.rb CHANGED
@@ -7,6 +7,9 @@ describe ToSpreadsheet::Rule::Format do
7
7
  format_xls do
8
8
  format column: 0, width: 25
9
9
  format 'tr', fg_color: lambda { |row| 'cccccc' if row.index.odd? }
10
+ format 'table' do |ws|
11
+ ws.name = 'Test'
12
+ end
10
13
  end
11
14
  %table
12
15
  %tr
@@ -22,11 +25,14 @@ describe ToSpreadsheet::Rule::Format do
22
25
  it 'sets column width' do
23
26
  sheet.column_info[0].width.should == 25
24
27
  end
25
- it 'runs lambdas' do
28
+ it 'runs lambdas on properties' do
26
29
  cell = sheet.rows[1].cells[0]
27
30
  styles = sheet.workbook.styles
28
31
  font_id = styles.cellXfs[cell.style].fontId
29
32
  styles.fonts[font_id].color.rgb.should == Axlsx::Color.new(rgb: 'cccccc').rgb
30
33
  end
34
+ it 'runs blocks for selectors' do
35
+ sheet.name.should == 'Test'
36
+ end
31
37
  end
32
38
  end
metadata CHANGED
@@ -1,113 +1,100 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_spreadsheet
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.0.3
4
+ version: 1.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Gleb Mazovetskiy
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-14 00:00:00.000000000 Z
11
+ date: 2013-06-26 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
- version_requirements: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
15
  requirement: !ruby/object:Gem::Requirement
23
- none: false
24
16
  requirements:
25
- - - ! '>='
17
+ - - '>='
26
18
  - !ruby/object:Gem::Version
27
19
  version: '0'
28
20
  type: :runtime
29
21
  prerelease: false
30
- - !ruby/object:Gem::Dependency
31
- name: nokogiri
32
22
  version_requirements: !ruby/object:Gem::Requirement
33
- none: false
34
23
  requirements:
35
- - - ! '>='
24
+ - - '>='
36
25
  - !ruby/object:Gem::Version
37
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
38
29
  requirement: !ruby/object:Gem::Requirement
39
- none: false
40
30
  requirements:
41
- - - ! '>='
31
+ - - '>='
42
32
  - !ruby/object:Gem::Version
43
33
  version: '0'
44
34
  type: :runtime
45
35
  prerelease: false
46
- - !ruby/object:Gem::Dependency
47
- name: axlsx
48
36
  version_requirements: !ruby/object:Gem::Requirement
49
- none: false
50
37
  requirements:
51
- - - ! '>='
38
+ - - '>='
52
39
  - !ruby/object:Gem::Version
53
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: axlsx
54
43
  requirement: !ruby/object:Gem::Requirement
55
- none: false
56
44
  requirements:
57
- - - ! '>='
45
+ - - '>='
58
46
  - !ruby/object:Gem::Version
59
47
  version: '0'
60
48
  type: :runtime
61
49
  prerelease: false
62
- - !ruby/object:Gem::Dependency
63
- name: chronic
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
- none: false
66
51
  requirements:
67
- - - ! '>='
52
+ - - '>='
68
53
  - !ruby/object:Gem::Version
69
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: chronic
70
57
  requirement: !ruby/object:Gem::Requirement
71
- none: false
72
58
  requirements:
73
- - - ! '>='
59
+ - - '>='
74
60
  - !ruby/object:Gem::Version
75
61
  version: '0'
76
62
  type: :runtime
77
63
  prerelease: false
78
- - !ruby/object:Gem::Dependency
79
- name: mocha
80
64
  version_requirements: !ruby/object:Gem::Requirement
81
- none: false
82
65
  requirements:
83
- - - ! '>='
66
+ - - '>='
84
67
  - !ruby/object:Gem::Version
85
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: haml-rails
86
71
  requirement: !ruby/object:Gem::Requirement
87
- none: false
88
72
  requirements:
89
- - - ! '>='
73
+ - - '>='
90
74
  - !ruby/object:Gem::Version
91
75
  version: '0'
92
76
  type: :development
93
77
  prerelease: false
94
- - !ruby/object:Gem::Dependency
95
- name: sqlite3-ruby
96
78
  version_requirements: !ruby/object:Gem::Requirement
97
- none: false
98
79
  requirements:
99
- - - ! '>='
80
+ - - '>='
100
81
  - !ruby/object:Gem::Version
101
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-rails
102
85
  requirement: !ruby/object:Gem::Requirement
103
- none: false
104
86
  requirements:
105
- - - ! '>='
87
+ - - '>='
106
88
  - !ruby/object:Gem::Version
107
89
  version: '0'
108
90
  type: :development
109
91
  prerelease: false
110
- description: Rendering spreadsheets from Rails made easy
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Render XLSX from Rails using existing views ( .*.html => .xlsx )
111
98
  email: glex.spb@gmail.com
112
99
  executables: []
113
100
  extensions: []
@@ -142,27 +129,26 @@ files:
142
129
  - spec/worksheets_spec.rb
143
130
  homepage: https://github.com/glebm/to_spreadsheet
144
131
  licenses: []
132
+ metadata: {}
145
133
  post_install_message:
146
134
  rdoc_options: []
147
135
  require_paths:
148
136
  - lib
149
137
  required_ruby_version: !ruby/object:Gem::Requirement
150
- none: false
151
138
  requirements:
152
- - - ! '>='
139
+ - - '>='
153
140
  - !ruby/object:Gem::Version
154
141
  version: '0'
155
142
  required_rubygems_version: !ruby/object:Gem::Requirement
156
- none: false
157
143
  requirements:
158
- - - ! '>='
144
+ - - '>='
159
145
  - !ruby/object:Gem::Version
160
146
  version: '0'
161
147
  requirements: []
162
148
  rubyforge_project:
163
- rubygems_version: 1.8.25
149
+ rubygems_version: 2.0.3
164
150
  signing_key:
165
- specification_version: 3
151
+ specification_version: 4
166
152
  summary: Render existing views as Excel documents with style!
167
153
  test_files:
168
154
  - spec/defaults_spec.rb