Sha256: 71039d55e65193724a955d5eb2f4824d4ef524e9e479ba8191b321d3741e6e3f
Contents?: true
Size: 1.76 KB
Versions: 3
Compression:
Stored size: 1.76 KB
Contents
module Docks @pattern_id = lambda do |filename| File.basename(filename).split('.').first.split(/(\-\-|__)/).first.sub(/^_+/, '').gsub(/(\s|\-|_)+/, '_') end def self.pattern_id(filename = nil, &block) return nil unless filename.kind_of?(String) @pattern_id.call(filename) end def self.pattern_id=(block) return if block.call("foo").nil? @pattern_id = block end class Grouper def self.group(globs) files = file_list_from_globs(globs) groups = {} return groups if files.empty? # Cycle through all files identified by the glob, then assign them to # the group matching their group ID. files.each do |filename| if should_include_file?(filename) identifier = Docks.pattern_id(filename) groups[identifier] ||= [] groups[identifier] << filename end end groups end def self.source_files_of_type(type) return @source_files_by_type[type] unless @source_files_by_type.nil? files = {} files[Docks::Types::Languages::MARKUP] = [] files[Docks::Types::Languages::STYLE] = [] files[Docks::Types::Languages::SCRIPT] = [] files[Docks::Types::Languages::STUB] = [] files[Docks::Types::Languages::DESCRIPTION] = [] file_list_from_globs(Docks.config.sources).each do |filename| files[Docks::Languages.file_type(filename)] << filename end @source_files_by_type = files @source_files_by_type[type] end private def self.should_include_file?(filename) Docks::Languages.extensions.include?(File.extname(filename)[1..-1]) && !filename.include?('.min.') end def self.file_list_from_globs(globs) Array(globs).map { |glob| Dir.glob(glob) }.flatten end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
docks_app-0.0.3 | lib/docks/group.rb |
docks_app-0.0.2 | lib/docks/group.rb |
docks_app-0.0.1 | lib/docks/group.rb |