Class: EpubForge::Project

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

Constant Summary collapse

SETTINGS_FOLDER =
"settings"
CONFIG_FILE_NAME =
"config.rb"
PROJECT_ACTIONS_DIRECTORY =
"actions"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_dir) ⇒ Project

Returns a new instance of Project.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/epubforge/project/project.rb', line 11

def initialize( root_dir )
  @root_dir = FunWith::Files::FilePath.new( root_dir ).expand
  
  load_configuration

  @notes_dir = config.notes_dir || @root_dir.join( "notes" )
  @book_dir  = config.book_dir  || @root_dir.join( "book" )

  @project_basename = default_project_basename
  @filename_for_book = @root_dir.join( "#{default_project_basename}" )
  @filename_for_notes = @root_dir.join( "#{default_project_basename}.notes" )
end

Instance Attribute Details

#actions_dirObject (readonly)

Returns the value of attribute actions_dir.



7
8
9
# File 'lib/epubforge/project/project.rb', line 7

def actions_dir
  @actions_dir
end

#book_dirObject (readonly)

Returns the value of attribute book_dir.



7
8
9
# File 'lib/epubforge/project/project.rb', line 7

def book_dir
  @book_dir
end

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/epubforge/project/project.rb', line 7

def config
  @config
end

#config_fileObject (readonly)

Returns the value of attribute config_file.



7
8
9
# File 'lib/epubforge/project/project.rb', line 7

def config_file
  @config_file
end

#filename_for_bookObject (readonly)

Returns the value of attribute filename_for_book.



7
8
9
# File 'lib/epubforge/project/project.rb', line 7

def filename_for_book
  @filename_for_book
end

#filename_for_notesObject (readonly)

Returns the value of attribute filename_for_notes.



7
8
9
# File 'lib/epubforge/project/project.rb', line 7

def filename_for_notes
  @filename_for_notes
end

#notes_dirObject (readonly)

Returns the value of attribute notes_dir.



7
8
9
# File 'lib/epubforge/project/project.rb', line 7

def notes_dir
  @notes_dir
end

#project_basenameObject (readonly)

Returns the value of attribute project_basename.



7
8
9
# File 'lib/epubforge/project/project.rb', line 7

def project_basename
  @project_basename
end

#root_dirObject (readonly)

Returns the value of attribute root_dir.



7
8
9
# File 'lib/epubforge/project/project.rb', line 7

def root_dir
  @root_dir
end

Class Method Details

.is_project_dir?(dir) ⇒ Boolean

TODO: should test be more definitive?

Returns:

  • (Boolean)


30
31
32
33
34
35
# File 'lib/epubforge/project/project.rb', line 30

def self.is_project_dir?( dir )
  dir = dir && (dir.is_a?(String) || dir.is_a?(FunWith::Files::FilePath)) ? dir.fwf_filepath : nil
  return false if dir.nil?
  
  ( dir.exist? && dir.join( SETTINGS_FOLDER, CONFIG_FILE_NAME ).exist? && dir.join( "book" ).directory? ) ? dir : false
end

Instance Method Details

#actions_directoryObject



50
51
52
# File 'lib/epubforge/project/project.rb', line 50

def actions_directory
  settings_folder( ACTIONS_DIRECTORY )
end

#chaptersObject



54
55
56
# File 'lib/epubforge/project/project.rb', line 54

def chapters
  @book_dir.glob("chapter-????.*")
end

#default_project_basenameObject

shorthand string that ‘names’ the project, like the_vampire_of_the_leeky_hills. Variable-ish, used within filenames



25
26
27
# File 'lib/epubforge/project/project.rb', line 25

def default_project_basename
  config.filename || @root_dir.basename.to_s.gsub( /\.epubforge$/ , '' )
end

#load_configurationObject



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/epubforge/project/project.rb', line 74

def load_configuration
  puts "NO CONFIGURATION FILE DETECTED" unless config_file.file?
  
  begin
    self.install_fwc_config_from_file( config_file )
    true
  rescue SyntaxError => e
    puts "Syntax Error in project configuration file #{config_file}. Quitting.".paint(:red)
    puts e.message
    exit(-1)
  end
end

#pages(orderer = nil) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/epubforge/project/project.rb', line 59

def pages( orderer = nil )
  case orderer
  when NilClass
    orderer = Utils::FileOrderer.new( self.config.pages.book || [] )
  when Utils::FileOrderer
    # pass
  when Array
    orderer = Utils::FileOrderer.new( orderer )
  else
    raise "Project#pages cannot take #{order.class} as an ordering object."
  end
  
  orderer.reorder( @book_dir.glob( ext: EpubForge::Builder::PAGE_FILE_EXTENSIONS ) )
end

#project_exists?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/epubforge/project/project.rb', line 37

def project_exists?
  @root_dir.exist? && config_file.exist?
end

#settings_folder(*args) ⇒ Object



41
42
43
44
# File 'lib/epubforge/project/project.rb', line 41

def settings_folder(*args)
  @settings_folder ||= @root_dir.join( SETTINGS_FOLDER )
  @settings_folder.join( *args )
end