Class: Kitchen::Directions::BakeIndex::V1
- Defined in:
- lib/kitchen/directions/bake_index/v1.rb
Overview
Bake directions for eob index
Defined Under Namespace
Classes: Index, IndexItem, IndexSection, Term
Instance Method Summary collapse
- #add_term_to_index(term_element, page_title, term_italicized) ⇒ Object
- #bake(book:, types: %w[main],, uuid_prefix: '') ⇒ Object
Instance Method Details
#add_term_to_index(term_element, page_title, term_italicized) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/kitchen/directions/bake_index/v1.rb', line 157 def add_term_to_index(term_element, page_title, term_italicized) type = if !term_element.key?('index') 'term' elsif term_element['cxlxt:index'] == 'name' || term_element['index'] == 'name' 'name' elsif term_element['cxlxt:index'] == 'foreign' || term_element['index'] == 'foreign' 'foreign' end if term_element.key?('reference') term_reference = term_element['cmlnle:reference'] || term_element['reference'] group_by = term_reference[0] content = term_reference else group_by = I18n.character_to_group(term_element.text.strip[0]) content = term_element.text end group_by = I18n.t(:eob_index_symbols_group) unless group_by.match?(/[[:alpha:]]/) term_element['group-by'] = group_by # Add it to our index object @indexes[type].add_term( Term.new( italicized: term_italicized, text: content, id: term_element.id, group_by: group_by, page_title: page_title.gsub(/\n/, '') ) ) end |
#bake(book:, types: %w[main],, uuid_prefix: '') ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/kitchen/directions/bake_index/v1.rb', line 117 def bake(book:, types: %w[main], uuid_prefix: '') @metadata_elements = book..children_to_keep.copy @uuid_prefix = uuid_prefix @indexes = types.each.with_object({}) do |type, hash| index_name = type == 'main' ? 'term' : type hash[index_name] = Index.new end # Numbering of IDs doesn't depend on term type book.pages.terms.each do |term_element| page = term_element.ancestor(:page) term_element.id = "auto_#{page.id}_term#{term_element.count_in(:book)}" page_title = page.title.text term_italicized = term_element&.first("em[data-effect='italics']") add_term_to_index(term_element, page_title, term_italicized) end book.chapters.composite_pages.terms.each do |term_element| page = term_element.ancestor(:composite_page) chapter = term_element.ancestor(:chapter) term_element.id = "auto_composite_page_term#{term_element.count_in(:book)}" chapter_number = chapter.count_in(:book) page_title = "#{chapter_number} #{page.title.text.strip}".strip term_italicized = term_element&.first("em[data-effect='italics']") add_term_to_index(term_element, page_title, term_italicized) end types.each do |type| @container_class = "os-index#{"-#{type}" unless type == 'main'}-container" @uuid_key = "#{uuid_prefix}index#{"-#{type}" unless type == 'main'}" @title = I18n.t("index.#{type}") index_name = type == 'main' ? 'term' : type @index = @indexes[index_name] book.first('body').append(child: render(file: 'v1.xhtml.erb')) end end |