Class: Jekyll::Anticache::Tag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll/anticache_tag.rb

Overview

anticache tag

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, text, tokens) ⇒ Tag

Returns a new instance of Tag.

Parameters:

  • tag_name (String)
  • text (String)
  • tokens (Object)


36
37
38
39
# File 'lib/jekyll/anticache_tag.rb', line 36

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

Class Method Details

.register(site) ⇒ Object

register tag with site config

:reek:DuplicateMethodCall

Parameters:

  • site (Object)


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

def register(site)
  config = site.config[CONFIG_NAMESPACE]
  
  tag = if config && config.dig('tag') 
          config.dig('tag')
        else
          'acasset'
        end
  
  Liquid::Template.register_tag(tag, self)
end

Instance Method Details

#render(context) ⇒ String

render string with time-based cache busting number when build

:reek:FeatureEnvy

Parameters:

  • context (Object)

Returns:

  • (String)


48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/jekyll/anticache_tag.rb', line 48

def render(context)
  env = context.environments&.first['jekyll']&.environment || ENV['JEKYLL_ENV']

  text = @text.strip.gsub(/['"]/, '')

  if env != 'development'
    site = context.registers[:site]

    "#{text}?#{site.time.to_i}"
  else
    text
  end
end