svelte-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +13 -0
  3. data/.gitignore +12 -0
  4. data/.nvmrc +1 -0
  5. data/.rspec +3 -0
  6. data/.travis.yml +6 -0
  7. data/CHANGELOG.md +0 -0
  8. data/CODE_OF_CONDUCT.md +74 -0
  9. data/Gemfile +7 -0
  10. data/Gemfile.lock +160 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +49 -0
  13. data/Rakefile +6 -0
  14. data/bin/console +14 -0
  15. data/bin/setup +8 -0
  16. data/lib/svelte/rails.rb +10 -0
  17. data/lib/svelte/rails/install_generator.rb +71 -0
  18. data/lib/svelte/rails/install_task.rake +8 -0
  19. data/lib/svelte/rails/railtie.rb +15 -0
  20. data/lib/svelte/rails/templates/app/javascript/components/Hello.svelte +36 -0
  21. data/lib/svelte/rails/templates/app/javascript/packs/application.js +3 -0
  22. data/lib/svelte/rails/templates/app/javascript/packs/server_rendering.js +3 -0
  23. data/lib/svelte/rails/templates/config/webpack/development.js +5 -0
  24. data/lib/svelte/rails/templates/config/webpack/environment.js +6 -0
  25. data/lib/svelte/rails/templates/config/webpack/loaders/svelte-ssr.js +11 -0
  26. data/lib/svelte/rails/templates/config/webpack/loaders/svelte.js +10 -0
  27. data/lib/svelte/rails/templates/config/webpack/production.js +5 -0
  28. data/lib/svelte/rails/templates/config/webpack/test.js +5 -0
  29. data/lib/svelte/rails/version.rb +5 -0
  30. data/lib/svelte/rails/view_helper.rb +7 -0
  31. data/lib/svelte/renderer.rb +74 -0
  32. data/package.json +29 -0
  33. data/svelte-rails.gemspec +34 -0
  34. data/svelte_ujs/WaitPlugin.js +35 -0
  35. data/svelte_ujs/getSvelteEnvironments.js +58 -0
  36. data/svelte_ujs/index.js +44 -0
  37. data/yarn.lock +6460 -0
  38. metadata +125 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 052fd518710717fbb8cadfb1c1a51c5e9f1fea3f77d96f2dd2824929904259e4
