Sha256: 8d73ef6eb8659fb365f666c72ab537738cda304af6802cedd2b31f468d52655a

Contents?: true

Size: 1.63 KB

Versions: 13

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

module Kitchen::Directions::BakeCustomSections
  class V1
    def bake(chapter:, custom_sections_properties:)
      custom_sections_properties.each do |_custom_section_name, property|
        title_text = I18n.t(:"custom-sections.#{property[:class]}")
        property_class = property[:class]
        inject = property[:inject]
        chapter.search(".#{property_class}").each do |custom_section|

          case inject
          when 'title'
            custom_section_title = custom_section.first('h2')
            custom_section_title_os_text = custom_section_title.first('.os-text')
            custom_section_title_sibling = custom_section.first('h2 + div')
            div_id = custom_section_title_sibling['id']
            custom_section_title_sibling.trash
            custom_section_title.append(sibling:
              <<~HTML
                <h3 class="os-subtitle" id="#{div_id}">#{custom_section_title_os_text.text}</h3>
              HTML
            )
            custom_section_title_os_text.replace_children(with: title_text)
          when 'subtitle'
            custom_section_title = custom_section.titles.first
            custom_section_title.name = 'h4'
            custom_section_title.prepend(sibling:
              <<~HTML
                <h3 class="os-title">#{title_text}</h3>
              HTML
            )
          when 'title_prefix'
            custom_section_title = custom_section.titles.first
            custom_section_title.replace_children(with: "#{title_text}: " +
                                                  custom_section_title.text)
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
openstax_kitchen-19.0.0 lib/kitchen/directions/bake_custom_sections/v1.rb
openstax_kitchen-18.0.0 lib/kitchen/directions/bake_custom_sections/v1.rb
openstax_kitchen-17.1.0 lib/kitchen/directions/bake_custom_sections/v1.rb
openstax_kitchen-17.0.0 lib/kitchen/directions/bake_custom_sections/v1.rb
openstax_kitchen-16.0.0 lib/kitchen/directions/bake_custom_sections/v1.rb
openstax_kitchen-15.0.0 lib/kitchen/directions/bake_custom_sections/v1.rb
openstax_kitchen-14.0.0 lib/kitchen/directions/bake_custom_sections/v1.rb
openstax_kitchen-13.0.0 lib/kitchen/directions/bake_custom_sections/v1.rb
openstax_kitchen-12.2.0 lib/kitchen/directions/bake_custom_sections/v1.rb
openstax_kitchen-12.1.0 lib/kitchen/directions/bake_custom_sections/v1.rb
openstax_kitchen-12.0.0 lib/kitchen/directions/bake_custom_sections/v1.rb
openstax_kitchen-11.2.0 lib/kitchen/directions/bake_custom_sections/v1.rb
openstax_kitchen-11.1.0 lib/kitchen/directions/bake_custom_sections/v1.rb