coursegen 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/Gemfile.lock +3 -3
- data/coursegen.gemspec +7 -2
- data/lib/coursegen.rb +12 -9
- data/lib/coursegen/cli.rb +2 -1
- data/lib/coursegen/course/{lib → data}/citem.rb +4 -2
- data/lib/coursegen/course/data/data_adaptor.rb +37 -0
- data/lib/coursegen/course/{lib → data}/lectures.rb +0 -0
- data/lib/coursegen/course/{lib → data}/section.rb +0 -0
- data/lib/coursegen/course/{lib → data}/section_def.rb +0 -0
- data/lib/coursegen/course/data/toc.rb +160 -0
- data/lib/coursegen/course/helpers/bootstrap_markup.rb +64 -0
- data/lib/coursegen/course/helpers/content_helpers.rb +10 -5
- data/lib/coursegen/course/helpers/list_of.rb +89 -0
- data/lib/coursegen/course/helpers/list_of_helpers.rb +19 -0
- data/lib/coursegen/course/helpers/navigation_helpers.rb +0 -1
- data/lib/coursegen/course/lib/helpers_.rb +1 -1
- data/lib/coursegen/course/lib/search_data_generator.rb +9 -3
- data/lib/coursegen/course/{lib → schedule}/schedule_def.rb +0 -0
- data/lib/coursegen/course/{lib → schedule}/scheduler.rb +0 -0
- data/lib/coursegen/templates.rb +10 -0
- data/lib/coursegen/version.rb +1 -1
- data/templates/Rules +18 -10
- data/templates/cg_config.rb +2 -1
- data/templates/content/bootstrap/css/custom.css +6 -0
- data/templates/content/chalkmark/chalkmark.js +30 -0
- data/templates/content/tipuesearch/img/loader.gif +0 -0
- data/templates/content/tipuesearch/img/search.png +0 -0
- data/templates/content/tipuesearch/tipuesearch_set.js +22 -0
- data/templates/content/tipuesearch/tipuesearchmin.js +14 -0
- data/templates/content/tipuesearch/tipuesearchnomin.js +444 -0
- data/templates/content/tipuesearch_logic/search.md.erb +8 -0
- data/templates/content/tipuesearch_logic/tipuesearch_content.js.erb +6 -0
- data/templates/layouts/course.html +15 -16
- data/templates/layouts/helpful_box.html +3 -0
- data/templates/layouts/main_navbar.html.erb +5 -5
- metadata +94 -26
- data/pkg/coursegen-0.0.1.gem +0 -0
- data/pkg/coursegen-0.0.2.gem +0 -0
- data/pkg/coursegen-0.0.3.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f6fafa449aaa1c612bd2ceee93620309658a577
|
4
|
+
data.tar.gz: 3944ddf885fdc20f3981aafc64f5eda9e5f68fa8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a51af70545c7dad4360845bc63c04fe211c2742988cb2295d8ac4ca2fe8daba44ff383df733e582bb2d44ded1d760937c68fc0816abae5a2938dbc70cfa958a4
|
7
|
+
data.tar.gz: 885fbdf8a783e77379114d906b573a4a2761e6896b69f127877000a9e8a00cb4783b2ddb586bb44fa96a2cea32ef430473f39a444f3a6788474364d04979d3c1
|
data/.gitignore
ADDED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
coursegen (0.0.
|
4
|
+
coursegen (0.0.5)
|
5
5
|
nanoc
|
6
6
|
thor
|
7
7
|
|
@@ -9,9 +9,9 @@ GEM
|
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
11
|
colored (1.2)
|
12
|
-
cri (2.6.
|
12
|
+
cri (2.6.1)
|
13
13
|
colored (~> 1.2)
|
14
|
-
nanoc (3.
|
14
|
+
nanoc (3.7.1)
|
15
15
|
cri (~> 2.3)
|
16
16
|
rake (10.3.2)
|
17
17
|
thor (0.19.1)
|
data/coursegen.gemspec
CHANGED
@@ -22,8 +22,13 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.6"
|
23
23
|
spec.add_development_dependency "rake"
|
24
24
|
|
25
|
-
|
25
|
+
|
26
|
+
spec.add_dependency "nanoc", "~>3.6.11"
|
26
27
|
spec.add_dependency "thor"
|
27
|
-
spec.add_dependency "
|
28
|
+
spec.add_dependency "rubytree"
|
29
|
+
spec.add_dependency "cri"
|
30
|
+
spec.add_dependency "pry"
|
31
|
+
spec.add_dependency "nokogiri"
|
32
|
+
spec.add_dependency "activesupport"
|
28
33
|
|
29
34
|
end
|
data/lib/coursegen.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'nanoc/toolbox'
|
2
|
-
require 'pry'
|
3
1
|
require 'nokogiri'
|
4
2
|
|
5
3
|
require "coursegen/version"
|
@@ -7,16 +5,21 @@ require "coursegen/course/helpers/sidebar_helpers"
|
|
7
5
|
require "coursegen/course/helpers/lecture_helpers"
|
8
6
|
require "coursegen/course/helpers/content_helpers"
|
9
7
|
require "coursegen/course/helpers/logging_helpers"
|
8
|
+
require "coursegen/course/helpers/list_of_helpers"
|
9
|
+
require 'coursegen/course/helpers/bootstrap_markup'
|
10
10
|
require "coursegen/course/helpers/navigation_helpers"
|
11
|
-
require
|
12
|
-
require "coursegen/course/
|
13
|
-
require 'coursegen/course/
|
11
|
+
require "coursegen/course/data/section"
|
12
|
+
require "coursegen/course/data/toc"
|
13
|
+
require 'coursegen/course/data/citem'
|
14
14
|
require 'coursegen/course/lib/helpers_'
|
15
|
-
require 'coursegen/course/
|
16
|
-
require 'coursegen/course/
|
17
|
-
require 'coursegen/course/
|
18
|
-
require 'coursegen/course/
|
15
|
+
require 'coursegen/course/schedule/schedule_def'
|
16
|
+
require 'coursegen/course/data/section_def'
|
17
|
+
require 'coursegen/course/schedule/scheduler'
|
18
|
+
require 'coursegen/course/data/lectures'
|
19
19
|
require 'coursegen/course/lib/search_data_generator'
|
20
|
+
require 'coursegen/course/data/data_adaptor'
|
21
|
+
require 'coursegen/course/helpers/list_of'
|
22
|
+
|
20
23
|
|
21
24
|
module Coursegen
|
22
25
|
# Your code goes here...
|
data/lib/coursegen/cli.rb
CHANGED
@@ -6,7 +6,7 @@ require 'active_support/inflector'
|
|
6
6
|
class CItem
|
7
7
|
|
8
8
|
attr_reader :order, :section, :subsection, :subsection_citem, :title,
|
9
|
-
:type, :identifier, :short_name, :status, :nitem, :css_class
|
9
|
+
:type, :identifier, :short_name, :status, :nitem, :css_class, :homework, :desc
|
10
10
|
attr_accessor :lecture_number, :lecture_date
|
11
11
|
|
12
12
|
# Callable with nitem=nil to create a mock
|
@@ -25,7 +25,7 @@ class CItem
|
|
25
25
|
@order = order
|
26
26
|
@title = ident
|
27
27
|
@style = nil
|
28
|
-
parse_identifier
|
28
|
+
parse_identifier(ident)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -70,6 +70,8 @@ class CItem
|
|
70
70
|
@section = @nitem[:section]
|
71
71
|
@title = @nitem[:title]
|
72
72
|
@css_class = @nitem[:css_class]
|
73
|
+
@homework = @nitem[:homework]
|
74
|
+
@desc = @nitem[:desc]
|
73
75
|
end
|
74
76
|
|
75
77
|
def parse_identifier ident
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class DataAdaptor
|
2
|
+
def initialize(source)
|
3
|
+
@section = Toc.instance.section(source)
|
4
|
+
end
|
5
|
+
|
6
|
+
# column_selector is one of: :number, :date, :title, :homework
|
7
|
+
COL_NAMES = { number: "#", date: "lecture date", title: "title", homework: "homework", desc: "description"}
|
8
|
+
|
9
|
+
def column_name(column_selector)
|
10
|
+
COL_NAMES[column_selector]
|
11
|
+
end
|
12
|
+
|
13
|
+
def rows
|
14
|
+
@section.each do |citem|
|
15
|
+
yield citem
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def cell_value(citem, col_selector)
|
20
|
+
case col_selector
|
21
|
+
when :number
|
22
|
+
citem.lecture_number
|
23
|
+
when :date
|
24
|
+
citem.lecture_date
|
25
|
+
when :title
|
26
|
+
citem.title
|
27
|
+
when :url
|
28
|
+
citem.identifier
|
29
|
+
when :desc
|
30
|
+
citem.desc
|
31
|
+
when :homework
|
32
|
+
citem.homework
|
33
|
+
else
|
34
|
+
"error!"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,160 @@
|
|
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
|
+
binding.pry if p.nil?
|
68
|
+
p
|
69
|
+
end
|
70
|
+
|
71
|
+
def find_previous_forn(nitem)
|
72
|
+
p = find_previous_for(n2c(nitem))
|
73
|
+
binding.pry 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 section_for nitem
|
86
|
+
# sec = @sections[n2c(nitem).section]
|
87
|
+
# binding.pry if sec.nil?
|
88
|
+
# sec
|
89
|
+
# end
|
90
|
+
|
91
|
+
def citem_section citem
|
92
|
+
@sections[citem.section]
|
93
|
+
end
|
94
|
+
|
95
|
+
def record_inclusion host_item, included_item
|
96
|
+
@info[included_item.identifier] = host_item
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def subsections(section, &block)
|
102
|
+
items = sort_section_by_subsection_name section
|
103
|
+
item_iterator = items.chunk do |item|
|
104
|
+
subsection_name section.to_s, item.identifier
|
105
|
+
end
|
106
|
+
item_iterator.each do |subsection_item|
|
107
|
+
block.call(subsection_item)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
def index_in_section item
|
114
|
+
section_for(item).find_index(item)
|
115
|
+
end
|
116
|
+
|
117
|
+
def each_by(section_selector, &block)
|
118
|
+
sub_toc = @sections[section_selector]
|
119
|
+
sub_toc.sort! { |a,b| a[:order] <=> b[:order] }.each do |member|
|
120
|
+
block.call(member)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def sort_section_by_order sect
|
125
|
+
@sections[sect].sort! { |a,b| a[:order] <=> b[:order] }
|
126
|
+
end
|
127
|
+
|
128
|
+
def sort_section_by_subsection_name(sect)
|
129
|
+
items = @sections[sect]
|
130
|
+
items.sort! do
|
131
|
+
|item1, item2|
|
132
|
+
subsection_name(sect.to_s, item1.identifier) <=> subsection_name(sect.to_s, item2.identifier)
|
133
|
+
end
|
134
|
+
items
|
135
|
+
end
|
136
|
+
|
137
|
+
def subsection_name section_name, item_name
|
138
|
+
item_matcher = item_name.match('\A/'+section_name+'/([^/]*)/([^/]*)/\z')
|
139
|
+
if !item_matcher.nil?
|
140
|
+
item_matcher[1]
|
141
|
+
else
|
142
|
+
""
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def lookup_inclusion included_item
|
147
|
+
@info[included_item.identifier]
|
148
|
+
end
|
149
|
+
|
150
|
+
def lookup_by_index section, index
|
151
|
+
sect = section.section
|
152
|
+
if index >= @sections[sect].count
|
153
|
+
index = @sections[sect].count-1
|
154
|
+
elsif index < 0
|
155
|
+
index = 0
|
156
|
+
end
|
157
|
+
@sections[sect][index]
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class BootstrapMarkup
|
2
|
+
def initialize
|
3
|
+
@str = ""
|
4
|
+
end
|
5
|
+
def table_begin
|
6
|
+
@str << "<table class=\"table table-condensed\">"
|
7
|
+
end
|
8
|
+
|
9
|
+
def table_end
|
10
|
+
@str << "</table>"
|
11
|
+
end
|
12
|
+
|
13
|
+
def headers_begin
|
14
|
+
@str << "<thead><tr>"
|
15
|
+
end
|
16
|
+
|
17
|
+
def headers_end
|
18
|
+
@str << "</tr></thead>"
|
19
|
+
end
|
20
|
+
|
21
|
+
def header_begin
|
22
|
+
@str << "<th>"
|
23
|
+
end
|
24
|
+
|
25
|
+
def header_end
|
26
|
+
@str << "</th>"
|
27
|
+
end
|
28
|
+
|
29
|
+
def header_content(str)
|
30
|
+
@str << str
|
31
|
+
end
|
32
|
+
|
33
|
+
def row_begin
|
34
|
+
@str << "<tr>"
|
35
|
+
end
|
36
|
+
|
37
|
+
def row_end
|
38
|
+
@str << "</tr>"
|
39
|
+
end
|
40
|
+
|
41
|
+
def cell_begin
|
42
|
+
@str << "<td>"
|
43
|
+
end
|
44
|
+
|
45
|
+
def cell_end
|
46
|
+
@str << "</td>"
|
47
|
+
end
|
48
|
+
|
49
|
+
def bigcell_begin
|
50
|
+
@str << "<td colspan=\"3\"><h5>"
|
51
|
+
end
|
52
|
+
|
53
|
+
def bigcell_end
|
54
|
+
@str << "</h5></td>"
|
55
|
+
end
|
56
|
+
|
57
|
+
def cell_content(str)
|
58
|
+
@str << str
|
59
|
+
end
|
60
|
+
|
61
|
+
def render
|
62
|
+
@str
|
63
|
+
end
|
64
|
+
end
|
@@ -1,7 +1,4 @@
|
|
1
1
|
module ContentHelpers
|
2
|
-
def generate_detailed_schedule section
|
3
|
-
# binding.pry
|
4
|
-
end
|
5
2
|
|
6
3
|
def include_topic item_symbol
|
7
4
|
incorporated_topic = lookup_nitem("topics", item_symbol.to_s)
|
@@ -22,7 +19,7 @@ module ContentHelpers
|
|
22
19
|
end
|
23
20
|
|
24
21
|
def bold_red string
|
25
|
-
"<span style=\"color: red; font-style: italic;\"
|
22
|
+
"<span style=\"color: red; font-style: italic;\">#{string}</span>"
|
26
23
|
end
|
27
24
|
|
28
25
|
def italic_red string
|
@@ -31,6 +28,14 @@ module ContentHelpers
|
|
31
28
|
|
32
29
|
def ir string; italic_red(string); end
|
33
30
|
|
31
|
+
def callout title, body, format=nil
|
32
|
+
template_string = <<-HTMLSTRING
|
33
|
+
<div class="well well-sm">
|
34
|
+
<span class="label label-primary">#{title}</span>#{body}
|
35
|
+
</div>
|
36
|
+
HTMLSTRING
|
37
|
+
end
|
38
|
+
|
34
39
|
def include_image_old string, extra_class: nil
|
35
40
|
css_class = "img-responsive"
|
36
41
|
css_class += " img-"+extra_class unless extra_class.nil?
|
@@ -42,7 +47,7 @@ module ContentHelpers
|
|
42
47
|
template_string = <<-HTMLSTRING
|
43
48
|
<div class="row">
|
44
49
|
<div class="col-md-offset-2 col-md-#{width}">
|
45
|
-
<img src="
|
50
|
+
<img src="../#{filename_string}" class="img-responsive img-thumbnail" />
|
46
51
|
</div>
|
47
52
|
</div>
|
48
53
|
HTMLSTRING
|
@@ -0,0 +1,89 @@
|
|
1
|
+
class ListOf
|
2
|
+
|
3
|
+
# source: name of a section as a string
|
4
|
+
# rows: array with one or more of:
|
5
|
+
# "pages"
|
6
|
+
# "subsections"
|
7
|
+
# cols: array with one or more of:
|
8
|
+
# :date
|
9
|
+
# :number
|
10
|
+
# :title
|
11
|
+
# :homeworks
|
12
|
+
|
13
|
+
def initialize(markup_adaptor, data_adaptor, rows, cols)
|
14
|
+
@mark = markup_adaptor
|
15
|
+
@rows = rows
|
16
|
+
@cols = cols
|
17
|
+
@data = data_adaptor
|
18
|
+
end
|
19
|
+
|
20
|
+
def render
|
21
|
+
@mark.table_begin
|
22
|
+
generate_headers
|
23
|
+
generate_rows
|
24
|
+
@mark.table_end
|
25
|
+
@mark.render
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def generate_headers
|
31
|
+
@mark.headers_begin
|
32
|
+
|
33
|
+
@cols.each do |col|
|
34
|
+
@mark.header_begin
|
35
|
+
@mark.header_content(@data.column_name(col))
|
36
|
+
@mark.header_end
|
37
|
+
end
|
38
|
+
|
39
|
+
@mark.headers_end
|
40
|
+
end
|
41
|
+
|
42
|
+
def generate_rows
|
43
|
+
@data.rows do |row_id|
|
44
|
+
next unless include_row?(row_id)
|
45
|
+
if subsection_hdr?(row_id)
|
46
|
+
generate_summary_row(row_id)
|
47
|
+
else
|
48
|
+
generate_detail_row(row_id)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def generate_detail_row(row_id)
|
54
|
+
@mark.row_begin
|
55
|
+
@cols.each do |col_selector|
|
56
|
+
@mark.cell_begin
|
57
|
+
@mark.cell_content(cell_content_string(row_id, col_selector, detail: true))
|
58
|
+
@mark.cell_end
|
59
|
+
end
|
60
|
+
@mark.row_end
|
61
|
+
end
|
62
|
+
|
63
|
+
def generate_summary_row(row_id)
|
64
|
+
@mark.row_begin
|
65
|
+
@mark.bigcell_begin
|
66
|
+
@mark.cell_content(cell_content_string(row_id, :title, detail: false))
|
67
|
+
@mark.bigcell_end
|
68
|
+
@mark.row_end
|
69
|
+
end
|
70
|
+
|
71
|
+
def cell_content_string(row_id, col_selector, detail:)
|
72
|
+
if (col_selector == :title && detail)
|
73
|
+
link_to_unless_current(row_id.nitem[:title], row_id.identifier)
|
74
|
+
elsif (col_selector == :date)
|
75
|
+
@data.cell_value(row_id, col_selector).strftime("%b %-d")
|
76
|
+
else
|
77
|
+
@data.cell_value(row_id, col_selector).to_s
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def include_row?(row_id)
|
82
|
+
@rows.include?(row_id.type)
|
83
|
+
end
|
84
|
+
|
85
|
+
def subsection_hdr?(row_id)
|
86
|
+
row_id.type == "subsection"
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|