al_cookie 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a08992fa6f34ce007c29aa92fc0e51285375da5607b1ab6b5c631c447ffd9662
4
+ data.tar.gz: d618c0fa1ff93ba06f1a5ef76baa0e4b13c82f1d8b21a99ffee5dd0295ba7494
5
+ SHA512:
6
+ metadata.gz: 2a2fe65b699a2da510cbf413ab11b8d44faad01b8e843d61900499d6d428a5365826c053f453eff3daaf5dded46a2210e1d502d28f78c548eefcf0e8f0307074
7
+ data.tar.gz: 5fd2dfea12cedd3c5a6ef665dd3dbc59477b009a6d9b0368915e9d9e98c5310365bccccd5878bd0dc8ba5a24897f6d2a22e0fee21e6b6ed7721e704c0231323c
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ - Initial extraction of cookie consent runtime from `al_folio_core` into `al_cookie`.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) al-folio maintainers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # al-cookie
2
+
3
+ Bootstrap branch for PR base.
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AlCookie
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll"
4
+ require "liquid"
5
+ require_relative "al_cookie/version"
6
+
7
+ module AlCookie
8
+ PLUGIN_ROOT = File.expand_path("..", __dir__)
9
+ TEMPLATES_ROOT = File.join(PLUGIN_ROOT, "lib", "templates")
10
+ ASSETS_ROOT = File.join(PLUGIN_ROOT, "lib", "assets")
11
+
12
+ class PluginStaticFile < Jekyll::StaticFile; end
13
+
14
+ module_function
15
+
16
+ def enabled?(site)
17
+ site.config["enable_cookie_consent"] == true
18
+ end
19
+
20
+ def render_setup_script(context)
21
+ template_path = File.join(TEMPLATES_ROOT, "cookie_consent_setup.js.liquid")
22
+ template = Liquid::Template.parse(File.read(template_path))
23
+ payload = context.registers[:site].site_payload
24
+ payload["page"] = context.registers[:page] || {}
25
+ template.render(payload, registers: context.registers)
26
+ end
27
+
28
+ class AssetsGenerator < Jekyll::Generator
29
+ safe true
30
+ priority :low
31
+
32
+ def generate(site)
33
+ return unless AlCookie.enabled?(site)
34
+
35
+ Dir.glob(File.join(ASSETS_ROOT, "**", "*")).sort.each do |source_path|
36
+ next if File.directory?(source_path)
37
+
38
+ relative_dir = File.dirname(source_path).sub("#{PLUGIN_ROOT}/", "")
39
+ site.static_files << PluginStaticFile.new(site, PLUGIN_ROOT, relative_dir, File.basename(source_path))
40
+ end
41
+ end
42
+ end
43
+
44
+ class CookieStylesTag < Liquid::Tag
45
+ def render(context)
46
+ site = context.registers[:site]
47
+ return "" unless site && AlCookie.enabled?(site)
48
+
49
+ libs = site.config["third_party_libraries"] || {}
50
+ <<~HTML
51
+ <link
52
+ defer
53
+ rel="stylesheet"
54
+ href="#{libs.dig("vanilla-cookieconsent", "url", "css")}"
55
+ integrity="#{libs.dig("vanilla-cookieconsent", "integrity", "css")}"
56
+ crossorigin="anonymous"
57
+ >
58
+ HTML
59
+ end
60
+ end
61
+
62
+ class CookieScriptsTag < Liquid::Tag
63
+ def render(context)
64
+ site = context.registers[:site]
65
+ return "" unless site && AlCookie.enabled?(site)
66
+
67
+ libs = site.config["third_party_libraries"] || {}
68
+ baseurl = site.config["baseurl"] || ""
69
+ setup_script = AlCookie.render_setup_script(context)
70
+
71
+ <<~HTML
72
+ <script
73
+ defer
74
+ src="#{libs.dig("vanilla-cookieconsent", "url", "js")}"
75
+ integrity="#{libs.dig("vanilla-cookieconsent", "integrity", "js")}"
76
+ crossorigin="anonymous"
77
+ ></script>
78
+ <script defer src="#{baseurl}/assets/al_cookie/js/cookie-theme-sync.js"></script>
79
+ <script>
80
+ #{setup_script}
81
+ </script>
82
+ HTML
83
+ end
84
+ end
85
+ end
86
+
87
+ Liquid::Template.register_tag("al_cookie_styles", AlCookie::CookieStylesTag)
88
+ Liquid::Template.register_tag("al_cookie_scripts", AlCookie::CookieScriptsTag)
data/lib/al_cookie.rb ADDED
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll"
4
+ require "liquid"
5
+ require_relative "al_cookie/version"
6
+
7
+ module AlCookie
8
+ PLUGIN_ROOT = File.expand_path("..", __dir__)
9
+ TEMPLATES_ROOT = File.join(PLUGIN_ROOT, "lib", "templates")
10
+ ASSETS_ROOT = File.join(PLUGIN_ROOT, "lib", "assets")
11
+
12
+ class PluginStaticFile < Jekyll::StaticFile; end
13
+
14
+ module_function
15
+
16
+ def enabled?(site)
17
+ site.config["enable_cookie_consent"] == true
18
+ end
19
+
20
+ def render_setup_script(context)
21
+ template_path = File.join(TEMPLATES_ROOT, "cookie_consent_setup.js.liquid")
22
+ template = Liquid::Template.parse(File.read(template_path))
23
+ payload = context.registers[:site].site_payload
24
+ payload["page"] = context.registers[:page] || {}
25
+ template.render(payload, registers: context.registers)
26
+ end
27
+
28
+ class AssetsGenerator < Jekyll::Generator
29
+ safe true
30
+ priority :low
31
+
32
+ def generate(site)
33
+ return unless AlCookie.enabled?(site)
34
+
35
+ Dir.glob(File.join(ASSETS_ROOT, "**", "*")).sort.each do |source_path|
36
+ next if File.directory?(source_path)
37
+
38
+ relative_dir = File.dirname(source_path).sub("#{PLUGIN_ROOT}/", "")
39
+ site.static_files << PluginStaticFile.new(site, PLUGIN_ROOT, relative_dir, File.basename(source_path))
40
+ end
41
+ end
42
+ end
43
+
44
+ class CookieStylesTag < Liquid::Tag
45
+ def render(context)
46
+ site = context.registers[:site]
47
+ return "" unless site && AlCookie.enabled?(site)
48
+
49
+ libs = site.config["third_party_libraries"] || {}
50
+ <<~HTML
51
+ <link
52
+ defer
53
+ rel="stylesheet"
54
+ href="#{libs.dig("vanilla-cookieconsent", "url", "css")}"
55
+ integrity="#{libs.dig("vanilla-cookieconsent", "integrity", "css")}"
56
+ crossorigin="anonymous"
57
+ >
58
+ HTML
59
+ end
60
+ end
61
+
62
+ class CookieScriptsTag < Liquid::Tag
63
+ def render(context)
64
+ site = context.registers[:site]
65
+ return "" unless site && AlCookie.enabled?(site)
66
+
67
+ libs = site.config["third_party_libraries"] || {}
68
+ baseurl = site.config["baseurl"] || ""
69
+ setup_script = AlCookie.render_setup_script(context)
70
+
71
+ <<~HTML
72
+ <script
73
+ defer
74
+ src="#{libs.dig("vanilla-cookieconsent", "url", "js")}"
75
+ integrity="#{libs.dig("vanilla-cookieconsent", "integrity", "js")}"
76
+ crossorigin="anonymous"
77
+ ></script>
78
+ <script defer src="#{baseurl}/assets/al_cookie/js/cookie-theme-sync.js"></script>
79
+ <script>
80
+ #{setup_script}
81
+ </script>
82
+ HTML
83
+ end
84
+ end
85
+ end
86
+
87
+ Liquid::Template.register_tag("al_cookie_styles", AlCookie::CookieStylesTag)
88
+ Liquid::Template.register_tag("al_cookie_scripts", AlCookie::CookieScriptsTag)
@@ -0,0 +1,35 @@
1
+ (function () {
2
+ function applyCookieThemeClass() {
3
+ var root = document.documentElement;
4
+ var theme = root.getAttribute("data-theme");
5
+
6
+ if (theme === "dark") {
7
+ root.classList.add("cc--darkmode");
8
+ } else {
9
+ root.classList.remove("cc--darkmode");
10
+ }
11
+ }
12
+
13
+ function setupObserver() {
14
+ if (typeof MutationObserver !== "function") {
15
+ return;
16
+ }
17
+
18
+ var root = document.documentElement;
19
+ var observer = new MutationObserver(function (mutations) {
20
+ for (var i = 0; i < mutations.length; i += 1) {
21
+ if (mutations[i].attributeName === "data-theme") {
22
+ applyCookieThemeClass();
23
+ break;
24
+ }
25
+ }
26
+ });
27
+
28
+ observer.observe(root, { attributes: true, attributeFilter: ["data-theme"] });
29
+ }
30
+
31
+ document.addEventListener("DOMContentLoaded", function () {
32
+ applyCookieThemeClass();
33
+ setupObserver();
34
+ });
35
+ })();
@@ -0,0 +1,115 @@
1
+ window.dataLayer = window.dataLayer || [];
2
+
3
+ if (typeof window.gtag !== "function") {
4
+ window.gtag = function () {
5
+ window.dataLayer.push(arguments);
6
+ };
7
+ }
8
+
9
+ var gtag = window.gtag;
10
+ gtag("consent", "default", {
11
+ ad_storage: "denied",
12
+ analytics_storage: "denied",
13
+ functionality_storage: "denied",
14
+ personalization_storage: "denied",
15
+ });
16
+
17
+ var cookieConsentRetryCount = 0;
18
+ var COOKIE_CONSENT_MAX_RETRIES = 50;
19
+
20
+ function initializeCookieConsent() {
21
+ if (!window.CookieConsent) {
22
+ if (cookieConsentRetryCount++ < COOKIE_CONSENT_MAX_RETRIES) {
23
+ setTimeout(initializeCookieConsent, 100);
24
+ } else {
25
+ console.error("CookieConsent library failed to load");
26
+ }
27
+ return;
28
+ }
29
+
30
+ window.CookieConsent.run({
31
+ categories: {
32
+ necessary: {
33
+ enabled: true,
34
+ readOnly: true,
35
+ },
36
+ analytics: {},
37
+ },
38
+ language: {
39
+ default: "en",
40
+ translations: {
41
+ en: {
42
+ consentModal: {
43
+ title: "We use cookies",
44
+ description:
45
+ 'This website uses cookies to improve your experience and analyze site traffic. By clicking "Accept all", you consent to our use of cookies.',
46
+ acceptAllBtn: "Accept all",
47
+ acceptNecessaryBtn: "Reject all",
48
+ showPreferencesBtn: "Manage Individual preferences",
49
+ },
50
+ preferencesModal: {
51
+ title: "Manage cookie preferences",
52
+ acceptAllBtn: "Accept all",
53
+ acceptNecessaryBtn: "Reject all",
54
+ savePreferencesBtn: "Accept current selection",
55
+ closeIconLabel: "Close modal",
56
+ sections: [
57
+ {
58
+ title: "Cookie usage",
59
+ description:
60
+ "We use cookies to ensure the basic functionalities of the website and to enhance your online experience. You can choose for each category to opt-in/out whenever you want.",
61
+ },
62
+ {
63
+ title: "Strictly Necessary cookies",
64
+ description:
65
+ "These cookies are essential for the proper functioning of the website. Without these cookies, the website would not work properly.",
66
+ linkedCategory: "necessary",
67
+ },
68
+ {
69
+ title: "Analytics cookies",
70
+ description:
71
+ "These cookies allow us to measure traffic and analyze your behavior to improve our service.",
72
+ linkedCategory: "analytics",
73
+ },
74
+ {
75
+ title: "More information",
76
+ description:
77
+ 'For any queries in relation to our policy on cookies and your choices, please <a class="cc-link" href="{{ site.url }}{{ site.baseurl }}/#contact">contact us</a>.',
78
+ },
79
+ ],
80
+ },
81
+ },
82
+ },
83
+ },
84
+ onFirstConsent: function (consentData) {
85
+ updateConsentMode(consentData);
86
+ },
87
+ onChange: function (consentData) {
88
+ updateConsentMode(consentData);
89
+ },
90
+ });
91
+
92
+ function updateConsentMode(consentData) {
93
+ var categories = consentData.categories || consentData;
94
+
95
+ if (!categories || typeof categories !== "object") {
96
+ console.warn("Invalid consent data structure:", consentData);
97
+ return;
98
+ }
99
+
100
+ gtag("consent", "update", {
101
+ analytics_storage: categories.analytics ? "granted" : "denied",
102
+ ad_storage: "denied",
103
+ functionality_storage: "denied",
104
+ personalization_storage: "denied",
105
+ });
106
+
107
+ if (categories.analytics) {
108
+ console.debug("Analytics consent granted; tracking enabled for configured providers.");
109
+ } else {
110
+ console.debug("Analytics consent denied; tracking remains blocked.");
111
+ }
112
+ }
113
+ }
114
+
115
+ initializeCookieConsent();
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: al_cookie
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - al-folio maintainers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-02-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.9'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.9'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: liquid
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '4.0'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '6.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '4.0'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '6.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '2.0'
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '2.0'
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '3.0'
73
+ - !ruby/object:Gem::Dependency
74
+ name: rake
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '13.0'
80
+ type: :development
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: '13.0'
87
+ - !ruby/object:Gem::Dependency
88
+ name: minitest
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '5.0'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '5.0'
101
+ description: Provides cookie consent runtime assets and Liquid tags for al-folio sites.
102
+ email:
103
+ - maintainers@al-folio.dev
104
+ executables: []
105
+ extensions: []
106
+ extra_rdoc_files: []
107
+ files:
108
+ - CHANGELOG.md
109
+ - LICENSE
110
+ - README.md
111
+ - lib/al_cookie 2.rb
112
+ - lib/al_cookie.rb
113
+ - lib/al_cookie/version.rb
114
+ - lib/assets/al_cookie/js/cookie-theme-sync.js
115
+ - lib/templates/cookie_consent_setup.js.liquid
116
+ homepage: https://github.com/al-org-dev/al-cookie
117
+ licenses:
118
+ - MIT
119
+ metadata:
120
+ allowed_push_host: https://rubygems.org
121
+ homepage_uri: https://github.com/al-org-dev/al-cookie
122
+ source_code_uri: https://github.com/al-org-dev/al-cookie
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '2.7'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubygems_version: 3.0.3.1
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Cookie consent plugin for al-folio v1.x
142
+ test_files: []