Class: Deplate::Region

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

Overview

Description:

Usage:

TODO:

CHANGES:

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



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/deplate/regions.rb', line 36

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



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

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

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



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/deplate/regions.rb', line 72

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



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

def regions
    @@regions
end

.register_as(name, c = self) ⇒ Object



28
29
30
# File 'lib/deplate/regions.rb', line 28

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

.set_line_cont(val = true) ⇒ Object



32
33
34
# File 'lib/deplate/regions.rb', line 32

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

Instance Method Details

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



135
136
137
# File 'lib/deplate/regions.rb', line 135

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

#finishObject



112
113
114
115
# File 'lib/deplate/regions.rb', line 112

def finish
    finish_accum
    return super
end

#finish_accumObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/deplate/regions.rb', line 96

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



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/deplate/regions.rb', line 117

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_current
    end
    fmt = self.class.formatter2 || self.class.formatter
    if fmt
        @elt = @deplate.formatter.join_blocks(acc)
        return format_current(fmt)
    else
        return @deplate.formatter.join_blocks(acc)
    end
end

#setup(region = nil) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/deplate/regions.rb', line 88

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