Class: Kitchen::Directions::BakeAutotitledExercise::V2

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

Overview

Differences from V1:

  1. Title is an <h3><span>, not <h4>, & above the problem instead of within it

  2. Title is generated in the recipe and passed to the method

Instance Method Summary collapse

Instance Method Details

#bake(exercise:, title:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/kitchen/directions/bake_autotitled_exercise/v2.rb', line 8

def bake(exercise:, title:)
  exercise.add_class('unnumbered')
  exercise.titles.first&.trash

  # bake problem
  exercise.prepend(child:
    <<~HTML
      <h3 class="os-title" data-type="title">
        <span class="os-title-label">#{title}</span>
      </h3>
    HTML
  )
  exercise.problem.wrap_children(class: 'os-problem-container')
  return unless exercise.solution

  exercise.solution.wrap_children(class: 'os-solution-container')
  exercise.solution.prepend(child:
    <<~HTML
      <h4 class="solution-title" data-type="title">
        <span class="os-text">#{I18n.t(:solution)}</span>
      </h4>
    HTML
  )
end