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!, #as_size, #book_txt_lines, #chapter_label, #commands, #current_book, #dependency_filename, #digest, #executable, #execute, #in_book_directory?, #language_labels, #linux?, #logged_in?, #master_content, #master_filename, #master_latex_header, #mkdir, #os_x?, #path, #raw_lines, #reset_current_book!, #rm, #silence, #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.



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

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

#fragment_nameObject



24
25
26
# File 'lib/softcover/book_manifest.rb', line 24

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

#fragment_pathObject



28
29
30
# File 'lib/softcover/book_manifest.rb', line 28

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

#full_nameObject



62
63
64
# File 'lib/softcover/book_manifest.rb', line 62

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

Returns a chapter heading for use in the navigation menu.



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/softcover/book_manifest.rb', line 37

def menu_heading
  raw_html = Polytexnic::Pipeline.new(title,
                                      language_labels: language_labels).
                                     to_html
  html = Nokogiri::HTML(raw_html).at_css('p').inner_html
  if chapter_number.zero?
    html
  else
    "#{chapter_label(chapter_number)}: #{html}"
  end
end

#nodesObject



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

def nodes
  @nodes ||= []
end

#sourceObject



53
54
55
56
57
58
59
60
# File 'lib/softcover/book_manifest.rb', line 53

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

#to_hashObject



49
50
51
# File 'lib/softcover/book_manifest.rb', line 49

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