Class: Bookery::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/bookery/project.rb

Constant Summary collapse

DEFAULTS =
{
  book_dir: 'book',
  assets_dir: 'assets',
  config_file: 'config.yml'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_dir, config = {}) ⇒ Project

Returns a new instance of Project.



11
12
13
14
# File 'lib/bookery/project.rb', line 11

def initialize(project_dir, config = {})
  @dir = project_dir
  @config = DEFAULTS.merge(config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/bookery/project.rb', line 3

def config
  @config
end

#dirObject (readonly)

Returns the value of attribute dir.



3
4
5
# File 'lib/bookery/project.rb', line 3

def dir
  @dir
end

Instance Method Details

#assetsObject



34
35
36
37
38
# File 'lib/bookery/project.rb', line 34

def assets
  Dir.glob(File.join(dir, config[:assets_dir], '**/*')).reject do |file|
    File.directory?(file) or file =~ /\/(includes|templates)\//
  end.sort
end

#book_configObject



16
17
18
19
20
21
22
# File 'lib/bookery/project.rb', line 16

def book_config
  @book_config ||= Proc.new do
    conf = config[:book]
    conf[:template] = File.join(dir, conf[:template])
    conf
  end.call
end

#booksObject



30
31
32
# File 'lib/bookery/project.rb', line 30

def books
  @books ||= load_books
end

#generator_configObject



24
25
26
27
28
# File 'lib/bookery/project.rb', line 24

def generator_config
  conf = config[:generator]
  conf[:project_dir] = dir
  conf
end

#publish(publishers) ⇒ Object



40
41
42
43
44
45
# File 'lib/bookery/project.rb', line 40

def publish(publishers)
  books.each do |book|
    prepare_output_dir(book)
    publishers.each { |publisher| publisher.publish(book) }
  end
end