Class: Charsi::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/charsi/generator.rb

Overview

The Generator class is responsible for creating new Charsi projects from our template.

Class Method Summary collapse

Class Method Details

.generate(project, template: 'site') ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/charsi/generator.rb', line 4

def self.generate(project, template: 'site')
  templates_dir  = File.join(__dir__, '../../templates', template)
  templates_glob = File.join(templates_dir, '**', '*.template')

  Dir.glob(templates_glob).each do |template|
    output_path = template.delete_prefix(templates_dir)
    output_path = output_path.delete_suffix('.template')
    output_path = File.join(Dir.pwd, project, output_path)
    
    processed_template = parse_erb(template, project)

    puts "[charsi] #{output_path}"

    Charsi::FileManagement.write(output_path, processed_template)
  end

  puts "\n[charsi] Created new static site: #{project}"
end