Class: Jekyll::Disqus::ScriptUI

Inherits:
Liquid::Tag
  • Object
show all
Includes:
Helper
Defined in:
lib/jekyll/disqus/tags.rb

Overview

Print the Javascript code to render the comment box.

Constant Summary collapse

@@ids =
{}

Instance Method Summary collapse

Methods included from Helper

#disabled_tag?, #page_disqus_id, #post_disqus_id, #post_selector

Constructor Details

#initialize(tag_name, param, tokens) ⇒ ScriptUI

Returns a new instance of ScriptUI.



75
76
77
78
# File 'lib/jekyll/disqus/tags.rb', line 75

def initialize(tag_name, param, tokens)
  super
  @param = param
end

Instance Method Details

#render(context) ⇒ Object

Raises:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/jekyll/disqus/tags.rb', line 80

def render(context)
  return "" if disabled_tag?("ui", context)

  raise MissingShortname unless context.registers[:site].config["jekyll-disqus"]["shortname"]

  id = page_disqus_id(context.registers)
  url = context.registers[:page]["url"]
  if @@ids.key?(id) && (@@ids[id] != url)
    raise DuplicatedDisqusId, { current_url: url, duplicated_url: @@ids[id], id: id }
  end

  @@ids[id] = url
  js_string(base_url: context.registers[:site].config["url"],
            page_url: url,
            disqus_shortname: context.registers[:site].config["jekyll-disqus"]["shortname"],
            disqus_id: id)
end