Sha256: 540f439874c069a5cc04970590b41e48c06395f7db8bbaf456d14a72b53a7c5b
Contents?: true
Size: 1.02 KB
Versions: 45
Compression:
Stored size: 1.02 KB
Contents
module Softcover module Commands module Exercises extend self def add_to_chapters! require 'securerandom' Dir["chapters/*.tex"].each do |path| str = "" in_exercise = false n = 0 line_number = 0 lines = [] File.read(path).each_line { |line| lines.push line } lines.each do |line| str += line case line when %r{\\subsubsection{Exercises}} in_exercise = true when %r{\\end{enumerate}} in_exercise = false when %r{\\item} if in_exercise && !(lines[line_number + 1] =~ /^%= <span/) str += "%= <span class='exercise' id='ex-#{SecureRandom.hex(3)}'></span>\n" n += 1 end end line_number += 1 end File.open(path, "w") { |f| f.write str } exercises = n == 1 ? "exercise" : "exercises" puts "#{path}: wrote #{n} #{exercises}" end end end end end
Version data entries
45 entries across 45 versions & 1 rubygems