module Roda::RodaPlugins::Assets::ClassMethods
def _compile_assets(type)
Internals of compile_assets, handling recursive calls for loading
def _compile_assets(type) type, *dirs = type if type.is_a?(Array) dirs ||= [] files = assets_opts[type] dirs.each{|d| files = files[d]} case files when Hash files.each_key{|dir| _compile_assets([type] + dirs + [dir])} else files = Array(files) compile_assets_files(files, type, dirs) unless files.empty? end end
def asset_digest(content)
a different digest type or to return a static string if you don't
SHA1 hash of the content. This method can be overridden to use
Return a unique id for the given content. By default, uses the
def asset_digest(content) require 'digest/sha1' Digest::SHA1.hexdigest(content) end
def assets_opts
def assets_opts opts[:assets] end
def compile_assets(type=nil)
can specify an array of types (e.g. [:css, :frontend]) to
is given, compile both the :css and :js asset types. You
Compile options for the given asset type. If no asset_type
def compile_assets(type=nil) require 'fileutils' unless assets_opts[:compiled] opts[:assets] = assets_opts.merge(:compiled => {}) end if type == nil _compile_assets(:css) _compile_assets(:js) else _compile_assets(type) end if assets_opts[:precompiled] require 'json' ::FileUtils.mkdir_p(File.dirname(assets_opts[:precompiled])) ::File.open(assets_opts[:precompiled], 'wb'){|f| f.write(assets_opts[:compiled].to_json)} end assets_opts[:compiled] end
def compile_assets_files(files, type, dirs)
file. Dirs should be an array of asset group names, if these
Compile each array of files for the given type into a single
def compile_assets_files(files, type, dirs) dirs = nil if dirs && dirs.empty? o = assets_opts app = new content = files.map do |file| file = "#{dirs.join('/')}/#{file}" if dirs && o[:group_subdirs] file = "#{o[:"#{type}_path"]}#{file}" app.read_asset_file(file, type) end.join unless o[:concat_only] content = compress_asset(content, type) end suffix = ".#{dirs.join('.')}" if dirs key = "#{type}#{suffix}" unique_id = o[:compiled][key] = asset_digest(content) path = "#{o[:"compiled_#{type}_path"]}#{suffix}.#{unique_id}.#{type}" ::FileUtils.mkdir_p(File.dirname(path)) ::File.open(path, 'wb'){|f| f.write(content)} nil end
def compress_asset(content, type)
a java runtime. This method can be overridden by the application
but handle cases where yuicompressor isn't installed or can't find
Compress the given content for the given type using yuicompressor,
def compress_asset(content, type) require 'yuicompressor' # :nocov: content = YUICompressor.send("compress_#{type}", content, :munge => true) # :nocov: rescue LoadError, Errno::ENOENT # yuicompressor or java not available, just use concatenated, uncompressed output content end