Module: Rpub::CompilationHelpers

Included in:
Rpub::Commands::Clean, Rpub::Commands::Compile, Rpub::Commands::Package, Rpub::Commands::Preview
Defined in:
lib/rpub/compilation_helpers.rb

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

#configHash

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

Returns:

  • (Hash)

    parsed configuration

Raises:



40
41
42
43
44
45
# File 'lib/rpub/compilation_helpers.rb', line 40

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:



12
13
14
15
16
# File 'lib/rpub/compilation_helpers.rb', line 12

def create_book
  book = Book.new(layout, config)
  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)



27
28
29
# File 'lib/rpub/compilation_helpers.rb', line 27

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>)


22
23
24
# File 'lib/rpub/compilation_helpers.rb', line 22

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)



32
33
34
# File 'lib/rpub/compilation_helpers.rb', line 32

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