Class: Jekyll::Anticache::Tag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::Anticache::Tag
- Defined in:
- lib/jekyll/anticache_tag.rb
Overview
anticache tag
Class Method Summary collapse
-
.register(site) ⇒ Object
register tag with site config.
Instance Method Summary collapse
-
#initialize(tag_name, text, tokens) ⇒ Tag
constructor
A new instance of Tag.
-
#render(context) ⇒ String
render string with time-based cache busting number when build.
Constructor Details
#initialize(tag_name, text, tokens) ⇒ Tag
Returns a new instance of Tag.
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
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
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 |