Module: ContentHelpers

Defined in:
lib/coursegen/course/helpers/content_helpers.rb

Overview

ContentHelpers is used to annotate content.

Instance Method Summary collapse

Instance Method Details

#bold_red(string) ⇒ Object



41
42
43
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 41

def bold_red(string)
  "<span style=\"color: red; font-style: italic;\">#{string}</span>"
end

#callout(title, body) ⇒ Object



69
70
71
72
73
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 69

def callout(title, body)
  %(<div class="jumbotron py-1 border border-primary border-rounded-lg">
     <h1 class="display-5">#{title}</h1>
     <p class="lead">#{body}</p></div>)
end

#callout_1(title, body) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 53

def callout_1(title, body)
  "    <div class=\"well well-sm callout\">\n    <span class=\"themebg label label-primary\">\#{title}</span>\#{body}\n    </div>\n  HTMLSTRING\nend\n"

#callout_2(title, body) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 61

def callout_2(title, body)
  "    <div class=\"callout border border-primary rounded p-2 m-3\">\n    <span class=\"badge badge-pill badge-primary\">\#{title}</span>\#{body}\n    </div>\n  HTMLSTRING\nend\n"

def carousel_work(filenames)

body = %(<div id="myCarousel" class="carousel slide" data-ride="carousel" style="width: 500px; margin: 0 auto;">
        <div class="carousel-inner" role="listbox" style="margin: 20px; ">)
counter = 0
filenames.each do |nam|
  ci = counter == 0 ? %(<div class="item active">) : %(<div class="item">)
  body << ci
  body << %(<img src=")
  body << nam
  body << %("/>"></div>)
  counter += 1
end
body << %(</div> <a class="left carousel-control" role="button" href="#myCarousel" data-slide="prev">
  <span class="glyphicon glyphicon-chevron-left"></span>
  <span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" role="button" href="#myCarousel" data-slide="next">
  <span class="glyphicon glyphicon-chevron-right"></span>
  <span class="sr-only">Next</span>
</a>
</div>)
body

end



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 237

def carousel_V4(filenames)
  body = "    <div id=\"carouselExampleControls\" class=\"carousel slide\" data-ride=\"carousel\">\n      <div class=\"carousel-inner\">\n  HEREDOC\n  count = 0\n  filenames.each do |fname|\n    active = count == 0 ? 'active' : ''\n    body << <<~HEREDOC\n      <div class=\"carousel-item \#{active}\">\n        <img class=\"d-block w-100\" src=\"/content/topics/images/\#{fname}\">\n      </div>\n    HEREDOC\n    count += 1\n  end\n  body << <<~HEREDOC\n      </div>\n      <a class=\"carousel-control-prev\" href=\"#carouselExampleControls\" role=\"button\" data-slide=\"prev\">\n      <span class=\"carousel-control-prev-icon\" aria-hidden=\"true\"></span>\n      <span class=\"sr-only\">Previous</span>\n    </a>\n    <a class=\"carousel-control-next\" href=\"#carouselExampleControls\" role=\"button\" data-slide=\"next\">\n      <span class=\"carousel-control-next-icon\" aria-hidden=\"true\"></span>\n      <span class=\"sr-only\">Next</span>\n    </a>\n    </div>\n  HEREDOC\n  body\nend\n"

#cloudbadgeObject



99
100
101
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 99

def cloudbadge
  iconbadge('cloud-fill', 'Work on code in your portfolio')
end

#code_beginObject



303
304
305
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 303

def code_begin
  "\n~~~~~~"
end

#code_end(lang = '') ⇒ Object



307
308
309
310
311
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 307

def code_end(lang = '')
  str = "~~~~~~\n"
  str += "{: .language-#{lang}}" if %w[ruby css java html].include? lang
  str
end

#code_string(str) ⇒ Object



313
314
315
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 313

def code_string(str)
  code_begin + "\n" + str + code_end
end

#codebadgeObject



95
96
97
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 95

def codebadge
  iconbadge('file-code-fill', 'Work on code in your portfolio')
end

#deliverable(string, append = '') ⇒ Object



161
162
163
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 161

def deliverable(string, append = '')
  "*Deliverable:*{: style=\"color: red\"} #{string + append} "
end

#deliverable_po(string) ⇒ Object



165
166
167
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 165

def deliverable_po(string)
  deliverable(string, ' *(graded for participation only)*')
end

#deliverable_popdf(string) ⇒ Object



169
170
171
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 169

def deliverable_popdf(string)
  deliverable(string, ' *(pdf with name and hw number, graded for participation only)*')
end

#discussion(string) ⇒ Object



177
178
179
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 177

def discussion(string)
  "*Discussion:*{: style=\"color: blue\"} *#{string}*"
end

#discussion_box(string) ⇒ Object



181
182
183
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 181

def discussion_box(string)
  %(<div class="alert alert-info"><strong>Discussion:</strong> #{string}</div>)
end

#homework_hdr(show_legend: :on) ⇒ Object



185
186
187
188
189
190
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 185

def homework_hdr(show_legend: :on)
  body = '## Homework due for today'
  legend = "\n**Legend**: #{partbadge}: Participation (pass/fail) | #{pdfbadge}: PDF | #{teambadge}: Team | #{zipbadge}:  Attachment"
  body += legend if show_legend == :on
  body
end

#iconbadge(icon, tooltip) ⇒ Object



79
80
81
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 79

def iconbadge(icon, tooltip)
  %(<svg class="bi iconbadge" fill="blue"><use xlink:href="/bootstrap/bootstrap-icons-1.0.0/bootstrap-icons.svg##{icon}"/></svg>)
end

#iconbadge1(icon, tooltip) ⇒ Object



75
76
77
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 75

def iconbadge1(icon, tooltip)
  %(<img src="/bootstrap/bootstrap-icons-1.0.0/#{icon}.svg" title="#{tooltip}" class="iconbadge">)
end

#iconbadge2(icon, tooltip) ⇒ Object



87
88
89
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 87

def iconbadge2(icon, tooltip)
  %(<span class="fas fa-#{icon} themefg" data-toggle="tooltip" data-placement="top" title="#{tooltip}"></span>)
end

#image(filename_string, extra: '') ⇒ Object



137
138
139
140
141
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 137

def image(filename_string, extra: '')
  "    <img src=\"/content/topics/images/\#{filename_string}\" class=\"img-responsive img-thumbnail\" \#{extra}/>\n  HTMLSTRING\nend\n"

#important(string = ':') ⇒ Object



143
144
145
146
147
148
149
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 143

def important(string = ':')
  "  <div class=\"cg-important\">\n      \#{string}\n  </div>\n  HTMLSTRING\nend\n"

#include_background(item_symbol) ⇒ Object



13
14
15
16
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 13

def include_background(item_symbol)
  incorporated_topic = lookup_nitem('background', item_symbol.to_s)
  items[incorporated_topic.identifier.to_s].compiled_content
end

#include_code(name) ⇒ Object



317
318
319
320
321
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 317

def include_code(name)
  filename = Dir.pwd + '/content/content/topics/scripts/' + name
  filecontents = File.new(filename).read
  code_string filecontents
end

#include_from_section(sect_symbol, item_symbol) ⇒ Object



23
24
25
26
27
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 23

def include_from_section(sect_symbol, item_symbol)
  incorporated_item = lookup_nitem(sect_symbol.to_s, item_symbol.to_s)
  Toc.instance.record_inclusion @item, incorporated_item
  items[incorporated_item.identifier.to_s].compiled_content
end

#include_image(filename_string, extra: '') ⇒ Object



127
128
129
130
131
132
133
134
135
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 127

def include_image(filename_string, extra: '')
  "    <div class=\"row\">\n      <div class=\"col-md-offset-2 col-md-8\">\n        <img src=\"\#{filename_string}\" class=\"img-responsive img-thumbnail\" \#{extra}/>\n      </div>\n    </div>\n  HTMLSTRING\nend\n"

#include_image_old(filename_string, extra_class: nil) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 119

def include_image_old(filename_string, extra_class: nil)
  css_class = 'img-responsive'
  css_class += ' img-' + extra_class unless extra_class.nil?
  "  <img src=\"\#{filename_string}\" class=\\\"%s\\\" />\" % css_class\n  HTMLSTRING\nend\n"

#include_intro(item_symbol) ⇒ Object



18
19
20
21
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 18

def include_intro(item_symbol)
  incorporated_topic = lookup_nitem('intro', item_symbol.to_s)
  items[incorporated_topic.identifier.to_s].compiled_content
end

#include_page(item_symbol) ⇒ Object



8
9
10
11
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 8

def include_page(item_symbol)
  incorporated_topic = lookup_nitem('pages', item_symbol.to_s)
  items[incorporated_topic.identifier.to_s].compiled_content
end

#include_python(name) ⇒ Object



297
298
299
300
301
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 297

def include_python(name)
  filename = Dir.pwd + '/content/content/topics/robotcode/' + name.to_s + '.py'
  filecontents = File.new(filename).read
  ruby_string filecontents
end

#include_ruby(name) ⇒ Object



291
292
293
294
295
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 291

def include_ruby(name)
  filename = Dir.pwd + '/content/content/topics/scripts/' + name.to_s + '.rb'
  filecontents = File.new(filename).read
  ruby_string filecontents
end

#include_topic(item_symbol) ⇒ Object



3
4
5
6
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 3

def include_topic(item_symbol)
  incorporated_topic = lookup_nitem('topics', item_symbol.to_s)
  items[incorporated_topic.identifier.to_s].compiled_content
end

#ir(string) ⇒ Object



49
50
51
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 49

def ir(string)
  italic_red(string)
end

#italic_red(string) ⇒ Object



45
46
47
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 45

def italic_red(string)
  " *#{string}*{: style=\"color: red\"} "
end

#lab_note(title) ⇒ Object



365
366
367
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 365

def lab_note(title)
  "<h3 style=\"font-family:'Permanent Marker'; font-szie:18px; color: red;\">#{title}</h3>"
end


33
34
35
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 33

def link_to_doc(label, file_name)
  "<a href=\"/docs/#{file_name}\">#{label}</a>"
end

#list_items(*items) ⇒ Object



355
356
357
358
359
360
361
362
363
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 355

def list_items(*items)
  items.reduce('') do |s, i|
    if i.start_with?('<ul>')
      s + i
    else
      s + '<li>' + i + '</li>'
    end
  end
end

#lookup_nitem(the_sect, short_name) ⇒ Object



29
30
31
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 29

def lookup_nitem(the_sect, short_name)
  Toc.instance.lookup_citem(the_sect, short_name).nitem
end

#nb(string = ':') ⇒ Object



151
152
153
154
155
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 151

def nb(string = ':')
  "  <div class=\"label label-info\">\#{string}</div>\n  HTMLSTRING\nend\n"

#partbadgeObject



107
108
109
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 107

def partbadge
  iconbadge('heart-half', 'Graded for participation only - pass/fail')
end

#pdfbadgeObject



91
92
93
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 91

def pdfbadge
  iconbadge('file-earmark-richtext-fill', 'Submit as 1 page pdf, include name and homework #')
end

#postit_begin(title) ⇒ Object



331
332
333
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 331

def postit_begin(title)
  '<div class="postit">' + '<h5>' + title + '</h5>'
end

#postit_endObject



335
336
337
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 335

def postit_end
  '</div>'
end

#python_beginObject



275
276
277
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 275

def python_begin
  "\n~~~~~~"
end

#python_endObject



279
280
281
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 279

def python_end
  "~~~~~~\n {: .language-python}"
end

#python_string(str) ⇒ Object



287
288
289
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 287

def python_string(str)
  python_begin + "\n" + str + "\n" + python_end
end

#ruby_beginObject



267
268
269
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 267

def ruby_begin
  "\n~~~~~~"
end

#ruby_endObject



271
272
273
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 271

def ruby_end
  "~~~~~~\n {: .language-ruby}"
end

#ruby_string(str) ⇒ Object



283
284
285
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 283

def ruby_string(str)
  ruby_begin + "\n" + str + "\n" + ruby_end
end

#slideObject



351
352
353
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 351

def slide
  '<slide_break></slide_break>'
end

#source_begin(language) ⇒ Object



323
324
325
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 323

def source_begin(language)
  "<pre class=\"#{language}\">"
end

#source_endObject



327
328
329
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 327

def source_end
  '</pre>'
end

#tbd(string = '') ⇒ Object



157
158
159
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 157

def tbd(string = '')
  "*[TO BE DETERMINED#{string}]*{: style=\"color: red\"}"
end

#team_deliverable(string) ⇒ Object



173
174
175
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 173

def team_deliverable(string)
  "*Team Deliverable:*{: style=\"color: red\"} *#{string}*"
end

#teambadgeObject



115
116
117
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 115

def teambadge
  iconbadge('people-fill', 'Team Deliverable')
end

#textbadge(text, tooltip) ⇒ Object



83
84
85
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 83

def textbadge(text, tooltip)
  %(<span class="label label-info" data-toggle="tooltip" data-placement="top" title="#{tooltip}">#{text}</span>)
end

#timebadgeObject



111
112
113
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 111

def timebadge
  iconbadge('alarm-fill', 'Must be submitted first thing on day of class')
end

#toasty(header, *items) ⇒ Object



369
370
371
372
373
374
375
376
377
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 369

def toasty(header, *items)
  str = %(<div class="border border-info rounded w-75 mx-auto p-2 m-3">
    <h5>#{header}</h5><ul>)
  items.each do |itm|
    str += '<li>' + itm + '</li>'
  end
  str += '</ul></div>'
  str
end


37
38
39
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 37

def toc_link_to(item)
  link_to_unless_current item[:title], item
end

#ul(body) ⇒ Object



347
348
349
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 347

def ul(body)
  "<ul>#{body}</ul>"
end

#ul_beginObject



339
340
341
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 339

def ul_begin
  '<ul>'
end

#ul_endObject



343
344
345
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 343

def ul_end
  '</ul>'
end

#zipbadgeObject



103
104
105
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 103

def zipbadge
  iconbadge('file-earmark-zip-fill', 'Submit work as an attachment')
end