Class: Deplate::Define

Inherits:
Region show all
Defined in:
lib/deplate/define.rb

Overview

Description:

Usage:

TODO:

CHANGES:

Defined Under Namespace

Modules: TemplateExpander Classes: Command, CommandNative, Element, Macro, MacroNative, Particle, Region

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Region

check_file, clean_strings, #deprecated_regnote, deprecated_regnote, #finish_accum, #format_compound, regions, register_as, set_line_cont, #setup

Methods inherited from Element

#join_lines, #join_lines_re_zh_cn

Class Method Details

.check_arguments(mandatory, args, source) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/deplate/define.rb', line 55

def check_arguments(mandatory, args, source)
    if mandatory
        diff = mandatory.split(/\s+/) - args.keys
        unless diff.empty?
            Deplate::Core.log(['Missing arguments', diff], :error, source)
        end
    end
end

.let_variables(deplate, args, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/deplate/define.rb', line 29

def let_variables(deplate, args, &block)
    unset = []
    saved = {}
    begin
        args.each do |key, val|
            if key.kind_of?(String)
                opt = deplate.variables[key]
                if opt
                    saved[key] = opt
                else
                    unset << key
                end
                deplate.variables[key] = val
            end
        end
        return block.call
    ensure
        unset.each do |key|
            deplate.variables.delete(key)
        end
        saved.each do |key, val|
            deplate.variables[key] = val
        end
    end
end

Instance Method Details

#finishObject



65
66
67
68
69
# File 'lib/deplate/define.rb', line 65

def finish
    finish_accum
    define
    return nil
end

#valid_id?(id) ⇒ Boolean

Returns:

  • (Boolean)


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

def valid_id?(id)
    if id =~ /\W/
        log(['Invalid ID', id], :error)
        return false
    else
        return true
    end
end

#valid_switch(arg, default) ⇒ Object



80
81
82
83
84
85
86
87
88
89
# File 'lib/deplate/define.rb', line 80

def valid_switch(arg, default)
    case arg
    when 'false', '0', 'F'
        'false'
    when 'true', '1', 'T'
        'true'
    else
        default
    end
end