Class: Assetify::DSL

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

Instance Attribute Summary collapse

Class Method 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

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



47
48
49
50
51
52
53
# File 'lib/assetify/dsl.rb', line 47

def method_missing method, name, uri, *params
  params, ver = params.partition { |param| param.is_a?(Hash) }
  opts = {:ns => @ns, :pkg => @pkg}
  params.each { |hsh| opts.merge! hsh }
  ver = ver[0]
  (@assets ||= []) << Asset.new(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

Class Method Details

.parse(io) ⇒ Object



57
58
59
# File 'lib/assetify/dsl.rb', line 57

def parse io
  new.instance_eval(io) #.assets
end

Instance Method Details

#dir(regex, to) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/assetify/dsl.rb', line 29

def dir regex, to
  to = to[: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 ||= []) << Asset.new(ext, name, path, nil, {
                                    :pkg => @pkg,
                                      :to => to})# h.split(".").last,                                        )
    end
  end
end

#group(name, &block) ⇒ Object



22
23
24
25
26
27
# File 'lib/assetify/dsl.rb', line 22

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

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



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

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
  end
  assets
end

#set_namespace(name) ⇒ Object



6
7
8
# File 'lib/assetify/dsl.rb', line 6

def set_namespace(name)
  @ns = @ns.nil? ? name : "#{@ns}/#{name}"
end