module ContentHelpers
ContentHelpers
is used to annotate content.
Public Instance Methods
bold_red(string)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 42 def bold_red(string) "<span style=\"color: red; font-style: italic;\">#{string}</span>" end
callout(title, body, style="big")
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 87 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)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 54 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)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 62 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")
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 70 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)
click to toggle source
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
# File lib/coursegen/course/helpers/content_helpers.rb, line 275 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()
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 133 def cloudbadge iconbadge('cloud-fill', 'Work on code in your portfolio', 'portfolio') end
code_begin()
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 341 def code_begin "\n~~~~~~" end
code_end(lang = '')
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 345 def code_end(lang = '') str = "~~~~~~\n" str += "{: .language-#{lang}}" if %w[ruby css java html].include? lang str end
code_string(str)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 351 def code_string(str) code_begin + "\n" + str + code_end end
codebadge()
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 129 def codebadge iconbadge('file-code-fill', 'Work on code in your portfolio', "portfolio") end
deliverable(string, append = '')
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 195 def deliverable(string, append = '') "*Deliverable:*{: style=\"color: red\"} #{string + append} " end
deliverable_po(string)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 199 def deliverable_po(string) deliverable(string, ' *(graded for participation only)*') end
deliverable_popdf(string)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 203 def deliverable_popdf(string) deliverable(string, ' *(pdf with name and hw number, graded for participation only)*') end
discussion(string)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 211 def discussion(string) "*Discussion:*{: style=\"color: blue\"} *#{string}*" end
discussion_box(string)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 219 def discussion_box(string) %(<div class="discussionbox"><strong>Discussion:</strong> #{string}</div>) end
discussion_box1(string)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 215 def discussion_box1(string) %(<div class="alert alert-info"><strong>Discussion:</strong> #{string}</div>) end
homework_hdr(show_legend: :on)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 223 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="")
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 113 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)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 105 def iconbadge1(icon, tooltip) %(<img src="/bootstrap/bootstrap-icons-1.0.0/#{icon}.svg" title="#{tooltip}" class="iconbadge">) end
iconbadge2(icon, tooltip)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 121 def iconbadge2(icon, tooltip) %(<span class="fas fa-#{icon} themefg" data-toggle="tooltip" data-placement="top" title="#{tooltip}"></span>) end
iconbadge3(icon, tooltip, shorttext="")
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 109 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: '')
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 171 def image(filename_string, extra: '') <<~HTMLSTRING <img src="/content/topics/images/#{filename_string}" class="img-responsive img-thumbnail" #{extra}/> HTMLSTRING end
important(string = ':')
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 177 def important(string = ':') <<-HTMLSTRING <div class="cg-important"> #{string} </div> HTMLSTRING end
include_background(item_symbol)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 14 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)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 355 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)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 24 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: '')
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 161 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)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 153 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)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 19 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)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 9 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)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 335 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)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 329 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)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 4 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)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 50 def ir(string) italic_red(string) end
italic_red(string)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 46 def italic_red(string) " *#{string}*{: style=\"color: red\"} " end
lab_note(title)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 403 def lab_note(title) "<h3 style=\"font-family:'Permanent Marker'; font-szie:18px; color: red;\">#{title}</h3>" end
link_to_doc(label, file_name)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 34 def link_to_doc(label, file_name) "<a href=\"/docs/#{file_name}\">#{label}</a>" end
list_items(*items)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 393 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)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 30 def lookup_nitem(the_sect, short_name) Toc.instance.lookup_citem(the_sect, short_name).nitem end
nb(string = ':')
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 185 def nb(string = ':') <<-HTMLSTRING <div class="label label-info">#{string}</div> HTMLSTRING end
partbadge()
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 141 def partbadge iconbadge('heart-half', 'Graded for participation only - pass/fail', 'participation') end
pdfbadge()
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 125 def pdfbadge iconbadge('file-earmark-richtext-fill', 'Submit a pdf file', "pdf") end
postit_begin(title)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 369 def postit_begin(title) '<div class="postit">' + '<h5>' + title + '</h5>' end
postit_end()
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 373 def postit_end '</div>' end
python_begin()
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 313 def python_begin "\n~~~~~~" end
python_end()
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 317 def python_end "~~~~~~\n {: .language-python}" end
python_string(str)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 325 def python_string(str) python_begin + "\n" + str + "\n" + python_end end
ruby_begin()
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 305 def ruby_begin "\n~~~~~~" end
ruby_end()
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 309 def ruby_end "~~~~~~\n {: .language-ruby}" end
ruby_string(str)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 321 def ruby_string(str) ruby_begin + "\n" + str + "\n" + ruby_end end
slide()
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 389 def slide '<slide_break></slide_break>' end
source_begin(language)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 361 def source_begin(language) "<pre class=\"#{language}\">" end
source_end()
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 365 def source_end '</pre>' end
tbd(string = '')
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 191 def tbd(string = '') "*[TO BE DETERMINED#{string}]*{: style=\"color: red\"}" end
team_deliverable(string)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 207 def team_deliverable(string) "*Team Deliverable:*{: style=\"color: red\"} *#{string}*" end
teambadge()
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 149 def teambadge iconbadge('people-fill', 'Team Deliverable', 'team deliverable') end
textbadge(text, tooltip)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 117 def textbadge(text, tooltip) %(<span class="label label-info" data-toggle="tooltip" data-placement="top" title="#{tooltip}">#{text}</span>) end
timebadge()
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 145 def timebadge iconbadge('alarm-fill', 'Must be submitted first thing on day of class', 'early submit') end
toasty(header, *items)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 407 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)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 38 def toc_link_to(item) link_to_unless_current item[:title], item end
ul(body)
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 385 def ul(body) "<ul>#{body}</ul>" end
ul_begin()
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 377 def ul_begin '<ul>' end
ul_end()
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 381 def ul_end '</ul>' end
zipbadge()
click to toggle source
# File lib/coursegen/course/helpers/content_helpers.rb, line 137 def zipbadge iconbadge('file-earmark-zip-fill', 'Submit work in a zipfile', 'zip') end