Module: ContentHelpers
- Defined in:
- lib/coursegen/course/helpers/content_helpers.rb
Instance Method Summary collapse
- #bold_red(string) ⇒ Object
- #callout(title, body) ⇒ Object
- #callout_1(title, body) ⇒ 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
- #homework_hdr(show_legend: :on) ⇒ Object
- #iconbadge(icon, tooltip) ⇒ 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
- #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
42 43 44 |
# 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) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 60 def callout(title, body) <<~HTMLSTRING <div class="border border-primary rounded p-2 m-3"> <span class="badge badge-pill badge-primary">#{title}</span>#{body} </div> HTMLSTRING end |
#callout_1(title, body) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 52 def callout_1(title, body) <<~HTMLSTRING <div class="well well-sm"> <span class="themebg label label-primary">#{title}</span>#{body} </div> HTMLSTRING 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
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 222 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-100" 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 puts body body end |
#cloudbadge ⇒ Object
84 85 86 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 84 def cloudbadge iconbadge("cloud-upload-alt", "Work on code in your portfolio") end |
#code_begin ⇒ Object
289 290 291 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 289 def code_begin "\n~~~~~~" end |
#code_end(lang = "") ⇒ Object
293 294 295 296 297 298 299 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 293 def code_end(lang = "") str = "~~~~~~\n" if ["ruby", "css", "java", "html"].include? lang str += "{: .language-#{lang}}" end str end |
#code_string(str) ⇒ Object
301 302 303 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 301 def code_string(str) code_begin + "\n" + str + code_end end |
#codebadge ⇒ Object
80 81 82 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 80 def codebadge iconbadge("code", "Work on code in your portfolio") end |
#deliverable(string, append = "") ⇒ Object
146 147 148 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 146 def deliverable(string, append = "") "*Deliverable:*{: style=\"color: red\"} #{string + append} " end |
#deliverable_po(string) ⇒ Object
150 151 152 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 150 def deliverable_po(string) deliverable(string, " *(graded for participation only)*") end |
#deliverable_popdf(string) ⇒ Object
154 155 156 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 154 def deliverable_popdf(string) deliverable(string, " *(pdf with name and hw number, graded for participation only)*") end |
#discussion(string) ⇒ Object
162 163 164 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 162 def discussion(string) "*Discussion:*{: style=\"color: blue\"} *#{string}*" end |
#discussion_box(string) ⇒ Object
166 167 168 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 166 def discussion_box(string) %(<div class="alert alert-info"><strong>Discussion:</strong> #{string}</div>) end |
#homework_hdr(show_legend: :on) ⇒ Object
170 171 172 173 174 175 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 170 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
72 73 74 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 72 def iconbadge(icon, tooltip) %(<span class="fas fa-#{icon} themefg" data-toggle="tooltip" data-placement="top" title="#{tooltip}"></span>) end |
#image(filename_string, extra: "") ⇒ Object
122 123 124 125 126 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 122 def image(filename_string, extra: "") <<-HTMLSTRING <img src="/content/topics/images/#{filename_string}" class="img-responsive img-thumbnail" #{extra}/> HTMLSTRING end |
#important(string = ":") ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 128 def important(string = ":") <<-HTMLSTRING <div class="cg-important"> #{string} </div> HTMLSTRING end |
#include_background(item_symbol) ⇒ Object
14 15 16 17 |
# 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) ⇒ Object
305 306 307 308 309 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 305 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
24 25 26 27 28 |
# 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: "") ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 112 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
104 105 106 107 108 109 110 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 104 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
19 20 21 22 |
# 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) ⇒ Object
9 10 11 12 |
# 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) ⇒ Object
283 284 285 286 287 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 283 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
277 278 279 280 281 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 277 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
4 5 6 7 |
# 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) ⇒ Object
50 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 50 def ir(string); italic_red(string); end |
#italic_red(string) ⇒ Object
46 47 48 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 46 def italic_red(string) " *#{string}*{: style=\"color: red\"} " end |
#lab_note(title) ⇒ Object
341 342 343 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 341 def lab_note(title) "<h5 style=\"font-family:'Permanent Marker'; font-szie:18px; color: red;\">#{title}</h5>" end |
#link_to_doc(label, file_name) ⇒ Object
34 35 36 |
# 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) ⇒ Object
331 332 333 334 335 336 337 338 339 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 331 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
30 31 32 |
# 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 = ":") ⇒ Object
136 137 138 139 140 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 136 def nb(string = ":") <<-HTMLSTRING <div class="label label-info">#{string}</div> HTMLSTRING end |
#partbadge ⇒ Object
92 93 94 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 92 def partbadge iconbadge("hand-peace", "Graded for participation only - pass/fail") end |
#pdfbadge ⇒ Object
76 77 78 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 76 def pdfbadge iconbadge("file-pdf", "Submit as 1 page pdf, include name and homework #") end |
#postit_begin(title) ⇒ Object
311 312 313 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 311 def postit_begin title "<div class=\"postit\">" + "<h5>" + title + "</h5>" end |
#postit_end ⇒ Object
315 316 317 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 315 def postit_end "</div>" end |
#python_begin ⇒ Object
261 262 263 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 261 def python_begin "\n~~~~~~" end |
#python_end ⇒ Object
265 266 267 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 265 def python_end "~~~~~~\n {: .language-python}" end |
#python_string(str) ⇒ Object
273 274 275 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 273 def python_string(str) python_begin + "\n" + str + "\n" + python_end end |
#ruby_begin ⇒ Object
253 254 255 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 253 def ruby_begin "\n~~~~~~" end |
#ruby_end ⇒ Object
257 258 259 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 257 def ruby_end "~~~~~~\n {: .language-ruby}" end |
#ruby_string(str) ⇒ Object
269 270 271 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 269 def ruby_string(str) ruby_begin + "\n" + str + "\n" + ruby_end end |
#tbd(string = "") ⇒ Object
142 143 144 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 142 def tbd(string = "") "*[TO BE DETERMINED#{string}]*{: style=\"color: red\"}" end |
#team_deliverable(string) ⇒ Object
158 159 160 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 158 def team_deliverable(string) "*Team Deliverable:*{: style=\"color: red\"} *#{string}*" end |
#teambadge ⇒ Object
100 101 102 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 100 def teambadge iconbadge("handshake", "Team Deliverable") end |
#textbadge(text, tooltip) ⇒ Object
68 69 70 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 68 def textbadge(text, tooltip) %(<span class="label label-info" data-toggle="tooltip" data-placement="top" title="#{tooltip}">#{text}</span>) end |
#timebadge ⇒ Object
96 97 98 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 96 def timebadge iconbadge("coffee", "Must be submitted first thing on day of class") end |
#toasty(header, *items) ⇒ Object
345 346 347 348 349 350 351 352 353 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 345 def toasty(header, *items) str = %Q(<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
38 39 40 |
# 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) ⇒ Object
327 328 329 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 327 def ul body "<ul>#{body}</ul>" end |
#ul_begin ⇒ Object
319 320 321 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 319 def ul_begin "<ul>" end |
#ul_end ⇒ Object
323 324 325 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 323 def ul_end "</ul>" end |
#zipbadge ⇒ Object
88 89 90 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 88 def zipbadge iconbadge("briefcase", "Submit work as an attachment") end |