Sha256: c1e5bc14fdedcf95e0af37332f5f19bfab8041ec6beeb39580dbbdbf2cf9d0e7
Contents?: true
Size: 1.59 KB
Versions: 1
Compression:
Stored size: 1.59 KB
Contents
module Belajar require 'fileutils' require 'active_support' require 'active_support/core_ext' class Generator def scaffold(courses_path, target_path) Dir[File.join(courses_path, "*/*/*/*.md")].each do |file| content_dir_parts = file.split('/')[-4..-2].map do |part| clean_up_path_part(part) end content_dir = File.join(content_dir_parts) directory = File.join(target_path, File.dirname(content_dir)) solution_file = File.basename(content_dir) + Solution::FILE_SUFFIX file_path = File.join(directory, solution_file) create_dir(directory) create_file(file_path) end end def prepare begin solutions_path = Belajar.config.solutions_path rescue ConfigurationError => e base_dir = File.dirname(Belajar.config.courses_path) solutions_dir = Belajar::Configuration::SOLUTIONS_DIR solutions_path = File.join(base_dir, solutions_dir) end create_dir(Belajar.config.courses_path) create_dir(solutions_path) Belajar.config.solutions_path = solutions_path Belajar.config.save end private def create_dir(path) return if path.blank? FileUtils.makedirs(path) unless Dir.exist?(path) end def create_file(path) return if path.blank? create_dir(File.dirname(path)) FileUtils.touch(path) unless File.exist?(path) end def clean_up_path_part(text) leading_numbers = /^\d+[\_\-\s]/ part_joints = /[\_\-\s]+/ text.gsub(leading_numbers, '').gsub(part_joints, '_').downcase end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
belajar-0.1.1 | lib/belajar/generator.rb |