Module: ContentHelpers
- Defined in:
- lib/coursegen/course/helpers/content_helpers.rb
Overview
ContentHelpers is used to annotate content.
Instance Method Summary collapse
- #bold_red(string) ⇒ Object
- #callout(title, body, style = "big") ⇒ Object
- #callout1(title, body) ⇒ Object
- #callout2(title, body) ⇒ Object
- #callout3(title, body, style = "big") ⇒ Object
-
#carousel_v4(filenames) ⇒ Object
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.
- #cloudbadge ⇒ Object
- #code_begin ⇒ Object
- #code_end(lang = '') ⇒ Object
- #code_string(str) ⇒ Object
- #codebadge ⇒ Object
- #deliverable(string, append = '') ⇒ Object
- #deliverable_po(string) ⇒ Object
- #deliverable_popdf(string) ⇒ Object
- #discussion(string) ⇒ Object
- #discussion_box(string) ⇒ Object
- #discussion_box1(string) ⇒ Object
- #homework_hdr(show_legend: :on) ⇒ Object
- #iconbadge(icon, tooltip, shorttext = "") ⇒ Object
- #iconbadge1(icon, tooltip) ⇒ Object
- #iconbadge2(icon, tooltip) ⇒ Object
- #iconbadge3(icon, tooltip, shorttext = "") ⇒ Object
- #image(filename_string, extra: '') ⇒ Object
- #important(string = ':') ⇒ Object
- #include_background(item_symbol) ⇒ Object
- #include_code(name) ⇒ Object
- #include_from_section(sect_symbol, item_symbol) ⇒ Object
- #include_image(filename_string, extra: '') ⇒ Object
- #include_image_old(filename_string, extra_class: nil) ⇒ Object
- #include_intro(item_symbol) ⇒ Object
- #include_page(item_symbol) ⇒ Object
- #include_python(name) ⇒ Object
- #include_ruby(name) ⇒ Object
- #include_topic(item_symbol) ⇒ Object
- #ir(string) ⇒ Object
- #italic_red(string) ⇒ Object
- #lab_note(title) ⇒ Object
- #link_to_doc(label, file_name) ⇒ Object
- #list_items(*items) ⇒ Object
- #lookup_nitem(the_sect, short_name) ⇒ Object
- #nb(string = ':') ⇒ Object
- #partbadge ⇒ Object
- #pdfbadge ⇒ Object
- #postit_begin(title) ⇒ Object
- #postit_end ⇒ Object
- #python_begin ⇒ Object
- #python_end ⇒ Object
- #python_string(str) ⇒ Object
- #ruby_begin ⇒ Object
- #ruby_end ⇒ Object
- #ruby_string(str) ⇒ Object
- #slide ⇒ Object
- #source_begin(language) ⇒ Object
- #source_end ⇒ Object
- #tbd(string = '') ⇒ Object
- #team_deliverable(string) ⇒ Object
- #teambadge ⇒ Object
- #textbadge(text, tooltip) ⇒ Object
- #timebadge ⇒ Object
- #toasty(header, *items) ⇒ Object
- #toc_link_to(item) ⇒ Object
- #ul(body) ⇒ Object
- #ul_begin ⇒ Object
- #ul_end ⇒ Object
- #zipbadge ⇒ Object
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, style = "big") ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 86 def callout(title, body, style="big") style = style.to_s if style.class != String if (style == "big") %(<div class="callout callout-big"> <h1 class="display-5">#{title}</h1> <p class="lead">#{body}</p></div>) elsif (style == "small") <<~HTMLSTRING <div class="callout callout-small"> <span class="callout-badge">#{title}</span>#{body} </div> HTMLSTRING else "error in callout call: .#{style}. #{style.class}" end end |
#callout1(title, body) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 53 def callout1(title, body) <<~HTMLSTRING <div class="well well-sm callout"> <span class="themebg label label-primary">#{title}</span>#{body} </div> HTMLSTRING end |
#callout2(title, body) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 61 def callout2(title, body) <<~HTMLSTRING <div class="callout border border-primary rounded p-2 m-3"> <span class="badge badge-pill badge-primary">#{title}</span>#{body} </div> HTMLSTRING end |
#callout3(title, body, style = "big") ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 69 def callout3(title, body, style="big") style = style.to_s if style.class != String if (style == "big") %(<div class="jumbotron py-1 border border-primary border-rounded-lg"> <h1 class="display-5">#{title}</h1> <p class="lead">#{body}</p></div>) elsif (style == "small") <<~HTMLSTRING <div class="callout border border-primary rounded p-2 m-3"> <span class="badge badge-pill badge-primary">#{title}</span>#{body} </div> HTMLSTRING else "error in callout call: .#{style}. #{style.class}" end end |
#carousel_v4(filenames) ⇒ Object
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
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 273 def carousel_v4(filenames) body = <<~HEREDOC <div id="carouselExampleControls" class="carousel slide" data-ride="carousel"> <div class="carousel-inner"> HEREDOC count = 0 filenames.each do |fname| active = count == 0 ? 'active' : '' body << <<~HEREDOC <div class="carousel-item #{active}"> <img class="d-block w-80" src="/content/topics/images/#{fname}"> </div> HEREDOC count += 1 end body << <<~HEREDOC </div> <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> HEREDOC body end |
#cloudbadge ⇒ Object
131 132 133 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 131 def cloudbadge iconbadge('cloud-fill', 'Work on code in your portfolio', 'portfolio') end |
#code_begin ⇒ Object
339 340 341 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 339 def code_begin "\n~~~~~~" end |
#code_end(lang = '') ⇒ Object
343 344 345 346 347 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 343 def code_end(lang = '') str = "~~~~~~\n" str += "{: .language-#{lang}}" if %w[ruby css java html].include? lang str end |
#code_string(str) ⇒ Object
349 350 351 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 349 def code_string(str) code_begin + "\n" + str + code_end end |
#codebadge ⇒ Object
127 128 129 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 127 def codebadge iconbadge('file-code-fill', 'Work on code in your portfolio', "portfolio") end |
#deliverable(string, append = '') ⇒ Object
193 194 195 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 193 def deliverable(string, append = '') "*Deliverable:*{: style=\"color: red\"} #{string + append} " end |
#deliverable_po(string) ⇒ Object
197 198 199 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 197 def deliverable_po(string) deliverable(string, ' *(graded for participation only)*') end |
#deliverable_popdf(string) ⇒ Object
201 202 203 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 201 def deliverable_popdf(string) deliverable(string, ' *(pdf with name and hw number, graded for participation only)*') end |
#discussion(string) ⇒ Object
209 210 211 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 209 def discussion(string) "*Discussion:*{: style=\"color: blue\"} *#{string}*" end |
#discussion_box(string) ⇒ Object
217 218 219 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 217 def discussion_box(string) %(<div class="discussionbox"><strong>Discussion:</strong> #{string}</div>) end |
#discussion_box1(string) ⇒ Object
213 214 215 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 213 def discussion_box1(string) %(<div class="alert alert-info"><strong>Discussion:</strong> #{string}</div>) end |
#homework_hdr(show_legend: :on) ⇒ Object
221 222 223 224 225 226 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 221 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, shorttext = "") ⇒ Object
111 112 113 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 111 def iconbadge(icon, tooltip, shorttext="") %(<svg class="iconbadge bi" title="#{tooltip}" data-placement="top" data-title="#{tooltip}" data-toggle="tooltip" fill="blue"><use xlink:href="/bootstrap/bootstrap-icons-1.0.0/bootstrap-icons.svg##{icon}"/></svg><span class="icontext" >#{shorttext}</span>) end |
#iconbadge1(icon, tooltip) ⇒ Object
103 104 105 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 103 def iconbadge1(icon, tooltip) %(<img src="/bootstrap/bootstrap-icons-1.0.0/#{icon}.svg" title="#{tooltip}" class="iconbadge">) end |
#iconbadge2(icon, tooltip) ⇒ Object
119 120 121 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 119 def iconbadge2(icon, tooltip) %(<span class="fas fa-#{icon} themefg" data-toggle="tooltip" data-placement="top" title="#{tooltip}"></span>) end |
#iconbadge3(icon, tooltip, shorttext = "") ⇒ Object
107 108 109 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 107 def iconbadge3(icon, tooltip, shorttext="") %(<svg class="iconbadge bi" title="#{tooltip}" data-placement="top" data-title="#{tooltip}" data-toggle="tooltip" fill="blue"><use xlink:href="/bootstrap/bootstrap-icons-1.0.0/bootstrap-icons.svg##{icon}"/></svg>#{shorttext}) end |
#image(filename_string, extra: '') ⇒ Object
169 170 171 172 173 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 169 def image(filename_string, extra: '') <<~HTMLSTRING <img src="/content/topics/images/#{filename_string}" class="img-responsive img-thumbnail" #{extra}/> HTMLSTRING end |
#important(string = ':') ⇒ Object
175 176 177 178 179 180 181 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 175 def important(string = ':') <<-HTMLSTRING <div class="cg-important"> #{string} </div> HTMLSTRING end |
#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
353 354 355 356 357 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 353 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
159 160 161 162 163 164 165 166 167 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 159 def include_image(filename_string, extra: '') <<~HTMLSTRING <div class="row"> <div class="col-md-offset-2 col-md-8"> <img src="#{filename_string}" class="img-responsive img-thumbnail" #{extra}/> </div> </div> HTMLSTRING end |
#include_image_old(filename_string, extra_class: nil) ⇒ Object
151 152 153 154 155 156 157 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 151 def include_image_old(filename_string, extra_class: nil) css_class = 'img-responsive' css_class += ' img-' + extra_class unless extra_class.nil? <<-HTMLSTRING <img src="#{filename_string}" class=\"%s\" />" % css_class HTMLSTRING end |
#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
333 334 335 336 337 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 333 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
327 328 329 330 331 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 327 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
401 402 403 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 401 def lab_note(title) "<h3 style=\"font-family:'Permanent Marker'; font-szie:18px; color: red;\">#{title}</h3>" end |
#link_to_doc(label, file_name) ⇒ Object
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
391 392 393 394 395 396 397 398 399 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 391 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
183 184 185 186 187 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 183 def nb(string = ':') <<-HTMLSTRING <div class="label label-info">#{string}</div> HTMLSTRING end |
#partbadge ⇒ Object
139 140 141 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 139 def partbadge iconbadge('heart-half', 'Graded for participation only - pass/fail', 'participation') end |
#pdfbadge ⇒ Object
123 124 125 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 123 def pdfbadge iconbadge('file-earmark-richtext-fill', 'Submit a pdf file', "pdf") end |
#postit_begin(title) ⇒ Object
367 368 369 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 367 def postit_begin(title) '<div class="postit">' + '<h5>' + title + '</h5>' end |
#postit_end ⇒ Object
371 372 373 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 371 def postit_end '</div>' end |
#python_begin ⇒ Object
311 312 313 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 311 def python_begin "\n~~~~~~" end |
#python_end ⇒ Object
315 316 317 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 315 def python_end "~~~~~~\n {: .language-python}" end |
#python_string(str) ⇒ Object
323 324 325 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 323 def python_string(str) python_begin + "\n" + str + "\n" + python_end end |
#ruby_begin ⇒ Object
303 304 305 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 303 def ruby_begin "\n~~~~~~" end |
#ruby_end ⇒ Object
307 308 309 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 307 def ruby_end "~~~~~~\n {: .language-ruby}" end |
#ruby_string(str) ⇒ Object
319 320 321 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 319 def ruby_string(str) ruby_begin + "\n" + str + "\n" + ruby_end end |
#slide ⇒ Object
387 388 389 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 387 def '<slide_break></slide_break>' end |
#source_begin(language) ⇒ Object
359 360 361 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 359 def source_begin(language) "<pre><code class=\"#{language}\">" end |
#source_end ⇒ Object
363 364 365 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 363 def source_end '</code></pre>' end |
#tbd(string = '') ⇒ Object
189 190 191 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 189 def tbd(string = '') "*[TO BE DETERMINED#{string}]*{: style=\"color: red\"}" end |
#team_deliverable(string) ⇒ Object
205 206 207 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 205 def team_deliverable(string) "*Team Deliverable:*{: style=\"color: red\"} *#{string}*" end |
#teambadge ⇒ Object
147 148 149 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 147 def teambadge iconbadge('people-fill', 'Team Deliverable', 'team deliverable') end |
#textbadge(text, tooltip) ⇒ Object
115 116 117 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 115 def textbadge(text, tooltip) %(<span class="label label-info" data-toggle="tooltip" data-placement="top" title="#{tooltip}">#{text}</span>) end |
#timebadge ⇒ Object
143 144 145 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 143 def timebadge iconbadge('alarm-fill', 'Must be submitted first thing on day of class', 'early submit') end |
#toasty(header, *items) ⇒ Object
405 406 407 408 409 410 411 412 413 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 405 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 |
#toc_link_to(item) ⇒ Object
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
383 384 385 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 383 def ul(body) "<ul>#{body}</ul>" end |
#ul_begin ⇒ Object
375 376 377 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 375 def ul_begin '<ul>' end |
#ul_end ⇒ Object
379 380 381 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 379 def ul_end '</ul>' end |
#zipbadge ⇒ Object
135 136 137 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 135 def zipbadge iconbadge('file-earmark-zip-fill', 'Submit work in a zipfile', 'zip') end |