Module: Roda::RodaPlugins::AssetsManifest
- Defined in:
- lib/roda/plugins/assets_manifest.rb
Overview
plugin :assets_manifest, host: { development: "/public/assets", production: "" }, host: "/public/assets" location: "../../public/assets/manifest.json", manifest: proc do { "app.js" => "app-123.js" } end, is_production: ENV == "production"
js_entrypoint_tag('/name/someting') # /public/assets/name/something.js and /public/assets/name/something-DIGESTED.js
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Constant Summary collapse
- DEFAULT_HREF_HOST =
'/public/assets'- DEFAULT_MANIFEST_LOCATION =
'/public/assets/manifest.json'- JS_ENTRYPOINT_TAG_CACHE =
{}
- CSS_ENTRYPOINT_TAG_CACHE =
{}
Class Method Summary collapse
Class Method Details
.configure(app, opts = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/roda/plugins/assets_manifest.rb', line 26 def self.configure(app, opts = {}) opts[:host] ||= DEFAULT_HREF_HOST if opts[:host].is_a?(String) app.opts[:assets_manifest_host_development] ||= opts[:host] app.opts[:assets_manifest_host_production] ||= opts[:host] elsif opts[:host].is_a?(Hash) app.opts[:assets_manifest_host_development] ||= opts.dig(:host, :development) || DEFAULT_HREF_HOST app.opts[:assets_manifest_host_production] ||= opts.dig(:host, :production) || app.opts[:assets_manifest_host_development] end app.opts[:assets_manifest_is_production] = if opts.key?(:is_production) opts[:is_production] else ENV["RACK_ENV"] == "production" end if opts[:manifest].respond_to?(:call) app.opts[:assets_manifest] = opts[:manifest].call else location = File.((opts[:location] || DEFAULT_MANIFEST_LOCATION), __dir__) if File.exist?(location) app.opts[:assets_manifest] = JSON.parse(File.read(location)) app.opts[:assets_version] = app.opts[:assets_manifest].hash.to_s else app.opts[:assets_manifest] = {} end end end |