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.

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.

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



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.



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



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

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