Module: BunBunBundle

Defined in:
lib/bun_bun_bundle.rb,
lib/bun_bun_bundle/config.rb,
lib/bun_bun_bundle/helpers.rb,
lib/bun_bun_bundle/railtie.rb,
lib/bun_bun_bundle/version.rb,
lib/bun_bun_bundle/manifest.rb,
lib/bun_bun_bundle/safe_html.rb,
lib/bun_bun_bundle/reload_tag.rb,
lib/bun_bun_bundle/dev_cache_middleware.rb

Defined Under Namespace

Modules: Helpers, ReloadTag, SafeHtml Classes: Config, DevCacheMiddleware, Manifest, Railtie

Constant Summary collapse

VERSION =
'0.9.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.asset_hostObject



23
24
25
# File 'lib/bun_bun_bundle.rb', line 23

def asset_host
  @asset_host || ''
end

.configObject



15
16
17
# File 'lib/bun_bun_bundle.rb', line 15

def config
  @config ||= Config.new
end

.environmentObject



27
28
29
# File 'lib/bun_bun_bundle.rb', line 27

def environment
  @environment || ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
end

.manifestObject



19
20
21
# File 'lib/bun_bun_bundle.rb', line 19

def manifest
  @manifest ||= Manifest.new
end

Class Method Details

.bun_pathObject

Returns the path to the bundled JS files shipped with the gem.



53
54
55
# File 'lib/bun_bun_bundle.rb', line 53

def bun_path
  File.expand_path('bun', __dir__)
end

.development?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/bun_bun_bundle.rb', line 31

def development?
  environment == 'development'
end

.production?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/bun_bun_bundle.rb', line 35

def production?
  environment == 'production'
end

.reset!Object

Resets all state. Useful for testing.



58
59
60
61
62
63
# File 'lib/bun_bun_bundle.rb', line 58

def reset!
  @config = nil
  @manifest = nil
  @asset_host = nil
  @environment = nil
end

.setup(root: Dir.pwd, hanami: nil) ⇒ Object

Loads config and manifest. Call this from Hanami’s config/app.rb or any Rack app’s startup.

Pass ‘hanami: config` from within a Hanami::App class body to automatically register middleware and configure CSP for development.



44
45
46
47
48
49
50
# File 'lib/bun_bun_bundle.rb', line 44

def setup(root: Dir.pwd, hanami: nil)
  self.config = Config.load(root: root.to_s)
  options = development? ? {} : { retries: 1, delay: 0 }
  self.manifest = Manifest.load(root: root.to_s, **options)

  configure_hanami(hanami) if hanami
end