Class: Assetify::DSL

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

Overview

Nice Assetfile reader

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

Filter/validate DSL to parse



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

def method_missing(method, name = nil, uri = nil, *params)
  if name && uri
    parse_method method, name, uri, params
  else
    raise SyntaxError, "Syntax Error on Assetfile. `#{method} :#{name}`"
  end
end

Instance Attribute Details

#assetsObject (readonly)

Returns the value of attribute assets.



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

def assets
  @assets
end

Class Method Details

.parse(chunk) ⇒ Object

DSL.parse()



98
99
100
101
102
# File 'lib/assetify/dsl.rb', line 98

def self.parse(chunk)
  # puts "Assetify - Error Parsing 'Assetfile'."
  # Instance eval with 2nd, 3rd args to the rescue
  new.instance_eval(chunk, 'Assetfile', 1)
end

Instance Method Details

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

Global command, detects the filetype

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


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

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



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

def dir(regex, params = {})
  to = params[:to]
  if @pkg
    @pkg.get(regex).each do |path, _data|
      next if path =~ %r{/$} # 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



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

def group(name, &block)
  use_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



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

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