lazibi 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.1.7 2007-06-18
2
+
3
+ * Bug fix: when .backup exists, code generation stops to work
4
+
1
5
  == 0.1.6 2007-06-18
2
6
 
3
7
  * Patched beautifier to support /\// style RE and %w() %w{}
data/README.txt CHANGED
@@ -1,10 +1,10 @@
1
1
  == Welcome to Lazibi
2
2
 
3
- Lazibi is a meta language which allows you to use Python like syntax ( tab-indented block ) in
4
- Ruby. It's backward compatible with plain Ruby if you indent your blocks properly.
3
+ Lazibi is a preprocessor that allows you to use Python style indenting in Ruby.
4
+ It tries to be backward compatible with plain Ruby if you like to indent your blocks properly.
5
5
 
6
6
  The idea is to edit .py.rb files in a meta directory and let the engine generates .rb files in
7
- the real directory for you.
7
+ the real directory for you in _real time_.
8
8
 
9
9
  == Examples
10
10
 
@@ -92,10 +92,13 @@ Start hacking ruby/python in meta :/
92
92
  - pattern_2
93
93
  - for_example_^vendor
94
94
 
95
+ == In Practice
96
+
97
+ 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 best using TDD.
98
+
95
99
  == Known issues
96
100
 
97
- Here document like long strings are likely to screw up code generation, try
98
- to indent long strings like the fix for rails
101
+ Here docs are likely to screw up code generation. Give them enough indent so they are treated like normal code inside current code block ;|
99
102
 
100
103
  == To Do
101
104
 
@@ -1,3 +1,7 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../vendor')
2
+
3
+ require 'beautifier'
4
+
1
5
  module Lazibi
2
6
  module ParserHelper
3
7
 
@@ -30,8 +34,8 @@ module Lazibi
30
34
  end
31
35
 
32
36
  def start_anchor?( str )
33
- str.gsub! /"[^"]+"|'[^']+'/, ''
34
37
  return false if str =~ /^#/
38
+ str = clean_line str
35
39
  return true if str =~ begin_keys
36
40
  end
37
41
 
@@ -42,5 +46,9 @@ module Lazibi
42
46
  def end_anchor?(str)
43
47
  str =~ end_keys
44
48
  end
49
+
50
+ def clean_line(line)
51
+ Beautifier::clean_line line
52
+ end
45
53
  end
46
54
  end
@@ -29,15 +29,5 @@ module Lazibi
29
29
  new_dir_name = to + dir_name[from.size..-1]
30
30
  new_path = File.join new_dir_name, base_name + new_ext
31
31
  end
32
-
33
-
34
- def get_metas
35
- meta_files = File.join('meta', "**", "*.py.rb")
36
- metas = {}
37
- Dir.glob(meta_files).each do |t|
38
- metas[t] = File.mtime t
39
- end
40
- metas
41
- end
42
32
  end
43
33
  end
@@ -2,7 +2,7 @@ module Lazibi #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 6
5
+ TINY = 7
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/lazibi.rb CHANGED
@@ -11,8 +11,9 @@ module Lazibi
11
11
  include Task
12
12
 
13
13
  def run
14
+ puts '-' * 40
14
15
  load_config
15
- init_meta unless File.exists? '.backup'
16
+ init_meta
16
17
  @metas = {}
17
18
  while true
18
19
  current_metas = get_metas
data/lib/task.rb CHANGED
@@ -32,6 +32,8 @@ module Lazibi
32
32
  if File.directory? real_dir
33
33
  backup_dir = '.backup'
34
34
  unless File.exists? backup_dir
35
+ puts "backup #{real_dir} to #{backup_dir}"
36
+ puts "-" * 40
35
37
  FileUtils.cp_r real_dir, backup_dir
36
38
  end
37
39
  else
@@ -40,6 +42,7 @@ module Lazibi
40
42
 
41
43
  # generate meta
42
44
  meta_dir = 'meta'
45
+ FileUtils.mkdir_p meta_dir
43
46
  if File.exists? meta_dir
44
47
  if File.directory? meta_dir
45
48
  FileUtils.rm_rf meta_dir
@@ -84,6 +87,8 @@ module Lazibi
84
87
  meta = open(meta_name)
85
88
  real_name = convert_path meta_name
