Class: Softcover::BookManifest::Chapter

Inherits:
OpenStruct
  • Object
show all
Includes:
Utils
Defined in:
lib/softcover/book_manifest.rb

Constant Summary

Constants included from Utils

Utils::UNITS

Instance Method Summary collapse

Methods included from Utils

#add_highlight_class!, #article?, #as_size, #book_file_lines, #chapter_label, #commands, #current_book, #dependency_filename, #digest, #executable, #execute, #filename_or_default, #get_filename, #in_book_directory?, #language_labels, #linux?, #logged_in?, #master_content, #master_filename, #master_latex_header, #mkdir, #non_comment_lines, #os_x?, #path, #raw_lines, #reset_current_book!, #rm, #rm_r, #silence, #template_dir, #tmpify, #unpublish_slug, #write_master_latex_file, #write_pygments_file

Instance Method Details

#cache_filenameObject

Returns the name for the cached version of the chapters. This is used when processing Markdown to avoid unnecessary calls to kramdown’s to_latex method, which can get expensive.



89
90
91
# File 'lib/softcover/book_manifest.rb', line 89

def cache_filename
  Softcover::Utils.path("tmp/#{full_name}.cache")
end

#fragment_nameObject



33
34
35
# File 'lib/softcover/book_manifest.rb', line 33

def fragment_name
  "#{slug}_fragment.html"
end

#fragment_pathObject



37
38
39
# File 'lib/softcover/book_manifest.rb', line 37

def fragment_path
  File.join('html', fragment_name)
end

#full_nameObject



82
83
84
# File 'lib/softcover/book_manifest.rb', line 82

def full_name
  "#{slug}#{extension}"
end

#html_titleObject

Run the title through the Polytexnic pipeline to make an HTML title.



64
65
66
67
# File 'lib/softcover/book_manifest.rb', line 64

def html_title
  Nokogiri::HTML(Polytexnic::Pipeline.new(title).to_html).at_css('p')
                                                         .inner_html.strip
end

Returns a chapter heading for use in the navigation menu.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/softcover/book_manifest.rb', line 46

def menu_heading
  raw_html = Polytexnic::Pipeline.new(title,
                                      language_labels: language_labels).
                                     to_html
  doc = Nokogiri::HTML(raw_html).at_css('p')
  # Handle case of a footnote in the chapter title.
  doc.css('sup').each do |footnote_node|
    footnote_node.remove
  end
  html = doc.inner_html
  if chapter_number.zero? || article?
    html
  else
    "#{chapter_label(chapter_number)}: #{html}"
  end
end

#nodesObject



41
42
43
# File 'lib/softcover/book_manifest.rb', line 41

def nodes
  @nodes ||= []
end

#sourceObject



73
74
75
76
77
78
79
80
# File 'lib/softcover/book_manifest.rb', line 73

def source
  case extension
  when '.md'
    :markdown
  when '.tex'
    :polytex
  end
end

#to_hashObject



69
70
71
# File 'lib/softcover/book_manifest.rb', line 69

def to_hash
  marshal_dump.merge({ menu_heading: menu_heading })
end