coursegen 0.3.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Gemfile.lock +50 -46
  4. data/coursegen.gemspec +2 -3
  5. data/deleteme.rb +2 -0
  6. data/lib/coursegen/cli.rb +5 -3
  7. data/lib/coursegen/course/data/citem.rb +26 -27
  8. data/lib/coursegen/course/data/data_adaptor.rb +5 -1
  9. data/lib/coursegen/course/data/lectures.rb +84 -72
  10. data/lib/coursegen/course/data/section.rb +53 -53
  11. data/lib/coursegen/course/data/section_def.rb +6 -6
  12. data/lib/coursegen/course/data/toc.rb +1 -2
  13. data/lib/coursegen/course/helpers/bootstrap_markup.rb +3 -2
  14. data/lib/coursegen/course/helpers/content_helpers.rb +121 -75
  15. data/lib/coursegen/course/helpers/ical_feed_helpers.rb +1 -1
  16. data/lib/coursegen/course/helpers/list_of.rb +12 -12
  17. data/lib/coursegen/course/helpers/list_of_helpers.rb +2 -2
  18. data/lib/coursegen/course/helpers/navigation_helpers.rb +35 -26
  19. data/lib/coursegen/course/helpers/sidebar_helpers.rb +12 -16
  20. data/lib/coursegen/course/lib/ical_adaptor.rb +3 -5
  21. data/lib/coursegen/course/lib/search_data_generator.rb +3 -4
  22. data/lib/coursegen/course/schedule/schedule_def.rb +12 -11
  23. data/lib/coursegen/course/schedule/schedule_feed.rb +3 -1
  24. data/lib/coursegen/course/schedule/scheduler.rb +20 -13
  25. data/lib/coursegen/version.rb +1 -1
  26. data/lib/coursegen.rb +10 -9
  27. data/spec/play_spec.rb +15 -19
  28. data/spec/scheduler_spec.rb +59 -63
  29. data/spec/spec_helper.rb +1 -1
  30. data/spec/toc_spec.rb +69 -71
  31. data/tech_debt.md +0 -3
  32. data/templates/Guardfile +2 -2
  33. data/templates/body_footer.html +8 -0
  34. data/templates/body_header.html.erb +6 -0
  35. data/templates/cg_config.rb +8 -7
  36. data/templates/content/bootstrap/css/custom.css +25 -8
  37. data/templates/content/content/intro/course_toc.md.erb +1 -1
  38. data/templates/course.html +59 -0
  39. data/templates/helpful_box.html +3 -0
  40. data/templates/layouts/body_header.html.erb +1 -1
  41. data/templates/layouts/course.html +3 -2
  42. data/templates/layouts/main_navbar.html.erb +1 -1
  43. data/templates/main_navbar.html.erb +21 -0
  44. metadata +22 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b322dd02a98ca5645c7d05ccf2719621d839e81
4
- data.tar.gz: 483636c23919921450427154eb2e1e024381fc97
3
+ metadata.gz: 4aa75e9754a6ce6c2062f4c37aab0846397a9412
4
+ data.tar.gz: 634163b939293459d18e57444f41919b3317d277
5
5
  SHA512:
