Class: Rpub::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/rpub/context.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Context

Returns a new instance of Context.



5
6
7
8
9
# File 'lib/rpub/context.rb', line 5

def initialize(options = {})
  @config_file = options[:config]
  @layout      = options[:layout]
  @styles      = options[:styles]
end

Instance Method Details

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


33
34
35
# File 'lib/rpub/context.rb', line 33

def chapter_files
  @chapter_files ||= filter_exceptions(source_files).sort.map(&method(:read))
end

#configObject



11
12
13
# File 'lib/rpub/context.rb', line 11

def config
  @config ||= OpenStruct.new(YAML.load_file(config_file) || {})
end

#fontsObject



25
26
27
# File 'lib/rpub/context.rb', line 25

def fonts
  @fonts ||= read(styles).scan(/url\((?:'|")?([^'")]+\.[ot]tf)(?:'|")?\)/i).flatten
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)



16
17
18
# File 'lib/rpub/context.rb', line 16

def layout
  @layout ||= own_or_support_file('layout.html')
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)



21
22
23
# File 'lib/rpub/context.rb', line 21

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