Module: Rpub::CompilationHelpers
- Included in:
- Rpub::Commands::Clean, Rpub::Commands::Compile, Rpub::Commands::Package, Rpub::Commands::Preview, Rpub::Commands::Stats
- 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
- #concatenated_document ⇒ Object
-
#config ⇒ Hash
Load the contents of
config.yml
into aHash
object. -
#create_book ⇒ Rpub::Book
Factory method for Book objects, loading every markdown file as a chapter.
-
#layout ⇒ String
Path to the current layout file (defaulting to built-in).
-
#markdown_files ⇒ Array<String>
All chapter input files loaded into strings.
-
#styles ⇒ String
Path to the current stylesheet file (defaulting to built-in).
Instance Method Details
#concatenated_document ⇒ Object
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 |
#config ⇒ Hash
Load the contents of config.yml
into a Hash
object.
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_book ⇒ Rpub::Book
Factory method for Book objects, loading every markdown file as a chapter.
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 |
#layout ⇒ String
Returns 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_files ⇒ Array<String>
All chapter input files loaded into strings. This does not include any of the files listed in the ignore
configuration key.
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 |
#styles ⇒ String
Returns 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 |