svelte-on-rails 0.0.40 → 0.0.42

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: 3aba14bf1be2f5922836ead6b80d3ec3c095b434eca70653615c1494972aa08c
4
- data.tar.gz: f5be349e7db50271dbfd7d353d71788149da16b82a69934badc4f0769dc610e5
3
+ metadata.gz: c46f6cb43c90617bc4798072b58a35e81a311886a858c379224216fc63c03d3e
4
+ data.tar.gz: 2bd3286eac9420225ac3f641d1cf783a84f48f575d69c0bce53a9b1da9d9d262
5
5
  SHA512:
6
- metadata.gz: 129581abaf1f4dfc69b38210fbaed7e467e6a0c9813ddd5412256092f9fa7d26bea8440e59974ef9a34277627ccb83e4f9897c894e8ae057894228093ce703ab
7
- data.tar.gz: b4653a855ad17d7f5f4953155089b3a62db3068e6099ef6853ebaa870ab9b7677c6c49dcc138ac71789d16e65f0c489550668c6e9b75ec557cf3a04b9b65266e
6
+ metadata.gz: 9e4ae887620aaabd737fc30864bed6eea15dcc9bb47e6ef9db4ab1e38f0ea96a1643b2f12cd81aeadf2c636e6e1575920da2efca62886e877a71dbe25b2818a2
7
+ data.tar.gz: 821084886d515faf8e68440a001bc4a3fd5d310c6068efbb1578ca558774f0ad731e5cf13f142b3223db7e5a2b380775319de9ce3e75a54e597ff59ba1a505cc
data/README.md CHANGED
@@ -263,10 +263,20 @@ Example from the rails console for a medium complex component
263
263
 
264
264
  ## Contributors Guide
265
265
 
266
- Tests are based on the included templates, like the `hello world template` and on the installer.
266
+ Contributors welcome!
267
+
268
+ After downloaded the gem, please run the task
269
+
270
+ ```bash
271
+ rake svelte_on_rails:create_contributor_configs_file
272
+ ```
273
+ and define a `generated_test_app_folder_path` (required) for apps, generated for the testings.
267
274
 
268
- On the gem folder you can put a file `generated_test_app_path`, and put the path for a existing
269
- folder where the tests generate a test rails app.
275
+ For development of the **npm package @csedl/svelte-on-rails** you can set the
276
+ `local_npm_package_path` (optional) and insert the path to the npm package on your local machine.
277
+ This will cause the installer, to install the npm package from a local path instead from the npm registry.
278
+
279
+ Tests are based on the included templates, like the `hello world template` and on the installer.
270
280
 
271
281
  **Installer tests** starting with completely destroy the rails app within the `generated_test_app_path`,
272
282
  generating a new rails app and running the installer and test by `playwright` if the components are working.
@@ -293,13 +303,6 @@ The current test cases including (among others):
293
303
  create a completely new rails app, running the full installer and check if a hello World component is visible and javascript is working.
294
304
  run assets:precompile within a rails app and check if the gem does its precompiling too.
295
305
 
296
- For development of the **npm package @csedl/svelte-on-rails** you can add the file
297
- `local_npm_package_path` and insert the path to the npm package on your local machine.
298
- This will cause the installer, not to install the npm package from npm, but to use the local one.
299
-
300
- ‼️ **ATTENTION:** Please do never commit the file `local_npm_package_path` to the repo! This is only for developers!
301
- Otherwise a user would, on running the installer, get an error, because the npm package is not found.
302
-
303
306
  ## Licence
304
307
 
305
308
  License is MIT
@@ -68,7 +68,7 @@ module SvelteOnRails
68
68
  if pkg
69
69
  {
70
70
  type: pkg.match(/^.*?(?=\/[^\/]*$)/).to_s,
71
- version: version.split('.').map(&:to_i)
71
+ version: version&.split('.')&.map(&:to_i)
72
72
  }
73
73
  end
74
74
 
@@ -2,18 +2,15 @@ module SvelteOnRails
2
2
  class DevelopmentUtils
3
3
 
4
4
  def self.local_npm_package_url
5
- config_file = gem_folder.join('local_npm_package_path')
6
- if !File.exist?(config_file)
7
- return nil
5
+ str = contributor_config('local_npm_package_path', required: false)
6
+ if !str.present?
7
+ nil
8
+ elsif !Dir.exist?(str)
9
+ raise "Invalid path given on local_npm_package_path: «#{str}»"
10
+ elsif !File.exist?(Pathname.new(str).join('package.json'))
11
+ raise "Given local_npm_package_path does not seem to be a valid npm package as it does not contain a package.json"
8
12
  else
