Class: Bookingit::Config

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/bookingit/config.rb

Defined Under Namespace

Classes: Chapter, Matter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_json, root_dir) ⇒ Config

Returns a new instance of Config.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bookingit/config.rb', line 16

def initialize(config_json,root_dir)
  config_hash = JSON.parse(config_json)

  @front_matter     = Matter.new(config_hash.delete('front_matter'),root_dir)
  @main_matter      = Matter.new(config_hash.delete('main_matter'),root_dir)
  @back_matter      = Matter.new(config_hash.delete('back_matter'),root_dir)
  @templates        = config_hash.delete("templates") || {}
  @templates["index"] ||= "index.html"
  @rendering_config = create_rendering_config(config_hash.delete('rendering'))
  @cache            = false
  @options          = config_hash

  all_chapters = (@front_matter.chapters + @main_matter.chapters + @back_matter.chapters)
  all_chapters.each_with_index do |chapter,i|
    if i > 0
      all_chapters[i-1].next_chapter = chapter
      chapter.previous_chapter = all_chapters[i-1]
    end
    if i < (all_chapters.size-1)
      all_chapters[i+1].previous_chapter = chapter
      chapter.next_chapter = all_chapters[i+1]
    end
  end
end

Instance Attribute Details

#back_matterObject (readonly)

Returns the value of attribute back_matter.



8
9
10
# File 'lib/bookingit/config.rb', line 8

def back_matter
  @back_matter
end

#cacheObject

Returns the value of attribute cache.



8
9
10
# File 'lib/bookingit/config.rb', line 8

def cache
  @cache
end

#front_matterObject (readonly)

Returns the value of attribute front_matter.



8
9
10
# File 'lib/bookingit/config.rb', line 8

def front_matter
  @front_matter
end

#main_matterObject (readonly)

Returns the value of attribute main_matter.



8
9
10
# File 'lib/bookingit/config.rb', line 8

def main_matter
  @main_matter
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/bookingit/config.rb', line 8

def options
  @options
end

#rendering_configObject (readonly)

Returns the value of attribute rendering_config.



8
9
10
# File 'lib/bookingit/config.rb', line 8

def rendering_config
  @rendering_config
end

#templatesObject (readonly)

Returns the value of attribute templates.



8
9
10
# File 'lib/bookingit/config.rb', line 8

def templates
  @templates
end