Class: Tilt::CSVTemplate

### Home Classes Methods

### In Files

- lib/tilt/csv.rb

### Parent

Template

### Methods

- ::engine
- ::engine_initialized?
- #initialize_engine
- #precompiled
- #precompiled_template
- #prepare

### Class/Module Index

Quicksearch

- Tilt
- Tilt::AsciidoctorTemplate
- Tilt::BlueClothTemplate
- Tilt::BuilderTemplate
- Tilt::CSVTemplate
- Tilt::Cache
- Tilt::CoffeeScriptTemplate
- Tilt::CompileSite
- Tilt::CreoleTemplate
- Tilt::ERBTemplate
- Tilt::ErubisTemplate
- Tilt::EtanniTemplate
- Tilt::HamlTemplate
- Tilt::KramdownTemplate
- Tilt::LessTemplate
- Tilt::LiquidTemplate
- Tilt::MarkabyTemplate
- Tilt::MarukuTemplate
- Tilt::NokogiriTemplate
- Tilt::PlainTemplate
- Tilt::RDiscountTemplate
- Tilt::RDocTemplate
- Tilt::RadiusTemplate
- Tilt::RedClothTemplate
- Tilt::RedcarpetTemplate
- Tilt::RedcarpetTemplate::Redcarpet1
- Tilt::RedcarpetTemplate::Redcarpet2
- Tilt::SassTemplate
- Tilt::ScssTemplate
- Tilt::StringTemplate
- Tilt::Template
- Tilt::WikiClothTemplate
- Tilt::YajlTemplate

No matching classes.

# Tilt::CSVTemplate

CSV Template implementation. See: ruby-doc.org/stdlib/libdoc/csv/rdoc/CSV.html

## Example

    # Example of csv template
    tpl = <<-EOS
      # header
      csv << ['NAME', 'ID']

      # data rows
      @people.each do |person|
        csv << [person[:name], person[:id]]
      end
    EOS

    @people = [
      {:name => "Joshua Peek", :id => 1},
      {:name => "Ryan Tomayko", :id => 2},
      {:name => "Simone Carletti", :id => 3}
    ]

    template = Tilt::CSVTemplate.new { tpl }
    template.render(self)

### Public Class Methods

engine() click to toggle source

    # File 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?() click to toggle source

    # File lib/tilt/csv.rb, line 33
    def self.engine_initialized?
      engine
    end

### Public Instance Methods

initialize_engine() click to toggle source

    # File 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) click to toggle source

    # File lib/tilt/csv.rb, line 65
    def precompiled(locals)
      source, offset = super
      [source, offset + 1]
    end

precompiled_template(locals) click to toggle source

    # File lib/tilt/csv.rb, line 61
    def precompiled_template(locals)
      @code
    end

prepare() click to toggle source

    # File lib/tilt/csv.rb, line 53
    def prepare
      @code =        #{self.class.engine}.generate do |csv|          #{data}        end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.