Class: Plansheet::LaTeXSheet
- Inherits:
-
Object
- Object
- Plansheet::LaTeXSheet
- Defined in:
- lib/plansheet/sheet/latex.rb
Overview
The Sheet class constructs a Markdown/LaTeX file for use with pandoc
Instance Method Summary collapse
-
#initialize(output_file, project_arr) ⇒ LaTeXSheet
constructor
A new instance of LaTeXSheet.
- #project_header(proj) ⇒ Object
- #project_minipage(proj) ⇒ Object
- #sanitize_string(str) ⇒ Object
- #sheet_footer ⇒ Object
- #sheet_header ⇒ Object
Constructor Details
#initialize(output_file, project_arr) ⇒ LaTeXSheet
Returns a new instance of LaTeXSheet.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/plansheet/sheet/latex.rb', line 7 def initialize(output_file, project_arr) projects_str = String.new projects_str << sheet_header project_arr.each do |p| projects_str << project_minipage(p) end puts "Writing to #{output_file}" projects_str << File.write(output_file, projects_str) end |
Instance Method Details
#project_header(proj) ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/plansheet/sheet/latex.rb', line 88 def project_header(proj) str = String.new str << "#{sanitize_string(proj.namespace)}: #{sanitize_string(proj.name)}\\\\\n" str << proj.status.to_s str << " - #{sanitize_string(proj.location)}" if proj.location str << " due: #{proj.due}" if proj.due str << " time: #{proj.time_estimate}" if proj.time_estimate str << " \\\\\n" str end |
#project_minipage(proj) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/plansheet/sheet/latex.rb', line 73 def project_minipage(proj) str = String.new str << "\\begin{minipage}{6cm}\n" str << project_header(proj) proj&.tasks&.each do |t| str << "$\\square$ #{sanitize_string(t)} \\\\\n" end str << "\\end{minipage}\n" str end |
#sanitize_string(str) ⇒ Object
84 85 86 |
# File 'lib/plansheet/sheet/latex.rb', line 84 def sanitize_string(str) str.gsub("_", '\_') end |
#sheet_footer ⇒ Object
69 70 71 |
# File 'lib/plansheet/sheet/latex.rb', line 69 def '\end{document}' end |
#sheet_header ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/plansheet/sheet/latex.rb', line 19 def sheet_header # LaTeX used to be generated by pandoc " \\\\PassOptionsToPackage{unicode}{hyperref}\n \\\\PassOptionsToPackage{hyphens}{url}\n \\\\documentclass[]{article}\n \\\\author{}\n \\\\date{\#{Date.today}}\n \\\\usepackage{amsmath,amssymb}\n \\\\usepackage{lmodern}\n \\\\usepackage{iftex}\n \\\\usepackage[T1]{fontenc}\n \\\\usepackage[utf8]{inputenc}\n \\\\usepackage{textcomp}\n \\\\IfFileExists{upquote.sty}{\\\\usepackage{upquote}}{}\n \\\\IfFileExists{microtype.sty}{\n \\\\usepackage[]{microtype}\n \\\\UseMicrotypeSet[protrusion]{basicmath}\n }{}\n \\\\makeatletter\n \\\\@ifundefined{KOMAClassName}{\n \\\\IfFileExists{parskip.sty}{\n \\\\usepackage{parskip}\n }{\n \\\\setlength{\\\\parindent}{0pt}\n \\\\setlength{\\\\parskip}{6pt plus 2pt minus 1pt}}\n }{\n \\\\KOMAoptions{parskip=half}}\n \\\\makeatother\n \\\\usepackage{xcolor}\n \\\\IfFileExists{xurl.sty}{\\\\usepackage{xurl}}{}\n \\\\IfFileExists{bookmark.sty}{\\\\usepackage{bookmark}}{\\\\usepackage{hyperref}}\n \\\\hypersetup{\n hidelinks,\n pdfcreator={LaTeX via plansheet}}\n \\\\urlstyle{same}\n \\\\usepackage[margin=1.5cm]{geometry}\n \\\\setlength{\\\\emergencystretch}{3em}\n \\\\providecommand{\\\\tightlist}{\n \\\\setlength{\\\\itemsep}{0pt}\\\\setlength{\\\\parskip}{0pt}}\n \\\\setcounter{secnumdepth}{-\\\\maxdimen}\n\n \\\\begin{document}\n\n \\\\thispagestyle{empty}\n\n \\\\section{Date: \#{Date.today}}\n FRONTMATTER\nend\n" |