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 = nil, uri = nil, *params) ⇒ Object

Filter/validate DSL to parse



74
75
76
77
78
79
80
# File 'lib/assetify/dsl.rb', line 74

def method_missing method, name=nil, uri=nil, *params
  unless name && uri
    raise SyntaxError.new "Syntax Error on Assetfile. `#{method} :#{name}`"
  else
    parse_method method, name, uri, params
  end
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"


65
66
67
68
# File 'lib/assetify/dsl.rb', line 65

def a name, url, *params
  extension = url.split(".").last
  parse_method 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