86
89
  begin
90
+ real_path = File.dirname real_name
91
+ FileUtils.mkdir_p real_path
87
92
  real_rb = open( real_name, 'w' )
88
93
  real_rb.write(to_rb(meta.read))
89
94
  rescue Exception => e
@@ -93,5 +98,15 @@ module Lazibi
93
98
  end
94
99
  meta.close
95
100
  end
101
+
102
+
103
+ def get_metas
104
+ meta_files = File.join('meta', "**", "*.py.rb")
105
+ metas = {}
106
+ Dir.glob(meta_files).each do |t|
107
+ metas[t] = File.mtime t
108
+ end
109
+ metas
110
+ end
96
111
  end
97
112
  end
@@ -56,6 +56,25 @@ module Beautifier
56
56
  return line + "\n"
57
57
  end
58
58
 
59
+ def self.clean_line( tline )
60
+
61
+ # throw out sequences that will
62
+ # only sow confusion
63
+ tline.gsub!(/\/.*?[^\\]\//,"")
64
+ tline.gsub!(/%r\{.*?\}/,"")
65
+ tline.gsub!(/%r(.).*?\1/,"")
66
+ tline.gsub!(/\\\"/,"'")
67
+ tline.gsub!(/".*?"/,"\"\"")
68
+ tline.gsub!(/'.*?'/,"''")
69
+ tline.gsub!(/#\{.*?\}/,"")
70
+
71
+ # more ..
72
+ tline.gsub!(/%w\{[^\{]*?\}/, '')
73
+ tline.gsub!(/%w\([^(]*?\)/, '')
74
+
75
+ tline
76
+ end
77
+
59
78
  def self.ruby( source )
60
79
  commentBlock = false
61
80
  multiLineArray = Array.new
@@ -88,17 +107,7 @@ module Beautifier
88
107
  if(!commentLine)
89
108
  # throw out sequences that will
90
109
  # only sow confusion
91
- tline.gsub!(/\/.*?[^\\]\//,"")
92
- tline.gsub!(/%r\{.*?\}/,"")
93
- tline.gsub!(/%r(.).*?\1/,"")
94
- tline.gsub!(/\\\"/,"'")
95
- tline.gsub!(/".*?"/,"\"\"")
96
- tline.gsub!(/'.*?'/,"''")
97
- tline.gsub!(/#\{.*?\}/,"")
98
-
99
- # more ..
100
- tline.gsub!(/%w\{[^\{]*?\}/, '')
101
- tline.gsub!(/%w\([^(]*?\)/, '')
110
+ tline = clean_line(tline)
102
111
 
103
112
  $outdentExp.each do |re|
104
113
  if(tline =~ re)
data/test/test_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  $:.unshift(File.dirname(__FILE__))
2
2
  $:.unshift(File.dirname(__FILE__) + '/../lib')
3
+ $:.unshift(File.dirname(__FILE__) + '/../lib/vendor')
3
4
 
4
5
  require 'test/unit'
5
- require 'lazibi'
6
+ require 'lazibi'
7
+ require 'beautifier'
data/test/test_unit.rb CHANGED
@@ -9,9 +9,9 @@ class TestLazibi < Test::Unit::TestCase
9
9
  # load fixtures
10
10
  @meta = {}
11
11
  @real = {}
12
+ @clean = {}
12
13
 
13
14
  fixture_dir = File.dirname(__FILE__) + '/fixtures/meta'
14
-
15
15
  Dir.open(fixture_dir).each do |fn|
16
16
  next unless fn =~ /[.]txt$/
17
17
  @meta[fn.scan(/(.*)[.]/).to_s.to_sym] = File.read(fixture_dir + "/#{fn}")
@@ -22,6 +22,12 @@ class TestLazibi < Test::Unit::TestCase
22
22
  next unless fn =~ /[.]txt$/
23
23
  @real[fn.scan(/(.*)[.]/).to_s.to_sym] = File.read(expected_dir + "/#{fn}")
24
24
  end
25
+
26
+ clean_dir = File.dirname(__FILE__) + '/fixtures/clean'
27
+ Dir.open(clean_dir).each do |fn|
28
+ next unless fn =~ /[.]txt$/
29
+ @clean[fn.scan(/(.*)[.]/).to_s.to_sym] = File.read(clean_dir + "/#{fn}")
30
+ end
25
31
 
26
32
  @r = Lazibi::Runner.new
27
33
  end
@@ -70,6 +76,12 @@ class TestLazibi < Test::Unit::TestCase
70
76
  def test_to_py
71
77
  assert_to_py :inline_end
72
78
  end
79
+
80
+ def test_beauty
81
+ @clean.keys.each do |k|
82
+ assert_beauty k
83
+ end
84
+ end
73
85
 
74
86
 
75
87
  private
@@ -93,4 +105,8 @@ class TestLazibi < Test::Unit::TestCase
93
105
  def assert_identity( s )
94
106
  assert_equal @r.to_rb( @r.to_py( s ) ), s
95
107
  end
108
+
109
+ def assert_beauty( name )
110
+ assert_equal Beautifier::ruby(@real[name]), @clean[name], name
111
+ end
96
112
  end
data/website/index.html CHANGED
@@ -33,16 +33,16 @@
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.6</a>
36
+ <a href="http://rubyforge.org/projects/lazibi" class="numbers">0.1.7</a>
37
37
  </div>
38
38
  <p>
39
- Lazibi is a meta language which allows you to use Python like syntax (
40
- tab-indented block ) in Ruby. It&#8217;s backward compatible with plain
41
- Ruby if you indent your blocks properly.
39
+ Lazibi is a preprocessor that allows you to use Python style indenting in
40
+ Ruby. It tries to be backward compatible with plain Ruby if you like to
41
+ indent your blocks properly.
42
42
  </p>
43
43
  <p>
44
44
  The idea is to edit .py.rb files in a meta directory and let the engine
45
- generates .rb files in the real directory for you.
45
+ generates .rb files in the real directory for you in _real time_.
46
46
  </p>
47
47
  <h2>Examples</h2>
48
48
  <p>
@@ -148,10 +148,16 @@ Start hacking ruby/python in meta :/
148
148
  </pre>
149
149
  </li>
150
150
  </ul>
151
+ <h2>In Practice</h2>
152
+ <p>
153
+ Lazibi is written using Lazibi itself ( incrementally ). Personally I think
154
+ autotest from http://www.zenspider.com/ZSS/Products/ZenTest/ is a must
155
+ have, and Lazibi works best using TDD.
156
+ </p>
151
157
  <h2>Known issues</h2>
152
158
  <p>
153
- Here document like long strings are likely to screw up code generation, try
154
- to indent long strings like the fix for rails
159
+ Here docs are likely to screw up code generation. Give them enough indent
160
+ so they are treated like normal code inside current code block ;|
155
161
  </p>
156
162
  <h2>To Do</h2>
157
163
  <ul>
data/website/index.txt CHANGED
@@ -1,10 +1,10 @@
1
1
  == Welcome to Lazibi
2
2
 
3
- Lazibi is a meta language which allows you to use Python like syntax ( tab-indented block ) in
4
- Ruby. It's backward compatible with plain Ruby if you indent your blocks properly.
3
+ Lazibi is a preprocessor that allows you to use Python style indenting in Ruby.
4
+ It tries to be backward compatible with plain Ruby if you like to indent your blocks properly.
5
5
 
6
6
  The idea is to edit .py.rb files in a meta directory and let the engine generates .rb files in
7
- the real directory for you.
7
+ the real directory for you in _real time_.
8
8
 
9
9
  == Examples
10
10
 
@@ -92,10 +92,13 @@ Start hacking ruby/python in meta :/
92
92
  - pattern_2
93
93
  - for_example_^vendor
94
94
 
95
+ == In Practice
96
+
97
+ 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 best using TDD.
98
+
95
99
  == Known issues
96
100
 
97
- Here document like long strings are likely to screw up code generation, try
98
- to indent long strings like the fix for rails
101
+ Here docs are likely to screw up code generation. Give them enough indent so they are treated like normal code inside current code block ;|
99
102
 
100
103
  == To Do
101
104
 
metadata CHANGED
@@ -3,7 +3,7 @@ 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.6
6
+ version: 0.1.7
7
7
  date: 2007-06-18 00:00:00 +08:00
8
8
  summary: Python like syntax for Ruby
9
9
  require_paths: