Class: Deplate::Command::INC

Inherits:
Deplate::Command show all
Defined in:
lib/deplate/commands.rb

Class Method Summary collapse

Methods inherited from Deplate::Command

commands, #finish, #format_special, #process, register_as, #setup, #setup_command, update_variables

Methods included from Names

name_match_c, name_match_fs, name_match_sf

Methods inherited from Element

#join_lines, #join_lines_re_zh_cn

Class Method Details

.accumulate(src, array, deplate, text, match, args, cmd) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/deplate/commands.rb', line 135

def accumulate(src, array, deplate, text, match, args, cmd)
    Deplate::Core.log("%s: %s" % [cmd, text], :debug, src)
    var  = args['var'] || args['var'] || args['val']
    if args.has_key?('file')
        if text
            Deplate::Core.log(['Conflicting arguments', 'file > @anonymous'], :error, src)
        end
        text = args['file']
    end
    args['INCLUDED'] = src.file
    vars         = swap_variables(deplate, args)
    input_format = args['inputFormat']
    pif          = deplate.push_input_format(input_format)

    begin
        if var
            strings = deplate.variables[var]
            if strings
                deplate.include_stringarray(strings, array, nil, src.file)
            else
                Deplate::Core.log(['Unknown doc variable', var], :error, src)
            end
        elsif !text or text == ''
            Deplate::Core.log(['Malformed command', cmd, text], :error, src)
        else
            fn = deplate.find_in_lib(text, :pwd => true)
            if fn
                deplate.include_file(array, fn, args)
            else
                Deplate::Core.log(['File not found', text], :error, src)
            end
        end
    ensure
        restore_variables(deplate, vars)
        deplate.pop_input_format(input_format) if pif
    end
end

.restore_variables(deplate, hash) ⇒ Object



197
198
199
200
201
202
203
204
205
206
# File 'lib/deplate/commands.rb', line 197

def restore_variables(deplate, hash)
    # deplate.variables = hash[:deplate]
    hash.each do |var, val|
        if val[:has_key]
            deplate.variables[var] = val[:value]
        else
            deplate.variables.delete(var)
        end
    end
end

.swap_variables(deplate, args, vars = {}) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/deplate/commands.rb', line 173

def swap_variables(deplate, args, vars={})
    # vars[:deplate] ||= deplate.variables.dup
    args.each do |var, val|
        case var
        when 'syntax'
            var = 'codeSyntax'
        when 'codeSyntax', 'embeddedTextRx', 'embeddedVerbatim'
        else
            if var[0..0] == '$'
                var = var[1..-1]
            else
                next
            end
        end
        has_key = deplate.variables.has_key?(var)
        vars[var] = {
            :has_key => has_key,
            :value => has_key ? deplate.variables[var] : nil,
        }
        deplate.variables[var] = val
    end
    vars
end