coursegen 0.8.3 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/pr.yml +19 -0
  3. data/.gitignore +3 -0
  4. data/Gemfile.lock +60 -35
  5. data/README.md +285 -69
  6. data/Rakefile +10 -1
  7. data/coursegen.gemspec +26 -26
  8. data/lib/coursegen.rb +5 -2
  9. data/lib/coursegen/cli.rb +49 -14
  10. data/lib/coursegen/course/data/citem.rb +10 -1
  11. data/lib/coursegen/course/data/data_adaptor.rb +16 -6
  12. data/lib/coursegen/course/data/section.rb +1 -1
  13. data/lib/coursegen/course/helpers/bootstrap_markup.rb +15 -15
  14. data/lib/coursegen/course/helpers/content_helpers.rb +86 -71
  15. data/lib/coursegen/course/helpers/formatting_helpers.rb +6 -10
  16. data/lib/coursegen/course/helpers/ical_feed_helpers.rb +2 -1
  17. data/lib/coursegen/course/helpers/lecture_helpers.rb +3 -2
  18. data/lib/coursegen/course/helpers/list_of.rb +40 -20
  19. data/lib/coursegen/course/helpers/list_of_helpers.rb +20 -14
  20. data/lib/coursegen/course/helpers/logging_helpers.rb +13 -12
  21. data/lib/coursegen/course/helpers/navigation_helpers.rb +62 -23
  22. data/lib/coursegen/course/helpers/sidebar_helpers.rb +19 -18
  23. data/lib/coursegen/course/helpers/table_helpers.rb +5 -4
  24. data/lib/coursegen/course/schedule/scheduler.rb +52 -19
  25. data/lib/coursegen/templates.rb +30 -23
  26. data/lib/coursegen/version.rb +3 -1
  27. data/spec/lectures_spec.rb +60 -50
  28. data/spec/play_spec.rb +24 -12
  29. data/spec/scheduler_spec.rb +87 -27
  30. data/tech_debt.md +5 -0
  31. data/templates/Rules +14 -19
  32. data/templates/cg_config.rb +105 -21
  33. data/templates/content/bootstrap/css/custom.css +87 -151
  34. data/templates/content/bootstrap/css/full-width-pics.css +8 -64
  35. data/templates/content/bootstrap/css/postit.css +7 -0
  36. data/templates/content/bootstrap/css/toasty.css +3 -0
  37. data/templates/content/content/index.md.erb +1 -1
  38. data/templates/content/content/intro/course_toc.md.erb +0 -1
  39. data/templates/content/content/intro/welcome.md.erb +1 -3
  40. data/templates/content/content/lectures/part1/02_here_we_go.md.erb +22 -1
  41. data/templates/content/content/lectures/part2/01_start_part2.md.erb +2 -1
  42. data/templates/content/content/lectures/part2/02_continue_part2.md.erb +3 -2
  43. data/templates/layouts/banner.html.erb +4 -4
  44. data/templates/layouts/body_footer.html +3 -4
  45. data/templates/layouts/body_header.html.erb +25 -7
  46. data/templates/layouts/bottom_includes.html.erb +21 -10
  47. data/templates/layouts/course.html.erb +7 -21
  48. data/templates/layouts/helpful_box.html +1 -1
  49. data/templates/layouts/nav-menus.html.erb +16 -36
  50. data/templates/layouts/sidebar.html.erb +9 -8
  51. data/templates/layouts/slides.html.erb +69 -0
  52. data/templates/layouts/top_includes.html.erb +24 -23
  53. metadata +32 -24
  54. data/.DS_Store +0 -0
  55. data/.vscode/settings.json +0 -2
  56. data/templates/.DS_Store +0 -0
  57. data/templates/Guardfile +0 -9
  58. data/templates/content/bootstrap/css/tipuesearch.css +0 -163
  59. data/templates/content/bootstrap/js/tipuesearch.js +0 -379
  60. data/templates/content/bootstrap/js/tipuesearch.min.js +0 -12
  61. data/templates/content/bootstrap/js/tipuesearch_content.js +0 -13
  62. data/templates/content/bootstrap/js/tipuesearch_set.js +0 -23
  63. data/templates/layouts/main_navbar.html.erb +0 -21
@@ -1,21 +1,17 @@
1
- # Helpers to be used to format content
1
+ # FormattingHelpers is used to format content.
2
2
  module FormattingHelpers
3
-
4
3
  def list_begin
5
- "<dl class=\"dl-horizontal\" style=\"font-size: 125%;\">"
4
+ '<dl class="dl-horizontal" style="font-size: 125%;">'
6
5
  end
7
6
 
8
7
  def list_end
9
- "</dd></dl>"
8
+ '</dd></dl>'
10
9
  end
11
10
 
12
- def le (name, first_entry=false)
13
- str = ""
14
- if !first_entry
15
- str += "</dd><br/>"
16
- end
11
+ def le(name, first_entry = false)
12
+ str = ''
13
+ str += '</dd><br/>' unless first_entry
17
14
  str += "<dt>#{name}</dt><dd>"
18
15
  str
19
16
  end
20
-
21
17
  end
@@ -1,5 +1,6 @@
1
+ # ICalFeedHelpers is used to create icalender.
1
2
  module ICalFeedHelpers
2
- def generate_ical source
3
+ def generate_ical(source)
3
4
  data_adaptor = DataAdaptor.new(source)
4
5
  ical_adaptor = ICalAdaptor.new
5
6
  schedule_feed = ScheduleFeed.new(ical_adaptor, data_adaptor)
@@ -1,9 +1,10 @@
1
+ # LectureHelpers is used to calculate lecture number and date.
1
2
  module LectureHelpers
2
- def lecture_number_str citem
3
+ def lecture_number_str(citem)
3
4
  citem.lecture_number.to_s
4
5
  end
5
6
 
6
7
  def lecture_date
7
- "-ddd-"
8
+ '-ddd-'
8
9
  end
9
10
  end
@@ -1,26 +1,33 @@
1
+ # Class ListOf represents a lecture table.
1
2
  class ListOf
2
- # source: name of a section as a string
3
- # rows: array with one or more of:
4
- # "pages"
5
- # "subsections"
6
- # subsections: array with one or more strings corresponding to subsection string in an item
7
- # .e.g. "/content/topics/arch/"
8
- # cols: array with one or more of:
9
- # :date
10
- # :number
11
- # :title
12
- # :homeworks
13
- # items: refers to nanoc's @items (temp hack!)
14
-
15
- def initialize(markup_adaptor, data_adaptor, rows, cols, subsections, items)
3
+ # Initialize creates an instance of ListOf.
4
+ #
5
+ # source: name of a section as a string
6
+ # rows: array with one or more of:
7
+ # "pages"
8
+ # "subsections"
9
+ # subsections: array with one or more strings corresponding to subsection
10
+ # string in an item
11
+ # e.g. "/content/topics/arch/"
12
+ # cols: array with one or more of:
13
+ # :date
14
+ # :number
15
+ # :title
16
+ # :homeworks
17
+ # :lectref
18
+ # :readings
19
+ # items: refers to nanoc's @items (temp hack!)
20
+ def initialize(markup_adaptor, data_adaptor, rows, cols, subsections, items, headers)
16
21
  @mark = markup_adaptor
17
22
  @rows = rows
18
23
  @cols = cols
19
24
  @data = data_adaptor
20
25
  @subsections = subsections
21
26
  @items = items
27
+ @headers = headers
22
28
  end
23
29
 
30
+ # Render renders the underlying lecture table.
24
31
  def render
25
32
  @mark.table_begin
26
33
  generate_headers
@@ -36,7 +43,7 @@ class ListOf
36
43
 
37
44
  @cols.each do |col|
38
45
  @mark.header_begin
39
- @mark.header_content(@data.column_name(col))
46
+ @mark.header_content(@headers[col] || @data.column_name(col))
40
47
  @mark.header_end
41
48
  end
42
49
 
@@ -46,6 +53,7 @@ class ListOf
46
53
  def generate_rows
47
54
  @data.rows do |row_id|
48
55
  next unless include_row?(row_id)
56
+
49
57
  if subsection_hdr?(row_id)
50
58
  generate_summary_row(row_id)
51
59
  else
@@ -73,11 +81,23 @@ class ListOf
73
81
  end
74
82
 
75
83
  def cell_content_string(row_id, col_selector, detail:)
76
- if (col_selector == :title && detail)
84
+ if col_selector == :title && detail
77
85
  nitem = @items[row_id.identifier]
78
86
  link_to_unless_current(nitem[:title], nitem)
79
- elsif (col_selector == :date)
80
- @data.cell_value(row_id, col_selector).strftime("%b %-d")
87
+ elsif col_selector == :hwref
88
+ tag_value = @data.cell_value(row_id, :hwref)
89
+ tag_value.nil? ? "n/a" : link_to_section(:homework, tag_value.to_sym)
90
+ elsif col_selector == :lectref
91
+ tag_value = @data.cell_value(row_id, :lectref)
92
+ if tag_value.nil?
93
+ "n/a"
94
+ else
95
+ atag_values = tag_value.split(" ")
96
+ atag_links = atag_values.map {|tv| link_to_lecture(tv.to_sym)}
97
+ atag_links.join(", ")
98
+ end
99
+ elsif col_selector == :date
100
+ @data.cell_value(row_id, col_selector).strftime('%b %-d')
81
101
  else
82
102
  @data.cell_value(row_id, col_selector).to_s
83
103
  end
@@ -92,10 +112,10 @@ class ListOf
92
112
  end
93
113
 
94
114
  def include_by_subsection_path?(row_id)
95
- @subsections.length == 0 || @subsections.include?(row_id.subsection)
115
+ @subsections.empty? || @subsections.include?(row_id.subsection)
96
116
  end
97
117
 
98
118
  def subsection_hdr?(row_id)
99
- row_id.type == "subsection"
119
+ row_id.type == 'subsection'
100
120
  end
101
121
  end
@@ -1,20 +1,26 @@
1
+ # ListOfHelpers is used to create a lecture table.
1
2
  module ListOfHelpers
2
-
3
- # source: name of a section as a string
4
- # rows: array with one or more of:
5
- # "page"
6
- # "subsection"
7
- # cols: array with one or more of:
8
- # :date
9
- # :number
10
- # :title
11
- # :homeworks
12
- # :assigned
13
-
14
- def list_of(source:, rows:, cols:, subsections: [], items:)
3
+ # List_of creates and renders a lecture table based on the given info.
4
+ #
5
+ # source: name of a section as a string
6
+ # rows: array with one or more of:
7
+ # "pages"
8
+ # "subsections"
9
+ # cols: array with one or more of:
10
+ # :date
11
+ # :number
12
+ # :title
13
+ # :homeworks
14
+ # :assigned
15
+ # :lectref
16
+ # subsections: array with one or more strings corresponding to subsection
17
+ # string in an item
18
+ # e.g. "/content/topics/arch/"
19
+ # items: refers to nanoc's @items (temp hack!)
20
+ def list_of(source:, rows:, cols:, headers: {}, subsections: [], items:)
15
21
  markup_adaptor = BootstrapMarkup.new
16
22
  data_adaptor = DataAdaptor.new(source)
17
- lecture_table_builder = ListOf.new(markup_adaptor, data_adaptor, rows, cols, subsections, items)
23
+ lecture_table_builder = ListOf.new(markup_adaptor, data_adaptor, rows, cols, subsections, items, headers)
18
24
  lecture_table_builder.render
19
25
  end
20
26
  end
@@ -1,14 +1,15 @@
1
+ # LoggingHelpers is used to debug log items.
1
2
  module LoggingHelpers
2
- def log_item_info
3
- puts
4
- puts "*** ITEM Info: #{item.identifier}"
5
- puts "Parent = #{item.parent}"
6
- puts "Children = #{item.children}"
7
- puts "Reps = #{item.reps}"
8
- pp item.attributes
9
- end
3
+ def log_item_info
4
+ puts
5
+ puts "*** ITEM Info: #{item.identifier}"
6
+ puts "Parent = #{item.parent}"
7
+ puts "Children = #{item.children}"
8
+ puts "Reps = #{item.reps}"
9
+ pp item.attributes
10
+ end
10
11
 
11
- def compiling item
12
- #puts "* compiling #{item[:title]}"
13
- end
14
- end
12
+ def compiling(item)
13
+ # puts "* compiling #{item[:title]}"
14
+ end
15
+ end
@@ -1,6 +1,8 @@
1
- # Used in the nav bar along the top of the page. Called by main_navbar.html.erb
1
+ # NavigationHelpers provides methods for navigating the course.
2
+ # This is used in the nav bar along the top of the page.
3
+ # Called by main_navbar.html.erb
2
4
  module NavigationHelpers
3
- def link_to_lecture item_symbol
5
+ def link_to_lecture(item_symbol)
4
6
  link_to_section :lectures, item_symbol
5
7
  end
6
8
 
@@ -10,73 +12,110 @@ module NavigationHelpers
10
12
  link_to(the_citem.title, the_item)
11
13
  end
12
14
 
13
- def link_to_topic item_symbol
15
+ def link_to_topic(item_symbol)
14
16
  link_to_section :topics, item_symbol
15
17
  end
16
18
 
17
- def link_to_background item_symbol
19
+ def link_to_background(item_symbol)
18
20
  link_to_section :background, item_symbol
19
21
  end
20
22
 
21
- def link_to_cribsheet item_symbol
23
+ def link_to_cribsheet(item_symbol)
22
24
  link_to_section :cribsheets, item_symbol
23
25
  end
24
26
 
25
- def link_to_intro item_symbol
27
+ def link_to_intro(item_symbol)
26
28
  link_to_section :intro, item_symbol
27
29
  end
28
30
 
29
- def link_to_incubator item_symbol
31
+ def link_to_incubator(item_symbol)
30
32
  link_to_section :incubator, item_symbol
31
33
  end
32
34
 
33
- def link_to_lab item_symbol
35
+ def link_to_lab(item_symbol)
34
36
  link_to_section :lab, item_symbol
35
37
  end
36
38
 
37
- def link_to_pa item_symbol
39
+ def link_to_pa(item_symbol)
38
40
  link_to_section :pa, item_symbol
39
41
  end
40
42
 
41
- def link_to_page item_symbol
43
+ def link_to_page(item_symbol)
42
44
  link_to_section :pages, item_symbol
43
45
  end
44
46
 
45
- def link_to_project item_symbol
47
+ def link_to_project(item_symbol)
46
48
  link_to_section :projects, item_symbol
47
49
  end
48
50
 
49
- def link_to_section section_symbol, item_symbol
51
+ def link_to_section(section_symbol, item_symbol)
50
52
  the_item = @items[lookup_nitem(section_symbol.to_s, item_symbol.to_s).identifier]
51
53
  link_to(the_item[:title], the_item)
52
54
  end
53
55
 
54
- def link_to_next toc, item
56
+ def link_to_next(toc, item, attrs = {})
55
57
  next_nitem = toc.find_next_forn(item).identifier
56
- nav_markup2 @items[next_nitem].path, "next"
58
+ link_to 'next', @items[next_nitem].path, attrs
57
59
  end
58
60
 
59
- def link_to_prev toc, item
61
+ def link_to_prev(toc, item, attrs = {})
60
62
  prev_nitem = toc.find_previous_forn(item).identifier
61
- nav_markup2 @items[prev_nitem].path, "previous"
63
+ link_to 'previous', @items[prev_nitem].path, attrs
62
64
  end
63
65
 
64
- def link_to_inclusion item
66
+ def link_to_inclusion(item)
65
67
  inclusion = Toc.instance.lookup_inclusion(item)
66
68
  if inclusion.nil?
67
- "(never included)"
69
+ '(never included)'
68
70
  else
69
71
  " (#{inclusion.identifier})"
70
72
  end
71
73
  end
72
74
 
73
- private
75
+ # def link_to_slides_2
76
+ # '<a
77
+ # class="btn btn-sm btn-primary"
78
+ # href="./slides.html"
79
+ # title="slides">
80
+ # <i class="fas fa-chalkboard-teacher"></i> Slides
81
+ # </a>'
82
+ # end
74
83
 
75
- def nav_markup text, path, icon, tooltip=""
76
- "<a class=\"nav-btn btn btn-mini\" href=\"#{path}\"><i class=\"#{icon}\" rel=\"tooltip\" title=\"#{tooltip}\"></i>#{text}</a>"
84
+ def link_to_slides(attrs = {})
85
+ link_to("slides", "./slides.html", attrs)
77
86
  end
78
87
 
79
- def nav_markup2 path, text
80
- "<a class=\"btn btn-sm btn-light\" href=\"#{path}\">#{text}</a>"
88
+ # def link_to_homework_2(citem)
89
+ # unless citem.hwref.nil?
90
+ # "<div class=\"btn btn-sm btn-primary\">" +
91
+ # "<i class=\"fad fa-backpack\"></i>" +
92
+ # link_to_section(:homework, citem.hwref.to_sym) +
93
+ # "</div>"
94
+ # end
95
+ # end
96
+
97
+ def link_to_homework(citem, attrs = {})
98
+ return "" if citem.hwref.nil?
99
+
100
+ the_item = @items[lookup_nitem("homework", citem.hwref).identifier]
101
+ # link_to(the_item[:title], the_item, attrs)
102
+ link_to("homework", the_item, attrs)
81
103
  end
104
+
105
+ private
106
+
107
+ # def nav_markup2(text, path, icon, tooltip = '')
108
+ # "<a class=\"nav-btn btn btn-mini\" href=\"#{path}\">
109
+ # <i class=\"#{icon}\" rel=\"tooltip\" title=\"#{tooltip}\"></i>#{text}</a>"
110
+ # end
111
+
112
+ def nav_markup(path, text)
113
+ "<a class=\"btn btn-sm btn-primary\" href=\"#{path}\">#{text}</a>"
114
+ end
115
+
116
+ # def nav_markup_3(path, text, fontawesome, tooltip = '')
117
+ # "<a class=\"btn btn-sm btn-primary\" href=\"#{path}\">" +
118
+ # "<i class=\"#{fontawesome}\"></i>" +
119
+ # "#{text}</a>"
120
+ # end
82
121
  end
@@ -1,22 +1,22 @@
1
- # Set of helpers to display the navigation sidebar
1
+ # SidebarHelpers is a set of helpers to display the navigation sidebar.
2
2
  module SidebarHelpers
3
- def section_helper title: nil, selector: nil
3
+ def section_helper(title: nil, selector: nil)
4
4
  sect = Toc.instance.section(selector)
5
5
  @sect_def = Toc.instance.section_def(selector)
6
6
  str = "<li>
7
7
  <label class=\"tree-toggler level1\">
8
8
  #{collapsed_indicator(sect.collapsed?)}
9
9
  #{title}
10
- </label>"
11
- str += sect.has_subsections? ? nested_section(sect) : flat_section(sect)
12
- str + "</li>"
10
+ </label>
11
+ #{sect.has_subsections? ? nested_section(sect) : flat_section(sect)}
12
+ </li>"
13
13
  end
14
14
 
15
- def nested_section sect
16
- sect.subsections.reduce("") {|acc, subs| acc + subsection_body(subs)}
15
+ def nested_section(sect)
16
+ sect.subsections.reduce('') { |acc, subs| acc + subsection_body(subs) }
17
17
  end
