class CourseGen::Templates

Class Templates represent a Coursegen template.

Public Class Methods

new() click to toggle source

invoke methods from Thor::Actions

Calls superclass method
# File lib/coursegen/templates.rb, line 49
def initialize
  super
  destination_root = Dir.getwd
end
source_root() click to toggle source
# File lib/coursegen/templates.rb, line 44
def self.source_root
  Pathname.new(File.dirname(__FILE__)).parent.parent.to_s
end

Public Instance Methods

copy_template_dir(from, to) click to toggle source
# File lib/coursegen/templates.rb, line 58
def copy_template_dir(from, to)
  directory("templates/#{from}", to.to_s)
end
copy_template_file(from, to) click to toggle source
# File lib/coursegen/templates.rb, line 62
def copy_template_file(from, to)
  template("templates/#{from}", to.to_s)
end
create_empty_dir(to) click to toggle source
# File lib/coursegen/templates.rb, line 54
def create_empty_dir(to)
  empty_directory(to)
end
delete_target_file(to) click to toggle source
# File lib/coursegen/templates.rb, line 66
def delete_target_file(to)
  remove_file(to)
end
generate_all() click to toggle source

Generate_all generates a Coursegen site using the default template.

# File lib/coursegen/templates.rb, line 11
def generate_all
  copy_template_dir('layouts', 'layouts')
  copy_template_dir('content/bootstrap', 'content/bootstrap')
  copy_template_dir('content/content', 'content/content')
  delete_target_file('lib/default.rb')
  copy_template_dir('lib', 'lib')
  delete_target_file('Rules')
  copy_template_file('Rules', 'Rules')
  copy_template_file('.gitignore', '.gitignore')
  copy_template_file('cg_config.rb', 'cg_config.rb')
  copy_template_file('cg_config.rb_sample', 'cg_config.rb_sample')
  delete_target_file('content/stylesheet.css')
  delete_target_file('content/index.html')
  delete_target_file('layouts/default.html')
  create_empty_dir('content/images')
end
valid_cg_directory?() click to toggle source

Valid_cg_directory? checks if the underlying directory is a valid nanoc site.

This method is used by Coursegen::CLI.

# File lib/coursegen/templates.rb, line 32
def valid_cg_directory?
  valid = true
  list = ['Rules', 'nanoc.yaml', 'content', 'lib']
  list.each do |filename|
    unless File.exist?(filename)
      valid = false
      say("Required file not found: #{filename}")
    end
  end
  valid
end