svelte-on-rails 0.0.16 → 0.0.17

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: 193590578f918035e5afd3c9fbe2feb498bd3749fe6250eec32b477d3c5c9fd2
4
+ data.tar.gz: 8a06c417a6f086be0ebe21e3abcc06b89910be18611a63db1a60eb4f7d723e6d
5
5
  SHA512:
6
- metadata.gz: 289186502e09d9e27b75b17f633cd017f066470efeafcaf1c9ab979f716f60705f4b7d7505da496380171d00ef971eef14b22fcfbb83781be810732ed3f4d3dc
7
- data.tar.gz: 620d66d405bfea65fc134c837c7832ea3c7dae6c566aaedea3431a2ebb8906700a9255afd088ff65ab607ea5789132760c2b12f3b3e2c4676ce36a6ecf540747
6
+ metadata.gz: 92a3c8ef7991f7e13c9293d27f6cd5c2e8bd4c6f73a6034c5ef8834f053cf43770eaa85715a55f0edb4549b2b277ee44ac1f9968b837efdef3c4809ce6b77125
7
+ data.tar.gz: b6bae2ed7f07ff00a398f27241f2bcc8d692e6aae98ad86ff4da19e723c44c06d7294f93dc48fbf6bc963aa0bcbab8e37677465c86de6ba88b3687bfd1ddd103
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,11 @@ 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("File not found", file_path, 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
+ raise file_not_found_messsage("File found but Upper and lower case letters are incorrect", file_path, filename)
15
15
  end
16
16
 
17
17
  # check what to do
@@ -74,5 +74,14 @@ module SvelteOnRails
74
74
  end
75
75
  end
76
76
 
77
+ def file_not_found_messsage(title, file_path, filename)
78
+ conf = SvelteOnRails::Configuration.instance
79
+ ff = conf.frontend_folder
80
+ cf = conf.components_folder
81
+ "svelte-on-rails gem, view helper #svelte_component\n\n#{title}:\n" +
82
+ "#{file_path}\n\n" +
83
+ "Your configurations are:\nfrontend_folder: «#{ff}»\ncomponents_folder: «#{cf}»\n.. and the filename attribute for the view helper: «#{filename}»\n"
84
+ end
85
+
77
86
  end
78
87
  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.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair