Class: CS50::LocalTag

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

Constant Summary collapse

@@regex =
"\d{4}-\d{2}-\d{2} \d{1,2}:\d{2}(:\d{2})?"

Instance Method Summary collapse

Methods included from Mixins

#initialize

Instance Method Details

#render(context) ⇒ Object



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/jekyll-theme-cs50.rb', line 245

def render(context)
  super

  # Parse required argument
  if @args.length < 1
    raise "Too few arguments"
  elsif @args.length > 2
    raise "Too many arguments: #{@markup}"
  end
  t1 = CS50::strptime(@args[0])
  local = t1.iso8601
  path = CS50::format(t1)

  # Parse optional argument
  if @args.length == 2
    t2 = CS50::strptime(@args[1], t1)
    if t2 < t1
      raise "Invalid interval: #{@markup}"
    end
    local += "/" + t2.iso8601
    path += "/" + CS50::format(t2)
  end

  # Return element
  # Even though text node will be replaced by JavaScript, ensures Kramdown can
  # assign an ID if this element is used as a heading
  "<span data-local='#{local}'>#{local}</span>"
end