Sha256: f6fab5a3fdf31af6803ef5ea6d86148f285ae8a4c1a1130eff08919f8371a2b5
Contents?: true
Size: 1.87 KB
Versions: 2
Compression:
Stored size: 1.87 KB
Contents
# frozen_string_literal: true module Kitchen module Directions module BakeNumberedNotes def self.v1(book:, classes:) classes.each do |klass| book.chapters.notes("$.#{klass}").each do |note| bake_note(note: note) bake_note_exercise(note: note) end end end def self.bake_note(note:) note.wrap_children(class: 'os-note-body') chapter_count = note.ancestor(:chapter).count_in(:book) note_count = note.count_in(:chapter) note.prepend(child: <<~HTML <div class="os-title"> <span class="os-title-label">#{note.autogenerated_title}</span> <span class="os-number">#{chapter_count}.#{note_count}</span> <span class="os-divider"> </span> </div> HTML ) return unless note['use-subtitle'] BakeNoteSubtitle.v1(note: note) end def self.bake_note_exercise(note:) exercise = note.exercises.first return unless exercise exercise.add_class('unnumbered') # bake problem exercise.problem.wrap_children('div', class: 'os-problem-container') exercise.problem.first('strong')&.trash exercise.search('[data-type="commentary"]').each(&:trash) solution = exercise.solution return unless solution # bake solution in place exercise.add_class('os-hasSolution') solution[:id] = "#{exercise[:id]}-solution" solution_number = note.first('.os-number').text solution.replace_children(with: <<~HTML <a class="os-number" href="##{exercise[:id]}">#{solution_number}</a> <span class="os-divider"> </span> <div class="os-solution-container"> #{solution.children} </div> HTML ) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
openstax_kitchen-3.2.0 | lib/kitchen/directions/bake_notes/bake_numbered_notes.rb |
openstax_kitchen-3.1.0 | lib/kitchen/directions/bake_notes/bake_numbered_notes.rb |