lazibi 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +44 -2
- data/History.txt +10 -1
- data/Manifest.txt +114 -91
- data/README.txt +4 -125
- data/Rakefile +20 -10
- data/config/lazibi_config_template.rb +15 -0
- data/lib/core/beautify_engine.rb +10 -0
- data/lib/core/default_engine.rb +11 -0
- data/lib/core/engine_base.rb +74 -0
- data/lib/filter/beautify_filter.rb +148 -0
- data/lib/filter/filter_base.rb +19 -0
- data/lib/filter/optional_do_filter.rb +66 -0
- data/lib/filter/optional_end_filter.rb +124 -0
- data/lib/filter/syntax_guard_filter.rb +77 -0
- data/lib/helper/application_helper.rb +9 -0
- data/lib/helper/beautify_filter_helper.rb +52 -0
- data/lib/helper/filter_helper.rb +133 -0
- data/lib/helper/task_helper.rb +53 -45
- data/lib/lazibi.rb +1 -4
- data/lib/lazibi/version.rb +1 -1
- data/lib/task.rb +41 -32
- data/spec/core/beautify_engine_spec.rb +12 -0
- data/spec/core/default_engine_spec.rb +28 -0
- data/spec/core/engine_base_spec.rb +23 -0
- data/spec/filter/beautify_filter_spec.rb +64 -0
- data/spec/filter/filter_spec_helper.rb +9 -0
- data/spec/filter/optional_do_filter_spec.rb +56 -0
- data/spec/filter/optional_end_filter_spec.rb +84 -0
- data/spec/filter/syntax_guard_filter_spec.rb +35 -0
- data/spec/fixtures/beautify/metas/square_brackets.txt +6 -0
- data/{test/fixtures/functional/ruby → spec/fixtures/beautify/rbs}/square_brackets.txt +1 -1
- data/{test → spec}/fixtures/clean/comment_break.txt +0 -0
- data/{test → spec}/fixtures/clean/complex_string.txt +0 -0
- data/{test → spec}/fixtures/clean/end_concat.txt +0 -0
- data/{test → spec}/fixtures/clean/long_indent.txt +0 -0
- data/{test → spec}/fixtures/clean/mixed_re.txt +0 -0
- data/{test → spec}/fixtures/clean/only_if.txt +0 -0
- data/{test → spec}/fixtures/clean/re.txt +0 -0
- data/{test → spec}/fixtures/clean/semi_colon_after_end.txt +0 -0
- data/{test → spec}/fixtures/clean/sep_line.txt +0 -0
- data/{test → spec}/fixtures/clean/unless_problem.txt +0 -0
- data/{test → spec}/fixtures/meta/basic_class.txt +0 -0
- data/{test → spec}/fixtures/meta/case.txt +0 -0
- data/{test → spec}/fixtures/meta/class_with_def.txt +0 -0
- data/{test → spec}/fixtures/meta/comment.txt +0 -0
- data/{test → spec}/fixtures/meta/comment_after_end.txt +0 -0
- data/{test → spec}/fixtures/meta/eval_code.txt +0 -0
- data/{test → spec}/fixtures/meta/here_doc.txt +0 -0
- data/{test → spec}/fixtures/meta/inline_do_end.txt +0 -0
- data/{test → spec}/fixtures/meta/inline_end.txt +0 -0
- data/{test → spec}/fixtures/meta/loop.txt +0 -0
- data/{test → spec}/fixtures/meta/middle.txt +0 -0
- data/{test → spec}/fixtures/meta/multi_blocks.txt +0 -0
- data/{test → spec}/fixtures/meta/nested_comment.txt +0 -0
- data/{test → spec}/fixtures/meta/optional_do.txt +0 -0
- data/{test → spec}/fixtures/meta/optional_do_with_nasty_chars.txt +0 -0
- data/{test → spec}/fixtures/meta/partial_method.txt +0 -0
- data/{test → spec}/fixtures/meta/single_method.txt +0 -0
- data/{test → spec}/fixtures/meta/two_methods.txt +0 -0
- data/{test/fixtures/functional/simply → spec/fixtures/optional_do/metas}/brackets_block.txt +0 -0
- data/{test/fixtures/functional/simply → spec/fixtures/optional_do/metas}/classical.txt +0 -0
- data/{test/fixtures/functional/simply → spec/fixtures/optional_do/metas}/describe.txt +0 -0
- data/{test/fixtures/functional/simply → spec/fixtures/optional_do/metas}/do_block.txt +0 -0
- data/{test/fixtures/functional/simply → spec/fixtures/optional_do/metas}/lambda.txt +0 -0
- data/{test/fixtures/functional/simply → spec/fixtures/optional_do/metas}/square_brackets.txt +2 -2
- data/{test/fixtures/functional/ruby → spec/fixtures/optional_do/rbs}/brackets_block.txt +0 -0
- data/{test/fixtures/functional/ruby → spec/fixtures/optional_do/rbs}/classical.txt +0 -0
- data/{test/fixtures/functional/ruby → spec/fixtures/optional_do/rbs}/describe.txt +0 -0
- data/{test/fixtures/functional/ruby → spec/fixtures/optional_do/rbs}/do_block.txt +0 -0
- data/{test/fixtures/functional/ruby → spec/fixtures/optional_do/rbs}/lambda.txt +0 -0
- data/spec/fixtures/optional_do/rbs/square_brackets.txt +6 -0
- data/{test → spec}/fixtures/real/basic_class.txt +0 -0
- data/{test → spec}/fixtures/real/case.txt +0 -0
- data/{test → spec}/fixtures/real/class_with_def.txt +0 -0
- data/{test → spec}/fixtures/real/comment.txt +0 -0
- data/{test → spec}/fixtures/real/comment_after_end.txt +0 -0
- data/{test → spec}/fixtures/real/comment_after_end_expected.txt +0 -0
- data/{test → spec}/fixtures/real/comment_break.txt +0 -0
- data/{test → spec}/fixtures/real/complex_string.txt +0 -0
- data/{test → spec}/fixtures/real/end_concat.txt +0 -0
- data/{test → spec}/fixtures/real/eval_code.txt +0 -0
- data/{test → spec}/fixtures/real/general_eval.txt +0 -0
- data/{test → spec}/fixtures/real/here_doc.txt +0 -0
- data/{test → spec}/fixtures/real/inline_do_end.txt +0 -0
- data/{test → spec}/fixtures/real/inline_end.txt +0 -0
- data/{test → spec}/fixtures/real/javascript.txt +0 -0
- data/{test → spec}/fixtures/real/long_indent.txt +0 -0
- data/{test → spec}/fixtures/real/loop.txt +0 -0
- data/{test → spec}/fixtures/real/middle.txt +0 -0
- data/{test → spec}/fixtures/real/mixed_re.txt +0 -0
- data/{test → spec}/fixtures/real/multi_blocks.txt +0 -0
- data/{test → spec}/fixtures/real/nested_comment.txt +0 -0
- data/{test → spec}/fixtures/real/only_if.txt +0 -0
- data/{test → spec}/fixtures/real/optional_do.txt +0 -0
- data/{test → spec}/fixtures/real/optional_do_with_nasty_chars.txt +0 -0
- data/{test → spec}/fixtures/real/partial_method.txt +0 -0
- data/{test → spec}/fixtures/real/re.txt +0 -0
- data/{test → spec}/fixtures/real/semi_colon_after_end.txt +0 -0
- data/{test → spec}/fixtures/real/sep_line.txt +0 -0
- data/{test → spec}/fixtures/real/single_method.txt +0 -0
- data/{test → spec}/fixtures/real/strange_syntax_1.txt +0 -0
- data/{test → spec}/fixtures/real/two_methods.txt +0 -0
- data/{test → spec}/fixtures/real/unless_problem.txt +0 -0
- data/spec/helper/filter_helper_spec.rb +35 -0
- data/spec/helper/task_helper_spec.rb +21 -0
- data/spec/lazibi_spec.rb +22 -0
- data/spec/spec_helper.rb +16 -0
- data/webgen/src/code/examples/migration.py.rb +10 -0
- data/webgen/src/code/examples/rspec.py.rb +7 -0
- data/webgen/src/css/blossom_base.css +172 -0
- data/webgen/src/css/blossom_v05.css +48 -0
- data/webgen/src/css/code.css +32 -0
- data/webgen/src/css/hack.css +13 -0
- data/webgen/src/css/print.css +178 -0
- data/webgen/src/default.template +90 -0
- data/webgen/src/development.page +19 -0
- data/webgen/src/documentation.page +44 -0
- data/webgen/src/faq.page +42 -0
- data/webgen/src/images/cover_landscape.jpg +0 -0
- data/webgen/src/images/example_picture03.jpg +0 -0
- data/webgen/src/images/example_picture04.jpg +0 -0
- data/webgen/src/index.page +45 -0
- data/webgen/src/installation.page +17 -0
- metadata +214 -175
- data/coverage/index.html +0 -476
- data/coverage/lib-helper-parser_helper_rb.html +0 -718
- data/coverage/lib-helper-task_helper_rb.html +0 -684
- data/coverage/lib-lazibi-version_rb.html +0 -640
- data/coverage/lib-lazibi_rb.html +0 -664
- data/coverage/lib-parser_rb.html +0 -787
- data/coverage/lib-task_rb.html +0 -751
- data/lib/helper/app_helper.rb +0 -0
- data/lib/helper/parser_helper.rb +0 -92
- data/lib/parser.rb +0 -194
- data/lib/vendor/beautifier.rb +0 -278
- data/test/test_functional.rb +0 -75
- data/test/test_helper.rb +0 -7
- data/test/test_unit.rb +0 -151
- data/website/index.html +0 -234
- data/website/index.txt +0 -135
- data/website/javascripts/rounded_corners_lite.inc.js +0 -285
- data/website/stylesheets/screen.css +0 -140
- data/website/template.rhtml +0 -48
@@ -0,0 +1,74 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../filter')
|
2
|
+
$:.unshift(File.dirname(__FILE__) + '/../helper')
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'active_support'
|
6
|
+
require 'application_helper'
|
7
|
+
|
8
|
+
module Lazibi
|
9
|
+
class EngineBase
|
10
|
+
include Helper::ApplicationHelper
|
11
|
+
|
12
|
+
attr :up_path
|
13
|
+
attr :down_path
|
14
|
+
attr :filters
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@filters = []
|
18
|
+
@up_path = []
|
19
|
+
@down_path = []
|
20
|
+
filter_dir = File.dirname(__FILE__) + '/../filter'
|
21
|
+
|
22
|
+
Dir.open(filter_dir).each do |fn|
|
23
|
+
next unless fn =~ /[.]rb$/
|
24
|
+
require fn
|
25
|
+
@filters << fn.scan(/(.*)[.]/).to_s.to_sym
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def go_up(*paths)
|
31
|
+
@up_path += Array(paths)
|
32
|
+
end
|
33
|
+
|
34
|
+
def go_down(*paths)
|
35
|
+
@down_path += Array(paths)
|
36
|
+
end
|
37
|
+
|
38
|
+
def up(source)
|
39
|
+
return source if source.blank?
|
40
|
+
transcript = source
|
41
|
+
valid = true
|
42
|
+
@up_path.each do |step|
|
43
|
+
class_name = step.to_s.camelize
|
44
|
+
filter = Filter.const_get(class_name).new
|
45
|
+
transcript = filter.up(transcript)
|
46
|
+
unless transcript
|
47
|
+
valid = false
|
48
|
+
break
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
valid ? transcript : skip_notice + "\n" + source
|
53
|
+
end
|
54
|
+
|
55
|
+
def down(source)
|
56
|
+
return source if source.blank?
|
57
|
+
transcript = source
|
58
|
+
if transcript.split("\n").first == skip_notice
|
59
|
+
return source.split("\n")[1..-1].join("\n")
|
60
|
+
end
|
61
|
+
|
62
|
+
@down_path.each do |step|
|
63
|
+
class_name = step.to_s.camelize
|
64
|
+
filter = Filter.const_get(class_name).new
|
65
|
+
transcript = filter.down(transcript)
|
66
|
+
end
|
67
|
+
transcript
|
68
|
+
end
|
69
|
+
|
70
|
+
def to_s
|
71
|
+
'up_path: ' + @up_path.to_s + "\n" + 'down_path: ' + @down_path.to_s
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# Ruby beautifier, version 1.3, 04/03/2006
|
2
|
+
# Copyright (c) 2006, P. Lutus
|
3
|
+
# TextMate modifications by T. Burks
|
4
|
+
# Released under the GPL
|
5
|
+
#
|
6
|
+
# Modified for lazibi filter by Jinjing
|
7
|
+
|
8
|
+
require 'filter_base'
|
9
|
+
require 'beautify_filter_helper'
|
10
|
+
|
11
|
+
module Lazibi
|
12
|
+
module Filter
|
13
|
+
class Beautify < FilterBase
|
14
|
+
include Helper::BeautifyFilterHelper
|
15
|
+
|
16
|
+
def make_tab(tab)
|
17
|
+
return (tab < 0) ? "": tab_str * tab_size * tab
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_line(line,tab)
|
21
|
+
line.strip!
|
22
|
+
line = make_tab(tab)+line if line.length > 0
|
23
|
+
return line + "\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
def join_sep_line( source )
|
27
|
+
lines = source.split("\n")
|
28
|
+
continue = false
|
29
|
+
buffer = ''
|
30
|
+
new_lines = []
|
31
|
+
for line in lines
|
32
|
+
if clean_line(line, true).strip =~ /#/
|
33
|
+
if continue
|
34
|
+
new_lines << buffer
|
35
|
+
new_lines << line
|
36
|
+
buffer = ''
|
37
|
+
else
|
38
|
+
new_lines << line
|
39
|
+
end
|
40
|
+
next
|
41
|
+
end
|
42
|
+
|
43
|
+
if continue
|
44
|
+
if line.strip == ''
|
45
|
+
continue = false
|
46
|
+
new_lines << buffer
|
47
|
+
new_lines << line
|
48
|
+
buffer = ''
|
49
|
+
elsif line.strip[-1..-1] == "\\"
|
50
|
+
continue = true
|
51
|
+
buffer += ' ' + line.strip[0...-1].strip
|
52
|
+
else
|
53
|
+
continue = false
|
54
|
+
buffer += ' ' + line.lstrip
|
55
|
+
new_lines << buffer
|
56
|
+
buffer = ''
|
57
|
+
end
|
58
|
+
else
|
59
|
+
if line.strip == ''
|
60
|
+
new_lines << line
|
61
|
+
elsif line.strip[-1..-1] == "\\"
|
62
|
+
continue = true
|
63
|
+
buffer += line.rstrip[0...-1].strip
|
64
|
+
else
|
65
|
+
new_lines << line
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
new_lines.join("\n")
|
71
|
+
end
|
72
|
+
|
73
|
+
def up( source )
|
74
|
+
source = split_end(source)
|
75
|
+
commentBlock = false
|
76
|
+
multiLineArray = Array.new
|
77
|
+
multiLineStr = ""
|
78
|
+
tab = 0
|
79
|
+
dest = ""
|
80
|
+
source.split("\n").each do |line|
|
81
|
+
# combine continuing lines
|
82
|
+
if(!(clean_line(line, true) =~ /\s*#/) && line =~ /[^\\]\\\s*$/)
|
83
|
+
multiLineArray.push line
|
84
|
+
multiLineStr += line.sub(/^(.*)\\\s*$/,"\\1")
|
85
|
+
next
|
86
|
+
end
|
87
|
+
|
88
|
+
# add final line
|
89
|
+
if(multiLineStr.length > 0)
|
90
|
+
multiLineArray.push line
|
91
|
+
multiLineStr += line.sub(/^(.*)\\\s*$/,"\\1")
|
92
|
+
end
|
93
|
+
|
94
|
+
tline = ((multiLineStr.length > 0)?multiLineStr:line).strip
|
95
|
+
if(tline =~ /^=begin/)
|
96
|
+
commentBlock = true
|
97
|
+
end
|
98
|
+
if(commentBlock)
|
99
|
+
# add the line unchanged
|
100
|
+
dest += line + "\n"
|
101
|
+
else
|
102
|
+
commentLine = (tline =~ /^#/)
|
103
|
+
if(!commentLine)
|
104
|
+
# throw out sequences that will
|
105
|
+
# only sow confusion
|
106
|
+
tline = clean_line(tline)
|
107
|
+
outdent_exp.each do |re|
|
108
|
+
if(tline =~ re)
|
109
|
+
tab -= 1
|
110
|
+
break
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
if (multiLineArray.length > 0)
|
115
|
+
first_line = true
|
116
|
+
multiLineArray.each do |ml|
|
117
|
+
if first_line
|
118
|
+
dest += add_line(ml,tab)
|
119
|
+
first_line = false
|
120
|
+
elsif ml.strip =~ /^unless/ || ml.strip =~ /^if/
|
121
|
+
dest = dest.chop.rstrip.chop.rstrip + ' ' + ml.strip + "\n"
|
122
|
+
else
|
123
|
+
dest += add_line(ml,tab)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
multiLineArray.clear
|
127
|
+
multiLineStr = ""
|
128
|
+
else
|
129
|
+
dest += add_line(line,tab)
|
130
|
+
end
|
131
|
+
if(!commentLine)
|
132
|
+
indent_exp.each do |re|
|
133
|
+
if(tline =~ re) && !(tline =~ /\s+end\s*$/)
|
134
|
+
tab += 1
|
135
|
+
break
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
if(tline =~ /^=end/)
|
141
|
+
commentBlock = false
|
142
|
+
end
|
143
|
+
end
|
144
|
+
dest
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../helper')
|
2
|
+
require 'filter_helper'
|
3
|
+
|
4
|
+
|
5
|
+
module Lazibi
|
6
|
+
module Filter
|
7
|
+
class FilterBase
|
8
|
+
include Helper::FilterHelper
|
9
|
+
|
10
|
+
def up(source)
|
11
|
+
source
|
12
|
+
end
|
13
|
+
|
14
|
+
def down(source)
|
15
|
+
source
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'filter_base'
|
2
|
+
|
3
|
+
module Lazibi
|
4
|
+
module Filter
|
5
|
+
class OptionalDo < FilterBase
|
6
|
+
def up(source)
|
7
|
+
lines = source.split("\n")
|
8
|
+
lines.each_index do |index|
|
9
|
+
l = lines[index]
|
10
|
+
l = optional_do_filter_to_py( lines, index )
|
11
|
+
lines[index] = l
|
12
|
+
end
|
13
|
+
lines.join "\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
def optional_do_filter_to_py(lines, index)
|
17
|
+
l = lines[index]
|
18
|
+
return l if l.strip == ''
|
19
|
+
return l if l.strip[0..0] == '#'
|
20
|
+
l_check = clean_line(l).strip
|
21
|
+
if l_check.size > 2 && l.strip[-3..-1] == ' do' && !nasty_line?(l_check)
|
22
|
+
l = l.rstrip[0...-3].rstrip
|
23
|
+
return l
|
24
|
+
end
|
25
|
+
return l
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def down(source)
|
30
|
+
lines = source.split("\n")
|
31
|
+
lines.each_index do |index|
|
32
|
+
l = lines[index]
|
33
|
+
l = optional_do_filter_to_rb(lines, index)
|
34
|
+
lines[index] = l
|
35
|
+
end
|
36
|
+
lines.join "\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
def optional_do_filter_to_rb(lines, index)
|
40
|
+
l = lines[index]
|
41
|
+
return l if l.strip == ''
|
42
|
+
return l if l =~ /[\{\[]\s*$/
|
43
|
+
rest = get_rest(l)
|
44
|
+
return l if start_anchor?(rest) || middle_anchor?(rest) || end_anchor?(rest)
|
45
|
+
|
46
|
+
l_check = clean_line l
|
47
|
+
next_line = ''
|
48
|
+
if index + 1 < lines.size
|
49
|
+
lines[index+1..-1].each_index do |i|
|
50
|
+
abs_i = index + 1 + i
|
51
|
+
next if lines[abs_i].strip == ''
|
52
|
+
next_line = lines[abs_i]
|
53
|
+
break
|
54
|
+
end
|
55
|
+
else
|
56
|
+
return l
|
57
|
+
end
|
58
|
+
if get_indent(next_line) > get_indent(l)
|
59
|
+
return l.rstrip + ' do'
|
60
|
+
else
|
61
|
+
return l
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'filter_base'
|
2
|
+
|
3
|
+
module Lazibi
|
4
|
+
module Filter
|
5
|
+
class OptionalEnd < FilterBase
|
6
|
+
|
7
|
+
def up( source )
|
8
|
+
rb = source
|
9
|
+
py = []
|
10
|
+
lines = rb.split("\n")
|
11
|
+
lines.each_index do |index|
|
12
|
+
l = lines[index]
|
13
|
+
if l.strip =~ /^end$/
|
14
|
+
next
|
15
|
+
end
|
16
|
+
l = remove_colon_at_end(l)
|
17
|
+
|
18
|
+
s = l
|
19
|
+
if comment_at_end(l)
|
20
|
+
s = s.sub(/(\s*;\s*end*\s*)(#.*)/, ' \2')
|
21
|
+
s = s.sub(/(\s+end*\s*)(#.*)/, ' \2')
|
22
|
+
else
|
23
|
+
s = s.sub(/\s+end\s*$/, '')
|
24
|
+
s = remove_colon_at_end(s)
|
25
|
+
end
|
26
|
+
|
27
|
+
py << s
|
28
|
+
end
|
29
|
+
|
30
|
+
py.join("\n")
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def remove_colon_at_end(l)
|
35
|
+
if comment_at_end(l)
|
36
|
+
l.sub /(\s*;\s*)(#.*)/, ' \2'
|
37
|
+
else
|
38
|
+
l.sub /;*$/, ''
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def down( source )
|
43
|
+
content = source
|
44
|
+
return '' if content.strip == ''
|
45
|
+
lines = content.split("\n")
|
46
|
+
first_line = lines.first.strip
|
47
|
+
return lines[1..-1].join("\n") if first_line == '#skip_parse'
|
48
|
+
insert_end content
|
49
|
+
end
|
50
|
+
|
51
|
+
def insert_end( content )
|
52
|
+
@lines = content.split("\n")
|
53
|
+
progress = 0
|
54
|
+
while progress < @lines.size
|
55
|
+
lines = @lines[progress..-1]
|
56
|
+
lines.each_index do |index|
|
57
|
+
l = lines[index]
|
58
|
+
safe_l = clean_block(clean_line(get_rest(l)))
|
59
|
+
if start_anchor? safe_l
|
60
|
+
relative_index_for_end = find_end( lines[index..-1], get_indent(l))
|
61
|
+
unless relative_index_for_end
|
62
|
+
progress += 1
|
63
|
+
break
|
64
|
+
end
|
65
|
+
index_for_end = relative_index_for_end + index
|
66
|
+
|
67
|
+
if relative_index_for_end == 0 && !comment_at_end(l)
|
68
|
+
#l = lines[index_for_end]
|
69
|
+
lines[index_for_end] = lines[index_for_end].rstrip + '; end'
|
70
|
+
else
|
71
|
+
lines[index_for_end] = lines[index_for_end] + "\n" + ' ' * get_indent(l) + "end"
|
72
|
+
end
|
73
|
+
head = @lines[0...progress]
|
74
|
+
tail = lines[index..-1].join("\n").split("\n")
|
75
|
+
|
76
|
+
@lines = head + tail
|
77
|
+
|
78
|
+
|
79
|
+
progress += 1
|
80
|
+
break
|
81
|
+
end
|
82
|
+
progress += 1
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
result = @lines.join("\n")
|
87
|
+
end
|
88
|
+
|
89
|
+
def find_end( lines, indent )
|
90
|
+
return 0 if lines.size == 1
|
91
|
+
|
92
|
+
anchor = 0
|
93
|
+
|
94
|
+
lines = lines[1..-1]
|
95
|
+
lines.each_index do |i|
|
96
|
+
l = lines[i]
|
97
|
+
next if l.strip == ''
|
98
|
+
if l.strip =~ /^#/
|
99
|
+
if get_indent(l) > indent
|
100
|
+
anchor = i + 1
|
101
|
+
end
|
102
|
+
next
|
103
|
+
end
|
104
|
+
return anchor if get_indent(l) < indent
|
105
|
+
if get_indent(l) == indent
|
106
|
+
rest = get_rest l
|
107
|
+
if start_anchor? rest
|
108
|
+
return anchor
|
109
|
+
elsif end_anchor? rest
|
110
|
+
return false
|
111
|
+
elsif middle_anchor? rest
|
112
|
+
anchor = i + 1
|
113
|
+
next
|
114
|
+
else
|
115
|
+
return anchor
|
116
|
+
end
|
117
|
+
end
|
118
|
+
anchor = i + 1
|
119
|
+
end
|
120
|
+
return anchor
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|