6
- metadata.gz: 019dbe06a5ea815dd3bbca53a0c8308bfd2465dffff50c9b29da8caedfdd710c3c211441531e31562c4037058e65078cadda60c1e1d979047b7e2fec8a417698
7
- data.tar.gz: 4054045714a2daf7044cf0f4e67f988cd3b536abbf234f36883536ad33d00bac758ff9df106fa964d71d2dd6f26f0782493a3d9d3be02e6a4d6539791c5691aa
6
+ metadata.gz: 10a00235c1a6e719df5ddf44006d46c1df8f2979151a3b0cf8a48ef97c0e726db41b62a4e1ea619133db69854f2a55c94189aa9dec2bfd4e1aa0429d6dabc639
7
+ data.tar.gz: b7eb6b5220879501cc8996d40c7ac960d1e5d9a41734090fe90831409090d90b51424ea141a4b537e2ac023a43c4c50dd322184f2d80313d82b6178bfbbe519d
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  pkg/*
2
2
  *.gem
3
- .idea/*
3
+ .idea/*
4
+ *.log
data/Gemfile.lock CHANGED
@@ -1,17 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coursegen (0.3.0)
4
+ coursegen (0.4.2)
5
5
  activesupport
6
6
  adsf
7
+ byebug
7
8
  cri
8
9
  guard
9
10
  guard-shell
10
11
  icalendar
11
12
  kramdown
12
- nanoc (~> 4.0.0rc2)
13
+ nanoc
13
14
  nokogiri
14
- pry-byebug
15
15
  rubytree
16
16
  thor
17
17
  tzinfo
@@ -19,26 +19,25 @@ PATH
19
19
  GEM
20
20
  remote: https://rubygems.org/
21
21
  specs:
22
- activesupport (4.2.4)
22
+ activesupport (5.1.3)
23
+ concurrent-ruby (~> 1.0, >= 1.0.2)
23
24
  i18n (~> 0.7)
24
- json (~> 1.7, >= 1.7.7)
25
25
  minitest (~> 5.1)
26
- thread_safe (~> 0.3, >= 0.3.4)
27
26
  tzinfo (~> 1.1)
28
- adsf (1.2.0)
27
+ adsf (1.2.1)
29
28
  rack (>= 1.0.0)
30
- byebug (5.0.0)
31
- columnize (= 0.9.0)
32
- coderay (1.1.0)
29
+ byebug (9.0.6)
30
+ coderay (1.1.1)
33
31
  colored (1.2)
34
- columnize (0.9.0)
35
- cri (2.7.0)
32
+ concurrent-ruby (1.0.5)
33
+ cri (2.9.1)
36
34
  colored (~> 1.2)
37
- ffi (1.9.10)
35
+ ddplugin (1.0.1)
36
+ ffi (1.9.18)
38
37
  formatador (0.2.5)
39
- guard (2.13.0)
38
+ guard (2.14.1)
40
39
  formatador (>= 0.2.4)
41
- listen (>= 2.7, <= 4.0)
40
+ listen (>= 2.7, < 4.0)
42
41
  lumberjack (~> 1.0)
43
42
  nenv (~> 0.1)
44
43
  notiffany (~> 0.0)
@@ -49,46 +48,51 @@ GEM
49
48
  guard-shell (0.7.1)
50
49
  guard (>= 2.0.0)
51
50
  guard-compat (~> 1.0)
52
- i18n (0.7.0)
53
- icalendar (2.3.0)
54
- json (1.8.3)
55
- kramdown (1.8.0)
56
- listen (3.0.3)
57
- rb-fsevent (>= 0.9.3)
58
- rb-inotify (>= 0.9)
59
- lumberjack (1.0.9)
51
+ hamster (3.0.0)
52
+ concurrent-ruby (~> 1.0)
53
+ i18n (0.8.6)
54
+ icalendar (2.4.1)
55
+ json (1.8.6)
56
+ kramdown (1.14.0)
57
+ listen (3.1.5)
58
+ rb-fsevent (~> 0.9, >= 0.9.4)
59
+ rb-inotify (~> 0.9, >= 0.9.7)
60
+ ruby_dep (~> 1.2)
61
+ lumberjack (1.0.12)
60
62
  method_source (0.8.2)
61
- mini_portile (0.6.2)
62
- minitest (5.8.0)
63
- nanoc (4.0.0rc2)
64
- cri (~> 2.3)
65
- nenv (0.2.0)
66
- nokogiri (1.6.6.2)
67
- mini_portile (~> 0.6.0)
68
- notiffany (0.0.7)
63
+ mini_portile2 (2.2.0)
64
+ minitest (5.10.3)
65
+ nanoc (4.8.2)
66
+ cri (~> 2.8)
67
+ ddplugin (~> 1.0)
68
+ hamster (~> 3.0)
69
+ ref (~> 2.0)
70
+ nenv (0.3.0)
71
+ nokogiri (1.8.0)
72
+ mini_portile2 (~> 2.2.0)
73
+ notiffany (0.1.1)
69
74
  nenv (~> 0.1)
70
75
  shellany (~> 0.0)
71
- pry (0.10.1)
76
+ pry (0.10.4)
72
77
  coderay (~> 1.1.0)
73
78
  method_source (~> 0.8.1)
74
79
  slop (~> 3.4)
75
- pry-byebug (3.2.0)
76
- byebug (~> 5.0)
77
- pry (~> 0.10)
78
- rack (1.6.4)
79
- rake (10.4.2)
80
- rb-fsevent (0.9.5)
81
- rb-inotify (0.9.5)
82
- ffi (>= 0.5.0)
83
- rubytree (0.9.6)
80
+ rack (2.0.3)
81
+ rake (11.3.0)
82
+ rb-fsevent (0.10.2)
83
+ rb-inotify (0.9.10)
84
+ ffi (>= 0.5.0, < 2)
85
+ ref (2.0.0)
86
+ ruby_dep (1.5.0)
87
+ rubytree (0.9.7)
84
88
  json (~> 1.8)
85
89
  structured_warnings (~> 0.2)
86
90
  shellany (0.0.1)
87
91
  slop (3.6.0)
88
- structured_warnings (0.2.0)
89
- thor (0.19.1)
90
- thread_safe (0.3.5)
91
- tzinfo (1.2.2)
92
+ structured_warnings (0.3.0)
93
+ thor (0.20.0)
94
+ thread_safe (0.3.6)
95
+ tzinfo (1.2.3)
92
96
  thread_safe (~> 0.1)
93
97
 
94
98
  PLATFORMS
@@ -100,4 +104,4 @@ DEPENDENCIES
100
104
  rake
101
105
 
102
106
  BUNDLED WITH
103
- 1.10.5
107
+ 1.15.3
data/coursegen.gemspec CHANGED
@@ -21,12 +21,10 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler"
22
22
  spec.add_development_dependency "rake"
23
23
 
24
-
25
- spec.add_dependency "nanoc", '~> 4.0.0rc2'
24
+ spec.add_dependency "nanoc"
26
25
  spec.add_dependency "thor"
27
26
  spec.add_dependency "rubytree"
28
27
  spec.add_dependency "cri"
29
- spec.add_dependency "pry-byebug"
30
28
  spec.add_dependency "nokogiri"
31
29
  spec.add_dependency "activesupport"
32
30
  spec.add_dependency "kramdown"
@@ -35,4 +33,5 @@ Gem::Specification.new do |spec|
35
33
  spec.add_dependency "guard-shell"
36
34
  spec.add_dependency "tzinfo"
37
35
  spec.add_dependency "icalendar"
36
+ spec.add_dependency "byebug"
38
37
  end
data/deleteme.rb ADDED
@@ -0,0 +1,2 @@
1
+ classs ViewGen
2
+ de
data/lib/coursegen/cli.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'thor'
2
2
  require 'coursegen/templates'
3
3
  require 'nanoc'
4
- require './cg_config.rb' if File.exists? 'cg_config.rb'
4
+ require './cg_config.rb' if File.exist? 'cg_config.rb'
5
5
 
6
6
  module CourseGen
7
7
  class CLI < Thor
@@ -47,9 +47,11 @@ module CourseGen
47
47
 
48
48
  no_commands do
49
49
  def check_valid_directory
50
- CourseGen::Templates.new.valid_cg_directory? ?
51
- say("Valid cg directory") :
50
+ if CourseGen::Templates.new.valid_cg_directory?
51
+ say("Valid cg directory")
52
+ else
52
53
  error("Invalid cg directory")
54
+ end
53
55
  end
54
56
  end
55
57
  end
@@ -1,23 +1,25 @@
1
+ require 'byebug'
1
2
  require 'active_support/inflector'
2
3
 
3
4
  #
4
5
  # Coursegen Item decorates Nanoc Item
5
6
  #
6
7
  class CItem
7
-
8
8
  attr_reader :order, :section, :subsection, :subsection_citem, :title,
9
- :type, :identifier, :short_name, :status, :nitem, :css_class, :homework, :desc
10
- attr_accessor :lecture_number, :lecture_date
9
+ :type, :identifier, :short_name, :status, :nitem, :css_class, :homework, :desc, :cat
10
+ attr_accessor :lecture_number, :lecture_date, :start_time, :end_time
11
11
 
12
12
  # Callable with nitem=nil to create a mock
13
- def initialize nitem=nil, ident=nil, type=nil, order=nil
13
+ def initialize(nitem=nil, ident=nil, type=nil, order=nil)
14
14
  if !nitem.nil?
15
- raise ArgumentError, "invalid CItem contruction" unless ident.nil?
15
+ # path to create a real citem
16
+ fail ArgumentError, "invalid CItem contruction" unless ident.nil?
16
17
  @nitem = nitem
17
- defaults_from_nitem @nitem
18
+ defaults_from_nitem
18
19
  parse_identifier @nitem.identifier
19
20
  else
20
- raise ArgumentError, "invalid CItem contruction" unless nitem.nil?
21
+ # path to create a mock citem
22
+ fail ArgumentError, "invalid CItem contruction" unless nitem.nil?
21
23
  @nitem = nil
22
24
  @status = nil
23
25
  @type = type
@@ -33,15 +35,11 @@ class CItem
33
35
  if @nitem.nil?
34
36
  false
35
37
  else
36
- @nitem[:status] == 'hidden' || %w(css min.css js png).include?(@nitem[:extension])
38
+ @nitem[:status] == 'hidden' || %w(css min.css js pdf png).include?(@nitem[:extension])
37
39
  end
38
40
  end
39
41
 
40
- def path
41
- @nitem.path
42
- end
43
-
44
- def is_lecture?
42
+ def lecture?
45
43
  !@lecture_date.nil?
46
44
  end
47
45
 
@@ -54,26 +52,26 @@ class CItem
54
52
  end
55
53
 
56
54
  def schedule_start_date_time
57
- if !@lecture_date.nil?
58
- schedule = Toc.instance.section(@section).schedule
59
- lecture_date + schedule.start_time
60
- end
55
+ return if @lecture_date.nil?
56
+ # schedule = Toc.instance.section(@section).schedule
57
+ # lecture_date + schedule.start_time
58
+ lecture_date + @start_time
61
59
  end
62
60
 
63
61
  def schedule_end_date_time
64
- if !@lecture_date.nil?
65
- schedule = Toc.instance.section(@section).schedule
66
- lecture_date + schedule.end_time
67
- end
62
+ return if @lecture_date.nil?
63
+ # schedule = Toc.instance.section(@section).schedule
64
+ # lecture_date + schedule.end_time
65
+ lecture_date + @end_time
68
66
  end
69
67
 
70
68
  def lecture_number_s
71
- "#{@section.singularize} #{@lecture_number.to_s}"
69
+ "#{@section.singularize} #{@lecture_number}"
72
70
  end
73
71
 
74
72
  private
75
73
 
76
- def defaults_from_nitem(nitem)
74
+ def defaults_from_nitem
77
75
  @type = @nitem[:type] || 'page'
78
76
  fail ArgumentError, 'Invalid page type' unless ["page", "subsection"].include? @type
79
77
 
@@ -86,21 +84,22 @@ class CItem
86
84
  @css_class = @nitem[:css_class]
87
85
  @homework = @nitem[:homework]
88
86
  @desc = @nitem[:desc]
87
+ @cat = @nitem[:cat]
89
88
  end
90
89
 
91
- def parse_identifier ident
90
+ def parse_identifier(ident)
92
91
  parts = ident.to_s.split("/")
93
92
  @section ||= parts[2]
94
- #parsed_title = parts[-1].match(/^((\d*)_)?([^\/]*)$/)
93
+ # parsed_title = parts[-1].match(/^((\d*)_)?([^\/]*)$/)
95
94
  parsed_title = parts[-1].match(/^((\d*)_)?(\w*)/)
96
- raise RuntimeError, "Invalid item title" if parsed_title.nil?
95
+ fail "Invalid item title" if parsed_title.nil?
97
96
 
98
97
  @order ||= parsed_title[2].to_i
99
98
  @short_name = parsed_title[3]
100
99
  @title ||= short_name
101
100
  if @type == "subsection"
102
101
  @subsection = "/#{parts[1..-2].join('/')}/"
103
- # @subsection = "/#{parts[1..-1].join('/')}/"
102
+ # @subsection = "/#{parts[1..-1].join('/')}/"
104
103
  elsif @type == "page"
105
104
  @subsection = "/#{parts[1..-2].join('/')}/"
106
105
  end
@@ -1,10 +1,12 @@
1
+ # Standard way to access information to be used in a list_of()
1
2
  class DataAdaptor
2
3
  def initialize(source)
3
4
  @section = Toc.instance.section(source)
4
5
  end
5
6
 
6
7
  # column_selector is one of: :number, :date, :title, :homework
7
- COL_NAMES = { number: "#", date: "lecture date", title: "title", homework: "homework", desc: "description"}
8
+ COL_NAMES = {number: "#", date: "lecture date", title: "title",
9
+ homework: "homework", desc: "description", cat: "category"}
8
10
 
9
11
  def column_name(column_selector)
10
12
  COL_NAMES[column_selector]
@@ -38,6 +40,8 @@ class DataAdaptor
38
40
  desc = citem.desc || ""
39
41
  hw = citem.homework || ""
40
42
  desc + ". HW: " + hw
43
+ when :cat
44
+ citem.cat
41
45
  else
42
46
  "error!"
43
47
  end
@@ -1,91 +1,103 @@
1
1
  require 'tree'
2
2
 
3
3
  class Lectures < Section
4
- def initialize(sect, citems, schedule=nil, collapsed=false)
5
- super sect, citems, collapsed
6
- @schedule = schedule || ::Scheduler.new
7
- @citems = sort_items
8
- build_tree
9
- end
4
+ def initialize(sect, citems, schedule=nil, collapsed=false)
5
+ super sect, citems, collapsed
6
+ @schedule = schedule || ::Scheduler.new
7
+ @citems = sort_items
8
+ build_tree
9
+ end
10
10
 
11
- def has_subsections?
12
- true
13
- end
11
+ def has_subsections?
12
+ true
13
+ end
14
14
 
15
- def has_lecture_numbers?
16
- true
17
- end
15
+ def has_lecture_numbers?
16
+ true
17
+ end
18
18
 
19
- def schedule
20
- @schedule
21
- end
19
+ def schedule
20
+ @schedule
21
+ end
22
22
 
23
- def build_tree
24
- lecture_num = 1
25
- @root = Tree::TreeNode.new("root", "root")
26
- @citems.each do |i|
27
- i.lecture_number = lecture_num
28
- i.lecture_date = @schedule.event_date_by_index(lecture_num - 1) # Lecture numbers are base 1
29
- if i.type == "subsection"
30
- @root.add(Tree::TreeNode.new(i.subsection, i))
31
- elsif i.type == "page"
32
- parent_tree_node = parent_node_of(i)
33
- parent_tree_node.add(Tree::TreeNode.new(i.identifier, i))
34
- lecture_num += 1
35
- else
36
- raise ArgumentError, "invalid lecture page type of #{i.type}for #{i.title}"
37
- end
38
- end
39
- end
23
+ def build_tree
24
+ lecture_num = 1
25
+ @root = Tree::TreeNode.new("root", "root")
26
+ @citems.each do |i|
27
+ i.lecture_number = lecture_num
28
+ i.lecture_date = @schedule.event_date_by_index(lecture_num - 1) # Lecture numbers are base 1
29
+ i.start_time = @schedule.event_start_times[lecture_num - 1]
30
+ i.end_time = @schedule.event_end_times[lecture_num - 1]
31
+ if i.type == "subsection"
32
+ @root.add(Tree::TreeNode.new(i.subsection, i))
33
+ elsif i.type == "page"
34
+ parent_tree_node = parent_node_of(i)
35
+ parent_tree_node.add(Tree::TreeNode.new(i.identifier, i))
36
+ lecture_num += 1
37
+ else
38
+ raise ArgumentError, "invalid lecture page type of #{i.type}for #{i.title}"
39
+ end
40
+ end
41
+ end
40
42
 
41
- def parent_node_of citem
42
- parent_node = @root[citem.subsection]
43
- raise RuntimeError, "Cant find section for item: #{citem.identifier}" if parent_node.nil?
44
- parent_node
45
- end
43
+ def parent_node_of citem
44
+ parent_node = @root[citem.subsection]
45
+ raise RuntimeError, "Cant find section for item: #{citem.identifier}" if parent_node.nil?
46
+ parent_node
47
+ end
46
48
 
47
- def treenode_of citem
48
- @root.find do
49
- |tree_node|
50
- if citem.type == "subsection"
51
- citem.subsection == tree_node.name
52
- else
53
- citem.identifier == tree_node.name
54
- end
55
- end
56
- end
49
+ def treenode_of citem
50
+ @root.find do |tree_node|
51
+ if citem.type == "subsection"
52
+ citem.subsection == tree_node.name
53
+ else
54
+ citem.identifier == tree_node.name
55
+ end
56
+ end
57
+ end
57
58
 
58
- def subsections
59
- @root.children
60
- end
59
+ def subsections
60
+ @root.children
61
+ end
61
62
 
62
- def next_for(citem)
63
- next_node = treenode_of(citem).next_sibling
64
- if !next_node.nil?
65
- next_node.content
66
- else
67
- citem
68
- end
69
- end
63
+ def next_for(citem)
64
+ next_node = treenode_of(citem).next_sibling
65
+ if !next_node.nil?
66
+ next_node.content
67
+ else
68
+ citem
69
+ end
70
+ end
70
71
 
71
- def previous_for(citem)
72
- prev_node = treenode_of(citem).previous_sibling
73
- if !prev_node.nil?
74
- prev_node.content
75
- else
76
- citem
77
- end
78
- end
72
+ def previous_for(citem)
73
+ prev_node = treenode_of(citem).previous_sibling
74
+ if !prev_node.nil?
75
+ prev_node.content
76
+ else
77
+ citem
78
+ end
79
+ end
79
80
 
80
- protected
81
+ protected
82
+
83
+ # @TODO: once there are skips, this calcluation doesn't work anymore!
84
+ def get_time(times, lect_num)
85
+ if times.nil?
86
+ "0"
87
+ else
88
+ times[(lect_num % 3) - 1]
89
+ end
90
+ end
81
91
 
82
92
  #
83
93
  # Sort all the items in this section: First by the ordering of the subseciton
84
94
  # that the item belongs to, and second by the item's own indicated order.
85
95
  #
86
- def sort_items
87
- new_citems = @citems.sort_by { |i| [ lookup_citem_by_identifier(i.subsection+"index.html").order, ((i.type == "page" ? 100 : 1 ) * i.order) ] }
88
- @items = new_citems
89
- end
90
-
96
+ def sort_items
97
+ new_citems = @citems.sort_by do |i|
98
+ [lookup_citem_by_identifier(i.subsection + "index.html").order,
99
+ ((i.type == "page" ? 100 : 1) * i.order)]
100
+ end
101
+ @items = new_citems
102
+ end
91
103
  end
@@ -1,60 +1,61 @@
1
1
  require 'forwardable'
2
- require 'pry'
2
+ require 'byebug'
3
3
 
4
4
  class Section
5
- extend Forwardable
6
- attr_reader :section
7
- def_delegators :@citems, :[], :count, :each, :sort!, :reduce
5
+ extend Forwardable
6
+ attr_reader :section
7
+ def_delegators :@citems, :[], :count, :each, :sort!, :reduce
8
8
 
9
- def initialize (sect, citems, collapsed)
10
- @section = sect
11
- @collapsed = collapsed
12
- @citems = section_filter(citems)
13
- sort_pages
14
- end
9
+ def initialize(sect, citems, collapsed)
10
+ @section = sect
11
+ @collapsed = collapsed
12
+ @citems = section_filter(citems)
13
+ sort_pages
14
+ end
15
15
 
16
- def find_index(citem)
17
- @citems.find_index(citem)
18
- end
16
+ def find_index(citem)
17
+ @citems.find_index(citem)
18
+ end
19
19
 
20
- def find_by_short_name(sname)
21
- matches = @citems.select { |c| sname == c.short_name}
22
- raise RuntimeError,"'#{sname}': invalid reference in section \"#{@section}\"" if matches.length == 0
23
- raise RunimeError, "'#{sname}': duplicate referenced in section \"#{@section}\"" if matches.length != 1
24
- matches[0]
25
- end
20
+ def find_by_short_name(sname)
21
+ matches = @citems.select { |c| sname == c.short_name }
22
+ raise RuntimeError,"'#{sname}': invalid reference in section \"#{@section}\"" if matches.length == 0
23
+ raise RuntimeError, "'#{sname}': duplicate referenced in section \"#{@section}\"" if matches.length != 1
24
+ matches[0]
25
+ end
26
26
 
27
- def [](ind)
28
- @citems[ind]
29
- end
27
+ def [](ind)
28
+ @citems[ind]
29
+ end
30
30
 
31
- def next_for(citem)
32
- index = @citems.find_index(citem)
33
- raise ArgumentError, "invalid citem in next_for" if index.nil?
34
- new_index = [index, @citems.length-2].min
35
- @citems[new_index+1]
36
- end
31
+ def next_for(citem)
32
+ index = @citems.find_index(citem)
33
+ raise ArgumentError, "invalid citem in next_for" if index.nil?
34
+ new_index = [index, @citems.length - 2].min
35
+ @citems[new_index + 1]
36
+ end
37
37
 
38
- def previous_for(citem)
39
- index = @citems.find_index(citem)
40
- raise ArgumentError, "invalid citem in next_for" if index.nil?
41
- new_index = [index, 1].max
42
- @citems[new_index-1]
43
- end
38
+ def previous_for(citem)
39
+ index = @citems.find_index(citem)
40
+ byebug if index.nil?
41
+ raise ArgumentError, "invalid citem in previous_for" if index.nil?
42
+ new_index = [index, 1].max
43
+ @citems[new_index - 1]
44
+ end
44
45
 
45
- def has_subsections?
46
- false
47
- end
46
+ def has_subsections?
47
+ false
48
+ end
48
49
 
49
- def has_lecture_numbers?
50
- false
51
- end
50
+ def has_lecture_numbers?
51
+ false
52
+ end
52
53
 
53
- def collapsed?
54
- @collapsed
55
- end
54
+ def collapsed?
55
+ @collapsed
56
+ end
56
57
 
57
- protected
58
+ protected
58
59
 
59
60
  def lookup_citem_by_identifier identifier
60
61
  res = @citems.select { |i| i.identifier.to_s == identifier }
@@ -64,15 +65,14 @@ class Section
64
65
  end
65
66
 
66
67
  # Remove citems that don't belong in this section, or are hidden
67
- def section_filter citems
68
- filtered_citems = citems.map do
69
- |citem|
70
- citem.section == @section && !citem.hidden? ? citem : nil
71
- end
72
- filtered_citems.compact
68
+ def section_filter citems
69
+ filtered_citems = citems.map do |citem|
70
+ citem.section == @section && !citem.hidden? ? citem : nil
71
+ end
72
+ filtered_citems.compact
73
73
  end
74
74
 
75
- def sort_pages
76
- @citems.sort! { |a,b| a.order <=> b.order } rescue fail "sort_pages in section.rb"
77
- end
75
+ def sort_pages
76
+ @citems.sort! { |a,b| a.order <=> b.order } rescue fail "sort_pages in section.rb"
77
+ end
78
78
  end