class EpubForge::Project

Constants

CONFIG_FILE_NAME
PROJECT_ACTIONS_DIRECTORY
SETTINGS_FOLDER

Attributes

actions_dir[R]
book_dir[R]
config[R]
config_file[R]
filename_for_book[R]
filename_for_notes[R]
notes_dir[R]
project_basename[R]
root_dir[R]

Public Class Methods

is_project_dir?( dir ) click to toggle source

TODO: should test be more definitive?

# 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
new( root_dir ) click to toggle source
# 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

Public Instance Methods

actions_directory() click to toggle source
# File lib/epubforge/project/project.rb, line 50
def actions_directory
  settings_folder( ACTIONS_DIRECTORY )
end
chapters() click to toggle source
# File lib/epubforge/project/project.rb, line 54
def chapters
  @book_dir.glob("chapter-????.*")
end
default_project_basename() click to toggle source

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

# File lib/epubforge/project/project.rb, line 25
def default_project_basename
  config.filename || @root_dir.basename.to_s.gsub( /\.epubforge$/ , '' )
end
load_configuration() click to toggle source
# 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 ) click to toggle source
# 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?() click to toggle source
# File lib/epubforge/project/project.rb, line 37
def project_exists?
  @root_dir.exist? && config_file.exist?
end
settings_folder(*args) click to toggle source
# File lib/epubforge/project/project.rb, line 41
def settings_folder(*args)
  @settings_folder ||= @root_dir.join( SETTINGS_FOLDER )
  @settings_folder.join( *args )
end