Class: Tilt::CSVTemplate
Overview
CSV Template implementation. See: ruby-doc.org/stdlib/libdoc/csv/rdoc/CSV.html
Example
tpl = " # header\n csv << ['NAME', 'ID']\n\n # data rows\n @people.each do |person|\n csv << [person[:name], person[:id]]\n end\n"
@people = [
{:name => "Joshua Peek", :id => 1},
{:name => "Ryan Tomayko", :id => 2},
{:name => "Simone Carletti", :id => 3}
]
template = Tilt::CSVTemplate.new { tpl }
template.render(self)
Instance Attribute Summary
Attributes inherited from Template
#data, #file, #line, #options
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Template
#allows_script?, #basename, #default_encoding, #eval_file, #initialize, #name, #read_template_file, #render
Constructor Details
This class inherits a constructor from Tilt::Template
Class Method Details
37
38
39
40
41
42
43
|
# File 'lib/vendor/tilt-1.4.1/lib/tilt/csv.rb', line 37
def self.engine
if RUBY_VERSION >= '1.9.0' && defined? ::CSV
::CSV
elsif defined? ::FasterCSV
::FasterCSV
end
end
|
.engine_initialized? ⇒ Boolean
33
34
35
|
# File 'lib/vendor/tilt-1.4.1/lib/tilt/csv.rb', line 33
def self.engine_initialized?
engine
end
|
Instance Method Details
#initialize_engine ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/vendor/tilt-1.4.1/lib/tilt/csv.rb', line 45
def initialize_engine
if RUBY_VERSION >= '1.9.0'
require_template_library 'csv'
else
require_template_library 'fastercsv'
end
end
|
#precompiled(locals) ⇒ Object
65
66
67
68
|
# File 'lib/vendor/tilt-1.4.1/lib/tilt/csv.rb', line 65
def precompiled(locals)
source, offset = super
[source, offset + 1]
end
|
#precompiled_template(locals) ⇒ Object
61
62
63
|
# File 'lib/vendor/tilt-1.4.1/lib/tilt/csv.rb', line 61
def precompiled_template(locals)
@code
end
|
53
54
55
56
57
58
59
|
# File 'lib/vendor/tilt-1.4.1/lib/tilt/csv.rb', line 53
def prepare
@code =" \#{self.class.engine}.generate do |csv|\n \#{data}\n end\n RUBY\nend\n"
|