rails up to 7.0and ruby to 2.7.2
mv lib to app/lib due to upgrade removing concerns from autoload path resolve zeitwerk issues make foodsoft run for dev on rails 7 and ruby 2.7 fix mail file permission bug fix database_config fix articles controller test ActiveModell::Error bump Gemfile.lock
This commit is contained in:
parent
d7591d46b9
commit
fb8ccfea4a
53 changed files with 583 additions and 594 deletions
44
app/lib/render_csv.rb
Normal file
44
app/lib/render_csv.rb
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
require 'csv'
|
||||
|
||||
class RenderCsv
|
||||
include ActionView::Helpers::NumberHelper
|
||||
|
||||
def initialize(object, options = {})
|
||||
@object = object
|
||||
@options = options
|
||||
# defaults to please Microsoft Excel ...
|
||||
@options[:col_sep] ||= FoodsoftConfig[:csv_col_sep] || ';'
|
||||
@options[:row_sep] ||= FoodsoftConfig[:csv_row_sep] if FoodsoftConfig[:csv_row_sep]
|
||||
@options[:encoding] ||= FoodsoftConfig[:csv_encoding] || 'ISO-8859-15'
|
||||
end
|
||||
|
||||
def to_csv
|
||||
options = @options.select { |k| %w(col_sep row_sep).include? k.to_s }
|
||||
ret = CSV.generate options do |csv|
|
||||
if h = header
|
||||
csv << h
|
||||
end
|
||||
data { |d| csv << d }
|
||||
end
|
||||
ret.encode(@options[:encoding], invalid: :replace, undef: :replace)
|
||||
end
|
||||
|
||||
def header
|
||||
nil
|
||||
end
|
||||
|
||||
def data
|
||||
yield []
|
||||
end
|
||||
|
||||
# Helper method to test pdf via rails console: OrderCsv.new(order).save_tmp
|
||||
def save_tmp
|
||||
encoding = @options[:encoding] || 'UTF-8'
|
||||
File.write("#{Rails.root}/tmp/#{self.class.to_s.underscore}.csv", to_csv.force_encoding(encoding))
|
||||
end
|
||||
|
||||
# XXX disable unit to avoid encoding problems, both in unit and whitespace. Also allows computations in spreadsheet.
|
||||
def number_to_currency(number, options = {})
|
||||
super(number, options.merge({ unit: '' }))
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue