vite_padrino 0.5.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: af9f03237868ee2b38532114c3d2871ce20186d1b3151c11c39fe70c3816a9dd
4
+ data.tar.gz: 38465a79692508566c2b12eb6e088b477315c093c98f870c1e62563e8a9bc824
5
+ SHA512:
6
+ metadata.gz: 0b2d4f7eaabbdf7e70cbf111c13f6256154329ba3e4110d37c110f347a890e20c8d35293774c499f8d632618e4a38f3a0d64362db13bb78358cb6ad108df9632
7
+ data.tar.gz: fa16a3aca5e4f6fec1898e3f68fac8b6722a45adc9a5e8d66ff6c4c023e0019b521d333102a62261e412c8b4071e9d474a25cb0c81f6e3e9ac723e42ad7b4e40
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # 0.5.0 (2021-02-25)
2
+
3
+
4
+ ### Features
5
+
6
+ * Create Vite.js integration with Padrino ([#17](https://github.com/ElMassimo/vite_ruby/issues/17)) ([9e9a0a6](https://github.com/ElMassimo/vite_ruby/commit/9e9a0a67abceed0a784d3c2e0554c717d7f5d1d6))
7
+
8
+
9
+
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Maximo Mussini
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.
data/README.md ADDED
@@ -0,0 +1,117 @@
1
+ <h1 align="center">
2
+ <a href="https://vite-ruby.netlify.app/">
3
+ <img src="https://raw.githubusercontent.com/ElMassimo/vite_ruby/main/docs/public/logo.svg" width="120px"/>
4
+ </a>
5
+
6
+ <br>
7
+
8
+ <a href="https://vite-ruby.netlify.app/">
9
+ Vite Padrino
10
+ </a>
11
+
12
+ <br>
13
+
14
+ <p align="center">
15
+ <a href="https://github.com/ElMassimo/vite_ruby/actions">
16
+ <img alt="Build Status" src="https://github.com/ElMassimo/vite_ruby/workflows/build/badge.svg"/>
17
+ </a>
18
+ <a href="https://codeclimate.com/github/ElMassimo/vite_ruby">
19
+ <img alt="Maintainability" src="https://codeclimate.com/github/ElMassimo/vite_ruby/badges/gpa.svg"/>
20
+ </a>
21
+ <a href="https://codeclimate.com/github/ElMassimo/vite_ruby">
22
+ <img alt="Test Coverage" src="https://codeclimate.com/github/ElMassimo/vite_ruby/badges/coverage.svg"/>
23
+ </a>
24
+ <a href="https://rubygems.org/gems/vite_padrino">
25
+ <img alt="Gem Version" src="https://img.shields.io/gem/v/vite_padrino.svg?colorB=e9573f"/>
26
+ </a>
27
+ <a href="https://github.com/ElMassimo/vite_ruby/blob/master/LICENSE.txt">
28
+ <img alt="License" src="https://img.shields.io/badge/license-MIT-428F7E.svg"/>
29
+ </a>
30
+ </p>
31
+ </h1>
32
+
33
+ [website]: https://vite-ruby.netlify.app/
34
+ [configuration reference]: https://vite-ruby.netlify.app/config/
35
+ [features]: https://vite-ruby.netlify.app/guide/introduction.html
36
+ [guides]: https://vite-ruby.netlify.app/guide/
37
+ [config]: https://vite-ruby.netlify.app/config/
38
+ [vite_rails]: https://github.com/ElMassimo/vite_ruby
39
+ [webpacker]: https://github.com/rails/webpacker
40
+ [vite]: http://vitejs.dev/
41
+ [config file]: https://github.com/ElMassimo/vite_ruby/blob/main/vite-plugin-ruby/default.vite.json
42
+ [example app]: https://github.com/ElMassimo/pingcrm-vite
43
+ [heroku]: https://pingcrm-vite.herokuapp.com/
44
+ [Issues]: https://github.com/ElMassimo/vite_ruby/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc
45
+ [Discussions]: https://github.com/ElMassimo/vite_ruby/discussions
46
+ [vite_rails]: https://github.com/ElMassimo/vite_ruby/tree/main/vite_rails
47
+ [vite_ruby]: https://github.com/ElMassimo/vite_ruby/tree/main/vite_ruby
48
+ [vite_padrino]: https://github.com/ElMassimo/vite_ruby/tree/main/vite_padrino
49
+ [no bundling]: https://vitejs.dev/guide/introduction.html#the-problem
50
+ [bundling]: https://vitejs.dev/guide/introduction.html#why-bundle-for-production
51
+
52
+ [Vite] is to frontend tooling as Ruby to programming, pure joy! 😍
53
+
54
+ [__Vite Padrino__][vite_padrino] provides easy setup for Padrino web apps, as well as idiomatic tag helpers.
55
+
56
+ ## Why Vite? 🤔
57
+
58
+ Vite [does not bundle your code during development][no bundling], which means the
59
+ dev server is extremely __fast to start__, and your changes will be __updated instantly__.
60
+
61
+ In production, Vite [bundles your code][bundling]
62
+ with tree-shaking, lazy-loading, and common chunk splitting out of the box, to achieve optimal loading performance.
63
+
64
+ ## Features ⚡️
65
+
66
+ - 💡 Instant server start
67
+ - ⚡️ Blazing fast hot reload
68
+ - 🚀 Zero-config deployments
69
+ - 🤝 Integrated with <kbd>assets:precompile</kbd>
70
+ - [And more!][features]
71
+
72
+ ## Documentation 📖
73
+
74
+ Visit the [documentation website][website] to check out the [guides] and searchable [configuration reference].
75
+
76
+ ## Installation 💿
77
+
78
+ Add this line to your application's Gemfile:
79
+
80
+ ```ruby
81
+ gem 'vite_padrino'
82
+ ```
83
+
84
+ Then, run:
85
+
86
+ ```bash
87
+ bundle install
88
+ bundle exec vite install
89
+ ```
90
+
91
+ This will generate configuration files and a sample setup.
92
+
93
+ Additional installation instructions are available in the [documentation website][website].
94
+
95
+ ## Getting Started 💻
96
+
97
+ Restart your Padrino web server, and then run <kbd>bin/vite dev</kbd> to start the Vite development server.
98
+
99
+ Visit any page and you should see a printed console output: `Vite ⚡️ Ruby`.
100
+
101
+ For more [guides] and a full [configuration reference], check the [documentation website][website].
102
+
103
+ ## Contact ✉️
104
+
105
+ Please use [Issues] to report bugs you find, and [Discussions] to make feature requests or get help.
106
+
107
+ Don't hesitate to _⭐️ star the project_ if you find it useful!
108
+
109
+
110
+ ## Special Thanks 🙏
111
+
112
+ - [webpacker]
113
+ - [vite]
114
+
115
+ ## License
116
+
117
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'vite_ruby'
4
+ require 'vite_padrino/version'
5
+ require 'vite_padrino/tag_helpers'
6
+
7
+ module VitePadrino
8
+ # Internal: Called when the Rack app is available.
9
+ def self.registered(app)
10
+ if RACK_ENV != 'production' && ViteRuby.run_proxy?
11
+ app.use(ViteRuby::DevServerProxy, ssl_verify_none: true)
12
+ end
13
+ included(app)
14
+ end
15
+
16
+ # Internal: Called when the module is registered in the Padrino app.
17
+ def self.included(base)
18
+ base.send :include, VitePadrino::TagHelpers
19
+ end
20
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'vite_padrino'
4
+
5
+ # Internal: Extends the base installation script from Vite Ruby to work for a
6
+ # typical Padrino app.
7
+ module VitePadrino::Installation
8
+ PADRINO_TEMPLATES = Pathname.new(File.expand_path('../../templates', __dir__))
9
+
10
+ # Override: Setup a typical apps/web Padrino app to use Vite.
11
+ def setup_app_files
12
+ cp PADRINO_TEMPLATES.join('config/padrino-vite.json'), config.config_path
13
+ inject_line_after root.join('app/app.rb'), 'register', ' register VitePadrino'
14
+ append root.join('Rakefile'), <<~RAKE
15
+ require 'vite_padrino'
16
+ ViteRuby.install_tasks
17
+ RAKE
18
+ end
19
+
20
+ # Override: Inject the vite client and sample script to the default HTML template.
21
+ def install_sample_files
22
+ super
23
+ inject_line_after root.join('app/views/layouts/application.haml'), '%title', <<-HTML
24
+ = vite_client_tag
25
+ = vite_javascript_tag 'application'
26
+ HTML
27
+ end
28
+ end
29
+
30
+ ViteRuby::CLI::Install.prepend(VitePadrino::Installation)
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Public: Allows to render HTML tags for scripts and styles processed by Vite.
4
+ module VitePadrino::TagHelpers
5
+ # Public: Renders a script tag for vite/client to enable HMR in development.
6
+ def vite_client_tag
7
+ return unless src = vite_manifest.vite_client_src
8
+
9
+ tag(:scripk, src: src, type: 'module')
10
+ end
11
+
12
+ # Public: Resolves the path for the specified Vite asset.
13
+ #
14
+ # Example:
15
+ # <%= vite_asset_path 'calendar.css' %> # => "/vite/assets/calendar-1016838bab065ae1e122.css"
16
+ def vite_asset_path(name, **options)
17
+ asset_path vite_manifest.path_for(name, **options)
18
+ end
19
+
20
+ # Public: Renders a <script> tag for the specified Vite entrypoints.
21
+ def vite_javascript_tag(*names,
22
+ type: 'module',
23
+ asset_type: :javascript,
24
+ skip_preload_tags: false,
25
+ skip_style_tags: false,
26
+ crossorigin: 'anonymous',
27
+ **options)
28
+ entries = vite_manifest.resolve_entries(*names, type: asset_type)
29
+ tags = javascript_include_tag(*entries.fetch(:scripts), crossorigin: crossorigin, type: type, **options)
30
+ tags << vite_preload_tag(*entries.fetch(:imports), crossorigin: crossorigin) unless skip_preload_tags
31
+ tags << stylesheet_link_tag(*entries.fetch(:stylesheets)) unless skip_style_tags
32
+ tags
33
+ end
34
+
35
+ # Public: Renders a <script> tag for the specified Vite entrypoints.
36
+ def vite_typescript_tag(*names, **options)
37
+ vite_javascript_tag(*names, asset_type: :typescript, extname: false, **options)
38
+ end
39
+
40
+ # Public: Renders a <link> tag for the specified Vite entrypoints.
41
+ def vite_stylesheet_tag(*names, **options)
42
+ style_paths = names.map { |name| vite_asset_path(name, type: :stylesheet) }
43
+ stylesheet_link_tag(*style_paths, **options)
44
+ end
45
+
46
+ private
47
+
48
+ # Internal: Returns the current manifest loaded by Vite Ruby.
49
+ def vite_manifest
50
+ ViteRuby.instance.manifest
51
+ end
52
+
53
+ # Internal: Renders a modulepreload link tag.
54
+ def vite_preload_tag(*sources, crossorigin:)
55
+ sources.map { |source|
56
+ href = asset_path(source)
57
+ try(:request).try(:send_early_hints, 'Link' => %(<#{ href }>; rel=modulepreload; as=script; crossorigin=#{ crossorigin }))
58
+ tag(:link, rel: 'modulepreload', href: href, as: 'script', crossorigin: crossorigin)
59
+ }.join("\n").html_safe
60
+ end
61
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VitePadrino
4
+ VERSION = '0.5.0'
5
+ end
@@ -0,0 +1,15 @@
1
+ {
2
+ "all": {
3
+ "sourceCodeDir": "app/frontend",
4
+ "watchAdditionalPaths": []
5
+ },
6
+ "development": {
7
+ "autoBuild": true,
8
+ "publicOutputDir": "vite-dev",
9
+ "port": 3036
10
+ },
11
+ "test": {
12
+ "autoBuild": true,
13
+ "publicOutputDir": "vite-test"
14
+ }
15
+ }
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vite_padrino
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Máximo Mussini
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: vite_ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-performance
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - maximomussini@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - CHANGELOG.md
77
+ - LICENSE.txt
78
+ - README.md
79
+ - lib/vite_padrino.rb
80
+ - lib/vite_padrino/installation.rb
81
+ - lib/vite_padrino/tag_helpers.rb
82
+ - lib/vite_padrino/version.rb
83
+ - templates/config/padrino-vite.json
84
+ homepage: https://github.com/ElMassimo/vite_ruby
85
+ licenses:
86
+ - MIT
87
+ metadata:
88
+ source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_padrino@0.5.0/vite_padrino
89
+ changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_padrino@0.5.0/vite_padrino/CHANGELOG.md
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '2.5'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubygems_version: 3.1.4
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Use Vite in Padrino and bring joy to your JavaScript experience
109
+ test_files: []