Module: Kitchen::Directions::EocSectionTitleLinkSnippet

Defined in:
lib/kitchen/directions/eoc_section_title_link_snippet.rb

Class Method Summary collapse

Class Method Details

.v1(page:, title_tag: 'h3', wrapper: 'link') ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/kitchen/directions/eoc_section_title_link_snippet.rb', line 6

def self.v1(page:, title_tag: 'h3', wrapper: 'link')
  if page.is_introduction?
    os_number = ''
  else
    chapter = page.ancestor(:chapter)
    os_number =
      <<~HTML
        <span class="os-number">#{chapter.count_in(:book)}.#{page.count_in_chapter_without_intro_page}</span>
        <span class="os-divider"> </span>
      HTML
  end

  title_snippet = <<~HTML
    <#{title_tag} data-type="document-title" id="#{page.title.copied_id}">
      #{os_number}
      <span class="os-text" data-type="" itemprop="">#{page.title_text}</span>
    </#{title_tag}>
  HTML

  case wrapper
  when 'link'
    <<~HTML
      <a href="##{page.title.id}">
        #{title_snippet}
      </a>
    HTML
  when 'div'
    <<~HTML
      <div>
        #{title_snippet}
      </div>
    HTML
  else
    title_snippet
  end
end