lazibi 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,15 @@
1
+ == 0.1.10 2007-06-20
2
+
3
+ * A taste of RSpec
4
+ * do is optional _only_ in spec directory, so you can write something like
5
+ describe Bowling
6
+ before(:each)
7
+ @bowling = Bowling.new
8
+
9
+ it "should score 0 for gutter game"
10
+ 20.times { @bowling.hit(0) }
11
+ @bowling.score.should == 0
12
+
1
13
  == 0.1.9 2007-06-19
2
14
 
3
15
  * Using rails as a regression test code base is rewarding
data/Manifest.txt CHANGED
@@ -66,6 +66,7 @@ test/fixtures/real/single_method.txt
66
66
  test/fixtures/real/strange_syntax_1.txt
67
67
  test/fixtures/real/two_methods.txt
68
68
  test/fixtures/real/unless_problem.txt
69
+ test/test_functional.rb
69
70
  test/test_helper.rb
70
71
  test/test_unit.rb
71
72
  website/index.html
data/README.txt CHANGED
@@ -7,6 +7,16 @@ the real directory for you in real time.
7
7
 
8
8
  == Examples
9
9
 
10
+ Sweeter RSpec
11
+
12
+ describe Bowling
13
+ before(:each)
14
+ @bowling = Bowling.new
15
+
16
+ it "should score 0 for gutter game"
17
+ 20.times { @bowling.hit(0) }
18
+ @bowling.score.should == 0
19
+
10
20
  More DIY Rails controller
11
21
 
12
22
  class AuctionsController < ApplicationController
@@ -78,9 +88,19 @@ Start hacking in meta :/
78
88
  * Create .lazibi in project/real path
79
89
 
80
90
  exclude:
81
- - pattern_1
82
- - pattern_2
83
- - for_example_^vendor
91
+ - ^vendor
92
+ - ^tmp
93
+ - etc
94
+
95
+ === RSpec taste
96
+
97
+ * Optional do is only enabled for spec directory. You can customize this behavior by editing .lazibi config file.
98
+
99
+ filters:
100
+ optional_do:
101
+ - ^spec
102
+ - ^test
103
+ - etc
84
104
 
85
105
  == In Practice
86
106
 
@@ -92,7 +112,7 @@ Here docs are likely to screw up code generation. Give them enough indent so the
92
112
 
93
113
  == To Do
94
114
 
95
- * Targeting Rspec
115
+ * Maybe a custom filter for RSpec runner? Still learning though...
96
116
  * Two way sync between real and meta
97
117
 
98
118
  == Author
@@ -76,7 +76,9 @@ module Lazibi
76
76
  Beautifier::clean_line line
77
77
  end
78
78
 
79
+ # why?
79
80
  def nasty_line?(line)
81
+ return false
80
82
  s = %w! \/ ' " \( \{ \[ !
81
83
  p = Regexp.new(s.join('|'))
82
84
  return line =~ p
@@ -4,8 +4,7 @@ module Lazibi
4
4
  def skip_path?(path)
5
5
  return false if @config[:exclude].nil?
6
6
  @config[:exclude].each do |f|
7
- offset = 'meta'.size + 1
8
- return true if path[offset..-1] =~ Regexp.new(f)
7
+ return true if original_path(path) =~ Regexp.new(f)
9
8
  end
10
9
  false
11
10
  end
@@ -29,5 +28,26 @@ module Lazibi
29
28
  new_dir_name = to + dir_name[from.size..-1]
30
29
  new_path = File.join new_dir_name, base_name + new_ext
31
30
  end
31
+
32
+ def get_filters(path)
33
+ filters = @config[:filters]
34
+ return unless filters
35
+ path_filters = []
36
+ for filter in filters.keys
37
+ path_patterns = filters[filter]
38
+ for p in path_patterns
39
+ if original_path(path) =~ Regexp.new(p)
40
+ path_filters << filter.to_sym
41
+ next
42
+ end
43
+ end
44
+ end
45
+ path_filters
46
+ end
47
+
48
+ def original_path(path)
49
+ offset = 'meta'.size + 1
50
+ path[offset..-1]
51
+ end
32
52
  end
33
53
  end
@@ -2,7 +2,7 @@ module Lazibi #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 9
5
+ TINY = 10
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/lazibi.rb CHANGED
@@ -9,10 +9,12 @@ module Lazibi
9
9
  class Runner
10
10
  include Parser
11
11
  include Task
12
+ attr :config
12
13
 
13
14
  def run
14
15
  puts '-' * 40
15
16
  load_config
17
+ #load_config
16
18
  init_meta
17
19
  @metas = {}
18
20
  while true
data/lib/parser.rb CHANGED
@@ -6,11 +6,11 @@ module Lazibi
6
6
  module Parser
7
7
  include ParserHelper
8
8
 
9
- def to_py( rb )
9
+ def to_py( rb, filters = [] )
10
10
  py = []
11
11
  lines = rb.split("\n")
12
12
  lines.each_index do |index|
13
- l = filter_for_to_py(lines, index)
13
+ l = filter_for_to_py(lines, index, filters)
14
14
  if l.strip =~ /^end$/
15
15
  next
16
16
  end
@@ -26,25 +26,25 @@ module Lazibi
26
26
  end
27
27
 
28
28
 
29
- def to_rb( content )
29
+ def to_rb( content, filters = [] )
30
30
  return '' if content.strip == ''
31
31
  lines = content.split("\n")
32
32
  first_line = lines.first.strip
33
33
  return lines[1..-1].join("\n") if first_line == '#skip_parse'
34
- insert_end content
34
+ insert_end content, filters
35
35
  end
36
36
 
37
37
 
38
38
  # private
39
39
 
40
- def insert_end( content )
40
+ def insert_end( content, filters )
41
41
  @lines = content.split("\n")
42
42
  progress = 0
43
43
  while progress < @lines.size
44
44
  lines = @lines[progress..-1]
45
45
  lines.each_index do |index|
46
46
  # run through filters
47
- l = filter_for_to_rb(lines, index)
47
+ l = filter_for_to_rb(lines, index, filters)
48
48
 
49
49
  if start_anchor?(get_rest(l))
50
50
  relative_index_for_end = find_end( lines[index..-1], get_indent(l))
@@ -86,9 +86,9 @@ module Lazibi
86
86
  if get_indent(l) == indent
87
87
  rest = get_rest l
88
88
  if start_anchor? rest
89
- return anchor
89
+ return anchor
90
90
  elsif end_anchor? rest
91
- return false
91
+ return false
92
92
  elsif middle_anchor? rest
93
93
  anchor = i + 1
94
94
  next
@@ -101,22 +101,23 @@ module Lazibi
101
101
  return anchor
102
102
  end
103
103
 
104
- def filter_for_to_rb(lines, index)
104
+ def filter_for_to_rb(lines, index, filters)
105
105
  l = lines[index]
106
+ if filters.include?( :optional_do )
107
+ l = optional_do_filter_to_rb(lines, index)
108
+ end
106
109
 
107
- # maybe do is a good thing .....
108
- return l
110
+ # destructive behaviour
111
+ lines[index] = l
112
+ l
113
+ end
109
114
 
115
+ def optional_do_filter_to_rb(lines, index)
116
+ l = lines[index]
110
117
  return l if l.strip == ''
111
118
  rest = get_rest l
112
119
  return l if start_anchor?(rest) || middle_anchor?(rest) || end_anchor?(rest)
113
- l = add_do(l, lines, index)
114
120
 
115
- # also change the original array
116
- lines[index] = l
117
- end
118
-
119
- def add_do(l, lines, index)
120
121
  l_check = clean_line l
121
122
  return l if nasty_line?(l_check)
122
123
  next_line = index + 1 < lines.size ? lines[index+1] : nil
@@ -129,18 +130,25 @@ module Lazibi
129
130
  end
130
131
 
131
132
 
132
- def filter_for_to_py(lines, index)
133
+ def filter_for_to_py(lines, index, filters)
133
134
  l = lines[index]
135
+ if filters.include?( :optional_do )
136
+ l = optional_do_filter_to_py( lines, index )
137
+ end
134
138
 
135
- # same
136
- return l
137
- l = remove_do(l, lines, index)
139
+ # destructive behaviour
140
+ lines[index] = l
141
+ l
138
142
  end
139
143
 
140
- def remove_do(l, lines, index)
144
+ def optional_do_filter_to_py(lines, index)
145
+ l = lines[index]
146
+ return l if l.strip == ''
147
+ return l if l.strip[0..0] == '#'
141
148
  l_check = clean_line(l).strip
