Module: ContentHelpers

Defined in:
lib/coursegen/course/helpers/content_helpers.rb

Instance Method Summary collapse

Instance Method Details

#bold_red(string) ⇒ Object



27
28
29
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 27

def bold_red string
    "<span style=\"color: red; font-style: italic;\">#{string}</span>"
end

#callout(title, body, format = nil) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 37

def callout title, body, format=nil
  template_string = <<-HTMLSTRING
<div class="well well-sm">
<span class="label label-primary">#{title}</span>#{body}
</div>
HTMLSTRING
end


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 90

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|
  if counter == 0
      body << %~<div class="item active">~
  else
      body << %~<div class="item">~
  end
  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


112
113
114
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 112

def carousel_new(filenames)
  carousel_work(filenames.map {|filename| "/content/topics/images/"+filename })
end


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 116

def carousel_work(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|
  if counter == 0
      body << %~<div class="item active">~
  else
      body << %~<div class="item">~
  end
  body << %~<img src="~
  body << 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

#code_beginObject



157
158
159
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 157

def code_begin
    "\n~~~~~~"
end

#code_endObject



161
162
163
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 161

def code_end
    "~~~~~~\n"
end

#code_string(str) ⇒ Object



165
166
167
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 165

def code_string (str)
  code_begin + "\n" + str + code_end
end

#deliverable(string) ⇒ Object



74
75
76
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 74

def deliverable string
    "*Deliverable:*{: style=\"color: red\"} *#{string}*"
end

#discussion(string) ⇒ Object



82
83
84
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 82

def discussion string
    "*Discussion:*{: style=\"color: blue\"} *#{string}*"
end

#homework_hdrObject



86
87
88
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 86

def homework_hdr
  "#### Homework due for today"
end

#important(string = ":") ⇒ Object



62
63
64
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 62

def important string=":"
    "**Important#{string}**{: style=\"color: red\"}"
end

#include_code(name) ⇒ Object



169
170
171
172
173
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 169

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



9
10
11
12
13
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 9

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].compiled_content
end

#include_image(filename_string, width: 8) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 52

def include_image filename_string, width: 8
template_string = <<-HTMLSTRING
<div class="row">
<div class="col-md-offset-2 col-md-#{width}">
  <img src="#{filename_string}" class="img-responsive img-thumbnail" />
</div>
</div>
HTMLSTRING
end

#include_image_old(string, extra_class: nil) ⇒ Object



45
46
47
48
49
50
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 45

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_ruby(name) ⇒ Object



151
152
153
154
155
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 151

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
7
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 3

def include_topic item_symbol
    incorporated_topic = lookup_nitem("topics", item_symbol.to_s)
    Toc.instance.record_inclusion @item, incorporated_topic
    items[incorporated_topic.identifier].compiled_content
end

#ir(string) ⇒ Object



35
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 35

def ir string; italic_red(string); end

#italic_red(string) ⇒ Object



31
32
33
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 31

def italic_red string
    " *#{string}*{: style=\"color: red\"} "
end


19
20
21
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 19

def link_to_doc label, file_name
    "<a href=\"/docs/#{file_name}\">#{label}</a>"
end

#lookup_nitem(the_sect, short_name) ⇒ Object



15
16
17
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 15

def lookup_nitem the_sect, short_name
    Toc.instance.lookup_citem(the_sect, short_name).nitem
end

#nb(string = "") ⇒ Object



66
67
68
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 66

def nb string=""
    "*NB: #{string}*{: style=\"color: green\"}"
end

#ruby_beginObject



139
140
141
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 139

def ruby_begin
    "\n~~~~~~"
end

#ruby_endObject



143
144
145
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 143

def ruby_end
    "~~~~~~\n {: .language-ruby}"
end

#ruby_string(str) ⇒ Object



147
148
149
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 147

def ruby_string (str)
    ruby_begin + "\n" +  str + "\n" + ruby_end
end

#tbd(string = "") ⇒ Object



70
71
72
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 70

def tbd string=""
    "*[TO BE DETERMINED#{string}]*{: style=\"color: red\"}"
end

#team_deliverable(string) ⇒ Object



78
79
80
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 78

def team_deliverable string
    "*Team Deliverable:*{: style=\"color: red\"} *#{string}*"
end


23
24
25
# File 'lib/coursegen/course/helpers/content_helpers.rb', line 23

def toc_link_to item
    link_to_unless_current item[:title], item
end