Class: CS50::AlertBlock

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/jekyll-theme-cs50.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, text, tokens) ⇒ AlertBlock

Returns a new instance of AlertBlock.


12
13
14
15
16
# File 'lib/jekyll-theme-cs50.rb', line 12

def initialize(tag_name, text, tokens)
  super
  alert = text.strip().gsub(/\A"|"\Z/, "").gsub(/\A"|"\Z/, "")
  @alert = (["primary", "secondary", "success", "danger", "warning", "info", "light", "dark"].include? alert) ? alert : ""
end

Instance Method Details

#render(context) ⇒ Object


18
19
20
21
22
23
24
25
26
27
# File 'lib/jekyll-theme-cs50.rb', line 18

def render(context)
  site = context.registers[:site]
  converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
  message = converter.convert(super(context))
  <<~EOT
    <div class="alert" data-alert="#{@alert}" role="alert">
      #{message}
    </div>
  EOT
end