Class: Assetify::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/assetify/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, name, uri, *params) ⇒ Object

Parse the assets.

js “foo”, “foo.com” js “foo”, “foo.com”, :to => “/other/place”



66
67
68
69
70
71
72
# File 'lib/assetify/dsl.rb', line 66

def method_missing method, name, uri, *params
  params, ver = params.partition { |param| param.is_a?(Hash) }
  opts = {}
  params.each { |hsh| opts.merge! hsh }
  ver = ver[0]
  create_asset(method.to_sym, name, uri, ver, opts)
end

Instance Attribute Details

#assetsObject (readonly)

Returns the value of attribute assets.



4
5
6
# File 'lib/assetify/dsl.rb', line 4

def assets
  @assets
end

Instance Method Details

#a(name, url, *params) ⇒ Object Also known as: asset

Global command, detects the filetype

a "jquery", "http://...jquery.js"


79
80
81
82
# File 'lib/assetify/dsl.rb', line 79

def a name, url, *params
  extension = url.split(".").last
  send(extension, name, url)
end

#dir(regex, params = {}) ⇒ Object

Makes assets out of the entire directory

pkg :foo do

dir "images/*"
dir "images/*jpg"

end



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/assetify/dsl.rb', line 48

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
      create_asset(ext, name, path, nil, { :to => to } )
    end
  end
end

#group(name, &block) ⇒ Object

Makes a group, a namespace for the assets.

group :foo do end



31
32
33
34
35
36
37
38
# File 'lib/assetify/dsl.rb', line 31

def group name, &block
  set_namespace name
  instance_exec &block
  @ns = nil
  assets
ensure
  @ns = nil
end

#pkg(name, url, opts = {}, &block) ⇒ Object

Makes a pkg, a gz/tar/zip asset/

pkg :foo, “to.tgz” do end



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/assetify/dsl.rb', line 12

def pkg name, url, opts = {}, &block
  @pkg = Pkg.new name, url
  if block_given?
    set_namespace name unless opts[:shallow]
    instance_exec &block
  else
    @pkg.unpack_all
  end
  assets
ensure
  @ns = @pkg = nil
end