9
- str = File.read(config_file).strip
10
- if !Dir.exist?(str)
11
- raise "Invalid path given on local_npm_package_path: «#{str}»"
12
- elsif !File.exist?(Pathname.new(str).join('package.json'))
13
- raise "Given local_npm_package_path does not seem to be a valid npm package as it does not contain a package.json"
14
- else
15
- return Pathname.new(str)
16
- end
13
+ return Pathname.new(str)
17
14
  end
18
15
  end
19
16
 
@@ -21,5 +18,21 @@ module SvelteOnRails
21
18
  Pathname.new(File.expand_path('../../..', __dir__))
22
19
  end
23
20
 
21
+ def self.contributor_config(key, required: true)
22
+ config_file = File.expand_path('../svelte_on_rails_contributor_configs.yml', gem_folder)
23
+ if !File.exist?(config_file)
24
+ if required
25
+ raise "Missing configuration file, searched at: «#{config_file}»"
26
+ end
27
+ else
28
+ yml = YAML.load_file(config_file)
29
+ value = yml[key.to_s]
30
+ if required && !value.present?
31
+ raise "Missing value «#{key}» in configuration file: «#{config_file}»"
32
+ end
33
+ value
34
+ end
35
+ end
36
+
24
37
  end
25
38
  end
@@ -71,4 +71,31 @@ namespace :svelte_on_rails do
71
71
  SvelteOnRails::Compiler.reset_and_compile_all
72
72
  end
73
73
 
74
+ desc "For contributors to this gem: writes a config file for developing options."
75
+ task :create_contributor_configs_file do
76
+ path = File.expand_path('../../../svelte_on_rails_contributor_configs.yml', __dir__)
77
+
78
+ if File.exist?(path)
79
+ puts "Config file for Contributors already exists: file://#{path}"
80
+ puts 'nothing done.'
81
+ exit
82
+ end
83
+
84
+ content = <<-END
85
+ #local_npm_package_path: /path/to/my/local/csedl-svelte-on-rails-main
86
+
87
+ # optional
88
+ # If you want to develop the @csedl/svelte-on-rails package
89
+ # add full path like /path/to/csedl-svelte-on-rails-main
90
+ # Then, on running the generator, it installs this package from your local root folder
91
+
92
+ generated_test_app_folder_path: /destination/folder/for/generated/test/app
93
+
94
+ # required!
95
+ # When you run tests, a rails app will be generated into this folder
96
+ END
97
+ File.write(path, content)
98
+ puts "Config file for Contributors created at: #{path}"
99
+ end
100
+
74
101
  end
