active_admin_csv_with_bom 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +16 -0
- data/.ruby-style.yml +242 -0
- data/.travis.yml +5 -0
- data/Appraisals +10 -0
- data/Gemfile +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +13 -0
- data/Rakefile +7 -0
- data/active_admin_csv_with_bom.gemspec +23 -0
- data/app/views/active_admin/page/index.csv.ruby +1 -0
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails42.gemfile +23 -0
- data/gemfiles/rails50.gemfile +24 -0
- data/lib/active_admin_csv_with_bom.rb +23 -0
- data/lib/active_admin_csv_with_bom/builder.rb +59 -0
- data/lib/active_admin_csv_with_bom/engine.rb +6 -0
- data/lib/active_admin_csv_with_bom/version.rb +3 -0
- data/tasks/test.rake +10 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e4546f335b5ab8c9817de0237e95a1d33b610835
|
4
|
+
data.tar.gz: 4a5840dcfa8d2c1a513eaa198c7402ac596b68e1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6c281372b40f6036de637d155fd37bea0fd44cc0bfee83523198995900826d2f54dde2c21dc46130531c4448299006627a88ad08b12cc9682c73de294ba57ac9
|
7
|
+
data.tar.gz: e68c47f64fe54a87a7513e97adcc2fefda30fc13798d451b2d5bc28f0cc3b40e03bf12a3a56918d4c02f3d2faa27dfb2423e2c3e0d5452c24dddc92c6fb30094
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
inherit_from:
|
2
|
+
- .ruby-style.yml
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
Exclude:
|
6
|
+
- "bin/*"
|
7
|
+
- "vendor/**/*"
|
8
|
+
- "gemfiles/**/*"
|
9
|
+
- "spec/rails/**/*"
|
10
|
+
- Gemfile
|
11
|
+
- Rakefile
|
12
|
+
DisplayCopNames: true
|
13
|
+
TargetRubyVersion: 2.1
|
14
|
+
|
15
|
+
Metrics/LineLength:
|
16
|
+
Enabled: false
|
data/.ruby-style.yml
ADDED
@@ -0,0 +1,242 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- "vendor/**/*"
|
4
|
+
UseCache: false
|
5
|
+
Style/CollectionMethods:
|
6
|
+
Description: Preferred collection methods.
|
7
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
|
8
|
+
Enabled: true
|
9
|
+
PreferredMethods:
|
10
|
+
collect: map
|
11
|
+
collect!: map!
|
12
|
+
find: detect
|
13
|
+
find_all: select
|
14
|
+
reduce: inject
|
15
|
+
Style/DotPosition:
|
16
|
+
Description: Checks the position of the dot in multi-line method calls.
|
17
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
|
18
|
+
Enabled: true
|
19
|
+
EnforcedStyle: trailing
|
20
|
+
SupportedStyles:
|
21
|
+
- leading
|
22
|
+
- trailing
|
23
|
+
Style/FileName:
|
24
|
+
Description: Use snake_case for source file names.
|
25
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
|
26
|
+
Enabled: false
|
27
|
+
Exclude: []
|
28
|
+
Style/GuardClause:
|
29
|
+
Description: Check for conditionals that can be replaced with guard clauses
|
30
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
|
31
|
+
Enabled: false
|
32
|
+
MinBodyLength: 1
|
33
|
+
Style/IfUnlessModifier:
|
34
|
+
Description: Favor modifier if/unless usage when you have a single-line body.
|
35
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
|
36
|
+
Enabled: false
|
37
|
+
MaxLineLength: 80
|
38
|
+
Style/OptionHash:
|
39
|
+
Description: Don't use option hashes when you can use keyword arguments.
|
40
|
+
Enabled: false
|
41
|
+
Style/PercentLiteralDelimiters:
|
42
|
+
Description: Use `%`-literal delimiters consistently
|
43
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
|
44
|
+
Enabled: false
|
45
|
+
PreferredDelimiters:
|
46
|
+
"%": "()"
|
47
|
+
"%i": "()"
|
48
|
+
"%q": "()"
|
49
|
+
"%Q": "()"
|
50
|
+
"%r": "{}"
|
51
|
+
"%s": "()"
|
52
|
+
"%w": "()"
|
53
|
+
"%W": "()"
|
54
|
+
"%x": "()"
|
55
|
+
Style/PredicateName:
|
56
|
+
Description: Check the names of predicate methods.
|
57
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
|
58
|
+
Enabled: true
|
59
|
+
NamePrefix:
|
60
|
+
- is_
|
61
|
+
- has_
|
62
|
+
- have_
|
63
|
+
NamePrefixBlacklist:
|
64
|
+
- is_
|
65
|
+
Exclude:
|
66
|
+
- spec/**/*
|
67
|
+
Style/RaiseArgs:
|
68
|
+
Description: Checks the arguments passed to raise/fail.
|
69
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
|
70
|
+
Enabled: false
|
71
|
+
EnforcedStyle: exploded
|
72
|
+
SupportedStyles:
|
73
|
+
- compact
|
74
|
+
- exploded
|
75
|
+
Style/SignalException:
|
76
|
+
Description: Checks for proper usage of fail and raise.
|
77
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
|
78
|
+
Enabled: false
|
79
|
+
EnforcedStyle: semantic
|
80
|
+
SupportedStyles:
|
81
|
+
- only_raise
|
82
|
+
- only_fail
|
83
|
+
- semantic
|
84
|
+
Style/SingleLineBlockParams:
|
85
|
+
Description: Enforces the names of some block params.
|
86
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
|
87
|
+
Enabled: false
|
88
|
+
Methods:
|
89
|
+
- reduce:
|
90
|
+
- a
|
91
|
+
- e
|
92
|
+
- inject:
|
93
|
+
- a
|
94
|
+
- e
|
95
|
+
Style/SingleLineMethods:
|
96
|
+
Description: Avoid single-line methods.
|
97
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
|
98
|
+
Enabled: false
|
99
|
+
AllowIfMethodIsEmpty: true
|
100
|
+
Style/StringLiterals:
|
101
|
+
Description: Checks if uses of quotes match the configured preference.
|
102
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
|
103
|
+
Enabled: true
|
104
|
+
EnforcedStyle: double_quotes
|
105
|
+
SupportedStyles:
|
106
|
+
- single_quotes
|
107
|
+
- double_quotes
|
108
|
+
Style/StringLiteralsInInterpolation:
|
109
|
+
Description: Checks if uses of quotes inside expressions in interpolated strings
|
110
|
+
match the configured preference.
|
111
|
+
Enabled: true
|
112
|
+
EnforcedStyle: single_quotes
|
113
|
+
SupportedStyles:
|
114
|
+
- single_quotes
|
115
|
+
- double_quotes
|
116
|
+
Style/TrailingCommaInArguments:
|
117
|
+
Description: 'Checks for trailing comma in argument lists.'
|
118
|
+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
|
119
|
+
Enabled: false
|
120
|
+
EnforcedStyleForMultiline: no_comma
|
121
|
+
SupportedStyles:
|
122
|
+
- comma
|
123
|
+
- consistent_comma
|
124
|
+
- no_comma
|
125
|
+
Style/TrailingCommaInLiteral:
|
126
|
+
Description: 'Checks for trailing comma in array and hash literals.'
|
127
|
+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
|
128
|
+
Enabled: false
|
129
|
+
EnforcedStyleForMultiline: no_comma
|
130
|
+
SupportedStyles:
|
131
|
+
- comma
|
132
|
+
- consistent_comma
|
133
|
+
- no_comma
|
134
|
+
Metrics/AbcSize:
|
135
|
+
Description: A calculated magnitude based on number of assignments, branches, and
|
136
|
+
conditions.
|
137
|
+
Enabled: false
|
138
|
+
Max: 15
|
139
|
+
Metrics/ClassLength:
|
140
|
+
Description: Avoid classes longer than 100 lines of code.
|
141
|
+
Enabled: false
|
142
|
+
CountComments: false
|
143
|
+
Max: 100
|
144
|
+
Metrics/ModuleLength:
|
145
|
+
CountComments: false
|
146
|
+
Max: 100
|
147
|
+
Description: Avoid modules longer than 100 lines of code.
|
148
|
+
Enabled: false
|
149
|
+
Metrics/CyclomaticComplexity:
|
150
|
+
Description: A complexity metric that is strongly correlated to the number of test
|
151
|
+
cases needed to validate a method.
|
152
|
+
Enabled: false
|
153
|
+
Max: 6
|
154
|
+
Metrics/MethodLength:
|
155
|
+
Description: Avoid methods longer than 10 lines of code.
|
156
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
|
157
|
+
Enabled: false
|
158
|
+
CountComments: false
|
159
|
+
Max: 10
|
160
|
+
Metrics/ParameterLists:
|
161
|
+
Description: Avoid parameter lists longer than three or four parameters.
|
162
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
|
163
|
+
Enabled: false
|
164
|
+
Max: 5
|
165
|
+
CountKeywordArgs: true
|
166
|
+
Metrics/PerceivedComplexity:
|
167
|
+
Description: A complexity metric geared towards measuring complexity for a human
|
168
|
+
reader.
|
169
|
+
Enabled: false
|
170
|
+
Max: 7
|
171
|
+
Lint/AssignmentInCondition:
|
172
|
+
Description: Don't use assignment in conditions.
|
173
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
|
174
|
+
Enabled: false
|
175
|
+
AllowSafeAssignment: true
|
176
|
+
Style/InlineComment:
|
177
|
+
Description: Avoid inline comments.
|
178
|
+
Enabled: false
|
179
|
+
Style/AccessorMethodName:
|
180
|
+
Description: Check the naming of accessor methods for get_/set_.
|
181
|
+
Enabled: false
|
182
|
+
Style/Alias:
|
183
|
+
Description: Use alias_method instead of alias.
|
184
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
|
185
|
+
Enabled: false
|
186
|
+
Style/Documentation:
|
187
|
+
Description: Document classes and non-namespace modules.
|
188
|
+
Enabled: false
|
189
|
+
Style/DoubleNegation:
|
190
|
+
Description: Checks for uses of double negation (!!).
|
191
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
|
192
|
+
Enabled: false
|
193
|
+
Style/EachWithObject:
|
194
|
+
Description: Prefer `each_with_object` over `inject` or `reduce`.
|
195
|
+
Enabled: false
|
196
|
+
Style/EmptyLiteral:
|
197
|
+
Description: Prefer literals to Array.new/Hash.new/String.new.
|
198
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
|
199
|
+
Enabled: false
|
200
|
+
Style/ModuleFunction:
|
201
|
+
Description: Checks for usage of `extend self` in modules.
|
202
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
|
203
|
+
Enabled: false
|
204
|
+
Style/OneLineConditional:
|
205
|
+
Description: Favor the ternary operator(?:) over if/then/else/end constructs.
|
206
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
|
207
|
+
Enabled: false
|
208
|
+
Style/PerlBackrefs:
|
209
|
+
Description: Avoid Perl-style regex back references.
|
210
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
|
211
|
+
Enabled: false
|
212
|
+
Style/Send:
|
213
|
+
Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
|
214
|
+
may overlap with existing methods.
|
215
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
|
216
|
+
Enabled: false
|
217
|
+
Style/SpecialGlobalVars:
|
218
|
+
Description: Avoid Perl-style global variables.
|
219
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
|
220
|
+
Enabled: false
|
221
|
+
Style/VariableInterpolation:
|
222
|
+
Description: Don't interpolate global, instance and class variables directly in
|
223
|
+
strings.
|
224
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
|
225
|
+
Enabled: false
|
226
|
+
Style/WhenThen:
|
227
|
+
Description: Use when x then ... for one-line cases.
|
228
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
|
229
|
+
Enabled: false
|
230
|
+
Lint/EachWithObjectArgument:
|
231
|
+
Description: Check for immutable argument given to each_with_object.
|
232
|
+
Enabled: true
|
233
|
+
Lint/HandleExceptions:
|
234
|
+
Description: Don't suppress exception.
|
235
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
|
236
|
+
Enabled: false
|
237
|
+
Lint/LiteralInCondition:
|
238
|
+
Description: Checks of literals used in conditions.
|
239
|
+
Enabled: false
|
240
|
+
Lint/LiteralInInterpolation:
|
241
|
+
Description: Checks for literals used in interpolation.
|
242
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Appraisals
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
appraise 'rails42' do
|
2
|
+
gem 'rails', '~> 4.2.0'
|
3
|
+
gem 'activeadmin', '1.0.0.pre4'
|
4
|
+
end
|
5
|
+
|
6
|
+
appraise 'rails50' do
|
7
|
+
gem 'rails', '~> 5.0.0'
|
8
|
+
gem 'inherited_resources', github: 'activeadmin/inherited_resources'
|
9
|
+
gem 'activeadmin', github: 'activeadmin/activeadmin'
|
10
|
+
end
|
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
gem 'rails', '~> 4.2.0'
|
6
|
+
gem 'activeadmin', '1.0.0.pre4'
|
7
|
+
|
8
|
+
gem "pry"
|
9
|
+
gem 'appraisal'
|
10
|
+
|
11
|
+
group :development do
|
12
|
+
gem "rubocop", "~> 0.40.0"
|
13
|
+
end
|
14
|
+
|
15
|
+
group :test do
|
16
|
+
gem "capybara"
|
17
|
+
gem "rspec-rails"
|
18
|
+
gem "database_cleaner"
|
19
|
+
gem 'shoulda-matchers'
|
20
|
+
gem "sqlite3", platforms: :mri
|
21
|
+
gem "poltergeist"
|
22
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Yoshiyuki Hirano
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "lib", "active_admin_csv_with_bom", "version")
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = "active_admin_csv_with_bom"
|
5
|
+
gem.version = ActiveAdminCsvWithBom::VERSION
|
6
|
+
gem.authors = ["Yoshiyuki Hirano"]
|
7
|
+
gem.email = ["yhirano@me.com"]
|
8
|
+
|
9
|
+
gem.summary = "Generate csv with byte order mark for Active Admin"
|
10
|
+
gem.description = gem.summary
|
11
|
+
gem.homepage = "https://github.com/yhirano55/active_admin_csv_with_bom"
|
12
|
+
gem.license = "MIT"
|
13
|
+
|
14
|
+
gem.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
|
17
|
+
gem.required_ruby_version = ">= 2.1.0"
|
18
|
+
|
19
|
+
gem.add_dependency "activeadmin", ">= 1.0.0.pre4"
|
20
|
+
|
21
|
+
gem.add_development_dependency "bundler", "~> 1.13"
|
22
|
+
gem.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
::ActiveAdminCsvWithBom.build(collection)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 4.2.0"
|
6
|
+
gem "activeadmin", "1.0.0.pre4"
|
7
|
+
gem "pry"
|
8
|
+
gem "appraisal"
|
9
|
+
|
10
|
+
group :development do
|
11
|
+
gem "rubocop", "~> 0.40.0"
|
12
|
+
end
|
13
|
+
|
14
|
+
group :test do
|
15
|
+
gem "capybara"
|
16
|
+
gem "rspec-rails"
|
17
|
+
gem "database_cleaner"
|
18
|
+
gem "shoulda-matchers"
|
19
|
+
gem "sqlite3", :platforms => :mri
|
20
|
+
gem "poltergeist"
|
21
|
+
end
|
22
|
+
|
23
|
+
gemspec :path => "../"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 5.0.0"
|
6
|
+
gem "activeadmin", :github => "activeadmin/activeadmin"
|
7
|
+
gem "pry"
|
8
|
+
gem "appraisal"
|
9
|
+
gem "inherited_resources", :github => "activeadmin/inherited_resources"
|
10
|
+
|
11
|
+
group :development do
|
12
|
+
gem "rubocop", "~> 0.40.0"
|
13
|
+
end
|
14
|
+
|
15
|
+
group :test do
|
16
|
+
gem "capybara"
|
17
|
+
gem "rspec-rails"
|
18
|
+
gem "database_cleaner"
|
19
|
+
gem "shoulda-matchers"
|
20
|
+
gem "sqlite3", :platforms => :mri
|
21
|
+
gem "poltergeist"
|
22
|
+
end
|
23
|
+
|
24
|
+
gemspec :path => "../"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "active_admin"
|
2
|
+
require "active_admin_csv_with_bom/builder"
|
3
|
+
require "active_admin_csv_with_bom/engine"
|
4
|
+
|
5
|
+
module ActiveAdminCsvWithBom
|
6
|
+
# NOTE: For resource of **NOT** Active Record
|
7
|
+
def self.build(collection)
|
8
|
+
Builder.new(collection).build
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.csv_options
|
12
|
+
@_csv_options ||= {
|
13
|
+
byte_order_mark: "\xFF\xFE".force_encoding("UTF-16LE").freeze,
|
14
|
+
encoding: "UTF-16LE",
|
15
|
+
encoding_options: "UTF-8",
|
16
|
+
col_sep: "\t",
|
17
|
+
row_sep: "\r\n",
|
18
|
+
force_quotes: true
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
ActiveAdmin::Application.inheritable_setting(:csv_options, ActiveAdminCsvWithBom.csv_options)
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "csv"
|
2
|
+
require "ostruct"
|
3
|
+
require "active_support/core_ext/module/delegation"
|
4
|
+
|
5
|
+
module ActiveAdminCsvWithBom
|
6
|
+
class Builder
|
7
|
+
attr_reader :collection
|
8
|
+
|
9
|
+
delegate :byte_order_mark, :encoding, :encoding_options,
|
10
|
+
:col_sep, :row_sep, :force_quotes, to: :config
|
11
|
+
|
12
|
+
def initialize(collection)
|
13
|
+
@collection = collection
|
14
|
+
end
|
15
|
+
|
16
|
+
def build
|
17
|
+
"".tap do |csv|
|
18
|
+
csv << byte_order_mark
|
19
|
+
csv << build_header
|
20
|
+
|
21
|
+
collection.each do |record|
|
22
|
+
csv << build_row(record)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def build_header
|
30
|
+
CSV.generate_line(column_names.map { |name| encode(resource_class.human_attribute_name(name)) }, options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_row(record)
|
34
|
+
CSV.generate_line(column_names.map { |name| encode(record.send(name)) }, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def resource_class
|
38
|
+
@_resource_class ||= collection[0].class
|
39
|
+
end
|
40
|
+
|
41
|
+
def column_names
|
42
|
+
@_column_names ||= resource_class.column_names
|
43
|
+
rescue NoMethodError => _e
|
44
|
+
raise NotImplementedError, "you must implement #{resource_class}.column_names"
|
45
|
+
end
|
46
|
+
|
47
|
+
def encode(value)
|
48
|
+
value.to_s.encode(encoding, encoding_options)
|
49
|
+
end
|
50
|
+
|
51
|
+
def options
|
52
|
+
@_options ||= { col_sep: col_sep, row_sep: row_sep, force_quotes: force_quotes }
|
53
|
+
end
|
54
|
+
|
55
|
+
def config
|
56
|
+
@_config ||= OpenStruct.new(::ActiveAdminCsvWithBom.csv_options)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/tasks/test.rake
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
desc "Creates a test rails app for the specs to run against"
|
2
|
+
task :setup do
|
3
|
+
require "rails/version"
|
4
|
+
system("mkdir spec/rails") unless File.exist?("spec/rails")
|
5
|
+
system "bundle exec rails new spec/rails/rails-#{Rails::VERSION::STRING} -m spec/support/rails_template.rb --skip-spring --skip-turbolinks"
|
6
|
+
end
|
7
|
+
|
8
|
+
require "rspec/core/rake_task"
|
9
|
+
RSpec::Core::RakeTask.new(:spec)
|
10
|
+
task default: :spec
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_admin_csv_with_bom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yoshiyuki Hirano
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activeadmin
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0.pre4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0.pre4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: Generate csv with byte order mark for Active Admin
|
56
|
+
email:
|
57
|
+
- yhirano@me.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".rubocop.yml"
|
65
|
+
- ".ruby-style.yml"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Appraisals
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- active_admin_csv_with_bom.gemspec
|
73
|
+
- app/views/active_admin/page/index.csv.ruby
|
74
|
+
- gemfiles/.bundle/config
|
75
|
+
- gemfiles/rails42.gemfile
|
76
|
+
- gemfiles/rails50.gemfile
|
77
|
+
- lib/active_admin_csv_with_bom.rb
|
78
|
+
- lib/active_admin_csv_with_bom/builder.rb
|
79
|
+
- lib/active_admin_csv_with_bom/engine.rb
|
80
|
+
- lib/active_admin_csv_with_bom/version.rb
|
81
|
+
- tasks/test.rake
|
82
|
+
homepage: https://github.com/yhirano55/active_admin_csv_with_bom
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 2.1.0
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.5.1
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Generate csv with byte order mark for Active Admin
|
106
|
+
test_files: []
|