Sha256: 7bebbe86878a564a1f6bf87c0d2096f3f1f61f821fe75cc55f0f1b7abff98aaf
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
# frozen_string_literal: true module IziLightup module InlineAsset class << self def inline_file(paths, format = nil) Array.wrap(paths).map do |asset_path| raw_source(with_ext(asset_path, format)) end.join("\n" * 3) end def inline_js(paths = []) return '' if paths.blank? "<script type='text/javascript'>#{inline_file(paths, :js)}</script>" end def inline_css(paths = []) return '' if paths.blank? "<style type='text/css'>#{inline_file(paths, :css)}</style>" end private def with_ext(path, format = nil) return path if format.nil? ext = File.extname(path) return path if ext.present? "#{path}.#{format}" end def raw_source(asset_path) return find_sources_fallback(asset_path) unless manifest.respond_to?(:find_sources) manifest.find_sources(asset_path).first&.html_safe end def manifest @manifest ||= Rails.application.assets_manifest end def find_sources_fallback(asset_path) src = manifest.send(:find_asset, asset_path) src&.source&.html_safe || '' end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
izi_lightup-1.0.2 | lib/izi_lightup/inline_asset.rb |