4
+ data.tar.gz: c580d4913b1941b856e0a5eeeb9489a9035772c113867057c0fb7bd5d3727037
5
+ SHA512:
6
+ metadata.gz: 051c1b3d9503ff68f78c797946821042d4cfa07115c43bcfda363eac4f292f94ee6af02fa9901384251b73aeea644acc5077e22c0e15c5eab2b2ae5b0cd8c06f
7
+ data.tar.gz: 3c783c15087de0bd415368e76590bf592d2203ca8078fc02592403839fc257eb0c3739b6dccb5027eced2e844346d8172378be22888ed1aedf6f38fbe9986c8f
@@ -0,0 +1,13 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ tab_width = 2
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ insert_final_newline = true
11
+
12
+ [*.md]
13
+ trim_trailing_whitespace = false
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /node_modules/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ 14
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
File without changes
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at henning.mueller@hmmh.de. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in svelte-rails.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,160 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ svelte-rails (0.1.0)
5
+ execjs
6
+ railties (>= 5.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (6.0.3.2)
12
+ actionpack (= 6.0.3.2)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ actionmailbox (6.0.3.2)
16
+ actionpack (= 6.0.3.2)
17
+ activejob (= 6.0.3.2)
18
+ activerecord (= 6.0.3.2)
19
+ activestorage (= 6.0.3.2)
20
+ activesupport (= 6.0.3.2)
21
+ mail (>= 2.7.1)
22
+ actionmailer (6.0.3.2)
23
+ actionpack (= 6.0.3.2)
24
+ actionview (= 6.0.3.2)
25
+ activejob (= 6.0.3.2)
26
+ mail (~> 2.5, >= 2.5.4)
27
+ rails-dom-testing (~> 2.0)
28
+ actionpack (6.0.3.2)
29
+ actionview (= 6.0.3.2)
30
+ activesupport (= 6.0.3.2)
31
+ rack (~> 2.0, >= 2.0.8)
32
+ rack-test (>= 0.6.3)
33
+ rails-dom-testing (~> 2.0)
34
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
35
+ actiontext (6.0.3.2)
36
+ actionpack (= 6.0.3.2)
37
+ activerecord (= 6.0.3.2)
38
+ activestorage (= 6.0.3.2)
39
+ activesupport (= 6.0.3.2)
40
+ nokogiri (>= 1.8.5)
41
+ actionview (6.0.3.2)
42
+ activesupport (= 6.0.3.2)
43
+ builder (~> 3.1)
44
+ erubi (~> 1.4)
45
+ rails-dom-testing (~> 2.0)
46
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
47
+ activejob (6.0.3.2)
48
+ activesupport (= 6.0.3.2)
49
+ globalid (>= 0.3.6)
50
+ activemodel (6.0.3.2)
51
+ activesupport (= 6.0.3.2)
52
+ activerecord (6.0.3.2)
53
+ activemodel (= 6.0.3.2)
54
+ activesupport (= 6.0.3.2)
55
+ activestorage (6.0.3.2)
56
+ actionpack (= 6.0.3.2)
57
+ activejob (= 6.0.3.2)
58
+ activerecord (= 6.0.3.2)
59
+ marcel (~> 0.3.1)
60
+ activesupport (6.0.3.2)
61
+ concurrent-ruby (~> 1.0, >= 1.0.2)
62
+ i18n (>= 0.7, < 2)
63
+ minitest (~> 5.1)
64
+ tzinfo (~> 1.1)
65
+ zeitwerk (~> 2.2, >= 2.2.2)
66
+ builder (3.2.4)
67
+ concurrent-ruby (1.1.6)
68
+ crass (1.0.6)
69
+ diff-lcs (1.4.4)
70
+ erubi (1.9.0)
71
+ execjs (2.7.0)
72
+ globalid (0.4.2)
73
+ activesupport (>= 4.2.0)
74
+ i18n (1.8.3)
75
+ concurrent-ruby (~> 1.0)
76
+ loofah (2.6.0)
77
+ crass (~> 1.0.2)
78
+ nokogiri (>= 1.5.9)
79
+ mail (2.7.1)
80
+ mini_mime (>= 0.1.1)
81
+ marcel (0.3.3)
82
+ mimemagic (~> 0.3.2)
83
+ method_source (1.0.0)
84
+ mimemagic (0.3.5)
85
+ mini_mime (1.0.2)
86
+ mini_portile2 (2.4.0)
87
+ minitest (5.14.1)
88
+ nio4r (2.5.2)
89
+ nokogiri (1.10.9)
90
+ mini_portile2 (~> 2.4.0)
91
+ rack (2.2.3)
92
+ rack-test (1.1.0)
93
+ rack (>= 1.0, < 3)
94
+ rails (6.0.3.2)
95
+ actioncable (= 6.0.3.2)
96
+ actionmailbox (= 6.0.3.2)
97
+ actionmailer (= 6.0.3.2)
98
+ actionpack (= 6.0.3.2)
99
+ actiontext (= 6.0.3.2)
100
+ actionview (= 6.0.3.2)
101
+ activejob (= 6.0.3.2)
102
+ activemodel (= 6.0.3.2)
103
+ activerecord (= 6.0.3.2)
104
+ activestorage (= 6.0.3.2)
105
+ activesupport (= 6.0.3.2)
106
+ bundler (>= 1.3.0)
107
+ railties (= 6.0.3.2)
108
+ sprockets-rails (>= 2.0.0)
109
+ rails-dom-testing (2.0.3)
110
+ activesupport (>= 4.2.0)
111
+ nokogiri (>= 1.6)
112
+ rails-html-sanitizer (1.3.0)
113
+ loofah (~> 2.3)
114
+ railties (6.0.3.2)
115
+ actionpack (= 6.0.3.2)
116
+ activesupport (= 6.0.3.2)
117
+ method_source
118
+ rake (>= 0.8.7)
119
+ thor (>= 0.20.3, < 2.0)
120
+ rake (12.3.3)
121
+ rspec (3.9.0)
122
+ rspec-core (~> 3.9.0)
123
+ rspec-expectations (~> 3.9.0)
124
+ rspec-mocks (~> 3.9.0)
125
+ rspec-core (3.9.2)
126
+ rspec-support (~> 3.9.3)
127
+ rspec-expectations (3.9.2)
128
+ diff-lcs (>= 1.2.0, < 2.0)
129
+ rspec-support (~> 3.9.0)
130
+ rspec-mocks (3.9.1)
131
+ diff-lcs (>= 1.2.0, < 2.0)
132
+ rspec-support (~> 3.9.0)
133
+ rspec-support (3.9.3)
134
+ sprockets (4.0.2)
135
+ concurrent-ruby (~> 1.0)
136
+ rack (> 1, < 3)
137
+ sprockets-rails (3.2.1)
138
+ actionpack (>= 4.0)
139
+ activesupport (>= 4.0)
140
+ sprockets (>= 3.0.0)
141
+ thor (1.0.1)
142
+ thread_safe (0.3.6)
143
+ tzinfo (1.2.7)
144
+ thread_safe (~> 0.1)
145
+ websocket-driver (0.7.2)
146
+ websocket-extensions (>= 0.1.0)
147
+ websocket-extensions (0.1.5)
148
+ zeitwerk (2.3.1)
149
+
150
+ PLATFORMS
151
+ ruby
152
+
153
+ DEPENDENCIES
154
+ rails (>= 5.2)
155
+ rake (~> 12.0)
156
+ rspec (~> 3.0)
157
+ svelte-rails!
158
+
159
+ BUNDLED WITH
160
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 henning mueller
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ # Svelte-Rails
2
+
3
+ Svelte-Rails integrates [Svelte](https://svelte.dev/) with Ruby on Rails. It has the following features:
4
+
5
+ * Automatically renders Svelte server-side and client-side
6
+ * Supports Webpacker >= 4.2 and Ruby on Rails >= 6
7
+
8
+ ## Usage
9
+
10
+ Make sure, you have [set-up Webpacker](https://github.com/rails/webpacker#installation) and it's [Svelte integration](https://github.com/rails/webpacker/blob/master/docs/integrations.md#svelte).
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'svelte-rails', path: '../svelte-rails'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+ $ rails svelte:install
22
+
23
+ If you have started with a fresh Rails app, you can overwrite conflicting files.
24
+
25
+ An example Rails app demonstrating the integration of svelte-rails can be found here:
26
+ https://github.com/nning/svelte-rails-demo/commits/master
27
+
28
+ ## View Helper
29
+
30
+ ```erb
31
+ <%= svelte_component :Hello, name: 'Svelte' %>
32
+ ```
33
+
34
+ ## Missing Features
35
+
36
+ * Turbolinks integration
37
+ * HMR and Bundle consistency (server-rendered HTML is cached and client-side updates on changes to the sources)
38
+ * Render components directly from controllers
39
+ * Generator for components
40
+ * Render pools
41
+ * Better documentation for setup
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nning/svelte-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/nning/svelte-rails/blob/master/CODE_OF_CONDUCT.md).
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "svelte/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ require 'svelte/rails/version'
2
+
3
+ module Svelte
4
+ module Rails
5
+ # class Error < StandardError; end
6
+ end
7
+ end
8
+
9
+ require 'svelte/rails/view_helper'
10
+ require 'svelte/rails/railtie' if defined?(Rails)
@@ -0,0 +1,71 @@
1
+ require 'rails/generators'
2
+
3
+
4
+ module Svelte
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ TEMPLATE_DIR = File.expand_path('../templates', __FILE__)
7
+ source_root TEMPLATE_DIR
8
+
9
+ desc 'Install Svelte support'
10
+
11
+ def create_directories
12
+ empty_directory components_dir
13
+ create_file File.join(components_dir, '.keep')
14
+ end
15
+
16
+ def copy_templates
17
+ copy_template(webpack_dir, 'environment.js')
18
+ copy_template(webpack_dir, 'development.js')
19
+ copy_template(webpack_dir, 'production.js')
20
+ copy_template(webpack_dir, 'test.js')
21
+
22
+ copy_template(webpack_dir, 'loaders', 'svelte.js')
23
+ copy_template(webpack_dir, 'loaders', 'svelte-ssr.js')
24
+
25
+ copy_template(packs_dir, 'server_rendering.js')
26
+ copy_template(components_dir, 'Hello.svelte')
27
+ end
28
+
29
+ def update_application_entry
30
+ path = Pathname.new('app/javascript/packs/application.js')
31
+ content = File.read(File.join(TEMPLATE_DIR, path))
32
+
33
+ if path.exist?
34
+ append_file(path, content)
35
+ else
36
+ create_file(path, content)
37
+ end
38
+ end
39
+
40
+ def install_svelte_ujs
41
+ `yarn add ../svelte-rails`
42
+ end
43
+
44
+ private
45
+
46
+ def rails_dir
47
+ Pathname.new(destination_root).relative_path_from(::Rails.root)
48
+ end
49
+
50
+ def packs_dir
51
+ Webpacker.config.source_entry_path.relative_path_from(::Rails.root)
52
+ end
53
+
54
+ def js_dir
55
+ packs_dir.parent
56
+ end
57
+
58
+ def components_dir
59
+ File.join(js_dir, 'components')
60
+ end
61
+
62
+ def webpack_dir
63
+ File.join(rails_dir, 'config', 'webpack')
64
+ end
65
+
66
+ def copy_template(*path_segments)
67
+ source = File.join(*path_segments)
68
+ template(source, ::Rails.root.join(source))
69
+ end
70
+ end
71
+ end