forked from gtd/csv_builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed Ruby 1.8.x/IConv/FasterCSV support
Removed Rails 2.x support Added BOM (Byte Order Mark) for UTF-16LE Added support for UTF-16LE for MS Excel Convert \r\n\t to whitespace Specs update
- Loading branch information
Showing
10 changed files
with
33 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,10 @@ | ||
# encoding: utf-8 | ||
require 'csv' | ||
require 'action_view' | ||
|
||
module CsvBuilder | ||
if RUBY_VERSION.to_f >= 1.9 | ||
require 'csv' | ||
CSV_LIB = CSV | ||
else | ||
require 'fastercsv' | ||
CSV_LIB = FasterCSV | ||
end | ||
end | ||
|
||
require 'action_view' | ||
require 'iconv' | ||
require 'csv_builder/transliterating_filter' | ||
require 'csv_builder/template_handler' | ||
require 'csv_builder/railtie' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class CsvBuilder::Railtie < Rails::Railtie | ||
initializer "csv_builder.register_template_handler.action_view" do | ||
ActionView::Template.register_template_handler 'csvbuilder', CsvBuilder::TemplateHandler | ||
ActionView::Template.register_template_handler :csvbuilder, CsvBuilder::TemplateHandler | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,14 @@ | ||
#encoding: utf-8 | ||
|
||
class CsvBuilder::TransliteratingFilter | ||
# Transliterate into the required encoding if necessary | ||
def initialize(faster_csv, input_encoding = 'UTF-8', output_encoding = 'LATIN1') | ||
@faster_csv = faster_csv | ||
|
||
# TODO: do some checking to make sure iconv works correctly in | ||
# current environment. See ActiveSupport::Inflector#transliterate | ||
# definition for details | ||
# | ||
# Not using the more standard //IGNORE//TRANSLIT because it raises | ||
# Iconv::IllegalSequence for some inputs | ||
@iconv = Iconv.new("#{output_encoding}//TRANSLIT//IGNORE", input_encoding) if input_encoding != output_encoding | ||
def initialize(csv, input_encoding = 'UTF-8', output_encoding = 'LATIN1') | ||
@csv = csv | ||
end | ||
|
||
# Transliterate before passing to FasterCSV so that the right characters (e.g. quotes) get escaped | ||
|
||
def <<(row) | ||
@faster_csv << if @iconv then row.map { |value| @iconv.iconv(value.to_s) } else row end | ||
@csv << row.map { |value| value.to_s.gsub(/\r|\n|\t/, ' ') } | ||
end | ||
|
||
alias :add_row :<< | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
require 'csv_builder' | ||
|
||
ActionView::Template.register_template_handler 'csvbuilder', CsvBuilder::TemplateHandler | ||
ActionView::Template.register_template_handler :csvbuilder, CsvBuilder::TemplateHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters