Module: ContentHelpers
- Defined in:
- lib/coursegen/course/helpers/content_helpers.rb
Overview
Helpers to be used to annotate content
Instance Method Summary collapse
- #bold_red(string) ⇒ Object
- #callout(title, body) ⇒ Object
- #carousel(filenames) ⇒ Object
- #carousel_new(filenames) ⇒ Object
- #carousel_work(filenames) ⇒ Object
- #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
- #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
- #link_to_doc(label, file_name) ⇒ Object
- #lookup_nitem(the_sect, short_name) ⇒ Object
- #nb(string = ":") ⇒ Object
- #partbadge ⇒ Object
- #pdfbadge ⇒ 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
- #toc_link_to(item) ⇒ 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) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 51 def callout title, body "<div class=\"well well-sm\">\n<span class=\"themebg label label-primary\">\#{title}</span>\#{body}\n</div>\n" end |
#carousel(filenames) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 163 def carousel(filenames) body = %(<div id="myCarousel" class="carousel slide" style="width: 500px; margin: 0 auto;"> <div class="carousel-inner" style="margin: 20px; ">) counter = 0 filenames.each do |nam| body << counter == 0 ? %(div class="item active">) : body << %(<div class="item">~ body << %~<img src=") body << "/content/images/#{nam}" body << %(" class="img-polaroid" alt=""></div>) counter += 1 end body << %(</div> <a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a> <a class="right carousel-control" href="#myCarousel" data-slide="next">›</a> </div>) body end |
#carousel_new(filenames) ⇒ Object
180 181 182 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 180 def carousel_new(filenames) carousel_work(filenames.map {|filename| "/content/topics/images/" + filename }) end |
#carousel_work(filenames) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 184 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
75 76 77 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 75 def cloudbadge codebadge end |
#code_begin ⇒ Object
245 246 247 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 245 def code_begin "\n~~~~~~" end |
#code_end(lang = "") ⇒ Object
249 250 251 252 253 254 255 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 249 def code_end lang="" str = "~~~~~~\n" if ["ruby", "css", "java", "html"].include? lang str += "{: .language-#{lang}}" end str end |
#code_string(str) ⇒ Object
257 258 259 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 257 def code_string str code_begin + "\n" + str + code_end end |
#codebadge ⇒ Object
71 72 73 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 71 def codebadge iconbadge("cloud", "Work on code in your portfolio") end |
#deliverable(string, append = "") ⇒ Object
132 133 134 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 132 def deliverable string, append="" "*Deliverable:*{: style=\"color: red\"} #{string + append} " end |
#deliverable_po(string) ⇒ Object
136 137 138 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 136 def deliverable_po(string) deliverable(string, " *(graded for participation only)*") end |
#deliverable_popdf(string) ⇒ Object
140 141 142 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 140 def deliverable_popdf(string) deliverable(string, " *(pdf with name and hw number, graded for participation only)*") end |
#discussion(string) ⇒ Object
148 149 150 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 148 def discussion string "*Discussion:*{: style=\"color: blue\"} *#{string}*" end |
#discussion_box(string) ⇒ Object
152 153 154 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 152 def discussion_box string %(<div class="alert alert-info"><strong>Discussion:</strong> #{string}</div>) end |
#homework_hdr(show_legend: :on) ⇒ Object
156 157 158 159 160 161 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 156 def homework_hdr(show_legend: :on) body = "#### Homework due for today" legend = "\n**Legend**: #{partbadge}: Participation | #{timebadge}: Early | #{pdfbadge}: PDF | #{teambadge}: Team | #{zipbadge}: Zipped" body += legend if show_legend == :on body end |
#iconbadge(icon, tooltip) ⇒ Object
63 64 65 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 63 def iconbadge icon, tooltip %(<span class="glyphicon glyphicon-#{icon} themefg" data-toggle="tooltip" data-placement="top" title="#{tooltip}"></span>) end |
#important(string = ":") ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 114 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
261 262 263 264 265 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 261 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
104 105 106 107 108 109 110 111 112 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 104 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" end |
#include_image_old(filename_string, extra_class: nil) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 96 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
238 239 240 241 242 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 238 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
232 233 234 235 236 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 232 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 |
# 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 |
#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 |
#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
122 123 124 125 126 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 122 def nb string = ":" " <div class=\"label label-info\">\#{string}</div>\n HTMLSTRING\nend\n" |
#partbadge ⇒ Object
83 84 85 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 83 def partbadge iconbadge("check", "Graded for participation only") end |
#pdfbadge ⇒ Object
67 68 69 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 67 def pdfbadge iconbadge("file", "Submit as 1 page pdf, include name and homework #") end |
#python_begin ⇒ Object
216 217 218 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 216 def python_begin "\n~~~~~~" end |
#python_end ⇒ Object
220 221 222 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 220 def python_end "~~~~~~\n {: .language-python}" end |
#python_string(str) ⇒ Object
228 229 230 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 228 def python_string str python_begin + "\n" + str + "\n" + python_end end |
#ruby_begin ⇒ Object
208 209 210 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 208 def ruby_begin "\n~~~~~~" end |
#ruby_end ⇒ Object
212 213 214 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 212 def ruby_end "~~~~~~\n {: .language-ruby}" end |
#ruby_string(str) ⇒ Object
224 225 226 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 224 def ruby_string str ruby_begin + "\n" + str + "\n" + ruby_end end |
#tbd(string = "") ⇒ Object
128 129 130 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 128 def tbd string = "" "*[TO BE DETERMINED#{string}]*{: style=\"color: red\"}" end |
#team_deliverable(string) ⇒ Object
144 145 146 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 144 def team_deliverable string "*Team Deliverable:*{: style=\"color: red\"} *#{string}*" end |
#teambadge ⇒ Object
91 92 93 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 91 def teambadge iconbadge("tent", "Team Deliverable") end |
#textbadge(text, tooltip) ⇒ Object
59 60 61 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 59 def textbadge text, tooltip %(<span class="label label-info" data-toggle="tooltip" data-placement="top" title="#{tooltip}">#{text}</span>) end |
#timebadge ⇒ Object
87 88 89 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 87 def timebadge iconbadge("time", "Must be submitted first thing on day of class") 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 |
#zipbadge ⇒ Object
79 80 81 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 79 def zipbadge iconbadge("briefcase", "Submit code as a .zip file") end |