basecoat 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1dcf92eb8d942f66523c91a21a820d5ff109cba67b38f98093eccdcac678c75
4
- data.tar.gz: 1a0404ad13c2e6ccbf20a9bfc7374253135acf5dd92fe3cc5eee7106c1b2b6e4
3
+ metadata.gz: dadf44785123af07635692a4f315fb01b9643fdd78ca5ad069f3a102569bcaf0
4
+ data.tar.gz: fcf782397f0232aa0e99456d80fb8169639d64a3aed3b910e39ecc8a5ad192cd
5
5
  SHA512:
6
- metadata.gz: ca937fa7dd72ca69780aa873be1eddb53e8ec6b38cf7295faba256b73c0349b212e5b27cb642b6cba2564d523c1f1fdeae117e9c0c5b356f6f737e53059ac03d
7
- data.tar.gz: ebb20c9cd7bd6e839423e9b396e36a01ad5d5177422163666d964c01b9dec11889254cf66b5c0eec9f3b6b667970d9104d750a4bd7699a639c06708ff8db7011
6
+ metadata.gz: ae5d800a24e3cbbfdf80577591615678ea1e176033b2e3ee5c0827f33d418e2bb30cf290d2329838ea13e8f588717dbf278ef6a6b86bfc24ebb1e318838a3e85
7
+ data.tar.gz: 03706d6dc426530b68bfa825de75e66ffd97138f268a6ce64e498ec02192650487f73a4d25dd3eb23af0c1a0fa88c7ee209020da1227ce18d1b3112b4652eec0
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basecoat
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
@@ -0,0 +1,38 @@
1
+ // Re-initialize basecoat-css components after Turbo navigation
2
+ document.addEventListener('turbo:load', () => {
3
+ document.dispatchEvent(new Event('DOMContentLoaded', { bubbles: true, cancelable: false }))
4
+ })
5
+
6
+ // View transitions for turbo frame navigation
7
+ addEventListener("turbo:before-frame-render", (event) => {
8
+ if (document.startViewTransition) {
9
+ const originalRender = event.detail.render
10
+ event.detail.render = async (currentElement, newElement) => {
11
+ const transition = document.startViewTransition(() => originalRender(currentElement, newElement))
12
+ await transition.finished
13
+ }
14
+ }
15
+ })
16
+
17
+ // Dark mode toggle
18
+ const apply = dark => {
19
+ document.documentElement.classList.toggle('dark', dark);
20
+ try { localStorage.setItem('themeMode', dark ? 'dark' : 'light'); } catch (_) {}
21
+ };
22
+
23
+ // Apply theme on initial load (runs immediately to prevent flash)
24
+ try {
25
+ const stored = localStorage.getItem('themeMode');
26
+ if (stored ? stored === 'dark'
27
+ : matchMedia('(prefers-color-scheme: dark)').matches) {
28
+ document.documentElement.classList.add('dark');
29
+ }
30
+ } catch (_) {}
31
+
32
+ // Set up theme toggle event listener
33
+ document.addEventListener('basecoat:theme', (event) => {
34
+ const mode = event.detail?.mode;
35
+ apply(mode === 'dark' ? true
36
+ : mode === 'light' ? false
37
+ : !document.documentElement.classList.contains('dark'));
38
+ })
@@ -12,12 +12,20 @@ namespace :basecoat do
12
12
  if File.exist?(Rails.root.join("config/importmap.rb"))
13
13
  importmap_path = Rails.root.join("config/importmap.rb")
14
14
  importmap_content = File.read(importmap_path)
15
+
15
16
  unless importmap_content.include?("basecoat-css")
16
17
  File.open(importmap_path, "a") do |f|
17
18
  f.puts "\npin \"basecoat-css/all\", to: \"https://cdn.jsdelivr.net/npm/basecoat-css@0.3.2/dist/js/all.js\""
18
19
  end
19
20
  puts " Added: basecoat-css to config/importmap.rb"
20
21
  end
22
+
23
+ unless importmap_content.include?("basecoat-helper")
24
+ File.open(importmap_path, "a") do |f|
25
+ f.puts "pin \"basecoat-helper\""
26
+ end
27
+ puts " Added: basecoat-helper to config/importmap.rb"
28
+ end
21
29
  end
22
30
 
23
31
  # Add JavaScript imports and code
@@ -25,6 +33,7 @@ namespace :basecoat do
25
33
  if File.exist?(js_path)
26
34
  js_content = File.read(js_path)
27
35
 
36
+ # Add basecoat-css import
28
37
  unless js_content.include?("basecoat-css")
29
38
  # Add import after the last import line
30
39
  js_content = js_content.sub(/(import\s+.*\n)(?!import)/, "\\1import \"basecoat-css/all\"\n")
@@ -32,54 +41,20 @@ namespace :basecoat do
32
41
  puts " Added: basecoat-css import to app/javascript/application.js"
33
42
  end
34
43
 
35
- # Add view transitions code
36
- unless js_content.include?("turbo:before-frame-render")
37
- view_transition_code = <<~JS
38
-
39
- // View transitions for turbo frame navigation
40
- addEventListener("turbo:before-frame-render", (event) => {
41
- if (document.startViewTransition) {
42
- const originalRender = event.detail.render
43
- event.detail.render = async (currentElement, newElement) => {
44
- const transition = document.startViewTransition(() => originalRender(currentElement, newElement))
45
- await transition.finished
46
- }
47
- }
48
- })
49
- JS
50
- File.open(js_path, "a") { |f| f.write(view_transition_code) }
51
- puts " Added: View transitions to app/javascript/application.js"
52
- end
44
+ # Copy basecoat-helper.js
45
+ helper_source = File.expand_path("../generators/basecoat/templates/basecoat-helper.js", __dir__)
46
+ helper_destination = Rails.root.join("app/javascript/basecoat-helper.js")
47
+
48
+ FileUtils.cp(helper_source, helper_destination)
49
+ puts " Created: app/javascript/basecoat-helper.js"
53
50
 
54
- # Add dark mode toggle code
55
- unless js_content.include?("basecoat:theme")
56
- dark_mode_code = <<~JS
57
-
58
- // Dark mode toggle
59
- const apply = dark => {
60
- document.documentElement.classList.toggle('dark', dark);
61
- try { localStorage.setItem('themeMode', dark ? 'dark' : 'light'); } catch (_) {}
62
- };
63
-
64
- // Apply theme on initial load (runs immediately to prevent flash)
65
- try {
66
- const stored = localStorage.getItem('themeMode');
67
- if (stored ? stored === 'dark'
68
- : matchMedia('(prefers-color-scheme: dark)').matches) {
69
- document.documentElement.classList.add('dark');
70
- }
71
- } catch (_) {}
72
-
73
- // Set up theme toggle event listener
74
- document.addEventListener('basecoat:theme', (event) => {
75
- const mode = event.detail?.mode;
76
- apply(mode === 'dark' ? true
77
- : mode === 'light' ? false
78
- : !document.documentElement.classList.contains('dark'));
79
- })
80
- JS
81
- File.open(js_path, "a") { |f| f.write(dark_mode_code) }
82
- puts " Added: Dark mode toggle to app/javascript/application.js"
51
+ # Add basecoat-helper import
52
+ js_content = File.read(js_path)
53
+ unless js_content.include?("basecoat-helper")
54
+ # Add import after the last import line
55
+ js_content = js_content.sub(/(import\s+.*\n)(?!import)/, "\\1import \"basecoat-helper\"\n")
56
+ File.write(js_path, js_content)
57
+ puts " Added: basecoat-helper import to app/javascript/application.js"
83
58
  end
84
59
  end
85
60
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basecoat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martijn Lafeber
@@ -43,6 +43,7 @@ files:
43
43
  - lib/basecoat/railtie.rb
44
44
  - lib/basecoat/version.rb
45
45
  - lib/generators/basecoat/templates/application.html.erb
46
+ - lib/generators/basecoat/templates/basecoat-helper.js
46
47
  - lib/generators/basecoat/templates/devise.html.erb
47
48
  - lib/generators/basecoat/templates/devise/confirmations/new.html.erb
48
49
  - lib/generators/basecoat/templates/devise/mailer/confirmation_instructions.html.erb