142
- if l_check.size > 3 && l.strip[-3..-1] == ' do' && !nasty_line?(l_check)
143
- return l.rstrip[0...-3].rstrip
149
+ if l_check.size > 2 && l.strip[-3..-1] == ' do' && !nasty_line?(l_check)
150
+ l = l.rstrip[0...-3].rstrip
151
+ return l
144
152
  end
145
153
  return l
146
154
  end
data/lib/task.rb CHANGED
@@ -10,9 +10,11 @@ module Lazibi
10
10
 
11
11
  def load_config
12
12
  @config = {}
13
- default = {:exclude => ['^vendor']}
14
- if File.exists? '.lazibi'
15
- f = open '.lazibi'
13
+ default = {:exclude => ['^vendor'], :filters => {:optional_do => ['^spec']}}
14
+ config_path = File.join('real','.lazibi')
15
+ if File.exists? config_path
16
+ puts 'loading .lazibi config'
17
+ f = open config_path
16
18
  h = YAML.load(f)
17
19
  for k in h.keys
18
20
  begin
@@ -21,11 +23,11 @@ module Lazibi
21
23
  raise "wrong pattern #{h[k]}"
22
24
  end
23
25
  end
26
+ else
27
+ @config = default
24
28
  end
25
- @config = default
26
29
  end
27
30
 
28
-
29
31
  def init_meta
30
32
  # backup real
31
33
  real_dir = 'real'
@@ -79,7 +81,7 @@ module Lazibi
79
81
  py_file = open(py_path, 'w')
80
82
  new_rb = Beautifier::ruby rb if beautify
81
83
  if new_rb
82
- py = to_py(new_rb)
84
+ py = to_py(new_rb, filters = get_filters(py_path) )
83
85
  else
84
86
  py = SKIP + "\n" + rb
85
87
  end
@@ -89,14 +91,14 @@ module Lazibi
89
91
  end
90
92
 
91
93
 
92
- def update_rb( meta_name )
94
+ def update_rb( meta_name, filters = {} )
93
95
  meta = open(meta_name)
94
96
  real_name = convert_path meta_name
95
97
  begin
96
98
  real_path = File.dirname real_name
97
99
  FileUtils.mkdir_p real_path
98
100
  real_rb = open( real_name, 'w' )
99
- real_rb.write(to_rb(meta.read))
101
+ real_rb.write(to_rb(meta.read, get_filters(meta_name)))
100
102
  rescue Exception => e
101
103
  puts e
102
104
  ensure
@@ -47,8 +47,8 @@ module Beautifier
47
47
  /^[^\{]*\}/,
48
48
  /^[^\[]*\]/
49
49
  ]
50
-
51
-
50
+
51
+
52
52
 
53
53
  def self.makeTab(tab)
54
54
  return (tab < 0) ? "":$tabStr * $tabSize * tab
@@ -69,31 +69,31 @@ module Beautifier
69
69
 
70
70
 
