class LessonsIndexer::Course
Attributes
dir[R]
headings[R]
headings_dir[R]
lessons[R]
title[R]
Public Class Methods
new(course_dir, headings_dir)
click to toggle source
# File lib/lessons_indexer/course.rb, line 8 def initialize(course_dir, headings_dir) @dir = course_dir @headings_dir = headings_dir @title = dir.gsub(/_handouts\z/i, '').titlecase @headings = [] end
Public Instance Methods
generate_files(lessons_count)
click to toggle source
# File lib/lessons_indexer/course.rb, line 15 def generate_files(lessons_count) within(dir, true) do lessons_count.map {|l| Integer(l)}.each_with_index do |steps, lesson| (1..steps).each do |step| File.new("lesson#{lesson + 1}-#{step}.md", 'w+').close end end end end
generate_headings() { |"\n\n", path| ... }
click to toggle source
# File lib/lessons_indexer/course.rb, line 31 def generate_headings lessons.each do |lesson| lesson_heading = headings.for(lesson) if lesson_heading yield "\n\n", lesson.path else warning pou('warnings.heading_not_found', lesson: lesson.name) end end end
generate_index()
click to toggle source
# File lib/lessons_indexer/course.rb, line 25 def generate_index lessons.list.sort.inject(pou('course.index_title', title: title)) do |memo, lesson| memo + lesson.link(dir) end end
generate_pdfs()
click to toggle source
# File lib/lessons_indexer/course.rb, line 42 def generate_pdfs within(dir, true) do lessons.list.sort.each do |lesson| %x{pandoc #{lesson.file_name} -f markdown_github -o #{lesson.file_name.gsub(/md\z/i, '')}pdf --variable geometry:"top=1.5cm, bottom=2.5cm, left=1.5cm, right=1.5cm" --latex-engine=xelatex --variable mainfont="Open Sans" --variable monofont="Liberation Mono" --variable fontsize="12pt"} end end end
load_headings!()
click to toggle source
# File lib/lessons_indexer/course.rb, line 50 def load_headings! within(dir + '/' + headings_dir, true) do @headings = HeadingsList.new(all_with_pattern(Heading::VERSION_PATTERN).map {|heading| Heading.new(heading)}) end end
load_lessons!()
click to toggle source
# File lib/lessons_indexer/course.rb, line 56 def load_lessons! within(dir, true) do @lessons = LessonsList.new(all_with_pattern(Lesson::NAME_PATTERN).map {|lesson| Lesson.new(lesson)}) end end
Private Instance Methods
all_with_pattern(pattern)
click to toggle source
# File lib/lessons_indexer/course.rb, line 64 def all_with_pattern(pattern) Dir.entries('.').keep_if {|f| f =~ pattern } end