@@ -0,0 +1,6 @@
1
+ class SvelteOnRailsHelloWorldController < ApplicationController
2
+
3
+ def index
4
+ end
5
+
6
+ end
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Pro 6.0.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --><path d="M256 224C238.3 224 223.1 238.4 223.1 256S238.3 288 256 288c17.62 0 32-14.38 32-32C287.9 238.4 273.6 224 256 224zM471.2 128c-15.62-27.75-49.62-41.38-93.11-41.38c-9.499 .125-18.87 .75-28.25 2C327.1 34.38 293.5 0 256 0S184.9 34.38 162.1 88.62c-9.374-1.25-18.75-1.875-28.25-2C90.39 86.62 56.4 100.2 40.78 128c-18.75 33.5-6.499 80.62 27.62 128c-34.12 47.38-46.37 94.5-27.62 128c15.62 27.75 49.62 41.38 93.11 41.38c9.499-.125 18.87-.75 28.25-2C184.9 477.6 218.5 512 256 512s71.12-34.38 93.86-88.63c9.374 1.25 18.75 1.875 28.25 2c43.49 0 77.49-13.62 93.11-41.38c18.75-33.5 6.499-80.63-27.62-128C477.7 208.6 489.1 161.5 471.2 128zM256 48c14.37 0 32.12 18.12 47.12 50C287.1 102.4 271.4 107.8 256 114.1c-15.37-6.375-31.12-11.76-47.12-16.14C223.9 66.12 241.6 48 256 48zM133.9 377.4c-26.5 0-46.74-6.625-52.74-17.38c-7.124-12.75-.5-37.63 18.62-66.63C111.4 305.2 123.8 316.5 136.8 327c2.25 16.5 5.374 33 9.624 49.13C142.3 376.4 137.9 377.4 133.9 377.4zM136.8 185C123.8 195.5 111.4 206.8 99.77 218.6C80.65 189.6 74.02 164.8 81.15 152c5.999-10.75 26.25-17.38 52.74-17.38c3.1 0 8.374 1 12.5 1.25C142.1 152 139 168.5 136.8 185zM256 464c-14.37 0-32.12-18.12-47.12-49.1C224.9 409.6 240.6 404.2 256 397.9c15.37 6.375 31.12 11.76 47.12 16.14C288.1 445.9 270.4 464 256 464zM256 352c-52.99 0-95.99-43-95.99-96S203 160 256 160s95.99 43 95.99 96S308.1 352 256 352zM430.9 360c-5.999 10.75-26.25 17.38-52.74 17.38c-3.1 0-8.374-1-12.5-1.25C369.9 360 372.1 343.5 375.2 327c12.1-10.5 25.37-21.75 36.1-33.63C431.4 322.4 437.1 347.2 430.9 360zM412.2 218.6C400.6 206.8 388.2 195.5 375.2 185C372.1 168.5 369.9 152 365.6 135.9c4.125-.25 8.499-1.25 12.5-1.25c26.5 0 46.74 6.625 52.74 17.38C437.1 164.8 431.4 189.6 412.2 218.6z"/></svg>
@@ -0,0 +1,3 @@
1
+ <svg width="100" height="50" xmlns="http://www.w3.org/2000/svg">
2
+ <text x="10" y="30" font-family="Arial, sans-serif" font-size="24" fill="black">svg</text>
3
+ </svg>
@@ -0,0 +1,14 @@
1
+ <script>
2
+ export let notice
3
+ let ary = ['item-1', 'item-2', 'item-3']
4
+ </script>
5
+
6
+ <template lang="pug">
7
+ h1 Hello, Pug!
8
+ p {notice}
9
+ ul
10
+ <!-- The | Syntax is a workaround for situations where pug integration in svelte is not working really well-->
11
+ | {#each ary as item}
12
+ | <li>{item}</li>
13
+ | {/each}
14
+ </template>
@@ -0,0 +1,66 @@
1
+ <script>
2
+ import svgRaw from '../../images/svg.svg?raw'
3
+ //import svg from '../../images/svg.svg'
4
+ import png from '../../images/check-circle-green.png'
5
+ import Nested from './sub/NestedComponent.svelte'
6
+ import {nestedJavascriptFunction} from '../nestedJavascript.js'
7
+ export let items
8
+ let count = 0;
9
+
10
+ function increment() {
11
+ count += 1;
12
+ }
13
+ </script>
14
+
15
+ <span class="svelte-component-wrapper">
16
+ <h1>Svelte is here!!</h1>
17
+
18
+ <hr/>
19
+ <p>click the button and check if the component is alive</p>
20
+ <button on:click={increment}>Increment: {count}</button>
21
+
22
+ <hr/>
23
+ <ul>
24
+ {#each items as item}
25
+ <li>{item}</li>
26
+ {/each}
27
+ </ul>
28
+
29
+ <hr/>
30
+ <span class="wrap-svg">{@html svgRaw}</span>
31
+ <!-- <img alt="svg ERROR" src={svg} />-->
32
+ <img alt="png ERROR" src={png} />
33
+
34
+ <hr/>
35
+ <Nested />
36
+
37
+ <hr/>
38
+ <p>{nestedJavascriptFunction()}</p>
39
+ </span>
40
+
41
+ <style>
42
+ button {
43
+ background-color: darkred;
44
+ color: white;
45
+ padding: 10px;
46
+ border: none;
47
+ cursor: pointer;
48
+ }
49
+
50
+ .svelte-component-wrapper {
51
+ border: 1px solid black;
52
+ padding: 10px;
53
+ margin: 10px;
54
+ background-color: #efefef;
55
+ display: inline-block;
56
+ box-shadow: 2px 3px 16px -1px rgba(0, 0, 0, 0.75);
57
+ -webkit-box-shadow: 2px 3px 16px -1px rgba(0, 0, 0, 0.75);
58
+ -moz-box-shadow: 2px 3px 16px -1px rgba(0, 0, 0, 0.75);
59
+ }
60
+ img, .wrap-svg {
61
+ display: inline-block;
62
+ width: 30px;
63
+ height: 30px;
64
+ margin: 30px;
65
+ }
66
+ </style>
@@ -0,0 +1,3 @@
1
+ export function nestedJavascriptFunction() {
2
+ return 'nestedJavascript!';
3
+ }
@@ -0,0 +1,3 @@
1
+ export function nestedJavascriptFunction() {
2
+ return 'nestedJavascript («toggled»)';
3
+ }
@@ -0,0 +1,5 @@
1
+ <p>Example view</p>
2
+
3
+ <%= svelte_component "SvelteOnRailsHelloWorld", items: ['attributes', 'are', 'parsed'] %>
4
+ <%= svelte_component "Pug", ssr: true, notice: "Pug is rendered server-side" %>
5
+ <%= svelte_component "Pug", ssr: false, notice: "Pug is rendered client-side" %>
@@ -0,0 +1,18 @@
1
+
2
+ import { initializeSvelteComponents, cleanupSvelteComponents } from '@csedl/svelte-on-rails';
3
+
4
+ const components = import.meta.glob('/javascript/components/**/*.svelte', { eager: true });
5
+ const componentsRoot = '/javascript/components';
6
+
7
+ // Initialize Svelte components
8
+ initializeSvelteComponents(componentsRoot, components, true);
9
+
10
+ // Turbo event listener for page load
11
+ document.addEventListener('turbo:load', () => {
12
+ initializeSvelteComponents(componentsRoot, components, true);
13
+ });
14
+
15
+ // Turbo event listener for cleanup before page cache
16
+ document.addEventListener('turbo:before-cache', () => {
17
+ cleanupSvelteComponents(false);
18
+ });
@@ -0,0 +1,23 @@
1
+ frontend_folder: "app/frontend"
2
+ # the entrypoint that is your web root, example for vite: where @ points to
3
+ # relative to Rails.root
4
+
5
+ components_folder: "javascript/components"
6
+ # relative to frontend_folder
7
+ # where your svelte components are located
8
+
9
+ ssr: :auto
10
+ # options: true, false, :auto
11
+ # :auto: render server side if request is initial request (works only with turbo, because it checks for the X-Turbo-Request-ID header)
12
+ # when not server-side rendered the components must be built as custom elements, see node-package @csedl/svelte-on-rails
13
+
14
+ development:
15
+ watch_changes: true
16
+ # Check on every request if any file within the svelte components folder have changed, for recompiling
17
+ # Case sensitive path checking, even the file system is case insensitive
18
+ # Make sure this ist set to tue for development and test, but not for production
19
+
20
+ test:
21
+ watch_changes: true
22
+
23
+ production:
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.40
4
+ version: 0.0.42
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair
@@ -52,6 +52,18 @@ files:
52
52
  - lib/svelte_on_rails/renderer/utils.js
53
53
  - lib/svelte_on_rails/view_helpers.rb
54
54
  - lib/tasks/svelte_on_rails_tasks.rake
55
+ - templates/rails_vite_hello_world/app/controllers/svelte_on_rails_hello_world_controller.rb
56
+ - templates/rails_vite_hello_world/app/frontend/images/atom.svg
57
+ - templates/rails_vite_hello_world/app/frontend/images/check-circle-green.png
58
+ - templates/rails_vite_hello_world/app/frontend/images/svg.svg
59
+ - templates/rails_vite_hello_world/app/frontend/javascript/components/Pug.svelte
60
+ - templates/rails_vite_hello_world/app/frontend/javascript/components/SvelteOnRailsHelloWorld.svelte
61
+ - templates/rails_vite_hello_world/app/frontend/javascript/components/sub/NestedComponent.svelte
62
+ - templates/rails_vite_hello_world/app/frontend/javascript/nestedJavascript.js
63
+ - templates/rails_vite_hello_world/app/frontend/javascript/nestedJavascriptToggled.js
64
+ - templates/rails_vite_hello_world/app/views/svelte_on_rails_hello_world/index.html.erb
65
+ - templates/svelte_on_rails_vite_base/app/frontend/initializers/svelte.js
66
+ - templates/svelte_on_rails_vite_base/config/svelte_on_rails.yml
55
67
  homepage: https://gitlab.com/sedl/svelte-on-rails
56
68
  licenses:
57
69
  - MIT