71
71
  tline.gsub!(/\/.*?[^\\]\//,"//")
72
-
72
+
73
73
  tline.gsub!(/#\{.*?\}/,"")
74
74
  tline.gsub!(/\\\"/,"'")
75
75
  tline.gsub!(/".*?"/,"\"\"")
76
76
  tline.gsub!(/'.*?'/,"''")
77
-
77
+
78
78
  # more ..
79
79
  tline.gsub!(/%r\{.*?\}/, "''")
80
80
  tline.gsub!(/%r\(.*?\)/, "''")
81
81
  tline.gsub!(/%r\[.*?\]/, "''")
82
82
  tline.gsub!(/%r(.).*?\1/, "''")
83
-
83
+
84
84
  tline.gsub!(/%w\{.*?\}/, "''")
85
85
  tline.gsub!(/%w\(.*?\)/, "''")
86
86
  tline.gsub!(/%w\[.*?\]/, "''")
87
87
  tline.gsub!(/%w(.).*?\1/, "''")
88
-
89
-
88
+
89
+
90
90
  tline.gsub!(/%q\{.*?\}/, "''")
91
91
  tline.gsub!(/%q\(.*?\)/, "''")
92
92
  tline.gsub!(/%q\[.*?\]/, "''")
93
93
  tline.gsub!(/%q(.).*?\1/, "''")
94
-
95
94
 
96
-
95
+
96
+
97
97
  tline.gsub!(/#.*$/, '') unless leave_comment
98
98
 
99
99
  tline
@@ -136,7 +136,7 @@ module Beautifier
136
136
  new_lines << buffer
137
137
  new_lines << line
138
138
  buffer = ''
139
- elsif line.strip[-1..-1] == "\\"
139
+ elsif line.strip[-1..-1] == "\\"
140
140
  continue = true
141
141
  buffer += ' ' + line.strip[0...-1].strip
142
142
  else
@@ -148,7 +148,7 @@ module Beautifier
148
148
  else
149
149
  if line.strip == ''
150
150
  new_lines << line
151
- elsif line.strip[-1..-1] == "\\"
151
+ elsif line.strip[-1..-1] == "\\"
152
152
  continue = true
153
153
  buffer += line.rstrip[0...-1].strip
154
154
  else
@@ -160,7 +160,7 @@ module Beautifier
160
160
  new_lines.join("\n")
161
161
  end
162
162
 
163
-
163
+
164
164
  def self.valid?( line )
165
165
  not_supported = using_eval?(line) || here_doc?(line) || special_syntax(line)
166
166
  return !not_supported
@@ -183,16 +183,16 @@ module Beautifier
183
183
  for p in patterns
184
184
  return true if line =~ p
185
185
  end
186
-
186
+
187
187
  false
188
188
  end
189
-
189
+
190
190
  def self.valid_before_clean?( line )
191
191
  r = line =~ /#\{[^\{]*#\{.*\}.*\}/
192
192
  r.nil?
193
193
  end
194
194
 
195
-
195
+
196
196
  def self.ruby( source )
197
197
  invalid = false
198
198
  #source = join_sep_line(split_end(source))
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require 'pp'
3
+
4
+ class TestLazibiFunctional < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @r = Lazibi::Runner.new
8
+ @r.load_config
9
+ end
10
+
11
+ def test_config_load
12
+ assert @r.config[:exclude]
13
+ end
14
+
15
+ def test_exclude_option
16
+ assert @r.skip_path?('meta/vendor')
17
+ end
18
+
19
+ def test_optional_do_for_spec
20
+ filters = @r.get_filters('meta/spec')
21
+ assert filters.include?(:optional_do)
22
+ end
23
+
24
+ def test_spec_sample
25
+ assert_equal @r.to_py('it do', [:optional_do]), 'it'
26
+ assert_equal @r.to_rb("it\n abc", [:optional_do]), "it do\n abc\nend"
27
+ end
28
+
29
+ def test_no_spec_sample
30
+ assert_equal @r.to_py('it do' ), 'it do'
31
+ assert_equal @r.to_rb("it\n abc" ), "it\n abc"
32
+ end
33
+ end
data/test/test_unit.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
  require 'pp'
3
3
 
4
- class TestLazibi < Test::Unit::TestCase
4
+ class TestLazibiUnit < Test::Unit::TestCase
5
5
  attr :fixtures, :expected
6
6
 
7
7
  def setup
@@ -100,8 +100,8 @@ class TestLazibi < Test::Unit::TestCase
100
100
  assert_clean 'str.gsub(/([^ \/a-zA-Z0-9_.-])/n)', 'str.gsub(//n)'
101
101
  assert_clean '%r{\A#{Regexp.escape(expanded_root)}(/|\\)}', "''"
102
102
  end
103
-
104
-
103
+
104
+
105
105
  private
106
106
  def assert_find( name, indent, end_i )
107
107
  assert_equal @r.find_end(@meta[name].split("\n"), indent), end_i
@@ -131,7 +131,7 @@ class TestLazibi < Test::Unit::TestCase
131
131
  def assert_skip( name )
132
132
  assert_equal Beautifier::ruby(@real[name]), false, name
133
133
  end
134
-
134
+
135
135
  def assert_clean( line, exp )
136
136
  assert_equal Beautifier::clean_line( line ).to_s, exp, line
137
137
  end
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.9</a>
36
+ <a href="http://rubyforge.org/projects/lazibi" class="numbers">0.1.10</a>
37
37
  </div>
38
38
  <p>
39
39
  Lazibi is a preprocessor that allows you to use Python style indentation in
@@ -45,6 +45,18 @@ 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
49
+ </p>
50
+ <pre>
51
+ describe Bowling
52
+ before(:each)
53
+ @bowling = Bowling.new
54
+
55
+ it &quot;should score 0 for gutter game&quot;
56
+ 20.times { @bowling.hit(0) }
57
+ @bowling.score.should == 0
58
+ </pre>
59
+ <p>
48
60
  More DIY Rails controller
49
61
  </p>
50
62
  <pre>
@@ -130,9 +142,23 @@ Start hacking in meta :/
130
142
 
131
143
  <pre>
132
144
  exclude:
133
- - pattern_1
134
- - pattern_2
135
- - for_example_^vendor
145
+ - ^vendor
146
+ - ^tmp
147
+ - etc
148
+ </pre>
149
+ </li>
150
+ </ul>
151
+ <h3>RSpec taste</h3>
152
+ <ul>
153
+ <li>Optional do is only enabled for spec directory. You can customize this
154
+ behavior by editing .lazibi config file.
155
+
156
+ <pre>
157
+ filters:
158
+ optional_do:
159
+ - ^spec
160
+ - ^test
161
+ - etc
136
162
  </pre>
137
163
  </li>
138
164
  </ul>
@@ -149,7 +175,7 @@ so they are treated like normal code inside current code block ;|
149
175
  </p>
150
176
  <h2>To Do</h2>
151
177
  <ul>
152
- <li>Targeting Rspec
178
+ <li>Maybe a custom filter for RSpec runner? Still learning though&#8230;
153
179
 
154
180
  </li>
155
181
  <li>Two way sync between real and meta
@@ -167,7 +193,7 @@ Released under the MIT license (included)
167
193
  </p>
168
194
 
169
195
  <p class="coda">
170
- <a href="mailto:nfjinjing@gmail.com">Jinjing</a>, 19th June 2007<br>
196
+ <a href="mailto:nfjinjing@gmail.com">Jinjing</a>, 20th June 2007<br>
171
197
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
172
198
  </p>
173
199
  </div>
data/website/index.txt CHANGED
@@ -7,6 +7,16 @@ the real directory for you in real time.
7
7
 
8
8
  == Examples
9
9
 
10
+ Sweeter RSpec
11
+
12
+ describe Bowling
13
+ before(:each)
14
+ @bowling = Bowling.new
15
+
16
+ it "should score 0 for gutter game"
17
+ 20.times { @bowling.hit(0) }
18
+ @bowling.score.should == 0
19
+
10
20
  More DIY Rails controller
11
21
 
12
22
  class AuctionsController < ApplicationController
@@ -78,9 +88,19 @@ Start hacking in meta :/
78
88
  * Create .lazibi in project/real path
79
89
 
80
90
  exclude:
81
- - pattern_1
82
- - pattern_2
83
- - for_example_^vendor
91
+ - ^vendor
92
+ - ^tmp
93
+ - etc
94
+
95
+ === RSpec taste
96
+
97
+ * Optional do is only enabled for spec directory. You can customize this behavior by editing .lazibi config file.
98
+
99
+ filters:
100
+ optional_do:
101
+ - ^spec
102
+ - ^test
103
+ - etc
84
104
 
85
105
  == In Practice
86
106
 
@@ -92,7 +112,7 @@ Here docs are likely to screw up code generation. Give them enough indent so the
92
112
 
93
113
  == To Do
94
114
 
95
- * Targeting Rspec
115
+ * Maybe a custom filter for RSpec runner? Still learning though...
96
116
  * Two way sync between real and meta
97
117
 
98
118
  == Author
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.9
7
- date: 2007-06-19 00:00:00 +08:00
6
+ version: 0.1.10
7
+ date: 2007-06-20 00:00:00 +08:00
8
8
  summary: Python like syntax for Ruby
9
9
  require_paths:
10
10
  - lib
@@ -97,6 +97,7 @@ files:
97
97
  - test/fixtures/real/strange_syntax_1.txt
98
98
  - test/fixtures/real/two_methods.txt
99
99
  - test/fixtures/real/unless_problem.txt
100
+ - test/test_functional.rb
100
101
  - test/test_helper.rb
101
102
  - test/test_unit.rb
102
103
  - website/index.html
@@ -105,6 +106,7 @@ files:
105
106
  - website/stylesheets/screen.css
106
107
  - website/template.rhtml
107
108
  test_files:
109
+ - test/test_functional.rb
108
110
  - test/test_helper.rb
109
111
  - test/test_unit.rb
110
112
  rdoc_options: