Skip to content

Instantly share code, notes, and snippets.

@fxn
Last active March 16, 2020 09:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fxn/80b25d3aeee7b5ff4dece7e2161cfdad to your computer and use it in GitHub Desktop.
Save fxn/80b25d3aeee7b5ff4dece7e2161cfdad to your computer and use it in GitHub Desktop.
<div class="card"><div class="content">{{Back}}</div></div>
<div class="card"><div class="content">{{Front}}</div></div>
#!/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
.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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment