lazibi 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -72,8 +72,8 @@ module Lazibi
72
72
  str =~ end_keys
73
73
  end
74
74
 
75
- def clean_line(line)
76
- Beautifier::clean_line line
75
+ def clean_line(line, leave_comment = false)
76
+ Beautifier::clean_line line, leave_comment
77
77
  end
78
78
 
79
79
  # why?
@@ -83,5 +83,10 @@ module Lazibi
83
83
  p = Regexp.new(s.join('|'))
84
84
  return line =~ p
85
85
  end
86
+
87
+ def comment_at_end(line)
88
+ return false if line.strip ==''
89
+ clean_line(line, true) =~ /#/
90
+ end
86
91
  end
87
92
  end
@@ -2,7 +2,7 @@ module Lazibi #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 10
5
+ TINY = 11
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/parser.rb CHANGED
@@ -14,9 +14,15 @@ module Lazibi
14
14
  if l.strip =~ /^end$/
15
15
  next
16
16
  end
17
+ l = remove_colon_at_end(l)
18
+
17
19
  s = l
18
- if l.rstrip[-4..-1] == ' end'
19
- s = l.rstrip[0...-3].rstrip
20
+ if comment_at_end(l)
21
+ s = s.sub(/(\s*;\s*end*\s*)(#.*)/, ' \2')
22
+ s = s.sub(/(\s+end*\s*)(#.*)/, ' \2')
23
+ else
24
+ s = s.sub(/\s+end\s*$/, '')
25
+ s = remove_colon_at_end(s)
20
26
  end
21
27
 
22
28
  py << s
@@ -26,6 +32,14 @@ module Lazibi
26
32
  end
27
33
 
28
34
 
35
+ def remove_colon_at_end(l)
36
+ if comment_at_end(l)
37
+ l.sub /(\s*;\s*)(#.*)/, ' \2'
38
+ else
39
+ l.sub /;*$/, ''
40
+ end
41
+ end
42
+
29
43
  def to_rb( content, filters = [] )
30
44
  return '' if content.strip == ''
31
45
  lines = content.split("\n")
@@ -53,7 +67,12 @@ module Lazibi
53
67
  break
54
68
  end
55
69
  index_for_end = relative_index_for_end + index
56
- lines[index_for_end] = lines[index_for_end] + "\n" + ' ' * get_indent(l) + "end"
70
+ if relative_index_for_end == 0 && !comment_at_end(l)
71
+ l = lines[index_for_end]
72
+ lines[index_for_end] = lines[index_for_end].rstrip + '; end'
73
+ else
74
+ lines[index_for_end] = lines[index_for_end] + "\n" + ' ' * get_indent(l) + "end"
75
+ end
57
76
  head = @lines[0...progress]
58
77
  tail = lines[index..-1].join("\n").split("\n")
59
78
  @lines = head + tail
@@ -65,7 +65,7 @@ module Beautifier
65
65
  # throw out sequences that will
66
66
  # only sow confusion
67
67
 
68
- tline = line.dup
68
+ tline = line.dup.sub /[;]*$/, ''
69
69
 
70
70
 
71
71
  tline.gsub!(/\/.*?[^\\]\//,"//")
@@ -0,0 +1,3 @@
1
+ class DevelopersProject; end;
2
+
3
+ class ManyToManyFixturesWithClassDefined < Test::Unit::TestCase
@@ -0,0 +1 @@
1
+ def #abc
@@ -1,3 +1,5 @@
1
1
  def abc
2
2
 
3
- def def abc end
3
+ def some def abc end
4
+
5
+ alias_method :proxy_extend, :extend
@@ -1,2 +1 @@
1
- class basic
2
- end
1
+ class basic; end
@@ -1,4 +1,3 @@
1
1
  class abc
2
- def
3
- end
2
+ def; end
4
3
  end
@@ -2,13 +2,10 @@ def a
2
2
  # comment
3
3
  end
4
4
 
5
- def b
6
- end
5
+ def b; end
7
6
 
8
7
  #comment
9
- def c
10
- end
8
+ def c; end
11
9
 
12
- def d
13
- end
10
+ def d; end
14
11
  #
@@ -0,0 +1 @@
1
+ def end #abc
@@ -0,0 +1,2 @@
1
+ def #abc
2
+ end
@@ -1,3 +1,5 @@
1
1
  def abc end
2
2
 
3
- def def abc end end
3
+ def some def abc end end
4
+
5
+ alias_method :proxy_extend, :extend
@@ -1,3 +1,2 @@
1
- def
2
- end
1
+ def; end
3
2
  end
@@ -0,0 +1,3 @@
1
+ class DevelopersProject; end;
2
+
3
+ class ManyToManyFixturesWithClassDefined < Test::Unit::TestCase
@@ -1,7 +1,5 @@
1
1
  class abc
2
- def a
3
- end
2
+ def a; end
4
3
 
5
- def b
6
- end
4
+ def b; end
7
5
  end
data/test/test_unit.rb CHANGED
@@ -65,7 +65,8 @@ class TestLazibiUnit < Test::Unit::TestCase
65
65
  end
66
66
 
67
67
  def test_convert_content
68
- @meta.keys.reject{|k| ['partial_method', 'inline_end', 'optional_do', 'eval_code', 'here_doc', 'single_method'].include? k.to_s }.each do |k|
68
+ @meta.keys.reject{|k| ['partial_method', 'inline_end', 'optional_do',
69
+ 'eval_code', 'here_doc', 'single_method', 'comment_after_end'].include? k.to_s }.each do |k|
69
70
  assert_convert k
70
71
  end
71
72
  end
@@ -74,10 +75,12 @@ class TestLazibiUnit < Test::Unit::TestCase
74
75
  assert_to_rb :partial_method
75
76
  # assert_to_rb :optional_do
76
77
  assert_to_rb :eval_code
78
+ assert_to_rb :comment_after_end, :comment_after_end_expected
77
79
  end
78
80
 
79
81
  def test_to_py
80
82
  assert_to_py :inline_end
83
+ assert_to_py :comment_after_end
81
84
  end
82
85
 
83
86
  def test_skip
@@ -102,17 +105,22 @@ class TestLazibiUnit < Test::Unit::TestCase
102
105
  end
103
106
 
104
107
 
108
+ def test_check_comment
109
+ assert @r.comment_at_end(' dab #abcd')
110
+ end
105
111
  private
106
112
  def assert_find( name, indent, end_i )
107
113
  assert_equal @r.find_end(@meta[name].split("\n"), indent), end_i
108
114
  end
109
115
 
110
- def assert_to_rb( name )
111
- assert_equal @r.to_rb( @meta[name]), @real[name], name
116
+ def assert_to_rb( name, name_2 = nil )
117
+ name_2 = name unless name_2
118
+ assert_equal @r.to_rb( @meta[name]), @real[name_2], name
112
119
  end
113
120
 
114
- def assert_to_py( name )
115
- assert_equal @r.to_py( @real[name]), @meta[name], name
121
+ def assert_to_py( name, name_2 = nil )
122
+ name_2 = name unless name_2
123
+ assert_equal @r.to_py( @real[name]), @meta[name_2], name
116
124
  end
117
125
 
118
126
  def assert_convert( name )
data/website/index.html CHANGED
@@ -33,7 +33,7 @@
33
33
  <h1>Welcome to Lazibi</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/lazibi"; return false'>
35
35
  <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/lazibi" class="numbers">0.1.10</a>
36
+ <a href="http://rubyforge.org/projects/lazibi" class="numbers">0.1.11</a>
37
37
  </div>
38
38
  <p>
39
39
  Lazibi is a preprocessor that allows you to use Python style indentation in
@@ -45,7 +45,7 @@ generates .rb files in the real directory for you in real time.
45
45
  </p>
46
46
  <h2>Examples</h2>
47
47
  <p>
48
- Sweeter RSpec
48
+ Sweeter RSpec [ Thanks Jay ]
49
49
  </p>
50
50
  <pre>
51
51
  describe Bowling
@@ -161,6 +161,18 @@ behavior by editing .lazibi config file.
161
161
  - etc
162
162
  </pre>
163
163
  </li>
164
+ <li>Personally I would not recommend using this filter outside the context of
165
+ RSpec
166
+
167
+ <ul>
168
+ <li>It&#8217;s not well tested
169
+
170
+ </li>
171
+ <li>Anything more complex then simple description will get unreadable
172
+
173
+ </li>
174
+ </ul>
175
+ </li>
164
176
  </ul>
165
177
  <h2>In Practice</h2>
166
178
  <p>
@@ -170,8 +182,15 @@ have, and Lazibi works pretty well using TDD.
170
182
  </p>
171
183
  <h2>Known issues</h2>
172
184
  <p>
173
- Here docs are likely to screw up code generation. Give them enough indent
174
- so they are treated like normal code inside current code block ;|
185
+ Here docs, eval, javascript related libs, and complex string evaluation are
186
+ currently not supported. Ruby code with above syntax will be preserved as
187
+ is. So your code should still works, just no parse. In other words, if you
188
+ don&#8217;t want your code to be parsed, simply add a dummy here doc
189
+ string&#8230;
190
+ </p>
191
+ <h2>Talk</h2>
192
+ <p>
193
+ http://groups.google.com/group/lazibi-talk
175
194
  </p>
176
195
  <h2>To Do</h2>
177
196
  <ul>
data/website/index.txt CHANGED
@@ -7,7 +7,7 @@ the real directory for you in real time.
7
7
 
8
8
  == Examples
9
9
 
10
- Sweeter RSpec
10
+ Sweeter RSpec [ Thanks Jay ]
11
11
 
12
12
  describe Bowling
13
13
  before(:each)
@@ -102,13 +102,22 @@ Start hacking in meta :/
102
102
  - ^test
103
103
  - etc
104
104
 
105
+ * Personally I would not recommend using this filter outside the context of RSpec
106
+ * It's not well tested
107
+ * Anything more complex then simple description will get unreadable
108
+
105
109
  == In Practice
106
110
 
107
111
  Lazibi is written using Lazibi itself ( incrementally ). Personally I think autotest from http://www.zenspider.com/ZSS/Products/ZenTest/ is a must have, and Lazibi works pretty well using TDD.
108
112
 
109
113
  == Known issues
110
114
 
111
- Here docs are likely to screw up code generation. Give them enough indent so they are treated like normal code inside current code block ;|
115
+ Here docs, eval, javascript related libs, and complex string evaluation are currently not supported.
116
+ Ruby code with above syntax will be preserved as is. So your code should still works, just no parse. In other words, if you don't want your code to be parsed, simply add a dummy here doc string...
117
+
118
+ == Talk
119
+
120
+ http://groups.google.com/group/lazibi-talk
112
121
 
113
122
  == To Do
114
123
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.3
3
3
  specification_version: 1
4
4
  name: lazibi
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.10
7
- date: 2007-06-20 00:00:00 +08:00
6
+ version: 0.1.11
7
+ date: 2007-06-21 00:00:00 +08:00
8
8
  summary: Python like syntax for Ruby
9
9
  require_paths:
10
10
  - lib
@@ -36,6 +36,13 @@ files:
36
36
  - README.txt
37
37
  - Rakefile
38
38
  - bin/lazibi
39
+ - coverage/index.html
40
+ - coverage/lib-helper-parser_helper_rb.html
41
+ - coverage/lib-helper-task_helper_rb.html
42
+ - coverage/lib-lazibi-version_rb.html
43
+ - coverage/lib-lazibi_rb.html
44
+ - coverage/lib-parser_rb.html
45
+ - coverage/lib-task_rb.html
39
46
  - lib/helper/app_helper.rb
40
47
  - lib/helper/parser_helper.rb
41
48
  - lib/helper/task_helper.rb
@@ -52,12 +59,14 @@ files:
52
59
  - test/fixtures/clean/mixed_re.txt
53
60
  - test/fixtures/clean/only_if.txt
54
61
  - test/fixtures/clean/re.txt
62
+ - test/fixtures/clean/semi_colon_after_end.txt
55
63
  - test/fixtures/clean/sep_line.txt
56
64
  - test/fixtures/clean/unless_problem.txt
57
65
  - test/fixtures/meta/basic_class.txt
58
66
  - test/fixtures/meta/case.txt
59
67
  - test/fixtures/meta/class_with_def.txt
60
68
  - test/fixtures/meta/comment.txt
69
+ - test/fixtures/meta/comment_after_end.txt
61
70
  - test/fixtures/meta/eval_code.txt
62
71
  - test/fixtures/meta/here_doc.txt
63
72
  - test/fixtures/meta/inline_end.txt
@@ -74,6 +83,8 @@ files:
74
83
  - test/fixtures/real/case.txt
75
84
  - test/fixtures/real/class_with_def.txt
76
85
  - test/fixtures/real/comment.txt
86
+ - test/fixtures/real/comment_after_end.txt
87
+ - test/fixtures/real/comment_after_end_expected.txt
77
88
  - test/fixtures/real/comment_break.txt
78
89
  - test/fixtures/real/end_concat.txt
79
90
  - test/fixtures/real/eval_code.txt
@@ -92,6 +103,7 @@ files:
92
103
  - test/fixtures/real/optional_do_with_nasty_chars.txt
93
104
  - test/fixtures/real/partial_method.txt
94
105
  - test/fixtures/real/re.txt
106
+ - test/fixtures/real/semi_colon_after_end.txt
95
107
  - test/fixtures/real/sep_line.txt
96
108
  - test/fixtures/real/single_method.txt
97
109
  - test/fixtures/real/strange_syntax_1.txt
@@ -123,12 +135,14 @@ extra_rdoc_files:
123
135
  - test/fixtures/clean/mixed_re.txt
124
136
  - test/fixtures/clean/only_if.txt
125
137
  - test/fixtures/clean/re.txt
138
+ - test/fixtures/clean/semi_colon_after_end.txt
126
139
  - test/fixtures/clean/sep_line.txt
127
140
  - test/fixtures/clean/unless_problem.txt
128
141
  - test/fixtures/meta/basic_class.txt
129
142
  - test/fixtures/meta/case.txt
130
143
  - test/fixtures/meta/class_with_def.txt
131
144
  - test/fixtures/meta/comment.txt
145
+ - test/fixtures/meta/comment_after_end.txt
132
146
  - test/fixtures/meta/eval_code.txt
133
147
  - test/fixtures/meta/here_doc.txt
134
148
  - test/fixtures/meta/inline_end.txt
@@ -145,6 +159,8 @@ extra_rdoc_files:
145
159
  - test/fixtures/real/case.txt
146
160
  - test/fixtures/real/class_with_def.txt
147
161
  - test/fixtures/real/comment.txt
162
+ - test/fixtures/real/comment_after_end.txt
163
+ - test/fixtures/real/comment_after_end_expected.txt
148
164
  - test/fixtures/real/comment_break.txt
149
165
  - test/fixtures/real/end_concat.txt
150
166
  - test/fixtures/real/eval_code.txt
@@ -163,6 +179,7 @@ extra_rdoc_files:
163
179
  - test/fixtures/real/optional_do_with_nasty_chars.txt
164
180
  - test/fixtures/real/partial_method.txt
165
181
  - test/fixtures/real/re.txt
182
+ - test/fixtures/real/semi_colon_after_end.txt
166
183
  - test/fixtures/real/sep_line.txt
167
184
  - test/fixtures/real/single_method.txt
168
185
  - test/fixtures/real/strange_syntax_1.txt