module Docfu::Skeleton

Public Class Methods

files_location() click to toggle source

The location of the files folder.

# File lib/docfu/skeleton.rb, line 15
def files_location
  File.join(File.expand_path(File.dirname(__FILE__)), 'files')
end
generate_info_yml(config) click to toggle source

Takes an info hash and converts it into it’s yaml equivalent config.yml.

@param [ Hash ] config The config hash to convert into the config.yml.

@return [ String ] The configuration yml in string format.

# File lib/docfu/skeleton.rb, line 53
def generate_info_yml(config)
  sane_config = config.inject({}) {|res, (k,v)| res[k.to_s] = v; res }
  sane_config['author'] ||= 'author'
  sane_config['title'] ||= 'title'
  sane_config['exclude'] = sane_config['exclude'].split(",")
  info_erb_file = "#{templates_location}/info.yml.erb"
  info_template = ERB.new(IO.read(info_erb_file), 0, '<>')
  info_template.result(binding)
end
setup_directory_structure(folder) click to toggle source

Sets up a new directory structure for a document project.

@param [ String ] folder The project path.

# File lib/docfu/skeleton.rb, line 6
def setup_directory_structure(folder)
  Dir.mkdir(folder) unless Dir.exists? folder
  %w( figures figures-dia figures-source en ).each do |fold|
    Dir.mkdir("#{folder}/#{fold}") unless Dir.exists? "#{folder}/#{fold}"
  end
  setup_readme(folder)
end
setup_readme(project) click to toggle source

Sets up the README for the project.

@param [ String ] project The name of the new project.

# File lib/docfu/skeleton.rb, line 27
def setup_readme(project)
  readme_erb_file = "#{templates_location}/README.md.erb"
  readme_template = ERB.new(IO.read(readme_erb_file), 0, '<>')
  unless File.exists? "#{project}/README.md"
    File.open("#{project}/README.md", 'w') { |f|
      f.write(readme_template.result(binding))
    }
  end
end
templates_location() click to toggle source

The location of the templates folder.

# File lib/docfu/skeleton.rb, line 20
def templates_location
  File.join(File.expand_path(File.dirname(__FILE__)), 'templates')
end
write_config_yml(project) click to toggle source

Writes the config.yml if it’s missing for the current project, otherwise it returns early.

# File lib/docfu/skeleton.rb, line 39
def write_config_yml(project)
  config_file = "#{project}/config.yml"
  unless File.exists? config_file
    puts "Creating config.yml..."
    cfg = File.open("#{files_location}/config.yml", 'r').read
    File.open(config_file, 'w') { |f| f.write(cfg) }
  end
end
write_info_yml(project, info) click to toggle source

Writes the info.yml if it’s missing for the current project, otherwise it returns early.

@param [ Hash ] info The info hash to pass.

# File lib/docfu/skeleton.rb, line 67
def write_info_yml(project, info)
  unless File.exists? "#{project}/info.yml"
    puts "Creating info.yml..."
    inf = generate_info_yml(info)
    File.open("#{project}/info.yml", 'w') { |f| f.write(inf) }
  end
end