fileboost 0.1.5 → 0.2.0.pre
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 +4 -4
- data/lib/fileboost/config.rb +2 -1
- data/lib/fileboost/engine.rb +5 -0
- data/lib/fileboost/image_tag_patch.rb +26 -0
- data/lib/fileboost/version.rb +1 -1
- data/lib/fileboost.rb +1 -0
- data/lib/generators/fileboost/templates/fileboost.rb +6 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e41eb33a273bb73c63284223566b994fca3583c8e72c82c0dde3ffc6c19b9adc
|
4
|
+
data.tar.gz: 21a0c4088aea9ac6eeb3bb82310d850b99fa718155c0b253798aa5343da46caa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11b1349683d425b709d351ca165394f86f6ce7db6e71af7359d8c10a8532d2f31843464fa82b4a7da4a98ba792601b97cfa86fa02d08a36e8fe5528defe8622f
|
7
|
+
data.tar.gz: df922239b99ecbd4e87e6272908bc85f1ecf6e303faa704e5f5843a991ad783df29f2b6eeccd961a140342b1c7ab6e560ed93eca3222d9a4ae89c3fd690553e6
|
data/lib/fileboost/config.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Fileboost
|
2
2
|
class Config
|
3
|
-
attr_accessor :project_id, :token
|
3
|
+
attr_accessor :project_id, :token, :patch_image_tag
|
4
4
|
|
5
5
|
CDN_DOMAIN = "cdn.fileboost.dev"
|
6
6
|
BASE_URL = "https://#{CDN_DOMAIN}"
|
@@ -8,6 +8,7 @@ module Fileboost
|
|
8
8
|
def initialize
|
9
9
|
@project_id = ENV["FILEBOOST_PROJECT_ID"]
|
10
10
|
@token = ENV["FILEBOOST_TOKEN"]
|
11
|
+
@patch_image_tag = false
|
11
12
|
end
|
12
13
|
|
13
14
|
def valid?
|
data/lib/fileboost/engine.rb
CHANGED
@@ -5,6 +5,11 @@ module Fileboost
|
|
5
5
|
initializer "fileboost.action_view" do
|
6
6
|
ActiveSupport.on_load :action_view do
|
7
7
|
include Fileboost::Helpers
|
8
|
+
|
9
|
+
# Conditionally patch image_tag if enabled in configuration
|
10
|
+
if Fileboost.config.patch_image_tag
|
11
|
+
prepend Fileboost::ImageTagPatch
|
12
|
+
end
|
8
13
|
end
|
9
14
|
end
|
10
15
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Fileboost
|
2
|
+
module ImageTagPatch
|
3
|
+
def image_tag(source, options = {})
|
4
|
+
# If this is an ActiveStorage asset and Fileboost is configured, use fileboost_image_tag
|
5
|
+
if valid_activestorage_asset?(source) && Fileboost.config.valid?
|
6
|
+
fileboost_image_tag(source, **options)
|
7
|
+
else
|
8
|
+
# Fall back to Rails' original image_tag for all other cases
|
9
|
+
super(source, options)
|
10
|
+
end
|
11
|
+
rescue
|
12
|
+
# If there's any error with Fileboost processing, fall back to original Rails behavior
|
13
|
+
super(source, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def valid_activestorage_asset?(asset)
|
19
|
+
return true if asset.is_a?(ActiveStorage::Blob)
|
20
|
+
return true if asset.is_a?(ActiveStorage::Attached)
|
21
|
+
return true if asset.is_a?(ActiveStorage::VariantWithRecord)
|
22
|
+
|
23
|
+
false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/fileboost/version.rb
CHANGED
data/lib/fileboost.rb
CHANGED
@@ -16,4 +16,10 @@ Fileboost.configure do |config|
|
|
16
16
|
# You can also set this via the FILEBOOST_TOKEN environment variable
|
17
17
|
# IMPORTANT: Keep this secret secure and never commit it to version control
|
18
18
|
config.token = ENV["FILEBOOST_TOKEN"] # || "your-secret-token"
|
19
|
+
|
20
|
+
# Drop-in replacement for Rails image_tag helper
|
21
|
+
# When enabled, image_tag will automatically use Fileboost optimization
|
22
|
+
# for ActiveStorage assets while falling back to standard Rails behavior
|
23
|
+
# for other image sources. Defaults to false.
|
24
|
+
# config.patch_image_tag = true
|
19
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fileboost
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bilal
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- lib/fileboost/engine.rb
|
139
139
|
- lib/fileboost/error_handler.rb
|
140
140
|
- lib/fileboost/helpers.rb
|
141
|
+
- lib/fileboost/image_tag_patch.rb
|
141
142
|
- lib/fileboost/signature_generator.rb
|
142
143
|
- lib/fileboost/url_builder.rb
|
143
144
|
- lib/fileboost/version.rb
|