# frozen_string_literal: true module Kitchen module Directions module BakeExample def self.v1(example:, number:, title_tag:, numbered_solutions: false) example.wrap_children(class: 'body') example.prepend(child: <<~HTML <#{title_tag} class="os-title"> #{I18n.t(:example_label)} #{number} HTML ) example.document .pantry(name: :link_text) .store("#{I18n.t(:example_label)} #{number}", label: example.id) example.titles.each do |title| if title.parent.has_class?('os-caption-container') || \ title.parent.has_class?('os-caption') next end title.name = 'h4' end example.exercises.each do |exercise| if (problem = exercise.problem) problem.titles.each { |title| title.name = 'h4' } problem.wrap_children(class: 'os-problem-container') end if (solution = exercise.solution) solution_number = if numbered_solutions "#{exercise.count_in(:example)}" else '' end solution.replace_children(with: <<~HTML

#{I18n.t(:solution)} #{solution_number}

#{solution.children}
HTML ) end exercise.add_class('unnumbered') commentary = exercise.first('[data-type="commentary"]') next unless commentary.present? commentary_title = commentary.titles.first commentary_title.name = 'h4' commentary_title['data-type'] = 'commentary-title' commentary_title.wrap_children('span', class: 'os-title-label') end end end end end