Class: Compressible::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/compressible/builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Builder

Returns a new instance of Builder.



9
10
11
# File 'lib/compressible/builder.rb', line 9

def initialize(*args, &block)
  instance_eval(&block) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/compressible/builder.rb', line 46

def method_missing(meth, *args, &block)
  if @context
    Compressible.send(@context, args, :to => [meth]) do |name, output|
      modify(name, output)
    end
  else
    super(meth, *args, &block)
  end
end

Class Method Details

.define!(*args, &block) ⇒ Object



4
5
6
# File 'lib/compressible/builder.rb', line 4

def define!(*args, &block)
  new(*args, &block)
end

Instance Method Details

#format(context = nil, &block) ⇒ Object

used to customize the output



26
27
28
29
30
31
32
# File 'lib/compressible/builder.rb', line 26

def format(context = nil, &block)
  if block_given?
    context ||= @context
    @format ||= {}
    @format[context] = block
  end
end

#javascript_path(value) ⇒ Object



21
22
23
# File 'lib/compressible/builder.rb', line 21

def javascript_path(value)
  Compressible.configure(:javascript_path => value)
end

#javascripts(&block) ⇒ Object



40
41
42
43
44
# File 'lib/compressible/builder.rb', line 40

def javascripts(&block)
  @context = "javascript"
  instance_eval(&block) if block_given?
  @context = nil
end

#read_only(value = true) ⇒ Object



13
14
15
# File 'lib/compressible/builder.rb', line 13

def read_only(value = true)
  Compressible.configure(:read_only => value)
end

#stylesheet_path(value) ⇒ Object



17
18
19
# File 'lib/compressible/builder.rb', line 17

def stylesheet_path(value)
  Compressible.configure(:stylesheet_path => value)
end

#stylesheets(&block) ⇒ Object



34
35
36
37
38
# File 'lib/compressible/builder.rb', line 34

def stylesheets(&block)
  @context = "stylesheet"
  instance_eval(&block) if block_given?
  @context = nil
end