svelte-on-rails 0.0.16 → 0.0.18

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: 677cbdec13a7a29dad5a6601755976aebce32a9cd5d4d132d62682650887b81d
4
- data.tar.gz: 3cd12a78ff280021ff44ba0bc29371a3268a4b50de93264f9388925cc6fdad21
3
+ metadata.gz: 0bdaed0f08472a9dde76f78c8d69f99b1b9cd1422ed75631620e3e60cff5c8ba
4
+ data.tar.gz: 6dedb73fdb5b1a85bdd6996c7947e9a66ab5e69663e86a5f868d1dfd20dc8115
5
5
  SHA512:
6
- metadata.gz: 289186502e09d9e27b75b17f633cd017f066470efeafcaf1c9ab979f716f60705f4b7d7505da496380171d00ef971eef14b22fcfbb83781be810732ed3f4d3dc
7
- data.tar.gz: 620d66d405bfea65fc134c837c7832ea3c7dae6c566aaedea3431a2ebb8906700a9255afd088ff65ab607ea5789132760c2b12f3b3e2c4676ce36a6ecf540747
6
+ metadata.gz: 270ba6319f043ac8aa36bf437d338a400aa2b03005d060b93e86c939df638c40688faf57c0758ccc231031ae6da969bc57d9570a04ae649c7f912e3df41a893f
7
+ data.tar.gz: 272da007dd9136464b1705b47f4d6fc0f1a3ba046ee1299d70442648c3b412b8450cf655d3888b60a4c7a117fa9a4ee63e56b01adc3d0742be7fcd7bcb763432
data/README.md CHANGED
@@ -49,78 +49,47 @@ If you want to start from a new rails app, follow theese tutorials
49
49
  within the app folder
50
50
 
51
51
  ```bash
52
- bundle add svelte-on-rails
52
+ bundle add svelte-on-rails
53
53
  ```
54
54
  ```bash
55
- rails svelte_on_rails:install_for_vite_and_turbo
55
+ rails svelte_on_rails:install_for_vite_and_turbo
56
56
  ```
57
57
 
58
58
 
59
- This will create a little config file, istalls the npm package,
59
+ This will create a little config file, installs the npm package,
60
60
  creates a initializer file and adds the import statement on `appplication.js` entrypoint file
61
61
  and it adds a HelloWorld.svelte component.
62
62
  If not installed, it installs `@hotwired/turbo-rails` too.
63
63
 
64
- Add a controller and a view with the view helper and you should see «Greetings from Svelte on your view».
64
+ #### Minimal installer
65
65
 
66
- There is also a smaller installer:
66
+ There is also a minimal installer:
67
67
 
68
68
  ```bash
69
- $ rails svelte_on_rails:install
69
+ rails svelte_on_rails:install
70
70
  ```
71
71
 
72
72
  that does nothing else than creating a config file.
73
73
 
74
- Within the config file, there are two tags:
74
+ Within the config file, there are mainly two important tags:
75
75
 
76
76
  - `frontend_folder` (relative to Rails.root)
77
77
  - `components_folder` (relative to frontend_folder)
78
78
 
79
- Set up the npm module [@csedl/svelte-on-rails](https://www.npmjs.com/package/@csedl/svelte-on-rails)
80
- on the client side.
79
+ ## Check if it all works
81
80
 
82
- ## Test if it works
81
+ Add a controller and a view with the helper `= svelte_component('HelloWorld', items: ['item1', 'item2'])`.
82
+ On loading you will see
83
83
 
84
- On the view
84
+ - Rendered HelloWorld.svelte server-side: 0.075ms
85
85
 
86
- ```haml
87
- = svelte_component("myComponent", items: ['item1', 'item2'])
88
- ```
89
-
90
- Above mentioned installer adds `HelloWorld.svelte`, like so:
91
-
92
- ```sveltehtml
93
- <script>
94
- export let items
95
- let count = 0;
96
-
97
- function increment() {
98
- count += 1;
99
- }
100
- </script>
101
-
102
- <h1>Greetings from svelte</h1>
103
-
104
- <ul>
105
- <button on:click={increment}>Increment: {count}</button>
106
- {#each items as item}
107
- <li>{item}</li>
108
- {/each}
109
- </ul>
110
-
111
- <style>
112
- button {
113
- background-color: darkred;
114
- color: white;
115
- padding: 10px;
116
- border: none;
117
- }
118
- </style>
119
- ```
120
-
121
- And you should see «Greetings from svelte» on the browser.
86
+ On the rails console and you will see «Greetings from svelte»
87
+ on your view with a styled «Increment» button.
88
+ Styles you find within the svelte component.
89
+ Click this button and see that the component is alive.
122
90
 
123
- Click the counter button and check if the component is alive.
91
+ On [@csedl/svelte-on-rails](https://www.npmjs.com/package/@csedl/svelte-on-rails)
92
+ are details how the frontend part is working.
124
93
 
125
94
  Without the npm package installed,
126
95
  or by passing `render_server_side: true` and `hydrate: false` to the view helper,
@@ -7,11 +7,13 @@ module SvelteOnRails
7
7
  conf = SvelteOnRails::Configuration.instance
8
8
  cff = conf.components_folder_full
9
9
  file_path = cff + "#{filename}.svelte"
10
- found = (conf.watch_changes? ? SvelteOnRails::RenderServerSide.file_exist_case_sensitive?(cff, filename + '.svelte') : File.exist?(file_path))
11
- unless found
12
- ff = conf.frontend_folder
13
- cf = conf.components_folder
14
- raise "File not found: #{file_path}\nsvelte-on-rails gem, view helper #svelte_component\n\nYour configurations are:\nfrontend_folder: «#{ff}»\ncomponents_folder: «#{cf}»\n.. and the filename attribute for the view helper: «#{filename}»\n"
10
+ if !File.exist?(file_path)
11
+ raise file_not_found_messsage(filename)
12
+ elsif conf.watch_changes? && !SvelteOnRails::RenderServerSide.file_exist_case_sensitive?(cff, filename + '.svelte')
13
+ # on development environments we check case sensitivity too
14
+ msg = "File found but Upper and lower case letters are incorrect\n" +
15
+ "(This check is only on development environments when watch_changes is true):\n."
16
+ raise file_case_sensitive_messsage(filename)
15
17
  end
16
18
 
17
19
  # check what to do
@@ -74,5 +76,25 @@ module SvelteOnRails
74
76
  end
75
77
  end
76
78
 
79
+ def file_not_found_messsage(filename)
80
+ conf = SvelteOnRails::Configuration.instance
81
+ ff = conf.frontend_folder
82
+ cf = conf.components_folder
83
+ "svelte-on-rails gem, view helper #svelte_component\n\nFile not found:\n" +
84
+ "#{conf.components_folder_full + "#{filename}.svelte"}\n\n" +
85
+ "Your configurations are:\n\nfrontend_folder: «#{ff}»\ncomponents_folder: «#{cf}»\n.. and the filename attribute for the view helper: «#{filename}»\n"
86
+ end
87
+
88
+ def file_case_sensitive_messsage(filename)
89
+ conf = SvelteOnRails::Configuration.instance
90
+ ff = conf.frontend_folder
91
+ cf = conf.components_folder
92
+ "svelte-on-rails gem, view helper #svelte_component\n\n" +
93
+ "File found but Upper and lower case letters are incorrect:\n" +
94
+ "(This check is only on development environments when watch_changes is true)\n\n" +
95
+ "#{conf.components_folder_full + "#{filename}.svelte"}\n\n" +
96
+ "Your configurations are:\nfrontend_folder: «#{ff}»\ncomponents_folder: «#{cf}»\n.. and the filename attribute for the view helper: «#{filename}»\n"
97
+ end
98
+
77
99
  end
78
100
  end
@@ -12,7 +12,7 @@ namespace :svelte_on_rails do
12
12
  end
13
13
 
14
14
  desc "Installs SvelteOnRails for usage together with vite_rails and @hotwired/turbo-rails"
15
- task :install_for_and_vite_turbo do
15
+ task :install_for_vite_and_turbo do
16
16
 
17
17
  create_configuration_file
18
18
 
@@ -28,6 +28,7 @@ namespace :svelte_on_rails do
28
28
 
29
29
  puts ''
30
30
  puts 'SvelteOnRails installed successfully for using together with vite_rails and @hotwired/turbo-rails.'
31
+ puts 'Restart the server and check if it all works.'
31
32
  puts 'Happy coding!'
32
33
 
33
34
  end
@@ -50,11 +51,12 @@ namespace :svelte_on_rails do
50
51
  file_content = File.exist?(pkg_js) ? File.read(pkg_js) : ""
51
52
 
52
53
  if file_content.match?(/#{package_name}/)
53
- puts "#{package_name} is already installed."
54
+ puts "#{package_name} is already present in package.json, assuming that it is set up well and working."
54
55
  else
55
56
  puts "Installing #{package_name} via npm..."
56
57
  if system("npm install #{package_name}")
57
58
  puts "#{package_name} successfully installed."
59
+ add_line_to_file(Rails.root.join("app", "frontend", "entrypoints", "application.js"), "import '#{package_name}';")
58
60
  else
59
61
  abort "Failed to install #{package_name}. Please ensure npm is installed and try running 'npm install #{package_name}' manually."
60
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svelte-on-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair