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, #first_path, #get_filename, #html_extension, #in_book_directory?, #language_labels, #linux?, #logged_in?, #master_content, #master_filename, #master_latex_header, #mkdir, #non_comment_lines, #os_x?, #path, #polytexnic_html, #raw_lines, #reset_current_book!, #rm, #rm_r, #silence, #silence_stream, #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.



93
94
95
# File 'lib/softcover/book_manifest.rb', line 93

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

#fragment_nameObject



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

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

#fragment_pathObject



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

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

#full_nameObject



86
87
88
# File 'lib/softcover/book_manifest.rb', line 86

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

#html_titleObject

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



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

def html_title
  self.polytexnic_html(title)
end

Returns a chapter heading for use in the navigation menu.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/softcover/book_manifest.rb', line 51

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



46
47
48
# File 'lib/softcover/book_manifest.rb', line 46

def nodes
  @nodes ||= []
end

#sourceObject



77
78
79
80
81
82
83
84
# File 'lib/softcover/book_manifest.rb', line 77

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

#to_hashObject



73
74
75
# File 'lib/softcover/book_manifest.rb', line 73

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