Sha256: f00439173d9722c630422c021966c5a9a5e3726b44780c0e53509c3150de91a7
Contents?: true
Size: 1.73 KB
Versions: 1
Compression:
Stored size: 1.73 KB
Contents
require 'pathname' module SlimGruntHelpers module Models class Usemin BASE_OPTIONS = {}.freeze def initialize @links = [] end def <<(path, options={}) @links << { path: path.to_s, options: base_options.merge(options) } end alias_method :add, :<< alias_method :include, :<< def require(path, options={}) self.include(path, options) unless file_already_included? path end def each(options={}) @links.each { |link| yield(transform_link(link, options)) } end def base_options BASE_OPTIONS end def require_tree(root_path, pattern, options={}) unless root_path.respond_to? :join root_path = Pathname.new(root_path.to_s) end Dir[root_path.join(pattern).to_s].reject do |file| File.directory? file end.each do |file| file_name = file.to_s real_root_path = "#{ root_path }/" file_name[real_root_path] = '' transform_ext = options[:transform_ext] unless transform_ext.nil? transform_ext = ".#{ transform_ext }" unless transform_ext[0] == '.' origin_ext = File.extname(file_name) file_name[origin_ext] = transform_ext end self.require file_name, options.reject { |key| key == :transform_ext } end end protected def transform_link(link, options={}) raise NotImplementedError, 'This method must be implemented in child classes' end private def file_already_included?(path) path = path.to_s @links.find { |link| link[:path] == path } end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
slim-grunt-helpers-0.4.1 | lib/slim-grunt-helpers/models/usemin.rb |