coursegen 0.1.3 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +48 -32
- data/coursegen.gemspec +4 -3
- data/lib/coursegen/course/data/citem.rb +22 -6
- data/lib/coursegen/course/data/data_adaptor.rb +9 -1
- data/lib/coursegen/course/data/lectures.rb +14 -5
- data/lib/coursegen/course/data/section.rb +6 -5
- data/lib/coursegen/course/data/toc.rb +10 -8
- data/lib/coursegen/course/helpers/content_helpers.rb +4 -4
- data/lib/coursegen/course/helpers/ical_feed_helpers.rb +8 -0
- data/lib/coursegen/course/helpers/list_of.rb +4 -3
- data/lib/coursegen/course/helpers/navigation_helpers.rb +4 -3
- data/lib/coursegen/course/helpers/sidebar_helpers.rb +3 -2
- data/lib/coursegen/course/lib/helpers_.rb +1 -0
- data/lib/coursegen/course/lib/ical_adaptor.rb +34 -0
- data/lib/coursegen/course/lib/search_data_generator.rb +4 -4
- data/lib/coursegen/course/schedule/schedule_def.rb +5 -2
- data/lib/coursegen/course/schedule/schedule_feed.rb +30 -0
- data/lib/coursegen/course/schedule/scheduler.rb +22 -7
- data/lib/coursegen/templates.rb +2 -0
- data/lib/coursegen/version.rb +1 -1
- data/lib/coursegen.rb +4 -2
- data/spec/citem_spec.rb +3 -2
- data/spec/lectures_spec.rb +7 -7
- data/spec/play_spec.rb +23 -0
- data/spec/spec_helper.rb +7 -8
- data/templates/.gitignore +1 -2
- data/{Guardfile → templates/Guardfile} +3 -0
- data/templates/Rules +37 -37
- data/templates/cg_config.rb +18 -5
- data/templates/cg_config.rb_sample +5 -3
- data/templates/content/content/extras/extra_content.md.erb +4 -0
- data/templates/content/content/index.md.erb +7 -1
- data/templates/content/content/intro/course_toc.md.erb +4 -0
- data/templates/content/content/intro/welcome.md.erb +8 -0
- data/templates/content/content/lectures/part1/01_first_lecture.md.erb +4 -0
- data/templates/content/content/lectures/part1/02_here_we_go.md.erb +5 -0
- data/templates/content/content/lectures/part1/index.html +6 -0
- data/templates/content/content/lectures/part2/01_start_part2.md.erb +5 -0
- data/templates/content/content/lectures/part2/02_continue_part2.md.erb +5 -0
- data/templates/content/content/lectures/part2/index.html +6 -0
- data/templates/content/content/lectures/schedule.ical.erb +5 -0
- data/templates/content/tipuesearch_logic/search.md.erb +1 -1
- data/templates/layouts/course.html +6 -6
- metadata +51 -9
- data/lib/coursegen/course/lib/toc.rb +0 -154
@@ -1,154 +0,0 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
class Toc
|
3
|
-
|
4
|
-
include Enumerable
|
5
|
-
include Singleton
|
6
|
-
|
7
|
-
def prepare items, config
|
8
|
-
raise "Toc.prepare called twice!" unless @sections.nil?
|
9
|
-
@section_config = config
|
10
|
-
build_mapping_table items
|
11
|
-
build_citem_table
|
12
|
-
build_sections @citems
|
13
|
-
@info = {}
|
14
|
-
end
|
15
|
-
|
16
|
-
def build_sections items
|
17
|
-
@sections = {}
|
18
|
-
@section_config.each do
|
19
|
-
|sect|
|
20
|
-
selector = sect.selector.to_s
|
21
|
-
if sect.options[:type] == :lecture
|
22
|
-
schedule = Scheduler.new
|
23
|
-
schedule.setup_from_schedule_def(sect.options[:schedule])
|
24
|
-
@sections[selector] = Lectures.new(selector, items, schedule, sect.options[:collapsed])
|
25
|
-
elsif sect.options[:type] == :section
|
26
|
-
@sections[selector] = Section.new(selector, items, sect.options[:collapsed])
|
27
|
-
else
|
28
|
-
raise ArgumentError.new("Invalid section option")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def build_mapping_table items
|
34
|
-
@map_n2c = {}
|
35
|
-
items.each do
|
36
|
-
|nitem|
|
37
|
-
citem = CItem.new(nitem)
|
38
|
-
@map_n2c[nitem] = citem
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def build_citem_table
|
43
|
-
@citems = @map_n2c.map { |k, v| v}
|
44
|
-
end
|
45
|
-
|
46
|
-
def n2c nitem
|
47
|
-
@map_n2c[nitem]
|
48
|
-
end
|
49
|
-
|
50
|
-
def lookup_citem the_sect, item_short_name
|
51
|
-
section(the_sect).find_by_short_name(item_short_name)
|
52
|
-
end
|
53
|
-
|
54
|
-
def reset
|
55
|
-
@sections = nil
|
56
|
-
end
|
57
|
-
|
58
|
-
def section selector
|
59
|
-
section = @sections[selector]
|
60
|
-
raise RuntimeError, "Invalid Section: #{selector}" if section.nil?
|
61
|
-
section
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
def find_next_forn(nitem)
|
66
|
-
p = find_next_for(n2c(nitem))
|
67
|
-
fail "find_next_forn in toc.rb" if p.nil?
|
68
|
-
p
|
69
|
-
end
|
70
|
-
|
71
|
-
def find_previous_forn(nitem)
|
72
|
-
p = find_previous_for(n2c(nitem))
|
73
|
-
fail "find_prev_forn in toc.rb" if p.nil?
|
74
|
-
p
|
75
|
-
end
|
76
|
-
|
77
|
-
def find_next_for(citem)
|
78
|
-
section(citem.section).next_for(citem)
|
79
|
-
end
|
80
|
-
|
81
|
-
def find_previous_for(citem)
|
82
|
-
section(citem.section).previous_for(citem)
|
83
|
-
end
|
84
|
-
|
85
|
-
def citem_section citem
|
86
|
-
@sections[citem.section]
|
87
|
-
end
|
88
|
-
|
89
|
-
def record_inclusion host_item, included_item
|
90
|
-
@info[included_item.identifier] = host_item
|
91
|
-
end
|
92
|
-
|
93
|
-
private
|
94
|
-
|
95
|
-
def subsections(section, &block)
|
96
|
-
items = sort_section_by_subsection_name section
|
97
|
-
item_iterator = items.chunk do |item|
|
98
|
-
subsection_name section.to_s, item.identifier
|
99
|
-
end
|
100
|
-
item_iterator.each do |subsection_item|
|
101
|
-
block.call(subsection_item)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
def index_in_section item
|
108
|
-
section_for(item).find_index(item)
|
109
|
-
end
|
110
|
-
|
111
|
-
def each_by(section_selector, &block)
|
112
|
-
sub_toc = @sections[section_selector]
|
113
|
-
sub_toc.sort! { |a,b| a[:order] <=> b[:order] }.each do |member|
|
114
|
-
block.call(member)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def sort_section_by_order sect
|
119
|
-
@sections[sect].sort! { |a,b| a[:order] <=> b[:order] }
|
120
|
-
end
|
121
|
-
|
122
|
-
def sort_section_by_subsection_name(sect)
|
123
|
-
items = @sections[sect]
|
124
|
-
items.sort! do
|
125
|
-
|item1, item2|
|
126
|
-
subsection_name(sect.to_s, item1.identifier) <=> subsection_name(sect.to_s, item2.identifier)
|
127
|
-
end
|
128
|
-
items
|
129
|
-
end
|
130
|
-
|
131
|
-
def subsection_name section_name, item_name
|
132
|
-
item_matcher = item_name.match('\A/'+section_name+'/([^/]*)/([^/]*)/\z')
|
133
|
-
if !item_matcher.nil?
|
134
|
-
item_matcher[1]
|
135
|
-
else
|
136
|
-
""
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def lookup_inclusion included_item
|
141
|
-
@info[included_item.identifier]
|
142
|
-
end
|
143
|
-
|
144
|
-
def lookup_by_index section, index
|
145
|
-
sect = section.section
|
146
|
-
if index >= @sections[sect].count
|
147
|
-
index = @sections[sect].count-1
|
148
|
-
elsif index < 0
|
149
|
-
index = 0
|
150
|
-
end
|
151
|
-
@sections[sect][index]
|
152
|
-
end
|
153
|
-
|
154
|
-
end
|