bun_bun_bundle 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1acf2b909cdf00c5e5533943ad600811ee2cdd0fcd53885ca3e007f94b12db91
4
- data.tar.gz: ee34bf6fd021e4470a9cb9f14ea7436f8b8eaf312229ad59724e4bb14a30afc1
3
+ metadata.gz: c51a065b214293e85467dfdd10f2c84bf763f65fe27d0b549b175ea7448563bf
4
+ data.tar.gz: f2d86b5d3650797b617fa3ecee6d3dac119d97850749bc830172bfa12cb83dfe
5
5
  SHA512:
6
- metadata.gz: 3ee9e73c7e1de4a56d70411f8ba49d755a09b7c4148fa220eeef75a2dd460f141ea57fe194c29df26f2bc68cbd9d11339941f62f130bfeb7fbf22f8e0c80994f
7
- data.tar.gz: 835bcd2d1b8203f6497931e3d92ca23a2d428fe84c750bc86eb508364805b4cae738b0fe32c30362be8a35e4dcdabea891f43b098f48de496f9585e8d9d06917
6
+ metadata.gz: c87530160b4f6829e32f7fc82c4f0d9180aa13b03089011fdb237d8daa4973453bd9cd074bd0402736f7fcab49e7d40c98f9b7fbb1a094aa07f718cd94ca9ac4
7
+ data.tar.gz: 0cbad61b7eff7af29f38cab146f09941a8f3dbd9354a1c470d36a35f94bbb36484543f7a06ef27e4810f2a1f51becb00026c7206de30e6b0049334cd224127fd
data/README.md CHANGED
@@ -87,21 +87,16 @@ stale asset caching.
87
87
  # config/app.rb
88
88
 
89
89
  require 'bun_bun_bundle/hanami'
90
- ```
91
-
92
- 2. Optionally add the dev cache middleware:
93
-
94
- ```ruby
95
- # config/app.rb
96
90
 
97
91
  module MyApp
98
92
  class App < Hanami::App
93
+ BunBunBundle.setup(root: root)
99
94
  config.middleware.use BunBunBundle::DevCacheMiddleware if Hanami.env?(:development)
100
95
  end
101
96
  end
102
97
  ```
103
98
 
104
- 3. Include the helpers in your views:
99
+ 2. Include the helpers in your views:
105
100
 
106
101
  ```ruby
107
102
  # app/views/helpers.rb
@@ -129,9 +124,7 @@ stale asset caching.
129
124
  ```ruby
130
125
  require 'bun_bun_bundle'
131
126
 
132
- # Configure manually
133
- BunBunBundle.config = BunBunBundle::Config.load(root: __dir__)
134
- BunBunBundle.manifest = BunBunBundle::Manifest.load(root: __dir__)
127
+ BunBunBundle.setup(root: __dir__)
135
128
 
136
129
  # Optionally set a CDN host
137
130
  BunBunBundle.asset_host = 'https://cdn.example.com'
@@ -5,10 +5,11 @@ module BunBunBundle
5
5
  #
6
6
  # Add to your Hanami app's config/app.rb:
7
7
  #
8
- # require "bun_bun_bundle/hanami"
8
+ # require 'bun_bun_bundle/hanami'
9
9
  #
10
10
  # module MyApp
11
11
  # class App < Hanami::App
12
+ # BunBunBundle.setup(root: root)
12
13
  # config.middleware.use BunBunBundle::DevCacheMiddleware if Hanami.env?(:development)
13
14
  # end
14
15
  # end
@@ -25,22 +26,4 @@ module BunBunBundle
25
26
  # end
26
27
  # end
27
28
  #
28
- module HanamiIntegration
29
- def self.setup(root: Dir.pwd)
30
- BunBunBundle.config = Config.load(root: root)
31
-
32
- BunBunBundle.manifest = if BunBunBundle.development?
33
- Manifest.load(root: root)
34
- else
35
- Manifest.load(root: root, retries: 1, delay: 0)
36
- end
37
- end
38
- end
39
- end
40
-
41
- # Auto-setup when loaded in a Hanami app.
42
- if defined?(Hanami)
43
- Hanami::App.after :configure do
44
- BunBunBundle::HanamiIntegration.setup(root: root.to_s)
45
- end
46
29
  end
@@ -13,6 +13,8 @@ module BunBunBundle
13
13
  # <%= bun_css_tag("css/app.css") %>
14
14
  #
15
15
  module Helpers
16
+ include SafeHtml
17
+
16
18
  # Returns the public path to an asset from the manifest.
17
19
  #
18
20
  # Prepends the configured public_path and asset_host:
@@ -33,7 +35,7 @@ module BunBunBundle
33
35
  def bun_js_tag(source, **options)
34
36
  src = bun_asset(source)
35
37
  attrs = { type: 'text/javascript' }.merge(options).merge(src: src)
36
- %(<script #{_bun_html_attrs(attrs)}></script>)
38
+ _bun_safe(%(<script #{_bun_html_attrs(attrs)}></script>))
37
39
  end
38
40
 
39
41
  # Generates a <link> tag for a CSS entry point.
@@ -44,7 +46,7 @@ module BunBunBundle
44
46
  def bun_css_tag(source, **options)
45
47
  href = bun_asset(source)
46
48
  attrs = { type: 'text/css', rel: 'stylesheet' }.merge(options).merge(href: href)
47
- %(<link #{_bun_html_attrs(attrs)}>)
49
+ _bun_safe(%(<link #{_bun_html_attrs(attrs)}>))
48
50
  end
49
51
 
50
52
  # Generates an <img> tag for an image asset.
@@ -56,7 +58,7 @@ module BunBunBundle
56
58
  src = bun_asset(source)
57
59
  alt = options.delete(:alt) || File.basename(source, '.*').tr('-_', ' ').capitalize
58
60
  attrs = { alt: alt }.merge(options).merge(src: src)
59
- %(<img #{_bun_html_attrs(attrs)}>)
61
+ _bun_safe(%(<img #{_bun_html_attrs(attrs)}>))
60
62
  end
61
63
 
62
64
  private
@@ -13,13 +13,7 @@ module BunBunBundle
13
13
 
14
14
  initializer 'bun_bun_bundle.manifest' do |app|
15
15
  config.after_initialize do
16
- BunBunBundle.config = Config.load(root: app.root.to_s)
17
-
18
- BunBunBundle.manifest = if BunBunBundle.development?
19
- Manifest.load(root: app.root.to_s)
20
- else
21
- Manifest.load(root: app.root.to_s, retries: 1, delay: 0)
22
- end
16
+ BunBunBundle.setup(root: app.root)
23
17
  end
24
18
  end
25
19
 
@@ -10,6 +10,8 @@ module BunBunBundle
10
10
  # Only outputs content when BunBunBundle.development? is true.
11
11
  #
12
12
  module ReloadTag
13
+ include SafeHtml
14
+
13
15
  # Returns the live reload <script> tag, or an empty string in production.
14
16
  #
15
17
  # Example (ERB):
@@ -24,7 +26,7 @@ module BunBunBundle
24
26
  "#{config.public_path}/#{key}"
25
27
  end
26
28
 
27
- <<~HTML
29
+ html = <<~HTML
28
30
  <script>
29
31
  (() => {
30
32
  const cssPaths = #{css_paths.to_json};
@@ -56,6 +58,7 @@ module BunBunBundle
56
58
  })()
57
59
  </script>
58
60
  HTML
61
+ _bun_safe(html)
59
62
  end
60
63
  end
61
64
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BunBunBundle
4
+ module SafeHtml
5
+ private
6
+
7
+ if String.method_defined?(:html_safe)
8
+ def _bun_safe(html) = html.html_safe
9
+ else
10
+ def _bun_safe(html) = html
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BunBunBundle
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.2'
5
5
  end
@@ -3,6 +3,7 @@
3
3
  require_relative 'bun_bun_bundle/version'
4
4
  require_relative 'bun_bun_bundle/config'
5
5
  require_relative 'bun_bun_bundle/manifest'
6
+ require_relative 'bun_bun_bundle/safe_html'
6
7
  require_relative 'bun_bun_bundle/helpers'
7
8
  require_relative 'bun_bun_bundle/reload_tag'
8
9
  require_relative 'bun_bun_bundle/dev_cache_middleware'
@@ -35,6 +36,14 @@ module BunBunBundle
35
36
  environment == 'production'
36
37
  end
37
38
 
39
+ # Loads config and manifest. Call this from Hanami's config/app.rb or
40
+ # any Rack app's startup.
41
+ def setup(root: Dir.pwd)
42
+ self.config = Config.load(root: root.to_s)
43
+ options = development? ? {} : { retries: 1, delay: 0 }
44
+ self.manifest = Manifest.load(root: root.to_s, **options)
45
+ end
46
+
38
47
  # Returns the path to the bundled JS files shipped with the gem.
39
48
  def bun_path
40
49
  File.expand_path('bun', __dir__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bun_bun_bundle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wout Fierens
@@ -48,6 +48,7 @@ files:
48
48
  - lib/bun_bun_bundle/manifest.rb
49
49
  - lib/bun_bun_bundle/railtie.rb
50
50
  - lib/bun_bun_bundle/reload_tag.rb
51
+ - lib/bun_bun_bundle/safe_html.rb
51
52
  - lib/bun_bun_bundle/version.rb
52
53
  homepage: https://codeberg.org/w0u7/bun_bun_bundle
53
54
  licenses: