vite_rails_legacy 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 28c8ea3aecb413e382f4fd94763c0a253b7c17905fb9808a2a6451efc9fd2e97
4
+ data.tar.gz: 67010d5af0d5608e5e844ae24e9078223542c592222c31e48c6e90a0edb710e1
5
+ SHA512:
6
+ metadata.gz: 29087a91abcc904b69041430f7acfacee25a0b90b8bd623191920b09dfd698b4c2dcda8aa077af57ca64ee8b0b74f45e4b2a202400650dfcb7bb5d0b6a603499
7
+ data.tar.gz: 301449f8cc17e08a12c0c16d5ba78f06674a989d9d8d178f31b5f30695515cb3aa485b434b76f81c9e4b7c2136c0a75bcba57982637bd1d0e9d2fc4522ddc03c
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## ViteRailsLegacy 2.0.2 (2020-02-11)
2
+
3
+ - Release a version of Vite Rails that supports Rails 4.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 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,50 @@
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 Rails Legacy
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_rails_legacy">
25
+ <img alt="Gem Version" src="https://img.shields.io/gem/v/vite_rails_legacy.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
+ [vite_rails]: https://github.com/ElMassimo/vite_ruby/tree/main/vite_rails
34
+ [vite_ruby]: https://github.com/ElMassimo/vite_ruby/tree/main/vite_ruby
35
+
36
+ __Vite Rails Legacy__ is [__Vite Rails__][vite_rails], modified to support Rails 4.
37
+
38
+ ## Why a separate library? 🤔
39
+
40
+ I don't want the burden of having to support Rails 4 in the main codebase.
41
+
42
+ And yet, after extracting [_Vite Ruby_][vite_ruby] the surface area is smaller,
43
+ and it was easy to adapt it to work with Rails 4.
44
+
45
+ This way, people get to use the library in Rails 4, and I get to not worry about
46
+ accidentally breaking support with changes that are tested on Rails 5 and onwards.
47
+
48
+ ## License
49
+
50
+ 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
+ # Set NODE_ENV before installation, so that Rails installs JS build dependencies
4
+ # on servers that precompile assets.
5
+ installation_tasks = ['yarn:install', 'webpacker:yarn_install'].select { |name| Rake::Task.task_defined?(name) }.each do |name|
6
+ Rake::Task[name].enhance([:'vite_rails:set_node_env'])
7
+ end
8
+
9
+ # Ensure dependencies are installed in older versions of Rails
10
+ Rake::Task['assets:precompile']&.enhance([:'vite:install_dependencies']) if installation_tasks.none?
11
+
12
+ require 'vite_ruby'
13
+ ViteRuby.install_tasks
14
+
15
+ namespace :vite_rails do
16
+ desc 'Fixes Rails management of node dev dependencies (build dependencies)'
17
+ task :set_node_env do
18
+ ENV['NODE_ENV'] = 'development'
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'vite_ruby'
4
+
5
+ require 'vite_rails_legacy/version'
6
+ require 'vite_rails_legacy/config'
7
+ require 'vite_rails_legacy/tag_helpers'
8
+ require 'vite_rails_legacy/engine' if defined?(Rails)
9
+
10
+ # Active Support 4 does not support multiple arguments in append.
11
+ class Array
12
+ alias append push
13
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViteRailsLegacy::Config
4
+ # Override: Default values for a Rails application.
5
+ def config_defaults
6
+ require 'rails'
7
+ super(
8
+ asset_host: Rails.application&.config&.action_controller&.asset_host,
9
+ mode: Rails.env.to_s,
10
+ root: Rails.root || Dir.pwd,
11
+ )
12
+ end
13
+ end
14
+
15
+ ViteRuby::Config.singleton_class.prepend(ViteRailsLegacy::Config)
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/railtie'
4
+
5
+ class ViteRailsLegacy::Engine < Rails::Engine
6
+ initializer 'vite_rails.proxy' do |app|
7
+ app.middleware.insert_before 0, 'ViteRuby::DevServerProxy', ssl_verify_none: true if ViteRuby.run_proxy?
8
+ end
9
+
10
+ initializer 'vite_rails_legacy.helper' do
11
+ ActiveSupport.on_load(:action_controller) do
12
+ ActionController::Base.helper(ViteRailsLegacy::TagHelpers)
13
+ end
14
+
15
+ ActiveSupport.on_load(:action_view) do
16
+ include ViteRailsLegacy::TagHelpers
17
+ end
18
+ end
19
+
20
+ initializer 'vite_rails.logger' do
21
+ config.after_initialize do
22
+ ViteRuby.instance.logger = Rails.logger
23
+ end
24
+ end
25
+
26
+ initializer 'vite_rails.bootstrap' do
27
+ if defined?(Rails::Server) || defined?(Rails::Console)
28
+ ViteRuby.bootstrap
29
+ if defined?(Spring)
30
+ require 'spring/watcher'
31
+ Spring.after_fork { ViteRuby.bootstrap }
32
+ Spring.watch(ViteRuby.config.config_path)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'vite_rails_legacy'
4
+
5
+ # Internal: Extends the base installation script from Vite Ruby to work for a
6
+ # typical Rails app.
7
+ module ViteRailsLegacy::Installation
8
+ RAILS_TEMPLATES = Pathname.new(File.expand_path('../../templates', __dir__))
9
+
10
+ # Override: Setup a typical apps/web Hanami app to use Vite.
11
+ def setup_app_files
12
+ cp RAILS_TEMPLATES.join('config/rails-vite.json'), config.config_path
13
+ if root.join('app/javascript').exist?
14
+ Dry::CLI::Utils::Files.replace_first_line config.config_path, 'app/frontend', %( "sourceCodeDir": "app/javascript",)
15
+ end
16
+ end
17
+
18
+ # Override: Create a sample JS file and attempt to inject it in an HTML template.
19
+ def install_sample_files
20
+ unless config.resolved_entrypoints_dir.join('application.js').exist?
21
+ cp RAILS_TEMPLATES.join('entrypoints/application.js'), config.resolved_entrypoints_dir.join('application.js')
22
+ end
23
+
24
+ if (layout_file = root.join('app/views/layouts/application.html.erb')).exist?
25
+ inject_line_before layout_file, '</head>', <<-HTML
26
+ <%= vite_client_tag %>
27
+ <%= vite_javascript_tag 'application' %>
28
+ HTML
29
+ end
30
+ end
31
+ end
32
+
33
+ ViteRuby::CLI::Install.prepend(ViteRailsLegacy::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 ViteRailsLegacy::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
+ "<script#{ tag_options({ src: src, type: 'module' }, escape: true) }></script>".html_safe
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
+ path_to_asset 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 = path_to_asset(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 ViteRailsLegacy
4
+ VERSION = '2.0.2'
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
+ }
@@ -0,0 +1,22 @@
1
+ // To see this message, add the following to the `<head>` section in your
2
+ // views/layouts/application.html.erb
3
+ //
4
+ // <%= vite_client_tag %>
5
+ // <%= vite_javascript_tag 'application' %>
6
+ console.log('Vite ⚡️ Rails')
7
+
8
+ // Example: Load Rails libraries in Vite.
9
+ //
10
+ // import '@rails/ujs'
11
+ //
12
+ // import Turbolinks from 'turbolinks'
13
+ // import ActiveStorage from '@rails/activestorage'
14
+ //
15
+ // // Import all channels.
16
+ // import.meta.globEager('./**/*_channel.js')
17
+ //
18
+ // Turbolinks.start()
19
+ // ActiveStorage.start()
20
+
21
+ // Example: Import a stylesheet in app/frontend/index.css
22
+ // import '~/index.css'
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vite_rails_legacy
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Máximo Mussini
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "<"
18
+ - !ruby/object:Gem::Version
19
+ version: '5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "<"
25
+ - !ruby/object:Gem::Version
26
+ version: '5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: vite_ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.3.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
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
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-performance
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - maximomussini@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - CHANGELOG.md
105
+ - LICENSE.txt
106
+ - README.md
107
+ - lib/tasks/vite.rake
108
+ - lib/vite_rails_legacy.rb
109
+ - lib/vite_rails_legacy/config.rb
110
+ - lib/vite_rails_legacy/engine.rb
111
+ - lib/vite_rails_legacy/installation.rb
112
+ - lib/vite_rails_legacy/tag_helpers.rb
113
+ - lib/vite_rails_legacy/version.rb
114
+ - templates/config/rails-vite.json
115
+ - templates/entrypoints/application.js
116
+ homepage: https://github.com/ElMassimo/vite_ruby
117
+ licenses:
118
+ - MIT
119
+ metadata:
120
+ source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_rails_legacy@2.0.2/vite_rails_legacy
121
+ changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_rails_legacy@2.0.2/vite_rails_legacy/CHANGELOG.md
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '2.5'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubygems_version: 3.1.4
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Use Vite in Rails 4 and bring joy to your JavaScript experience
141
+ test_files: []