decisive 0.6.1 → 0.7.1
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +23 -0
- data/lib/decisive/template_handler.rb +77 -6
- data/lib/decisive/version.rb +1 -1
- metadata +3 -6
- data/gemfiles/rails_5.1.gemfile.lock +0 -93
- data/gemfiles/rails_5.2.gemfile.lock +0 -93
- data/gemfiles/rails_6.0.gemfile.lock +0 -95
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ca9f98c729ce8368e606d9e9d83da4e2a574807af3490c3f73a7203950ce585
|
4
|
+
data.tar.gz: 9cf78cb8f9720de00574f0171bf77324862a262646d8f3d40b5c7f36187d2d0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f3d41825e1c28901ff15d740de4c56e00e742a1e0080290fdb80cb367540fc6546c1be9d0c0aa747f27a1a3c6a3743123a6aa9b1c9a505243131acee7e53dbd
|
7
|
+
data.tar.gz: 140f98ccc7ddbfaf046b4af54f87fa571b80c9cdf86a599b92c51c7724ebcdbeb9db46c3e3cb6b57f22422e2b06a911004f42f714d541ed0fee5718a71afb9f7
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -92,6 +92,29 @@ class ReportController < ApplicationController
|
|
92
92
|
end
|
93
93
|
```
|
94
94
|
|
95
|
+
## Gotchas
|
96
|
+
|
97
|
+
Sometimes the streaming templates will hang in test mode. This could be because `action_controller/test_case` has been loaded, which monkeypatches AC::Live in a way that seems to breaks things. If you are running into this, try this workaround (cucumber example):
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
# features/support/fix_ac_live.rb
|
101
|
+
# requiring cucumber/rails requires rails/test_help which requires action_controller/test_case which redefines AC::Live#new_controller_thread to be single threaded, which breaks our downloads
|
102
|
+
# set it back to original method definition
|
103
|
+
|
104
|
+
module ActionController
|
105
|
+
module Live
|
106
|
+
silence_redefinition_of_method :new_controller_thread
|
107
|
+
def new_controller_thread # :nodoc:
|
108
|
+
Thread.new {
|
109
|
+
t2 = Thread.current
|
110
|
+
t2.abort_on_exception = true
|
111
|
+
yield
|
112
|
+
}
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
```
|
117
|
+
|
95
118
|
## Development
|
96
119
|
|
97
120
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -11,8 +11,7 @@ module Decisive
|
|
11
11
|
|
12
12
|
def self.call template, source=template.source
|
13
13
|
<<~RUBY
|
14
|
-
extend Decisive::DSL
|
15
|
-
context = (#{source})
|
14
|
+
extend Decisive::DSL; context = (#{source})
|
16
15
|
|
17
16
|
response.headers["Content-Transfer-Encoding"] = "binary"
|
18
17
|
response.headers["Content-Disposition"] = %(attachment; filename="\#{context.filename}")
|
@@ -25,7 +24,6 @@ module Decisive
|
|
25
24
|
context.each do |row|
|
26
25
|
response.stream.write row.to_csv(force_quotes: true)
|
27
26
|
end
|
28
|
-
raise if Rails.env.test? # WTF WTF without this the stream isn't closed in test mode??? WTF WTF
|
29
27
|
ensure
|
30
28
|
response.stream.close
|
31
29
|
end
|
@@ -65,11 +63,75 @@ module Decisive
|
|
65
63
|
end
|
66
64
|
end
|
67
65
|
|
68
|
-
def xls worksheets, filename:, &block
|
69
|
-
|
66
|
+
def xls worksheets=nil, filename:, &block
|
67
|
+
if worksheets
|
68
|
+
XLSContext.new(worksheets, filename, block)
|
69
|
+
else
|
70
|
+
XLSWithWorksheetsContext.new(filename, [], &block)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class XLSWithWorksheetsContext < Struct.new(:filename, :worksheets)
|
76
|
+
class Worksheet < Struct.new(:records, :name, :block); end
|
77
|
+
|
78
|
+
def initialize *args, &block
|
79
|
+
super
|
80
|
+
instance_eval &block
|
81
|
+
end
|
82
|
+
|
83
|
+
def to_xls
|
84
|
+
to_string(render(Spreadsheet::Workbook.new))
|
85
|
+
end
|
86
|
+
|
87
|
+
def csv?
|
88
|
+
false
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def worksheet records, name:, &block
|
94
|
+
worksheets.push Worksheet.new(records, name, block)
|
95
|
+
end
|
96
|
+
|
97
|
+
def render xls
|
98
|
+
worksheets.each do |worksheet|
|
99
|
+
sheet = xls.create_worksheet(name: sanitize_name(worksheet.name))
|
100
|
+
|
101
|
+
rows = to_array(worksheet)
|
102
|
+
|
103
|
+
rows.each.with_index do |row, index|
|
104
|
+
sheet.row(index).concat row
|
105
|
+
end
|
106
|
+
end
|
107
|
+
xls
|
108
|
+
end
|
109
|
+
|
110
|
+
def sanitize_name name
|
111
|
+
name
|
112
|
+
.gsub(/[\[\]\*\?:\/\\\t\n\r]/, " ")
|
113
|
+
.gsub(/^'/, "")
|
114
|
+
.gsub(/'$/, "")
|
115
|
+
.strip
|
116
|
+
.slice(0,31)
|
117
|
+
end
|
118
|
+
|
119
|
+
def to_array worksheet
|
120
|
+
context = RenderContext.new(worksheet.records, nil, worksheet.block)
|
121
|
+
context.send(:header) + context.send(:body)
|
122
|
+
end
|
123
|
+
|
124
|
+
def to_string xls
|
125
|
+
io = StringIO.new
|
126
|
+
xls.write(io)
|
127
|
+
io.rewind
|
128
|
+
string = io.read
|
129
|
+
string.force_encoding(Encoding::ASCII_8BIT)
|
130
|
+
string
|
70
131
|
end
|
71
132
|
end
|
72
133
|
|
134
|
+
|
73
135
|
class XLSContext < Struct.new(:worksheets, :filename, :block)
|
74
136
|
def to_xls
|
75
137
|
to_string(render(Spreadsheet::Workbook.new))
|
@@ -83,7 +145,7 @@ module Decisive
|
|
83
145
|
|
84
146
|
def render xls
|
85
147
|
worksheets.each do |name, enumerable|
|
86
|
-
sheet = xls.create_worksheet(name: name)
|
148
|
+
sheet = xls.create_worksheet(name: sanitize_name(name))
|
87
149
|
|
88
150
|
rows = to_array(enumerable)
|
89
151
|
|
@@ -94,6 +156,15 @@ module Decisive
|
|
94
156
|
xls
|
95
157
|
end
|
96
158
|
|
159
|
+
def sanitize_name name
|
160
|
+
name
|
161
|
+
.gsub(/[\[\]\*\?:\/\\\t\n\r]/, " ")
|
162
|
+
.gsub(/^'/, "")
|
163
|
+
.gsub(/'$/, "")
|
164
|
+
.strip
|
165
|
+
.slice(0,31)
|
166
|
+
end
|
167
|
+
|
97
168
|
def to_array records
|
98
169
|
context = RenderContext.new(records, nil, block)
|
99
170
|
context.send(:header) + context.send(:body)
|
data/lib/decisive/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decisive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Micah Geisel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -130,11 +130,8 @@ files:
|
|
130
130
|
- decisive.gemspec
|
131
131
|
- gemfiles/.bundle/config
|
132
132
|
- gemfiles/rails_5.1.gemfile
|
133
|
-
- gemfiles/rails_5.1.gemfile.lock
|
134
133
|
- gemfiles/rails_5.2.gemfile
|
135
|
-
- gemfiles/rails_5.2.gemfile.lock
|
136
134
|
- gemfiles/rails_6.0.gemfile
|
137
|
-
- gemfiles/rails_6.0.gemfile.lock
|
138
135
|
- lib/decisive.rb
|
139
136
|
- lib/decisive/template_handler.rb
|
140
137
|
- lib/decisive/version.rb
|
@@ -157,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
154
|
- !ruby/object:Gem::Version
|
158
155
|
version: '0'
|
159
156
|
requirements: []
|
160
|
-
rubygems_version: 3.0.
|
157
|
+
rubygems_version: 3.0.8
|
161
158
|
signing_key:
|
162
159
|
specification_version: 4
|
163
160
|
summary: DSL for rendering CSVs
|
@@ -1,93 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: ..
|
3
|
-
specs:
|
4
|
-
decisive (0.6.0)
|
5
|
-
actionview
|
6
|
-
spreadsheet
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
actionview (5.1.0)
|
12
|
-
activesupport (= 5.1.0)
|
13
|
-
builder (~> 3.1)
|
14
|
-
erubi (~> 1.4)
|
15
|
-
rails-dom-testing (~> 2.0)
|
16
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
17
|
-
activesupport (5.1.0)
|
18
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
|
-
i18n (~> 0.7)
|
20
|
-
minitest (~> 5.1)
|
21
|
-
tzinfo (~> 1.1)
|
22
|
-
appraisal (2.2.0)
|
23
|
-
bundler
|
24
|
-
rake
|
25
|
-
thor (>= 0.14.0)
|
26
|
-
builder (3.2.3)
|
27
|
-
byebug (11.0.1)
|
28
|
-
concurrent-ruby (1.1.5)
|
29
|
-
crass (1.0.4)
|
30
|
-
diff-lcs (1.3)
|
31
|
-
erubi (1.8.0)
|
32
|
-
i18n (0.9.5)
|
33
|
-
concurrent-ruby (~> 1.0)
|
34
|
-
loofah (2.2.3)
|
35
|
-
crass (~> 1.0.2)
|
36
|
-
nokogiri (>= 1.5.9)
|
37
|
-
mini_portile2 (2.4.0)
|
38
|
-
minitest (5.11.3)
|
39
|
-
nokogiri (1.10.4)
|
40
|
-
mini_portile2 (~> 2.4.0)
|
41
|
-
rails-dom-testing (2.0.3)
|
42
|
-
activesupport (>= 4.2.0)
|
43
|
-
nokogiri (>= 1.6)
|
44
|
-
rails-html-sanitizer (1.2.0)
|
45
|
-
loofah (~> 2.2, >= 2.2.2)
|
46
|
-
rake (12.3.3)
|
47
|
-
roo (2.8.3)
|
48
|
-
nokogiri (~> 1)
|
49
|
-
rubyzip (>= 1.3.0, < 3.0.0)
|
50
|
-
roo-xls (1.2.0)
|
51
|
-
nokogiri
|
52
|
-
roo (>= 2.0.0, < 3)
|
53
|
-
spreadsheet (> 0.9.0)
|
54
|
-
rspec (3.8.0)
|
55
|
-
rspec-core (~> 3.8.0)
|
56
|
-
rspec-expectations (~> 3.8.0)
|
57
|
-
rspec-mocks (~> 3.8.0)
|
58
|
-
rspec-core (3.8.2)
|
59
|
-
rspec-support (~> 3.8.0)
|
60
|
-
rspec-expectations (3.8.4)
|
61
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
-
rspec-support (~> 3.8.0)
|
63
|
-
rspec-mocks (3.8.1)
|
64
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
-
rspec-support (~> 3.8.0)
|
66
|
-
rspec-support (3.8.2)
|
67
|
-
ruby-ole (1.2.12.2)
|
68
|
-
rubyzip (2.3.0)
|
69
|
-
simple-spreadsheet (0.5.0)
|
70
|
-
roo (~> 2.4)
|
71
|
-
roo-xls (~> 1.0)
|
72
|
-
spreadsheet (1.2.6)
|
73
|
-
ruby-ole (>= 1.0)
|
74
|
-
thor (0.20.3)
|
75
|
-
thread_safe (0.3.6)
|
76
|
-
tzinfo (1.2.5)
|
77
|
-
thread_safe (~> 0.1)
|
78
|
-
|
79
|
-
PLATFORMS
|
80
|
-
ruby
|
81
|
-
|
82
|
-
DEPENDENCIES
|
83
|
-
actionview (= 5.1)
|
84
|
-
appraisal
|
85
|
-
bundler
|
86
|
-
byebug
|
87
|
-
decisive!
|
88
|
-
rake
|
89
|
-
rspec (~> 3.0)
|
90
|
-
simple-spreadsheet
|
91
|
-
|
92
|
-
BUNDLED WITH
|
93
|
-
2.0.2
|
@@ -1,93 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: ..
|
3
|
-
specs:
|
4
|
-
decisive (0.6.0)
|
5
|
-
actionview
|
6
|
-
spreadsheet
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
actionview (5.2.0)
|
12
|
-
activesupport (= 5.2.0)
|
13
|
-
builder (~> 3.1)
|
14
|
-
erubi (~> 1.4)
|
15
|
-
rails-dom-testing (~> 2.0)
|
16
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
17
|
-
activesupport (5.2.0)
|
18
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
|
-
i18n (>= 0.7, < 2)
|
20
|
-
minitest (~> 5.1)
|
21
|
-
tzinfo (~> 1.1)
|
22
|
-
appraisal (2.2.0)
|
23
|
-
bundler
|
24
|
-
rake
|
25
|
-
thor (>= 0.14.0)
|
26
|
-
builder (3.2.3)
|
27
|
-
byebug (11.0.1)
|
28
|
-
concurrent-ruby (1.1.5)
|
29
|
-
crass (1.0.4)
|
30
|
-
diff-lcs (1.3)
|
31
|
-
erubi (1.8.0)
|
32
|
-
i18n (1.6.0)
|
33
|
-
concurrent-ruby (~> 1.0)
|
34
|
-
loofah (2.2.3)
|
35
|
-
crass (~> 1.0.2)
|
36
|
-
nokogiri (>= 1.5.9)
|
37
|
-
mini_portile2 (2.4.0)
|
38
|
-
minitest (5.11.3)
|
39
|
-
nokogiri (1.10.4)
|
40
|
-
mini_portile2 (~> 2.4.0)
|
41
|
-
rails-dom-testing (2.0.3)
|
42
|
-
activesupport (>= 4.2.0)
|
43
|
-
nokogiri (>= 1.6)
|
44
|
-
rails-html-sanitizer (1.2.0)
|
45
|
-
loofah (~> 2.2, >= 2.2.2)
|
46
|
-
rake (12.3.3)
|
47
|
-
roo (2.8.3)
|
48
|
-
nokogiri (~> 1)
|
49
|
-
rubyzip (>= 1.3.0, < 3.0.0)
|
50
|
-
roo-xls (1.2.0)
|
51
|
-
nokogiri
|
52
|
-
roo (>= 2.0.0, < 3)
|
53
|
-
spreadsheet (> 0.9.0)
|
54
|
-
rspec (3.8.0)
|
55
|
-
rspec-core (~> 3.8.0)
|
56
|
-
rspec-expectations (~> 3.8.0)
|
57
|
-
rspec-mocks (~> 3.8.0)
|
58
|
-
rspec-core (3.8.2)
|
59
|
-
rspec-support (~> 3.8.0)
|
60
|
-
rspec-expectations (3.8.4)
|
61
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
-
rspec-support (~> 3.8.0)
|
63
|
-
rspec-mocks (3.8.1)
|
64
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
-
rspec-support (~> 3.8.0)
|
66
|
-
rspec-support (3.8.2)
|
67
|
-
ruby-ole (1.2.12.2)
|
68
|
-
rubyzip (2.3.0)
|
69
|
-
simple-spreadsheet (0.5.0)
|
70
|
-
roo (~> 2.4)
|
71
|
-
roo-xls (~> 1.0)
|
72
|
-
spreadsheet (1.2.6)
|
73
|
-
ruby-ole (>= 1.0)
|
74
|
-
thor (0.20.3)
|
75
|
-
thread_safe (0.3.6)
|
76
|
-
tzinfo (1.2.5)
|
77
|
-
thread_safe (~> 0.1)
|
78
|
-
|
79
|
-
PLATFORMS
|
80
|
-
ruby
|
81
|
-
|
82
|
-
DEPENDENCIES
|
83
|
-
actionview (= 5.2)
|
84
|
-
appraisal
|
85
|
-
bundler
|
86
|
-
byebug
|
87
|
-
decisive!
|
88
|
-
rake
|
89
|
-
rspec (~> 3.0)
|
90
|
-
simple-spreadsheet
|
91
|
-
|
92
|
-
BUNDLED WITH
|
93
|
-
2.0.2
|
@@ -1,95 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: ..
|
3
|
-
specs:
|
4
|
-
decisive (0.6.0)
|
5
|
-
actionview
|
6
|
-
spreadsheet
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
actionview (6.0.0)
|
12
|
-
activesupport (= 6.0.0)
|
13
|
-
builder (~> 3.1)
|
14
|
-
erubi (~> 1.4)
|
15
|
-
rails-dom-testing (~> 2.0)
|
16
|
-
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
17
|
-
activesupport (6.0.0)
|
18
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
|
-
i18n (>= 0.7, < 2)
|
20
|
-
minitest (~> 5.1)
|
21
|
-
tzinfo (~> 1.1)
|
22
|
-
zeitwerk (~> 2.1, >= 2.1.8)
|
23
|
-
appraisal (2.2.0)
|
24
|
-
bundler
|
25
|
-
rake
|
26
|
-
thor (>= 0.14.0)
|
27
|
-
builder (3.2.3)
|
28
|
-
byebug (11.0.1)
|
29
|
-
concurrent-ruby (1.1.5)
|
30
|
-
crass (1.0.4)
|
31
|
-
diff-lcs (1.3)
|
32
|
-
erubi (1.8.0)
|
33
|
-
i18n (1.6.0)
|
34
|
-
concurrent-ruby (~> 1.0)
|
35
|
-
loofah (2.2.3)
|
36
|
-
crass (~> 1.0.2)
|
37
|
-
nokogiri (>= 1.5.9)
|
38
|
-
mini_portile2 (2.4.0)
|
39
|
-
minitest (5.11.3)
|
40
|
-
nokogiri (1.10.4)
|
41
|
-
mini_portile2 (~> 2.4.0)
|
42
|
-
rails-dom-testing (2.0.3)
|
43
|
-
activesupport (>= 4.2.0)
|
44
|
-
nokogiri (>= 1.6)
|
45
|
-
rails-html-sanitizer (1.2.0)
|
46
|
-
loofah (~> 2.2, >= 2.2.2)
|
47
|
-
rake (12.3.3)
|
48
|
-
roo (2.8.3)
|
49
|
-
nokogiri (~> 1)
|
50
|
-
rubyzip (>= 1.3.0, < 3.0.0)
|
51
|
-
roo-xls (1.2.0)
|
52
|
-
nokogiri
|
53
|
-
roo (>= 2.0.0, < 3)
|
54
|
-
spreadsheet (> 0.9.0)
|
55
|
-
rspec (3.8.0)
|
56
|
-
rspec-core (~> 3.8.0)
|
57
|
-
rspec-expectations (~> 3.8.0)
|
58
|
-
rspec-mocks (~> 3.8.0)
|
59
|
-
rspec-core (3.8.2)
|
60
|
-
rspec-support (~> 3.8.0)
|
61
|
-
rspec-expectations (3.8.4)
|
62
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
63
|
-
rspec-support (~> 3.8.0)
|
64
|
-
rspec-mocks (3.8.1)
|
65
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
66
|
-
rspec-support (~> 3.8.0)
|
67
|
-
rspec-support (3.8.2)
|
68
|
-
ruby-ole (1.2.12.2)
|
69
|
-
rubyzip (2.3.0)
|
70
|
-
simple-spreadsheet (0.5.0)
|
71
|
-
roo (~> 2.4)
|
72
|
-
roo-xls (~> 1.0)
|
73
|
-
spreadsheet (1.2.6)
|
74
|
-
ruby-ole (>= 1.0)
|
75
|
-
thor (0.20.3)
|
76
|
-
thread_safe (0.3.6)
|
77
|
-
tzinfo (1.2.5)
|
78
|
-
thread_safe (~> 0.1)
|
79
|
-
zeitwerk (2.1.9)
|
80
|
-
|
81
|
-
PLATFORMS
|
82
|
-
ruby
|
83
|
-
|
84
|
-
DEPENDENCIES
|
85
|
-
actionview (= 6.0)
|
86
|
-
appraisal
|
87
|
-
bundler
|
88
|
-
byebug
|
89
|
-
decisive!
|
90
|
-
rake
|
91
|
-
rspec (~> 3.0)
|
92
|
-
simple-spreadsheet
|
93
|
-
|
94
|
-
BUNDLED WITH
|
95
|
-
2.0.2
|