Class: Belajar::Generator
- Inherits:
-
Object
- Object
- Belajar::Generator
- Defined in:
- lib/belajar/generator.rb
Constant Summary collapse
- LEADING_NUMBERS =
/^\d+[\_\-\s]/
- PART_JOINTS =
/[\_\-\s]+/
Instance Method Summary collapse
Instance Method Details
#prepare ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/belajar/generator.rb', line 25 def prepare begin solutions_path = Belajar.config.solutions_path rescue ConfigurationError 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 |
#scaffold(courses_path, target_path) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/belajar/generator.rb', line 8 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 |