lib/assetify/asset.rb in assetify-1.0.0.rc1 vs lib/assetify/asset.rb in assetify-1.0.0

- old
+ new

@@ -29,22 +29,25 @@ def filename return @filename if @filename @filename = "#{name}.#{ext}" end + def find_ext_for file + file.split(".").last[0,3] + end + + # + # Find correct path to put me + # def find_path_for txt case txt when /js/ then :javascripts when /css|style/ then :stylesheets else :images end end - def find_ext_for file - file.split(".").last[0,3] - end - def path args = if @to.empty? tpath = Opt[find_path_for(type)] raise "Don`t know where to put #{type} files..." unless tpath [tpath, @ns ? @ns.to_s : ""] @@ -60,26 +63,32 @@ def file_exists? File.exists? fullpath end - def print_version - return "" unless ver - ver_str = ver.size > 10 ? ver[0..10] : ver[0] - "v#{ver_str} " - end - def data # Get data, from a pkg or download directly @data ||= @pkg ? @pkg.get(url, :force).values.first : get_data(url) end + # + # Asset version + # def ver return nil unless @data @ver ||= find_version(@data) end + def print_version + return "" unless ver + ver_str = ver.size > 10 ? ver[0..10] : ver[0] + "v#{ver_str} " + end + + # + # Prints info about the asset (TODO: move this to cli...) + # def header LINE.p "-> #{name}.#{type}" end def check! @@ -90,10 +99,13 @@ else LINE.f "Not Found", :red end end + # + # Write down asset to disk + # def install!(force = false) header if !force && file_exists? # Return if file is on path @data = File.read(fullpath) return LINE.f "#{print_version}Installed" @@ -112,16 +124,20 @@ end end class << self - # Simple cache for Jsfile - def self.set_all v - @all = v + # + # Simple cache store, read Assetfile and dump it here to use. + # + def all + @all ||= Assetfile.read end - def self.all - @all + + def filter params + all.select { |a| "#{a.name}#{a.pkg}" =~ /#{params}/ } end + end end end