Module: Kitchen::Directions::BakeCheckpoint

Defined in:
lib/kitchen/directions/bake_checkpoint.rb

Class Method Summary collapse

Class Method Details

.v1(checkpoint:, number:) ⇒ Object



6
7
8
9
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
# File 'lib/kitchen/directions/bake_checkpoint.rb', line 6

def self.v1(checkpoint:, number:)
  checkpoint.wrap_children(class: 'os-note-body')

  checkpoint.prepend(child:
    <<~HTML
      <div class="os-title">
        <span class="os-title-label">#{I18n.t(:checkpoint)} </span>
        <span class="os-number">#{number}</span>
        <span class="os-divider"> </span>
      </div>
    HTML
  )

  exercise = checkpoint.exercises.first!
  exercise.search("[data-type='commentary']").trash

  problem = exercise.problem
  problem.wrap_children(class: 'os-problem-container')

  solution = exercise.solution
  exercise.add_class('unnumbered') unless solution.present?
  return unless solution.present?

  solution.id = "#{exercise.id}-solution"
  exercise.add_class('os-hasSolution')

  solution.replace_children(with:
    <<~HTML
      <span class="os-divider"> </span>
      <a class="os-number" href="##{exercise.id}">#{number}</a>
      <div class="os-solution-container">#{solution.children}</div>
    HTML
  )

  exercise.add_class('unnumbered')
end