Sha256: 99cd91edc26e64e14c559f625a7089c285731dbb0f96e001c27bcc9a49b27d9a

Contents?: true

Size: 1.11 KB

Versions: 16

Compression:

Stored size: 1.11 KB

Contents

require 'csv'

format :csv  do
  def get_inclusion_defaults nested_card
    { :view => :core }
  end
  
  def default_item_view 
    @depth == 0 ? :csv_row : :name
  end

  
  view :csv_row do |args|
    array = _render_raw.scan( /\{\{[^\}]*\}\}/ ).map do |inc|
      process_content( inc ).strip
    end
    
    CSV.generate_line(array).strip
    #strip is because search already joins with newlines
  end

  view :missing do |args|
    ''
  end

  view :csv_title_row do |args|
    #NOTE: assumes all cards have the same structure!
    begin
      card1 = search_results.first
    
      parsed_content = Card::Content.new card1.raw_content, self
      unless String === parsed_content.__getobj__
        titles = parsed_content.map do |chunk|
          next if chunk.class != Card::Chunk::Include
          opts = chunk.options
          if ['name','link'].member? opts[:view]
            opts[:view]
          else
            opts[:inc_name].to_name.tag
          end
        end.compact.map {|title| title.to_s.upcase }
        CSV.generate_line titles
        
      else
        ''
      end
    rescue
      ''
    end
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
card-1.16.6 mod/02_basic_types/set/all/all_csv.rb
card-1.16.5 mod/02_basic_types/set/all/all_csv.rb
card-1.16.4 mod/02_basic_types/set/all/all_csv.rb
card-1.16.3 mod/02_basic_types/set/all/all_csv.rb
card-1.16.2 mod/02_basic_types/set/all/all_csv.rb
card-1.16.1 mod/02_basic_types/set/all/all_csv.rb
card-1.16.0 mod/02_basic_types/set/all/all_csv.rb
card-1.15.7 mod/02_basic_types/set/all/all_csv.rb
card-1.15.6 mod/02_basic_types/set/all/all_csv.rb
card-1.15.5 mod/02_basic_types/set/all/all_csv.rb
card-1.15.4 mod/02_basic_types/set/all/all_csv.rb
card-1.15.3 mod/02_basic_types/set/all/all_csv.rb
card-1.15.2 mod/02_basic_types/set/all/all_csv.rb
card-1.15.1 mod/02_basic_types/set/all/all_csv.rb
card-1.15.0 mod/02_basic_types/set/all/all_csv.rb
card-1.15.pre2 mod/02_basic_types/set/all/all_csv.rb