Module: Kitchen::Directions::BakeLearningObjectives
- Defined in:
- lib/kitchen/directions/bake_learning_objectives.rb
Class Method Summary collapse
- .v1(chapter:) ⇒ Object
- .v2(chapter:, add_title: true) ⇒ Object
-
.v3(chapter:) ⇒ Object
Wraps & moves abstract under the corresponding chapter objective in the intro page.
Class Method Details
.v1(chapter:) ⇒ Object
6 7 8 9 10 |
# File 'lib/kitchen/directions/bake_learning_objectives.rb', line 6 def self.v1(chapter:) chapter.abstracts.each do |abstract| abstract.prepend(child: "<h3 data-type='title'>#{I18n.t(:learning_objectives)}</h3>") end end |
.v2(chapter:, add_title: true) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/kitchen/directions/bake_learning_objectives.rb', line 12 def self.v2(chapter:, add_title: true) learning_objectives = chapter.abstracts.any? ? chapter.abstracts : chapter.learning_objectives learning_objectives.each do |abstract| if add_title abstract.prepend(child: "<h3 data-type='title'>#{I18n.t(:learning_objectives)}</h3>") end ul = abstract.first!('ul') ul.add_class('os-abstract') ul.search('li').each_with_index do |li, index| li.replace_children(with: <<~HTML <span class="os-abstract-token">#{chapter.count_in(:book)}.#{abstract.count_in(:chapter)}.#{index + 1}</span> <span class="os-abstract-content">#{li.children}</span> HTML ) end end end |
.v3(chapter:) ⇒ Object
Wraps & moves abstract under the corresponding chapter objective in the intro page
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/kitchen/directions/bake_learning_objectives.rb', line 35 def self.v3(chapter:) abstracts = chapter.abstracts.map do |abstract| abstract.wrap('<div class="learning-objective">') abstract.parent end chapter.introduction_page.search('div.os-chapter-objective') \ .each_with_index do |objective, index| objective.append(child: abstracts[index].cut.paste) end end |