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
- #homework_hdr ⇒ 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, width: 8) ⇒ Object
- #include_image_old(string, extra_class: nil) ⇒ Object
- #include_intro(item_symbol) ⇒ Object
- #include_page(item_symbol) ⇒ 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
- #ruby_begin ⇒ Object
- #ruby_end ⇒ Object
- #ruby_string(str) ⇒ Object
- #tbd(string = "") ⇒ Object
- #team_deliverable(string) ⇒ 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
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 144 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
161 162 163 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 161 def carousel_new(filenames) carousel_work(filenames.map {|filename| "/content/topics/images/" + filename }) end |
#carousel_work(filenames) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 165 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="carousel-item active">) : %(<div class="carousel-item">) puts "****** #{ci}" body << ci body << %(<img src=") body << nam body << %(" class="d-block img-fluid"></div>) counter += 1 end body << %(</div> <a class="carousel-control-prev" role="button" href="#myCarousel" data-slide="prev">‹</a> <a class="carousel-control-next" role="button" href="#myCarousel" data-slide="next">›</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
202 203 204 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 202 def code_begin "\n~~~~~~" end |
#code_end(lang = "") ⇒ Object
206 207 208 209 210 211 212 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 206 def code_end lang="" str = "~~~~~~\n" if ["ruby", "css", "java", "html"].include? lang str += "{: .language-#{lang}}" end str end |
#code_string(str) ⇒ Object
214 215 216 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 214 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
120 121 122 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 120 def deliverable string, append="" "*Deliverable:*{: style=\"color: red\"} #{string + append} " end |
#deliverable_po(string) ⇒ Object
124 125 126 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 124 def deliverable_po(string) deliverable(string, " *(graded for participation only)*") end |
#deliverable_popdf(string) ⇒ Object
128 129 130 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 128 def deliverable_popdf(string) deliverable(string, " *(pdf with name and hw number, graded for participation only)*") end |
#discussion(string) ⇒ Object
136 137 138 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 136 def discussion string "*Discussion:*{: style=\"color: blue\"} *#{string}*" end |
#homework_hdr ⇒ Object
140 141 142 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 140 def homework_hdr "#### Homework due for today" 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
108 109 110 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 108 def important string = ":" "**Important#{string}**{: style=\"color: red\"}" 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
218 219 220 221 222 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 218 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, width: 8) ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 98 def include_image filename_string, width: 8 "<div class=\"row\">\n<div class=\"col-md-offset-2 col-md-\#{width}\">\n <img src=\"\#{filename_string}\" class=\"img-responsive img-thumbnail\" />\n</div>\n</div>\n" end |
#include_image_old(string, extra_class: nil) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 91 def include_image_old string, extra_class: nil css_class = "img-responsive" css_class += " img-" + extra_class unless extra_class.nil? "<img src=\"/content/images/#{string}\" class=\"%s\" />" % css_class 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_ruby(name) ⇒ Object
196 197 198 199 200 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 196 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
112 113 114 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 112 def nb string = "" "*NB: #{string}*{: style=\"color: green\"}" end |
#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 |
#ruby_begin ⇒ Object
184 185 186 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 184 def ruby_begin "\n~~~~~~" end |
#ruby_end ⇒ Object
188 189 190 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 188 def ruby_end "~~~~~~\n {: .language-ruby}" end |
#ruby_string(str) ⇒ Object
192 193 194 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 192 def ruby_string str ruby_begin + "\n" + str + "\n" + ruby_end end |
#tbd(string = "") ⇒ Object
116 117 118 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 116 def tbd string = "" "*[TO BE DETERMINED#{string}]*{: style=\"color: red\"}" end |
#team_deliverable(string) ⇒ Object
132 133 134 |
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 132 def team_deliverable string "*Team Deliverable:*{: style=\"color: red\"} *#{string}*" 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 |