Class: Deplate::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/deplate/converter.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formatter = "html", args = {}) ⇒ Converter

Returns a new instance of Converter.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/deplate/converter.rb', line 45

def initialize(formatter="html", args={})
    Deplate::Converter.setup
    @master            = args[:master]
    @options           = args[:options]
    @options         ||= @master.options.dup if @master
    @options         ||= Deplate::Core.deplate_options
    @options.fmt       = formatter
    @options.modules ||= args[:modules] || []
    Deplate::Core.require_standard(@options)
    if block_given?
        yield(self)
    end
    @deplate = Deplate::Core.new(formatter, :options => @options)
    vars   = args[:variables]
    vars ||= @master.variables.dup if @master
    @deplate.instance_eval {@variables = vars} if vars
    @formatter_method = "to_%s" % formatter.gsub(/[^[:alnum:]_]/, "_")
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



72
73
74
75
76
77
78
# File 'lib/deplate/converter.rb', line 72

def method_missing(method, *args, &block)
    if @deplate.respond_to?(method)
        @deplate.send(method, *args, &block)
    else
        super
    end
end

Class Attribute Details

.setup_doneObject (readonly)

Returns the value of attribute setup_done.



35
36
37
# File 'lib/deplate/converter.rb', line 35

def setup_done
  @setup_done
end

Instance Attribute Details

#deplateObject (readonly)

Returns the value of attribute deplate.



30
31
32
# File 'lib/deplate/converter.rb', line 30

def deplate
  @deplate
end

#optionsObject (readonly)

Returns the value of attribute options.



30
31
32
# File 'lib/deplate/converter.rb', line 30

def options
  @options
end

Class Method Details

.setupObject



37
38
39
40
41
42
# File 'lib/deplate/converter.rb', line 37

def setup
    unless @setup_done
        Deplate::Core.collect_standard
        @setup_done = true
    end
end

Instance Method Details

#convert_file(filename) ⇒ Object



68
69
70
# File 'lib/deplate/converter.rb', line 68

def convert_file(filename)
    @deplate.send(@formatter_method, nil, filename)
end

#convert_string(string) ⇒ Object



64
65
66
# File 'lib/deplate/converter.rb', line 64

def convert_string(string)
    @deplate.send(@formatter_method, string)
end