Module: Rpub::CompilationHelpers

Overview

Provide a set of helper methods that are used across various commands to simplify the compilation process. These methods mostly deal with loading files from the current project directory.

Instance Method Summary collapse

Instance Method Details

#concatenated_documentObject



7
8
9
10
11
12
# File 'lib/rpub/compilation_helpers.rb', line 7

def concatenated_document
  Kramdown::Document.new(
    markdown_files.join("\n"),
    KRAMDOWN_OPTIONS.merge(:template => layout)
  )
end

#configHash

Load the contents of +config.yml+ into a +Hash+ object.

Returns:

  • (Hash)

    parsed configuration

Raises:



47
48
49
50
51
52
# File 'lib/rpub/compilation_helpers.rb', line 47

def config
  @config_file ||= begin
    raise NoConfiguration unless File.exist?('config.yml')
    YAML.load_file('config.yml') || {}
  end
end

#create_bookRpub::Book

Factory method for Book objects, loading every markdown file as a chapter.

Returns:

See Also:



19
20
21
22
23
# File 'lib/rpub/compilation_helpers.rb', line 19

def create_book
  book = Book.new(layout, config, fonts)
  markdown_files.each(&book.method(:<<))
  book
end

#layoutString

Returns path to the current layout file (defaulting to built-in).

Returns:

  • (String)

    path to the current layout file (defaulting to built-in)



34
35
36
# File 'lib/rpub/compilation_helpers.rb', line 34

def layout
  @layout ||= own_or_support_file('layout.html')
end

#markdown_filesArray<String>

All chapter input files loaded into strings. This does not include any of the files listed in the +ignore+ configuration key.

Returns:

  • (Array<String>)


29
30
31
# File 'lib/rpub/compilation_helpers.rb', line 29

def markdown_files
  @markdown_files ||= filter_exceptions(Dir['*.md']).sort.map(&File.method(:read))
end

#stylesString

Returns path to the current stylesheet file (defaulting to built-in).

Returns:

  • (String)

    path to the current stylesheet file (defaulting to built-in)



39
40
41
# File 'lib/rpub/compilation_helpers.rb', line 39

def styles
  @styles ||= own_or_support_file('styles.css')
end