18
18
 
19
- def subsection_body sect
19
+ def subsection_body(sect)
20
20
  "<ul class=\"tree\">
21
21
  <li>
22
22
  <label class=\"tree-toggler level2\">
@@ -33,34 +33,35 @@ module SidebarHelpers
33
33
  end
34
34
 
35
35
  def subsection(subsect, collapsed)
36
- disp_clause = collapsed ? "display: none" : "display: block"
36
+ disp_clause = collapsed ? 'display: none' : 'display: block'
37
37
  str = "<ul class=\"tree\" style=\"#{disp_clause}\">"
38
38
  str = subsect.children.reduce(str) { |acc, item| acc + subsection_item_link(item) }
39
- str + "</ul>"
39
+ str + '</ul>'
40
40
  end
41
41
 
42
- def subsection_item_link tree_node
42
+ def subsection_item_link(tree_node)
43
43
  bullet = @sect_def.options[:bullet]
44
44
  link_path = @items[tree_node.content.identifier].path
45
45
  "<li class=\"#{tree_node.content.css_class}\">#{icon_markup(bullet)}<a href=\"#{link_path}\">#{tree_node.content.title}</a></li>"
46
46
  end
47
47
 
48
- def flat_section sect
49
- disp_clause = sect.collapsed? ? "display: none" : "display: block"
48
+ def flat_section(sect)
49
+ disp_clause = sect.collapsed? ? 'display: none' : 'display: block'
50
50
  str = "<ul class=\"tree\" style=\"#{disp_clause}\">"
51
51
  str = sect.reduce(str) { |acc, item| acc + flat_section_item_link(item) }
52
- str + "</ul>"
52
+ str + '</ul>'
53
53
  end
54
54
 
55
- def flat_section_item_link citem
55
+ def flat_section_item_link(citem)
56
56
  bullet = @sect_def.options[:bullet]
57
57
  path = @items[citem.identifier].path
58
58
  "<li class=\"#{citem.css_class}\">#{icon_markup(bullet)}<a href=\"#{path}\">#{citem.title}</a></li>"
59
59
  end
60
60
 
61
- def icon_markup icon_type
62
- return "" if icon_type.nil?
63
- css_class = {dash: "glyphicon-minus", star: "glyphicon-star", plus: "glyphicon-plus-sign", minus: "glyphicon-minus-sign"}.fetch(icon_type)
61
+ def icon_markup(icon_type)
62
+ return '' if icon_type.nil?
63
+
64
+ css_class = { dash: 'glyphicon-minus', star: 'glyphicon-star', plus: 'glyphicon-plus-sign', minus: 'glyphicon-minus-sign' }.fetch(icon_type)
64
65
  "<span class=\"glyphicon #{css_class}\" style=#{STYLING_CONFIG[:bullet_style]}></span>"
65
66
  end
66
67
  end
@@ -1,3 +1,4 @@
1
+ # Class TableHelper provides methods for creating a table.
1
2
  class TableHelper
2
3
  def initialize(*property)
3
4
  @prop = property
@@ -5,9 +6,9 @@ class TableHelper
5
6
  end
6
7
 
7
8
  def headers(*labels)
8
- css_style = ""
9
- css_style += " table-condensed" if @prop.include? :normal
10
- css_style += " table-bordered" if @prop.include? :bordered
9
+ css_style = ''
10
+ css_style += ' table-condensed' if @prop.include? :normal
11
+ css_style += ' table-bordered' if @prop.include? :bordered
11
12
  @bm.table_begin(css_style)
12
13
  @bm.headers_begin
13
14
  labels.each do |h|
@@ -28,7 +29,7 @@ class TableHelper
28
29
  @bm.row_end
29
30
  end
30
31
 
31
- def render()
32
+ def render
32
33
  @bm.table_end
33
34
  @bm.render
34
35
  end