Class: Deplate::Region

Inherits:
Element show all
Defined in:
lib/deplate/regions.rb

Defined Under Namespace

Classes: SecondOrder

Constant Summary collapse

@@regions =
{}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Element

#join_lines, #join_lines_re_zh_cn

Class Method Details

.check_file(container, out, file, source) ⇒ 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
54
55
56
57
58
# File 'lib/deplate/regions.rb', line 29

def check_file(container, out, file, source)
    if Dir[out].empty?
        container.log(['Output not found', out, Dir.pwd])
        return false
    elsif file and source
        if File.exist?(file)
            accum = File.open(file) {|io| io.read}.split(/[\n\r]+/)
            clean_strings(accum)
            clean_strings(source)
            if accum === source
                container.log(['Output exists and source matches', file])
                return true
            else
                container.log(['Source has changed', file, accum.size, source.size])
                # p "DBG", accum, source
                # puts caller[0..10].join("\n")
                for i in 0..[accum.size, source.size].max
                    unless accum[i] === source[i]
                        container.log('%S != %S', [accum[i], source[i]])
                    end
                end
            end
        else
            container.log(['Source not found; assume that output is okay', file])
            return true
        end
    end
    container.log(['Output needs updating', file])
    return false
end

.clean_strings(strings) ⇒ Object



60
61
62
63
# File 'lib/deplate/regions.rb', line 60

def clean_strings(strings)
    strings.delete('')
    strings.each {|l| l.chomp!}
end

.deprecated_regnote(invoker, args, regNote, arg = '@note') ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/deplate/regions.rb', line 65

def deprecated_regnote(invoker, args, regNote, arg='@note')
    # if [email protected]_key?(arg) or (!@args[arg] and @regNote)
    if !args.has_key?(arg)
        if regNote and !regNote.empty?
            invoker.log(['Deprecated region syntax: Use argument instead', arg, regNote]
                        # , :anyway
                       )
            # puts caller[0..10].join("\n")
        end
        args[arg] = regNote
    end
    args[arg]
end

.regionsObject



17
18
19
# File 'lib/deplate/regions.rb', line 17

def regions
    @@regions
end

.register_as(name, c = self) ⇒ Object



21
22
23
# File 'lib/deplate/regions.rb', line 21

def register_as(name, c=self)
    @@regions[name] = self
end

.set_line_cont(val = true) ⇒ Object



25
26
27
# File 'lib/deplate/regions.rb', line 25

def set_line_cont(val=true)
    self.line_cont=val
end

Instance Method Details

#deprecated_regnote(arg = '@note') ⇒ Object



128
129
130
# File 'lib/deplate/regions.rb', line 128

def deprecated_regnote(arg='@note')
    Deplate::Region.deprecated_regnote(self, @args, @regNote, arg)
end

#finishObject



105
106
107
108
# File 'lib/deplate/regions.rb', line 105

def finish
    finish_accum
    return super
end

#finish_accumObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/deplate/regions.rb', line 89

def finish_accum
    if @region
        unify_now(@region)
        @regNote = @region.regNote ? @region.regNote.strip : ''
        @accum   = @region.accum
    else
        @regNote = ''
    end
    if defined?(@indent)
        rx = /^#{@indent}/
        @accum.each do |l|
            l.gsub!(rx, "")
        end
    end
end

#format_compoundObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/deplate/regions.rb', line 110

def format_compound
    acc = []
    prototype = @expected || @prototype.class
    for e in @elt
        e.match_expected(prototype, self) # if prototype
        # e.doc_type = doc_type
        # e.doc_slot = doc_slot
        acc << e.format_contained(self)
    end
    fmt = self.class.formatter2 || self.class.formatter
    if fmt
        @elt = @deplate.formatter.join_blocks(acc)
        return format_contained(self, fmt)
    else
        return @deplate.formatter.join_blocks(acc)
    end
end

#setup(region = nil) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/deplate/regions.rb', line 81

def setup(region=nil)
    if region
        @region = region
        @args.merge!(region.args)
        update_args
    end
end