Skip to content

Instantly share code, notes, and snippets.

@fxn
Last active March 16, 2020 09:02
Show Gist options
  • Select an option

  • Save fxn/80b25d3aeee7b5ff4dece7e2161cfdad to your computer and use it in GitHub Desktop.

Select an option

Save fxn/80b25d3aeee7b5ff4dece7e2161cfdad to your computer and use it in GitHub Desktop.

Revisions

  1. fxn renamed this gist Mar 16, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. fxn revised this gist Mar 16, 2020. 2 changed files with 2 additions and 0 deletions.
    1 change: 1 addition & 0 deletions back.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    <div class="card"><div class="content">{{Back}}</div></div>
    1 change: 1 addition & 0 deletions front.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    <div class="card"><div class="content">{{Front}}</div></div>
  3. fxn created this gist Mar 16, 2020.
    33 changes: 33 additions & 0 deletions generate_ank_cards.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    #!/usr/bin/env ruby

    require 'find'
    require 'yaml'
    require 'csv'
    require 'erb'

    all = ARGV[0] == "all"

    def process_card(card)
    ERB::Util.h(card.strip).gsub(/\\n/, '<br>')
    end

    root = File.expand_path('..', __dir__)
    Find.find(root) do |file|
    Find.prune if File.basename(file) == 'bin'
    next unless file.end_with?('.yml')

    deck = file.sub(/\.yml\z/, '.csv')
    if all || (!File.exist?(deck) || File.mtime(file) > File.mtime(deck))
    deck_name = deck.sub(%r(.*?/decks/), '').gsub('/', '::').sub(/\.csv\z/, '')
    puts "generating #{deck_name}"

    CSV.open(deck, 'w', col_sep: "\t", force_quotes: true) do |csv|
    cards = YAML.load_file(file)
    cards.each do |card|
    question = process_card(card['q'])
    answer = process_card(card['a'])
    csv << [question, answer]
    end
    end
    end
    end
    16 changes: 16 additions & 0 deletions style.css
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    .card {
    font-family: Menlo;
    font-size: 22px;
    font-weight: bold;
    text-align: center;
    }

    .content {
    white-space: pre;
    text-align: left;
    display: inline-block;
    }

    .replaybutton {
    display: none;
    }