Class: Minify::Parser

Inherits:
Object
  • Object
show all
Extended by:
MetaTools
Defined in:
lib/minify/parser/class_methods.rb,
lib/minify/parser/instance_methods.rb,
lib/minify/parser/registered_mime_types.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.indexObject (readonly)

Returns the value of attribute index.



6
7
8
# File 'lib/minify/parser/class_methods.rb', line 6

def index
  @index
end

Class Method Details

.call(mime_type, input) ⇒ Object

Parser.register



15
16
17
# File 'lib/minify/parser/class_methods.rb', line 15

def call(mime_type, input)
  send(@index[mime_type], input)
end

.register(mime_type, &blk) ⇒ Object



8
9
10
11
12
13
# File 'lib/minify/parser/class_methods.rb', line 8

def register(mime_type, &blk)
  mime_type = MIME::Types[mime_type].first unless mime_type.is_a?(MIME::Type)
  meth = mime_type.sub_type.gsub(/-/, "_").to_sym
  (@index ||= {})[mime_type.to_s] = meth
  meta_def(meth, &blk)
end

.use(*libs) ⇒ Object

Try to require multiple libraries and return the first library that exists and require it

Raises:

  • (LoadError)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/minify/parser/class_methods.rb', line 25

def use(*libs)
  lib = libs.find do |lib|
    result = begin
      r = require(lib)
      puts "r: #{r}"
      true
    rescue LoadError
      false
    end
    puts "result: #{result}"
    result
  end
  puts "lib: #{lib}"
  raise(LoadError, "no such files to load -- #{libs.join(", ")}") if lib.nil?
  
  lib
end