Class: Kitchen::Directions::BakeInjectedExercise::V1

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/directions/bake_injected_exercise/bake_injected_exercise.rb

Instance Method Summary collapse

Instance Method Details

#bake(exercise:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/kitchen/directions/bake_injected_exercise/bake_injected_exercise.rb', line 9

def bake(exercise:)
  question_count = exercise.injected_questions.count
  exercise[:'data-question-count'] = question_count
  exercise[:'data-is-multipart'] = question_count > 1 ? 'True' : 'False'

  context = exercise&.exercise_context

  return unless context

  # link replacement is done by BakeLinkPlaceholders
  link = context.first('a').cut
  context.replace_children(with: "#{I18n.t(:context_lead_text)}#{link.paste}")
  return unless question_count == 1

  question = exercise.exercise_question
  question.prepend(child: context.cut.paste)
end