lib/assetify/dsl.rb in assetify-1.0.0 vs lib/assetify/dsl.rb in assetify-2.0.0

- old
+ new

@@ -1,10 +1,10 @@ module Assetify class DSL attr_reader :assets - + # # Makes a pkg, a gz/tar/zip asset/ # # pkg :foo, "http://to.tgz" do # end @@ -12,39 +12,49 @@ def pkg name, url, opts = {}, &block @pkg = Pkg.new name, url if block_given? set_namespace name unless opts[:shallow] instance_exec &block - @ns = @pkg = nil else - @pkg.unpack_to_vendor + @pkg.unpack_all end assets + ensure + @ns = @pkg = nil end # - # Makes a group, a namspace for the assets. + # Makes a group, a namespace for the assets. # # group :foo do # end # def group name, &block set_namespace name instance_exec &block @ns = nil assets + ensure + @ns = nil end - def dir regex, to - to = to[:to] + # + # Makes assets out of the entire directory + # + # pkg :foo do + # dir "images/*" + # dir "images/*jpg" + # end + # + def dir regex, params = {} + to = params[:to] if @pkg @pkg.get(regex).each do |path, data| next if path =~ /\/$/ # dont let dirs get in... ugly ext, *name = path.split(".").reverse name = name.reverse.join(".").split("/").last - @assets ||= [] - @assets << Asset.new(ext, name, path, nil, { :pkg => @pkg , :to => to } ) + create_asset(ext, name, path, nil, { :to => to } ) end end end # @@ -53,15 +63,14 @@ # js "foo", "http://foo.com" # js "foo", "http://foo.com", :to => "/other/place" # def method_missing method, name, uri, *params params, ver = params.partition { |param| param.is_a?(Hash) } - opts = {:ns => @ns, :pkg => @pkg} + opts = {} params.each { |hsh| opts.merge! hsh } ver = ver[0] - @assets ||= [] - @assets << Asset.new(method.to_sym, name, uri, ver, opts) + create_asset(method.to_sym, name, uri, ver, opts) end # # Global command, detects the filetype # @@ -69,20 +78,33 @@ # def a name, url, *params extension = url.split(".").last send(extension, name, url) end + alias :asset :a # - # Create Assetfile assets path setters + # Creates Assetfile assets path setters # # javascript "new/path" # ... Assetify::ASSETS.each do |asset| define_method asset do |path| Opt[asset] = path end end + + private + + # + # Helper to create asset with correct options + # + def create_asset(ext, name, path, ver, opts = {}) + opts.merge! ({pkg: @pkg, ns: @ns }) + @assets ||= [] + @assets << Asset.new(ext, name, path, ver, opts) + end + def set_namespace name @ns = @ns.nil? ? name : "#{@ns}/#{name}" end