Class: Jekyll::Share::Single

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

Overview

Single service rendering.

Instance Method Summary collapse

Methods included from Helper

#extract_page_data, #extract_preview_data, #preview?

Constructor Details

#initialize(tag_name, text, tokens) ⇒ Single

Returns a new instance of Single.



13
14
15
16
17
# File 'lib/jekyll/share/tags.rb', line 13

def initialize(tag_name, text, tokens)
  super
  @@share_single ||= {}
  @text = text
end

Instance Method Details

#render(context) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/jekyll/share/tags.rb', line 19

def render(context)
  @params = init_params(@text, context)
  if @@share_single.key? @name
    @@share_single[@name].reset!
  else
    @@share_single[@name] = ShareWith::Service.new @name,
                                                   extend_with: @extend_with,
                                                   paths: Config.paths
  end

  @params = if preview?(context)
              extract_preview_data(context).merge @params
            else
              extract_page_data(context).merge @params
            end

  @params.each do |key, value|
    @@share_single[@name].set_conditional_param(key, value)
  end

  @@share_single[@name].render(@template)
end