pghero_assets 1.0.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 +7 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +24 -0
- data/Rakefile +8 -0
- data/lib/pghero_assets/asset_root.rb +5 -0
- data/lib/pghero_assets/disable_api_check.rb +8 -0
- data/lib/pghero_assets/middleware.rb +36 -0
- data/lib/pghero_assets/prepare_assets.rb +30 -0
- data/lib/pghero_assets/railtie.rb +11 -0
- data/lib/pghero_assets/version.rb +5 -0
- data/lib/pghero_assets.rb +1 -0
- metadata +68 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e83b5fb670c4e164b6925cfb13dce15b5de832e26dcd287691956580d2383ae9
|
|
4
|
+
data.tar.gz: b549f82a4542a874aa902c1f3e409994bfa9471c43bc24c419d655ee1038a017
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ac560b792ac554dce1e7a74aa5be580829b65e971b1ac389b462ebc3d8d812eb44f415a86f18765930ea516a963f614d5ee77c52ea45339286de1fdf8a9d1ad7
|
|
7
|
+
data.tar.gz: c9651cf1e98b1d8b4feaa5e56993a583934057e91989115fa9f28c321ce40b540ed1ed864a60e3a2f7b173677494f8a7d1622c131a562c1a77d1bf701b2ae194
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Janosch Müller
|
|
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,24 @@
|
|
|
1
|
+
[](http://badge.fury.io/rb/pghero_assets)
|
|
2
|
+
[](https://github.com/jaynetics/pghero_assets/actions)
|
|
3
|
+
|
|
4
|
+
# PgHeroAssets
|
|
5
|
+
|
|
6
|
+
This gem is for you if you want to be able to run [PgHero](https://github.com/pghero/pghero) without the asset pipeline or in Rails' api mode.
|
|
7
|
+
|
|
8
|
+
It serves all required PgHero assets from a custom middleware and disables the api mode check.
|
|
9
|
+
|
|
10
|
+
## Caveats
|
|
11
|
+
|
|
12
|
+
- This might break with PgHero updates, though I don't consider it likely so its not version-locked yet.
|
|
13
|
+
|
|
14
|
+
## Installation / usage
|
|
15
|
+
|
|
16
|
+
Add `pghero_assets` to your Gemfile.
|
|
17
|
+
|
|
18
|
+
## Contributing
|
|
19
|
+
|
|
20
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jaynetics/pghero_assets.
|
|
21
|
+
|
|
22
|
+
## License
|
|
23
|
+
|
|
24
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
module PgHeroAssets
|
|
2
|
+
def self.disable_pghero_api_check
|
|
3
|
+
require 'pghero'
|
|
4
|
+
require PgHero::Engine.root.join('app/helpers/pg_hero/home_helper')
|
|
5
|
+
require PgHero::Engine.root.join('app/controllers/pg_hero/home_controller')
|
|
6
|
+
PgHero::HomeController.define_method(:check_api) {}
|
|
7
|
+
end
|
|
8
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'rack/mime'
|
|
2
|
+
|
|
3
|
+
module PgHeroAssets
|
|
4
|
+
# Catches pghero asset requests and serves them from the gem.
|
|
5
|
+
class Middleware
|
|
6
|
+
def initialize(app, *)
|
|
7
|
+
@app = app
|
|
8
|
+
@regexp = %r{\A/(?:javascripts|images|stylesheets)/pghero}
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def call(env)
|
|
12
|
+
@regexp.match?(env[Rack::PATH_INFO]) &&
|
|
13
|
+
serve(env[Rack::PATH_INFO]) ||
|
|
14
|
+
@app.call(env)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def serve(path)
|
|
18
|
+
PgHeroAssets.prepare_assets
|
|
19
|
+
send_data(path)
|
|
20
|
+
rescue StandardError => e
|
|
21
|
+
Rails.logger.warn("PgHeroAssets::Middleware: #{e.class} #{e.message}")
|
|
22
|
+
nil
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def send_data(path)
|
|
26
|
+
prepared_asset_path = PgHeroAssets.asset_root.join(path.sub(%r{^/}, ''))
|
|
27
|
+
data = File.read(prepared_asset_path)
|
|
28
|
+
headers = {
|
|
29
|
+
'cache-control' => 'public, max-age=86400',
|
|
30
|
+
'content-length' => data.bytesize.to_s,
|
|
31
|
+
'content-type' => Rack::Mime.mime_type(File.extname(path)),
|
|
32
|
+
}
|
|
33
|
+
[200, headers, [data]]
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
|
|
3
|
+
# prepares assets for PgHero lazily / on demand
|
|
4
|
+
# based on discussion in https://github.com/ankane/pghero/pull/421
|
|
5
|
+
module PgHeroAssets
|
|
6
|
+
PREPARE_ASSETS_MUTEX = Mutex.new
|
|
7
|
+
|
|
8
|
+
def self.prepare_assets
|
|
9
|
+
root_dir = PgHeroAssets.asset_root
|
|
10
|
+
PREPARE_ASSETS_MUTEX.synchronize do
|
|
11
|
+
root_dir.exist? ? return : FileUtils.mkdir_p(root_dir)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Create application.js file for PgHero
|
|
15
|
+
asset_src = PgHero::Engine.root.join('app/assets')
|
|
16
|
+
js_file = root_dir.join('javascripts/pghero/application.js')
|
|
17
|
+
js_file.dirname.mkpath
|
|
18
|
+
files = Dir[asset_src.join('javascripts/**/*.js')].sort_by { _1.index(/application\.\w+\z/) || 0 }
|
|
19
|
+
File.open(js_file, 'w') { |main| files.each { |f| main << File.read(f) << "\n\n" } }
|
|
20
|
+
|
|
21
|
+
# Create application.css file for PgHero
|
|
22
|
+
css_file = root_dir.join('stylesheets/pghero/application.css')
|
|
23
|
+
css_file.dirname.mkpath
|
|
24
|
+
files = Dir[asset_src.join('stylesheets/**/*.css')].sort_by { _1.index(/application\.\w+\z/) || 0 }
|
|
25
|
+
File.open(css_file, 'w') { |main| files.each { |f| main << File.read(f) << "\n\n" } }
|
|
26
|
+
|
|
27
|
+
# Symlink to PgHero's images
|
|
28
|
+
FileUtils.ln_sf asset_src.join('images'), root_dir.join('images')
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'rails/railtie'
|
|
2
|
+
require 'rails/engine/railties'
|
|
3
|
+
|
|
4
|
+
module PgHeroAssets
|
|
5
|
+
class Railtie < ::Rails::Railtie
|
|
6
|
+
initializer 'pghero_assets.initializer' do |app|
|
|
7
|
+
PgHeroAssets.disable_pghero_api_check
|
|
8
|
+
app.middleware.insert(0, PgHeroAssets::Middleware)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Dir[File.join(__dir__, 'pghero_assets', '*.rb')].each { |f| require f }
|
metadata
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: pghero_assets
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Janosch Müller
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 2024-09-22 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: pghero
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 3.6.0
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 3.6.0
|
|
26
|
+
email:
|
|
27
|
+
- janosch84@gmail.com
|
|
28
|
+
executables: []
|
|
29
|
+
extensions: []
|
|
30
|
+
extra_rdoc_files: []
|
|
31
|
+
files:
|
|
32
|
+
- ".rspec"
|
|
33
|
+
- CHANGELOG.md
|
|
34
|
+
- LICENSE.txt
|
|
35
|
+
- README.md
|
|
36
|
+
- Rakefile
|
|
37
|
+
- lib/pghero_assets.rb
|
|
38
|
+
- lib/pghero_assets/asset_root.rb
|
|
39
|
+
- lib/pghero_assets/disable_api_check.rb
|
|
40
|
+
- lib/pghero_assets/middleware.rb
|
|
41
|
+
- lib/pghero_assets/prepare_assets.rb
|
|
42
|
+
- lib/pghero_assets/railtie.rb
|
|
43
|
+
- lib/pghero_assets/version.rb
|
|
44
|
+
homepage: https://github.com/jaynetics/pghero_assets
|
|
45
|
+
licenses:
|
|
46
|
+
- MIT
|
|
47
|
+
metadata:
|
|
48
|
+
homepage_uri: https://github.com/jaynetics/pghero_assets
|
|
49
|
+
source_code_uri: https://github.com/jaynetics/pghero_assets
|
|
50
|
+
changelog_uri: https://github.com/jaynetics/pghero_assets/blob/main/CHANGELOG.md
|
|
51
|
+
rdoc_options: []
|
|
52
|
+
require_paths:
|
|
53
|
+
- lib
|
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
|
+
requirements:
|
|
56
|
+
- - ">="
|
|
57
|
+
- !ruby/object:Gem::Version
|
|
58
|
+
version: 3.1.0
|
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
|
+
requirements:
|
|
61
|
+
- - ">="
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: '0'
|
|
64
|
+
requirements: []
|
|
65
|
+
rubygems_version: 3.6.0.dev
|
|
66
|
+
specification_version: 4
|
|
67
|
+
summary: Run PgHero without asset pipeline.
|
|
68
|
+
test_files: []
|