spreadsheet_architect 1.4.8 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -2
  3. data/README.md +117 -98
  4. data/Rakefile +8 -1
  5. data/lib/generators/spreadsheet_architect/add_project_defaults_generator.rb +12 -3
  6. data/lib/spreadsheet_architect.rb +19 -330
  7. data/lib/spreadsheet_architect/action_controller_renderers.rb +9 -19
  8. data/lib/spreadsheet_architect/class_methods/csv.rb +22 -0
  9. data/lib/spreadsheet_architect/class_methods/ods.rb +61 -0
  10. data/lib/spreadsheet_architect/class_methods/xlsx.rb +162 -0
  11. data/lib/spreadsheet_architect/exceptions.rb +47 -0
  12. data/lib/spreadsheet_architect/{set_mime_types.rb → mime_types.rb} +0 -2
  13. data/lib/spreadsheet_architect/monkey_patches/axlsx_column_width.rb +23 -0
  14. data/lib/spreadsheet_architect/utils.rb +223 -0
  15. data/lib/spreadsheet_architect/utils/xlsx.rb +126 -0
  16. data/lib/spreadsheet_architect/version.rb +1 -1
  17. data/test/rails_app/Gemfile +17 -0
  18. data/test/rails_app/Gemfile.lock +176 -0
  19. data/test/rails_app/README.md +24 -0
  20. data/test/rails_app/Rakefile +6 -0
  21. data/test/rails_app/app/assets/config/manifest.js +3 -0
  22. data/test/rails_app/app/assets/javascripts/application.js +16 -0
  23. data/test/rails_app/app/assets/javascripts/cable.js +13 -0
  24. data/test/rails_app/app/assets/stylesheets/application.css +15 -0
  25. data/test/rails_app/app/channels/application_cable/channel.rb +4 -0
  26. data/test/rails_app/app/channels/application_cable/connection.rb +4 -0
  27. data/test/rails_app/app/controllers/application_controller.rb +3 -0
  28. data/test/rails_app/app/controllers/spreadsheets_controller.rb +74 -0
  29. data/test/rails_app/app/helpers/application_helper.rb +2 -0
  30. data/test/rails_app/app/jobs/application_job.rb +2 -0
  31. data/test/rails_app/app/mailers/application_mailer.rb +4 -0
  32. data/test/rails_app/app/models/active_model_object.rb +14 -0
  33. data/test/rails_app/app/models/application_record.rb +3 -0
  34. data/test/rails_app/app/models/bad_plain_ruby_object.rb +3 -0
  35. data/test/rails_app/app/models/custom_post.rb +15 -0
  36. data/test/rails_app/app/models/plain_ruby_object.rb +19 -0
  37. data/test/rails_app/app/models/post.rb +3 -0
  38. data/test/rails_app/app/views/layouts/application.html.erb +14 -0
  39. data/test/rails_app/app/views/layouts/mailer.html.erb +13 -0
  40. data/test/rails_app/app/views/layouts/mailer.text.erb +1 -0
  41. data/test/rails_app/bin/bundle +3 -0
  42. data/test/rails_app/bin/rails +9 -0
  43. data/test/rails_app/bin/rake +9 -0
  44. data/test/rails_app/bin/setup +34 -0
  45. data/test/rails_app/bin/spring +16 -0
  46. data/test/rails_app/bin/update +29 -0
  47. data/test/rails_app/config.ru +5 -0
  48. data/test/rails_app/config/application.rb +15 -0
  49. data/test/rails_app/config/boot.rb +3 -0
  50. data/test/rails_app/config/cable.yml +9 -0
  51. data/test/rails_app/config/database.yml +16 -0
  52. data/test/rails_app/config/environment.rb +5 -0
  53. data/test/rails_app/config/environments/development.rb +54 -0
  54. data/test/rails_app/config/environments/production.rb +86 -0
  55. data/test/rails_app/config/environments/test.rb +42 -0
  56. data/test/rails_app/config/initializers/application_controller_renderer.rb +6 -0
  57. data/test/rails_app/config/initializers/assets.rb +11 -0
  58. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  59. data/test/rails_app/config/initializers/cookies_serializer.rb +5 -0
  60. data/test/rails_app/config/initializers/filter_parameter_logging.rb +4 -0
  61. data/test/rails_app/config/initializers/inflections.rb +16 -0
  62. data/test/rails_app/config/initializers/mime_types.rb +4 -0
  63. data/test/rails_app/config/initializers/new_framework_defaults.rb +24 -0
  64. data/test/rails_app/config/initializers/session_store.rb +3 -0
  65. data/test/rails_app/config/initializers/wrap_parameters.rb +14 -0
  66. data/test/rails_app/config/locales/en.yml +23 -0
  67. data/test/rails_app/config/routes.rb +7 -0
  68. data/test/rails_app/config/secrets.yml +22 -0
  69. data/test/{spreadsheet_architect.sqlite3.db → rails_app/db/development.sqlite3} +0 -0
  70. data/test/rails_app/db/migrate/20170103234524_add_posts.rb +10 -0
  71. data/test/rails_app/db/schema.rb +23 -0
  72. data/test/rails_app/db/seeds.rb +7 -0
  73. data/test/rails_app/db/test.sqlite3 +0 -0
  74. data/test/rails_app/log/development.log +1195 -0
  75. data/test/rails_app/log/test.log +52766 -0
  76. data/test/rails_app/public/404.html +67 -0
  77. data/test/rails_app/public/422.html +67 -0
  78. data/test/rails_app/public/500.html +66 -0
  79. data/test/rails_app/public/apple-touch-icon-precomposed.png +0 -0
  80. data/test/rails_app/public/apple-touch-icon.png +0 -0
  81. data/test/rails_app/public/favicon.ico +0 -0
  82. data/test/rails_app/public/robots.txt +5 -0
  83. data/test/rails_app/test/controllers/spreadsheets_controller_test.rb +46 -0
  84. data/test/rails_app/test/models/active_model_object_test.rb +54 -0
  85. data/test/rails_app/test/models/bad_plain_ruby_object_test.rb +30 -0
  86. data/test/rails_app/test/models/csv_test.rb +60 -0
  87. data/test/rails_app/test/models/custom_post_test.rb +47 -0
  88. data/test/rails_app/test/models/ods_test.rb +68 -0
  89. data/test/rails_app/test/models/plain_ruby_object_test.rb +54 -0
  90. data/test/rails_app/test/models/post_test.rb +47 -0
  91. data/test/rails_app/test/models/spreadsheet_architect_utils_test.rb +68 -0
  92. data/test/rails_app/test/models/xlsx_test.rb +99 -0
  93. data/test/rails_app/test/test_helper.rb +21 -0
  94. data/test/rails_app/tmp/active_model_object/csv.csv +21 -0
  95. data/test/rails_app/tmp/active_model_object/ods.ods +0 -0
  96. data/test/rails_app/tmp/active_model_object/xlsx.xlsx +0 -0
  97. data/test/rails_app/tmp/controller_tests/alt_xlsx.xlsx +0 -0
  98. data/test/rails_app/tmp/controller_tests/csv.csv +1 -0
  99. data/test/rails_app/tmp/controller_tests/ods.ods +0 -0
  100. data/test/rails_app/tmp/controller_tests/xlsx.xlsx +0 -0
  101. data/test/rails_app/tmp/custom_posts/csv.csv +1 -0
  102. data/test/rails_app/tmp/custom_posts/empty.xlsx +0 -0
  103. data/test/rails_app/tmp/custom_posts/ods.ods +0 -0
  104. data/test/rails_app/tmp/custom_posts/xlsx.xlsx +0 -0
  105. data/test/rails_app/tmp/empty_model.csv +1 -0
  106. data/test/rails_app/tmp/empty_model.xlsx +0 -0
  107. data/test/rails_app/tmp/empty_sa.csv +0 -0
  108. data/test/rails_app/tmp/empty_sa.xlsx +0 -0
  109. data/test/rails_app/tmp/extreme.xlsx +0 -0
  110. data/test/rails_app/tmp/model.csv +1 -0
  111. data/test/rails_app/tmp/model.xlsx +0 -0
  112. data/test/rails_app/tmp/ods/empty_model.ods +0 -0
  113. data/test/rails_app/tmp/ods/empty_sa.ods +0 -0
  114. data/test/rails_app/tmp/ods/model.ods +0 -0
  115. data/test/rails_app/tmp/ods/model_options.ods +0 -0
  116. data/test/rails_app/tmp/ods/sa.ods +0 -0
  117. data/test/rails_app/tmp/options.csv +1 -0
  118. data/test/rails_app/tmp/plain_ruby_object/csv.csv +4 -0
  119. data/test/rails_app/tmp/plain_ruby_object/ods.ods +0 -0
  120. data/test/rails_app/tmp/plain_ruby_object/xlsx.xlsx +0 -0
  121. data/test/rails_app/tmp/posts/csv.csv +1 -0
  122. data/test/rails_app/tmp/posts/empty.xlsx +0 -0
  123. data/test/rails_app/tmp/posts/ods.ods +0 -0
  124. data/test/rails_app/tmp/posts/xlsx.xlsx +0 -0
  125. data/test/rails_app/tmp/sa.csv +4 -0
  126. data/test/rails_app/tmp/sa.xlsx +0 -0
  127. metadata +255 -21
  128. data/lib/spreadsheet_architect/axlsx_column_width_patch.rb +0 -13
  129. data/test/database.yml +0 -3
  130. data/test/helper.rb +0 -52
  131. data/test/tc_spreadsheet_architect.rb +0 -84
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-agent: *
5
+ # Disallow: /
@@ -0,0 +1,46 @@
1
+ require "test_helper"
2
+
3
+ class SpreadsheetsControllerTest < ActionController::TestCase
4
+
5
+ def setup
6
+ DatabaseCleaner.start
7
+
8
+ FileUtils.mkdir_p('tmp/controller_tests')
9
+ end
10
+
11
+ def test_csv
12
+ get :csv
13
+ assert_response :success
14
+ File.open('tmp/controller_tests/csv.csv', 'w+b') do |f|
15
+ f.write @response.body
16
+ end
17
+ end
18
+
19
+ def test_ods
20
+ get :ods
21
+ assert_response :success
22
+
23
+ File.open('tmp/controller_tests/ods.ods', 'w+b') do |f|
24
+ f.write @response.body
25
+ end
26
+ end
27
+
28
+ def test_xlsx
29
+ get :xlsx
30
+ assert_response :success
31
+ File.open('tmp/controller_tests/xlsx.xlsx', 'w+b') do |f|
32
+ f.write @response.body
33
+ end
34
+
35
+ get :alt_xlsx, params: {format: :xlsx}
36
+ assert_response :success
37
+ File.open('tmp/controller_tests/alt_xlsx.xlsx', 'w+b') do |f|
38
+ f.write @response.body
39
+ end
40
+ end
41
+
42
+ def teardown
43
+ DatabaseCleaner.clean
44
+ end
45
+
46
+ end
@@ -0,0 +1,54 @@
1
+ require "test_helper"
2
+
3
+ class ActiveModelObjectTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ @path = 'tmp/active_model_object'
7
+ FileUtils.mkdir_p(@path)
8
+
9
+ DatabaseCleaner.start
10
+ end
11
+
12
+ def test_csv
13
+ assert_raise SpreadsheetArchitect::Exceptions::NoInstancesError do
14
+ ActiveModelObject.to_csv
15
+ end
16
+
17
+ instances = 20.times.map{|_| ActiveModelObject.new(name: :asd, content: :asd, created_at: Time.now)}
18
+ data = ActiveModelObject.to_csv(instances: instances)
19
+
20
+ File.open(File.join(@path, 'csv.csv'), 'w+b') do |f|
21
+ f.write data
22
+ end
23
+ end
24
+
25
+ def test_ods
26
+ assert_raise SpreadsheetArchitect::Exceptions::NoInstancesError do
27
+ ActiveModelObject.to_ods
28
+ end
29
+
30
+ instances = 20.times.map{|_| ActiveModelObject.new(name: :asd, content: :asd, created_at: Time.now)}
31
+ data = ActiveModelObject.to_ods(instances: instances)
32
+
33
+ File.open(File.join(@path, 'ods.ods'), 'w+b') do |f|
34
+ f.write data
35
+ end
36
+ end
37
+
38
+ def test_xlsx
39
+ assert_raise SpreadsheetArchitect::Exceptions::NoInstancesError do
40
+ ActiveModelObject.to_xlsx
41
+ end
42
+
43
+ instances = 20.times.map{|_| ActiveModelObject.new(name: :asd, content: :asd, created_at: Time.now)}
44
+ data = ActiveModelObject.to_xlsx(instances: instances)
45
+
46
+ File.open(File.join(@path, 'xlsx.xlsx'), 'w+b') do |f|
47
+ f.write data
48
+ end
49
+ end
50
+
51
+ def teardown
52
+ DatabaseCleaner.clean
53
+ end
54
+ end
@@ -0,0 +1,30 @@
1
+ require "test_helper"
2
+
3
+ class BadPlainRubyObjectTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ DatabaseCleaner.start
7
+ end
8
+
9
+ def test_csv
10
+ assert_raise SpreadsheetArchitect::Exceptions::SpreadsheetColumnsNotDefinedError do
11
+ BadPlainRubyObject.to_csv(instances: [])
12
+ end
13
+ end
14
+
15
+ def test_ods
16
+ assert_raise SpreadsheetArchitect::Exceptions::SpreadsheetColumnsNotDefinedError do
17
+ BadPlainRubyObject.to_ods(instances: [])
18
+ end
19
+ end
20
+
21
+ def test_xlsx
22
+ assert_raise SpreadsheetArchitect::Exceptions::SpreadsheetColumnsNotDefinedError do
23
+ BadPlainRubyObject.to_xlsx(instances: [])
24
+ end
25
+ end
26
+
27
+ def teardown
28
+ DatabaseCleaner.clean
29
+ end
30
+ end
@@ -0,0 +1,60 @@
1
+ require 'test_helper'
2
+
3
+ class CsvTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ @headers = ['test1', 'test2','test3']
7
+ @data = [
8
+ ['row1'],
9
+ ['row2 c1', 'row2 c2'],
10
+ ['the','data']
11
+ ]
12
+ @options = {
13
+ headers: true,
14
+ header_style: {background_color: 'AAAAAA', color: 'FFFFFF', align: :center, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false},
15
+ row_style: {background_color: nil, color: '000000', align: :left, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false},
16
+ sheet_name: 'My Project Export',
17
+ column_styles: [],
18
+ range_styles: [],
19
+ merges: [],
20
+ borders: [],
21
+ column_types: []
22
+ }
23
+ end
24
+
25
+ def test_empty_model
26
+ Post.delete_all
27
+ File.open('tmp/empty_model.csv','w+b') do |f|
28
+ f.write Post.to_csv
29
+ end
30
+ end
31
+
32
+ def test_empty_sa
33
+ File.open('tmp/empty_sa.csv','w+b') do |f|
34
+ f.write SpreadsheetArchitect.to_csv(data: [])
35
+ end
36
+ end
37
+
38
+ def test_sa
39
+ File.open('tmp/sa.csv','w+b') do |f|
40
+ f.write SpreadsheetArchitect.to_csv(headers: @headers, data: @data)
41
+ end
42
+ end
43
+
44
+ def test_model
45
+ File.open('tmp/model.csv','w+b') do |f|
46
+ f.write Post.to_csv
47
+ end
48
+ end
49
+
50
+ def test_options
51
+ File.open('tmp/options.csv','w+b') do |f|
52
+ f.write Post.to_csv(@options)
53
+ end
54
+ end
55
+
56
+ def teardown
57
+ DatabaseCleaner.clean
58
+ end
59
+
60
+ end
@@ -0,0 +1,47 @@
1
+ require "test_helper"
2
+
3
+ class CustomPostTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ @path = File.join(Rails.root, 'tmp/custom_posts')
7
+ FileUtils.mkdir_p(@path)
8
+
9
+ DatabaseCleaner.start
10
+ end
11
+
12
+ def test_csv
13
+ data = CustomPost.to_csv
14
+
15
+ File.open(File.join(@path, 'csv.csv'), 'w+b') do |f|
16
+ f.write data
17
+ end
18
+ end
19
+
20
+ def test_ods
21
+ data = CustomPost.to_ods
22
+
23
+ File.open(File.join(@path, 'ods.ods'), 'w+b') do |f|
24
+ f.write data
25
+ end
26
+ end
27
+
28
+ def test_xlsx
29
+ data = CustomPost.all.to_xlsx
30
+
31
+ File.open(File.join(@path, 'xlsx.xlsx'), 'w+b') do |f|
32
+ f.write data
33
+ end
34
+ end
35
+
36
+ def test_empty
37
+ Post.destroy_all
38
+
39
+ File.open(File.join(@path, 'empty.xlsx'), 'w+b') do |f|
40
+ f.write Post.to_xlsx
41
+ end
42
+ end
43
+
44
+ def teardown
45
+ DatabaseCleaner.clean
46
+ end
47
+ end