Module: AlCookie

Defined in:
lib/al_cookie.rb,
lib/al_cookie/version.rb

Defined Under Namespace

Classes: AssetsGenerator, CookieScriptsTag, CookieStylesTag, PluginStaticFile

Constant Summary collapse

PLUGIN_ROOT =
File.expand_path("..", __dir__)
TEMPLATES_ROOT =
File.join(PLUGIN_ROOT, "lib", "templates")
LIB_ROOT =

Jekyll writes a StaticFile to /

/, where is relative to the base passed to the constructor. That base must be lib/, not the gem root, or the runtime lands at /lib/assets/al_cookie/... while the script tag below points at /assets/al_cookie/... .

__dir__
ASSETS_ROOT =
File.join(LIB_ROOT, "assets")
VERSION =
"1.0.1"

Class Method Summary collapse

Class Method Details

.asset_entriesObject

[relative_dir, filename] for everything this gem publishes. Exposed so the destination path can be asserted without booting a full Jekyll site.



35
36
37
38
39
# File 'lib/al_cookie.rb', line 35

def asset_entries
  Dir.glob(File.join(ASSETS_ROOT, "**", "*")).sort.reject { |p| File.directory?(p) }.map do |source_path|
    [File.dirname(source_path).sub("#{LIB_ROOT}/", ""), File.basename(source_path)]
  end
end

.enabled?(site) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/al_cookie.rb', line 21

def enabled?(site)
  site.config["enable_cookie_consent"] == true
end

.render_setup_script(context) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/al_cookie.rb', line 25

def render_setup_script(context)
  template_path = File.join(TEMPLATES_ROOT, "cookie_consent_setup.js.liquid")
  template = Liquid::Template.parse(File.read(template_path))
  payload = context.registers[:site].site_payload
  payload["page"] = context.registers[:page] || {}
  template.render(payload, registers: context.registers)
end