Class: Lazibi::Filter::SyntaxGuard
Instance Method Summary
collapse
Methods inherited from FilterBase
#down
#begin_keys, #clean_block, #clean_line, #comment_at_end, #end_anchor?, #end_keys, #get_indent, #get_rest, #group_match, #middle_anchor?, #middle_keys, #nasty_line?, #split_end, #start_anchor?
Instance Method Details
#here_doc?(line) ⇒ Boolean
16
17
18
|
# File 'lib/filter/syntax_guard_filter.rb', line 16
def here_doc?( line )
line =~ /(=\s*<<)|(<<-)/
end
|
#special_syntax(line) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/filter/syntax_guard_filter.rb', line 20
def special_syntax( line )
patterns = [
/:\[\]=/,
/\beval\b/,
/javascript_cdata/
]
for p in patterns
return true if line =~ p
end
false
end
|
#up(source) ⇒ Object
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
66
67
68
69
70
71
72
73
74
|
# File 'lib/filter/syntax_guard_filter.rb', line 38
def up( source )
source = split_end(source)
= false
multiLineStr = ""
source.split("\n").each do |line|
if(!(clean_line(line, true) =~ /\s*#/) && line =~ /[^\\]\\\s*$/)
multiLineStr += line.sub(/^(.*)\\\s*$/,"\\1")
next
end
if(multiLineStr.length > 0)
multiLineStr += line.sub(/^(.*)\\\s*$/,"\\1")
end
tline = ((multiLineStr.length > 0)?multiLineStr:line).strip
if(tline =~ /^=begin/)
= true
elsif !
= (tline =~ /^#/)
if(!)
valid_before = valid_before_clean?( tline )
tline = clean_line(tline)
unless ( valid?(tline) && valid_before )
puts '- ' + tline
return false
end
multiLineStr = ""
end
end
if(tline =~ /^=end/)
= false
end
end
return source
end
|
#using_eval?(line) ⇒ Boolean
12
13
14
|
# File 'lib/filter/syntax_guard_filter.rb', line 12
def using_eval?( line )
line =~ /\b(class|module|instance)_eval\b/
end
|
#valid?(line) ⇒ Boolean
7
8
9
10
|
# File 'lib/filter/syntax_guard_filter.rb', line 7
def valid?( line )
not_supported = using_eval?(line) || here_doc?(line) || special_syntax(line)
return !not_supported
end
|
#valid_before_clean?(line) ⇒ Boolean
33
34
35
36
|
# File 'lib/filter/syntax_guard_filter.rb', line 33
def valid_before_clean?( line )
r = line =~ /#\{[^\{]*#\{.*\}.*\}/
r.nil?
end
|