@@ -13,12 +13,8 @@ class Quiz < Edify::Command | |||
parse_command_line do |p| | |||
p.banner = 'Usage: edify quiz [options]' | |||
p.on('-m', '--markdown=DIR', 'Set the markdown directory as DIR') do |m| | |||
@config.question_markdown_dir = File.expand_path(m) | |||
end | |||
p.on('-y', '--yaml=DIR', 'Set the question YAML directory as DIR') do |y| | |||
@config.question_meta_dir = File.expand_path(y) | |||
p.on('-q', '--questions=DIR', 'Set the questions directory as DIR') do |q| | |||
@config.questions_dir = File.expand_path(q) | |||
end | |||
p.on('-I', '--add-path=PATH', 'Add a path to the load path') do |p| | |||
@@ -53,13 +49,13 @@ class Quiz < Edify::Command | |||
def load_questions | |||
random = Random.new | |||
Dir.foreach(@config.question_meta_dir) do |file| | |||
Dir.foreach(@config.questions_dir) do |file| | |||
next if file.match(/^\./) or !file.match(/\.yml$/) | |||
verbose("loading question #{file}") | |||
question = Edify::Quiz::Question.new(@config, file) | |||
if !question.valid? | |||
full_path = File.join(@config.question_meta_dir, file) | |||
full_path = File.join(@config.questions_dir, file) | |||
errors = question.errors.full_messages | |||
raise("invalid question: #{full_path}: #{errors}") | |||
end |
@@ -4,7 +4,7 @@ class Edify::Quiz::Config | |||
include(ActiveModel::Validations) | |||
############################################################################## | |||
attr_accessor(:load_path, :question_meta_dir, :question_markdown_dir, :save_dir) | |||
attr_accessor(:load_path, :questions_dir, :save_dir) | |||
attr_accessor(:questions) | |||
############################################################################## | |||
@@ -17,14 +17,12 @@ class Edify::Quiz::Config | |||
end | |||
############################################################################## | |||
validates(:question_markdown_dir, :presence => true, :file => true) | |||
validates(:question_meta_dir, :presence => true, :file => true) | |||
validates(:questions_dir, :presence => true, :file => true) | |||
############################################################################## | |||
def initialize | |||
@load_path = %w(code) | |||
@question_meta_dir = 'meta/questions' | |||
@question_markdown_dir = 'questions' | |||
@questions_dir = 'questions' | |||
@save_dir = Time.now.strftime('saved-%Y-%m-%d') | |||
@html_title = 'Assessment' | |||
@questions = [] | |||
@@ -33,12 +31,12 @@ class Edify::Quiz::Config | |||
############################################################################## | |||
def question_meta_file (name) | |||
base = File.basename(name, File.extname(name)) | |||
File.join(question_meta_dir, base) + '.yml' | |||
File.join(questions_dir, base) + '.yml' | |||
end | |||
############################################################################## | |||
def question_markdown_file (name) | |||
base = File.basename(name, File.extname(name)) | |||
File.join(question_markdown_dir, base) + '.md' | |||
File.join(questions_dir, base) + '.md' | |||
end | |||
end |
@@ -50,6 +50,8 @@ class Edify::Quiz::Server < Sinatra::Base | |||
if @grade.graded? and (q.correct_answer_id == aid) | |||
"correct" | |||
elsif @grade.graded? and @grade.answers[quid.to_s] == aid.to_s | |||
"wrong" | |||
else | |||
"" | |||
end |
@@ -1,5 +1,5 @@ | |||
module Edify | |||
VERSION = '0.2.0' | |||
VERSION = '0.2.1' | |||
end |
@@ -20,6 +20,10 @@ pre.sourceCode { | |||
background-color: #88b324; | |||
} | |||
.answers .wrong { | |||
background-color: #dc5c5a; | |||
} | |||
/* From pandoc */ | |||
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode { | |||
margin: 0; padding: 0; vertical-align: baseline; border: none; } |
@@ -27,12 +27,13 @@ | |||
<% q.answers.each_with_index do |a, j| %> | |||
<li class="<%= css_class(i, j) %>"> | |||
<input type="radio" | |||
<input id="q_<%= i %>" | |||
type="radio" | |||
name="q[<%= i %>]" | |||
value="<%= j %>" | |||
<%= selected(i, j) %> | |||
<%= disabled %>/> | |||
<%= a.text %> | |||
<label for="q_<%= i %>"><%= a.text %></label> | |||
</li> | |||
<% end %> | |||
</ol> |