10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/asciidoctor-question/multiple_choice/extension.rb', line 10
def process(parent, source, tag)
id = tag[:id]
err = nil
question = Array.new
answers = Array.new ['[options=interactive]']
switch = false
source.lines.each do |line|
switch = true if line =~ /^-\s?\[/
if switch
answers.push line
else
question.push line
end
end
answers = prepare_answer_lines answers
attrs = {'id' => "question_#{id}_type=mc"}
attrs['id'] += '_shuffle' unless tag[:shuffle].nil?
new_parent = Asciidoctor::Block.new parent, :open, {:attributes => attrs}
reader = Asciidoctor::Reader.new(question)
loop do
block = Asciidoctor::Parser.next_block reader, new_parent
break if block.nil?
new_parent.blocks.push block
end
reader = Asciidoctor::Reader.new(answers)
answers_block = Asciidoctor::Parser.next_block reader, new_parent
if answers_block.nil?
err = 'Es sind keine Antworten vorhanden!'
end
if err.nil?
new_parent.blocks.push prepare_answers answers_block, tag
post_answers new_parent, tag
else
process_error_push new_parent, err, answers
end
new_parent
end
|