lazibi 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,5 +1,10 @@
1
1
  == 0.1.4 2007-06-15
2
2
 
3
+ * Use beautifier to pre-format ruby scripts
4
+ * Completely compatible with Rails projects now, no fix anymore :]
5
+
6
+ == 0.1.4 2007-06-15
7
+
3
8
  * Added case syntax support, with test case
4
9
 
5
10
  == 0.1.3 2007-06-14
data/Manifest.txt CHANGED
@@ -4,19 +4,29 @@ Manifest.txt
4
4
  README.txt
5
5
  Rakefile
6
6
  bin/lazibi
7
+ lib/helper/parser_helper.rb
8
+ lib/helper/task_helper.rb
7
9
  lib/lazibi.rb
8
10
  lib/lazibi/version.rb
11
+ lib/parser.rb
12
+ lib/task.rb
13
+ lib/vendor/beautifier.rb
14
+ scripts/rdoc2html
9
15
  scripts/txt2html
10
16
  test/fixtures/meta/basic_class.txt
17
+ test/fixtures/meta/case.txt
11
18
  test/fixtures/meta/class_with_def.txt
12
19
  test/fixtures/meta/comment.txt
20
+ test/fixtures/meta/inline_end.txt
13
21
  test/fixtures/meta/middle.txt
14
22
  test/fixtures/meta/nested_comment.txt
15
23
  test/fixtures/meta/partial_method.txt
16
24
  test/fixtures/meta/two_methods.txt
17
25
  test/fixtures/real/basic_class.txt
26
+ test/fixtures/real/case.txt
18
27
  test/fixtures/real/class_with_def.txt
19
28
  test/fixtures/real/comment.txt
29
+ test/fixtures/real/inline_end.txt
20
30
  test/fixtures/real/middle.txt
21
31
  test/fixtures/real/nested_comment.txt
22
32
  test/fixtures/real/partial_method.txt
data/README.txt CHANGED
@@ -63,22 +63,13 @@ Make sure everything still works
63
63
  cd shiny_project/real
64
64
  rake test / autotest
65
65
 
66
- Start hacking ruby/python :/
66
+ Start hacking ruby/python in meta :/
67
67
 
68
68
  cd shiny_project
69
69
  $your_editor meta
70
70
 
71
71
  == Tips
72
72
 
73
- === Rails fix
74
-
75
- After bootstrap, edit config/boot.py.rb in meta
76
-
77
- STDERR.puts %(Cannot find gem for Rails ~>#{version}.0:
78
- Install the missing gem with 'gem install -v=#{version} rails', or
79
- change environment.rb to define RAILS_GEM_VERSION with your desired version.
80
- )
81
-
82
73
  === Manually create meta files
83
74
 
84
75
  * Bootstrap your project as usual, just don't run lazibi
@@ -92,6 +83,14 @@ After bootstrap, edit config/boot.py.rb in meta
92
83
 
93
84
  * create .py.rb files in corresponding directories inside 'meta', .rb files will be created and updated in 'real' as usual
94
85
 
86
+ === Prevent certain directories from being parsed during bootstrap ( default is ^vendor )
87
+
88
+ * Create .lazibi in project/real path
89
+
90
+ exclude:
91
+ - pattern_1
92
+ - pattern_2
93
+ - for_example_^vendor
95
94
 
96
95
  == Known issues
97
96
 
data/bin/lazibi CHANGED
@@ -4,5 +4,5 @@ $:.unshift(File.dirname(__FILE__) + '/../lib')
4
4
 
5
5
  require 'lazibi'
6
6
 
7
- r = Lazibi::Lazibi.new
7
+ r = Lazibi::Runner.new
8
8
  r.run
@@ -0,0 +1,46 @@
1
+ module Lazibi
2
+ module ParserHelper
3
+
4
+ def get_indent( line )
5
+ line =~ /( *)/
6
+ $1.size
7
+ end
8
+
9
+ def get_rest( line )
10
+ line =~/( *)/
11
+ $'
12
+ end
13
+
14
+ def begin_keys
15
+ s = %w( module def class if begin for while unless do case )
16
+ m = ['\sdo\s*$|\sdo\s+(\|[^|]+\|)']
17
+ s.map!{|key| "^#{key}\\b"}
18
+
19
+ Regexp.new(s.concat(m).join('|'))
20
+ end
21
+
22
+ def middle_keys
23
+ s = %w( rescue else ensure elsif when )
24
+ s.map!{|key| "^#{key}\\b"}
25
+ Regexp.new(s.join('|'))
26
+ end
27
+
28
+ def end_keys
29
+ /^end\b/
30
+ end
31
+
32
+ def start_anchor?( str )
33
+ str.gsub! /"[^"]+"|'[^']+'/, ''
34
+ return false if str =~ /^#/
35
+ return true if str =~ begin_keys
36
+ end
37
+
38
+ def middle_anchor?( str )
39
+ str =~ middle_keys
40
+ end
41
+
42
+ def end_anchor?(str)
43
+ str =~ end_keys
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,43 @@
1
+ module Lazibi
2
+ module TaskHelper
3
+
4
+ def skip_path?(path)
5
+ return false if @config[:exclude].nil?
6
+ @config[:exclude].each do |f|
7
+ offset = 'meta'.size + 1
8
+ return true if path[offset..-1] =~ Regexp.new(f)
9
+ end
10
+ false
11
+ end
12
+
13
+ def convert_path( path )
14
+ if path =~ /.*[.]py[.]rb/
15
+ from = 'meta'
16
+ to = 'real'
17
+ old_ext = '.py.rb'
18
+ new_ext = '.rb'
19
+ else
20
+ from = 'real'
21
+ to = 'meta'
22
+ old_ext = '.rb'
23
+ new_ext = '.py.rb'
24
+ end
25
+
26
+ dir_name = File.dirname path
27
+ base_name = File.basename path, old_ext
28
+
29
+ new_dir_name = to + dir_name[from.size..-1]
30
+ new_path = File.join new_dir_name, base_name + new_ext
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
+ end
43
+ end
@@ -2,7 +2,7 @@ module Lazibi #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 4
5
+ TINY = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/lazibi.rb CHANGED
@@ -1,276 +1,30 @@
1
1
  require 'fileutils'
2
2
  require 'find'
3
3
  require 'yaml'
4
+ require 'parser'
5
+ require 'task'
6
+ require 'lazibi/version'
4
7
 
5
8
  module Lazibi
6
- class Lazibi
7
- attr :config
8
-
9
- def load_config
10
- @config = {}
11
- default = {:exclude => ['^vendor']}
12
- if File.exists? '.lazibi'
13
- f = open '.lazibi'
14
- h = YAML.load(f)
15
- for k in h.keys
16
- begin
17
- @config[k.to_sym] = h[k]
18
- rescue
19
- raise "wrong pattern #{h[k]}"
20
- end
21
- end
22
- end
23
- @config = default
24
- end
25
-
26
-
27
- def init_meta
28
- # backup real
29
- real_dir = 'real'
30
- if File.directory? real_dir
31
- backup_dir = '.backup'
32
- unless File.exists? backup_dir
33
- FileUtils.cp_r real_dir, backup_dir
34
- end
35
- else
36
- raise 'No directory named "real"'
37
- end
38
-
39
- # generate meta
40
- meta_dir = 'meta'
41
- if File.exists? meta_dir
42
- if File.directory? meta_dir
43
- FileUtils.rm_rf meta_dir
44
- else
45
- raise 'meta directory is reserved for instiki'
46
- end
47
- end
48
-
49
-
50
- puts "Generating meta files:"
51
- puts "-" * 40
52
- Dir.glob(File.join('real', '**', '*.rb')) do |f|
53
- if skip_path? f
54
- puts "- #{f}"
55
- next
56
- end
57
-
58
- next unless File.file? f
59
- next if f =~ /.*[.]py[.]rb$/
60
- py_path = convert_path f
61
- dir_name = File.dirname py_path
62
-
63
- puts ' ' + py_path
64
- FileUtils.mkdir_p dir_name
65
- make_py f, py_path
66
- end
67
-
68
- puts "-" * 40
69
- end
70
-
71
-
72
- def skip_path?(path)
73
- return false if @config[:exclude].nil?
74
- @config[:exclude].each do |f|
75
- offset = 'meta'.size + 1
76
- return true if path[offset..-1] =~ Regexp.new(f)
77
- end
78
- false
79
- end
80
-
81
- def convert_path( path )
82
- if path =~ /.*[.]py[.]rb/
83
- from = 'meta'
84
- to = 'real'
85
- old_ext = '.py.rb'
86
- new_ext = '.rb'
87
- else
88
- from = 'real'
89
- to = 'meta'
90
- old_ext = '.rb'
91
- new_ext = '.py.rb'
92
- end
93
-
94
- dir_name = File.dirname path
95
- base_name = File.basename path, old_ext
9
+ class Runner
10
+ include Parser
11
+ include Task
96
12
 
97
- new_dir_name = to + dir_name[from.size..-1]
98
- new_path = File.join new_dir_name, base_name + new_ext
99
- end
100
-
101
- def make_py( rb_path, py_path )
102
- rb = open(rb_path).read
103
-
104
- py_file = open(py_path, 'w')
105
- py_file.write(to_py(rb))
106
- py_file.close
107
- end
108
-
109
- def to_py( rb )
110
- py = []
111
- rb.split("\n").each do |l|
112
- if l.strip =~ /^end$/
113
- next
114
- end
115
- s = l
116
- if l.rstrip[-4..-1] == ' end'
117
- s = l.rstrip[0...-3].rstrip
118
- end
119
-
120
- py << s
121
- end
122
-
123
- py.join("\n")
124
- end
125
-
126
-
127
13
  def run
128
- load_config
129
- init_meta unless File.exists? '.backup'
130
- @metas = {}
131
- while true
132
- current_metas = get_metas
133
- current_metas.each_pair do |meta, m_time|
134
- if @metas[meta] != m_time
135
- update_rb meta
136
- puts "+ #{meta}..."
137
- end
138
- end
139
- @metas = current_metas
140
- sleep 1
141
- end
142
- end
143
-
144
- def get_metas
145
- meta_files = File.join('meta', "**", "*.py.rb")
146
- metas = {}
147
- Dir.glob(meta_files).each do |t|
148
- metas[t] = File.mtime t
149
- end
150
- metas
151
- end
152
-
153
- def update_rb( meta_name )
154
- meta = open(meta_name)
155
- real_name = convert_path meta_name
156
- begin
157
- real_rb = open( real_name, 'w' )
158
- real_rb.write(to_rb(meta.read))
159
- rescue Exception => e
160
- puts e
161
- ensure
162
- real_rb.close unless real_rb.nil?
163
- end
164
- meta.close
165
- end
166
-
167
- def to_rb( content )
168
- insert_end content
169
- end
170
-
171
- def insert_end( content )
172
- @lines = content.split("\n")
173
- progress = 0
174
- while progress < @lines.size
175
- lines = @lines[progress..-1]
176
- lines.each_index do |index|
177
- l = lines[index]
178
- if start_anchor?(get_rest(l))
179
- relative_index_for_end = find_end( lines[index..-1], get_indent(l))
180
- unless relative_index_for_end
181
- progress += 1
182
- break
183
- end
184
- index_for_end = relative_index_for_end + index
185
- lines[index_for_end] = lines[index_for_end] + "\n" + ' ' * get_indent(l) + "end"
186
- head = @lines[0...progress]
187
- tail = lines[index..-1].join("\n").split("\n")
188
- @lines = head + tail
189
- progress += 1
190
- break
191
- end
192
- progress += 1
193
- end
194
- end
195
-
196
- result = @lines.join("\n")
197
- end
198
-
199
- def find_end( lines, indent )
200
- return 0 if lines.size == 1
201
-
202
- anchor = 0
203
-
204
- lines = lines[1..-1]
205
- lines.each_index do |i|
206
- l = lines[i]
207
- next if l.strip == ''
208
- if l.strip =~ /^#/
209
- if get_indent(l) > indent
210
- anchor = i + 1
211
- end
212
- next
213
- end
214
- return anchor if get_indent(l) < indent
215
- if get_indent(l) == indent
216
- rest = get_rest l
217
- if middle_anchor? rest
218
- anchor = i + 1
219
- next
220
- elsif end_anchor? rest
221
- return false
222
- else
223
- return anchor
224
- end
225
- end
226
- anchor = i + 1
227
- end
228
- return anchor
229
- end
230
-
231
- def get_indent( line )
232
- line =~ /( *)/
233
- $1.size
234
- end
235
-
236
- def get_rest( line )
237
- line =~/( *)/
238
- $'
239
- end
240
-
241
- def begin_keys
242
- s = %w( module def class if begin for while unless do case )
243
- m = ['\sdo\s*$|\sdo\s+(\|[^|]+\|)']
244
- s.map!{|key| "^#{key}\\b"}
245
-
246
- Regexp.new(s.concat(m).join('|'))
247
- end
248
-
249
-
250
-
251
- def middle_keys
252
- s = %w( rescue else ensure elsif when )
253
- s.map!{|key| "^#{key}\\b"}
254
- Regexp.new(s.join('|'))
255
- end
256
-
257
- def end_keys
258
- /^end\b/
259
- end
260
-
261
- def start_anchor?( str )
262
- str.gsub! /"[^"]+"|'[^']+'/, ''
263
- return false if str =~ /^#/
264
- return true if str =~ begin_keys
265
- end
266
-
267
- def middle_anchor?( str )
268
- str =~ middle_keys
269
- end
270
-
271
- def end_anchor?(str)
272
- str =~ end_keys
14
+ load_config
15
+ init_meta unless File.exists? '.backup'
16
+ @metas = {}
17
+ while true
18
+ current_metas = get_metas
19
+ current_metas.each_pair do |meta, m_time|
20
+ if @metas[meta] != m_time
21
+ update_rb meta
22
+ puts "+ #{meta}..."
23
+ end
24
+ end
25
+ @metas = current_metas
26
+ sleep 1
27
+ end
273
28
  end
274
29
  end
275
- end
276
- require 'lazibi/version'
30
+ end
data/lib/parser.rb ADDED
@@ -0,0 +1,93 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/helper')
2
+
3
+ require 'parser_helper'
4
+
5
+ module Lazibi
6
+ module Parser
7
+ include ParserHelper
8
+
9
+ def to_py( rb )
10
+ py = []
11
+ rb.split("\n").each do |l|
12
+ if l.strip =~ /^end$/
13
+ next
14
+ end
15
+ s = l
16
+ if l.rstrip[-4..-1] == ' end'
17
+ s = l.rstrip[0...-3].rstrip
18
+ end
19
+
20
+ py << s
21
+ end
22
+
23
+ py.join("\n")
24
+ end
25
+
26
+ def to_rb( content )
27
+ insert_end content
28
+ end
29
+
30
+
31
+ # private
32
+
33
+ def insert_end( content )
34
+ @lines = content.split("\n")
35
+ progress = 0
36
+ while progress < @lines.size
37
+ lines = @lines[progress..-1]
38
+ lines.each_index do |index|
39
+ l = lines[index]
40
+ if start_anchor?(get_rest(l))
41
+ relative_index_for_end = find_end( lines[index..-1], get_indent(l))
42
+ unless relative_index_for_end
43
+ progress += 1
44
+ break
45
+ end
46
+ index_for_end = relative_index_for_end + index
47
+ lines[index_for_end] = lines[index_for_end] + "\n" + ' ' * get_indent(l) + "end"
48
+ head = @lines[0...progress]
49
+ tail = lines[index..-1].join("\n").split("\n")
50
+ @lines = head + tail
51
+ progress += 1
52
+ break
53
+ end
54
+ progress += 1
55
+ end
56
+ end
57
+
58
+ result = @lines.join("\n")
59
+ end
60
+
61
+ def find_end( lines, indent )
62
+ return 0 if lines.size == 1
63
+
64
+ anchor = 0
65
+
66
+ lines = lines[1..-1]
67
+ lines.each_index do |i|
68
+ l = lines[i]
69
+ next if l.strip == ''
70
+ if l.strip =~ /^#/
71
+ if get_indent(l) > indent
72
+ anchor = i + 1
73
+ end
74
+ next
75
+ end
76
+ return anchor if get_indent(l) < indent
77
+ if get_indent(l) == indent
78
+ rest = get_rest l
79
+ if middle_anchor? rest
80
+ anchor = i + 1
81
+ next
82
+ elsif end_anchor? rest
83
+ return false
84
+ else
85
+ return anchor
86
+ end
87
+ end
88
+ anchor = i + 1
89
+ end
90
+ return anchor
91
+ end
92
+ end
93
+ end
data/lib/task.rb ADDED
@@ -0,0 +1,97 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/helper')
2
+ $:.unshift(File.dirname(__FILE__) + '/vendor')
3
+
4
+ require 'task_helper'
5
+ require 'beautifier'
6
+
7
+ module Lazibi
8
+ module Task
9
+ include TaskHelper
10
+
11
+ def load_config
12
+ @config = {}
13
+ default = {:exclude => ['^vendor']}
14
+ if File.exists? '.lazibi'
15
+ f = open '.lazibi'
16
+ h = YAML.load(f)
17
+ for k in h.keys
18
+ begin
19
+ @config[k.to_sym] = h[k]
20
+ rescue
21
+ raise "wrong pattern #{h[k]}"
22
+ end
23
+ end
24
+ end
25
+ @config = default
26
+ end
27
+
28
+
29
+ def init_meta
30
+ # backup real
31
+ real_dir = 'real'
32
+ if File.directory? real_dir
33
+ backup_dir = '.backup'
34
+ unless File.exists? backup_dir
35
+ FileUtils.cp_r real_dir, backup_dir
36
+ end
37
+ else
38
+ raise 'No directory named "real"'
39
+ end
40
+
41
+ # generate meta
42
+ meta_dir = 'meta'
43
+ if File.exists? meta_dir
44
+ if File.directory? meta_dir
45
+ FileUtils.rm_rf meta_dir
46
+ else
47
+ raise 'meta directory is reserved for instiki'
48
+ end
49
+ end
50
+
51
+
52
+ puts "Generating meta files:"
53
+ puts "-" * 40
54
+ Dir.glob(File.join('real', '**', '*.rb')) do |f|
55
+ if skip_path? f
56
+ puts "- #{f}"
57
+ next
58
+ end
59
+
60
+ next unless File.file? f
61
+ next if f =~ /.*[.]py[.]rb$/
62
+ py_path = convert_path f
63
+ dir_name = File.dirname py_path
64
+
65
+ puts ' ' + py_path
66
+ FileUtils.mkdir_p dir_name
67
+ make_py f, py_path, beautify = true
68
+ end
69
+
70
+ puts "-" * 40
71
+ end
72
+
73
+ def make_py( rb_path, py_path, beautify = false )
74
+ rb = open(rb_path).read
75
+
76
+ py_file = open(py_path, 'w')
77
+ rb = Beautifier::ruby rb if beautify
78
+ py_file.write(to_py(rb))
79
+ py_file.close
80
+ end
81
+
82
+
83
+ def update_rb( meta_name )
84
+ meta = open(meta_name)
85
+ real_name = convert_path meta_name
86
+ begin
87
+ real_rb = open( real_name, 'w' )
88
+ real_rb.write(to_rb(meta.read))
89
+ rescue Exception => e
90
+ puts e
91
+ ensure
92
+ real_rb.close unless real_rb.nil?
93
+ end
94
+ meta.close
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,135 @@
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
+ # Modified for lazibi by Jinjing
6
+
7
+ module Beautifier
8
+
9
+ $tabSize = 2
10
+ $tabStr = " "
11
+
12
+ # indent regexp tests
13
+
14
+ $indentExp = [
15
+ /^module\b/,
16
+ /(=\s*|^)if\b/,
17
+ /(=\s*|^)until\b/,
18
+ /(=\s*|^)for\b/,
19
+ /(=\s*|^)unless\b/,
20
+ /(=\s*|^)while\b/,
21
+ /(=\s*|^)begin\b/,
22
+ /(=\s*|^)case\b/,
23
+ /\bthen\b/,
24
+ /^class\b/,
25
+ /^rescue\b/,
26
+ /^def\b/,
27
+ /\bdo\b/,
28
+ /^else\b/,
29
+ /^elsif\b/,
30
+ /^ensure\b/,
31
+ /\bwhen\b/,
32
+ /\{[^\}]*$/,
33
+ /\[[^\]]*$/
34
+ ]
35
+
36
+ # outdent regexp tests
37
+
38
+ $outdentExp = [
39
+ /^rescue\b/,
40
+ /^ensure\b/,
41
+ /^elsif\b/,
42
+ /^end\b/,
43
+ /^else\b/,
44
+ /\bwhen\b/,
45
+ /^[^\{]*\}/,
46
+ /^[^\[]*\]/
47
+ ]
48
+
49
+ def self.makeTab(tab)
50
+ return (tab < 0) ? "":$tabStr * $tabSize * tab
51
+ end
52
+
53
+ def self.addLine(line,tab)
54
+ line.strip!
55
+ line = makeTab(tab)+line if line.length > 0
56
+ return line + "\n"
57
+ end
58
+
59
+ def self.ruby( source )
60
+ commentBlock = false
61
+ multiLineArray = Array.new
62
+ multiLineStr = ""
63
+ tab = 0
64
+ dest = ""
65
+ source.split("\n").each do |line|
66
+ # combine continuing lines
67
+ if(!(line =~ /^\s*#/) && line =~ /[^\\]\\\s*$/)
68
+ multiLineArray.push line
69
+ multiLineStr += line.sub(/^(.*)\\\s*$/,"\\1")
70
+ next
71
+ end
72
+
73
+ # add final line
74
+ if(multiLineStr.length > 0)
75
+ multiLineArray.push line
76
+ multiLineStr += line.sub(/^(.*)\\\s*$/,"\\1")
77
+ end
78
+
79
+ tline = ((multiLineStr.length > 0)?multiLineStr:line).strip
80
+ if(tline =~ /^=begin/)
81
+ commentBlock = true
82
+ end
83
+ if(commentBlock)
84
+ # add the line unchanged
85
+ dest += line + "\n"
86
+ else
87
+ commentLine = (tline =~ /^#/)
88
+ if(!commentLine)
89
+ # throw out sequences that will
90
+ # 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
+ $outdentExp.each do |re|
99
+ if(tline =~ re)
100
+ tab -= 1
101
+ break
102
+ end
103
+ end
104
+ end
105
+ if (multiLineArray.length > 0)
106
+ multiLineArray.each do |ml|
107
+ dest += addLine(ml,tab)
108
+ end
109
+ multiLineArray.clear
110
+ multiLineStr = ""
111
+ else
112
+ dest += addLine(line,tab)
113
+ end
114
+ if(!commentLine)
115
+ $indentExp.each do |re|
116
+ if(tline =~ re && !(tline =~ /\s+end\s*$/))
117
+ tab += 1
118
+ break
119
+ end
120
+ end
121
+ end
122
+ end
123
+ if(tline =~ /^=end/)
124
+ commentBlock = false
125
+ end
126
+ end
127
+ # STDOUT.write(dest)
128
+ # uncomment this to complain about mismatched blocks
129
+ # if(tab != 0)
130
+ # STDERR.puts "Indentation error: #{tab}"
131
+ #
132
+
133
+ dest
134
+ end
135
+ end
data/scripts/rdoc2html ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ require 'rubygems'
5
+ require 'syntax/convertors/html'
6
+ require 'erb'
7
+ require 'rdoc/markup/simple_markup'
8
+ require 'rdoc/markup/simple_markup/to_html'
9
+
10
+ require File.dirname(__FILE__) + '/../lib/lazibi/version.rb'
11
+
12
+ version = Lazibi::VERSION::STRING
13
+ download = 'http://rubyforge.org/projects/lazibi'
14
+
15
+ class Fixnum
16
+ def ordinal
17
+ # teens
18
+ return 'th' if (10..19).include?(self % 100)
19
+ # others
20
+ case self % 10
21
+ when 1: return 'st'
22
+ when 2: return 'nd'
23
+ when 3: return 'rd'
24
+ else return 'th'
25
+ end
26
+ end
27
+ end
28
+
29
+ class Time
30
+ def pretty
31
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
32
+ end
33
+ end
34
+
35
+ def convert_syntax(syntax, source)
36
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
37
+ end
38
+
39
+ if ARGV.length >= 1
40
+ src, template = ARGV
41
+ template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
42
+
43
+ else
44
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
45
+ exit!
46
+ end
47
+
48
+ template = ERB.new(File.open(template).read)
49
+
50
+ title = nil
51
+ body = nil
52
+ p = SM::SimpleMarkup.new
53
+ h = SM::ToHtml.new
54
+ File.open(src) do |fsrc|
55
+ title_text = fsrc.readline
56
+ body_text = fsrc.read
57
+ syntax_items = []
58
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m){
59
+ ident = syntax_items.length
60
+ element, syntax, source = $1, $2, $3
61
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
62
+ "syntax-temp-#{ident}"
63
+ }
64
+ title = p.convert(title_text, h).gsub(%r!<.*?>!,'').strip
65
+ body = p.convert(body_text, h)
66
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
67
+ end
68
+
69
+
70
+ stat = File.stat(src)
71
+ created = stat.ctime
72
+ modified = stat.mtime
73
+
74
+ $stdout << template.result(binding)
@@ -0,0 +1,7 @@
1
+ case abc
2
+ when 'a'
3
+ puts 'a'
4
+ when 'b'
5
+ puts 'b'
6
+ else
7
+ puts 'c'
@@ -0,0 +1,3 @@
1
+ def abc
2
+
3
+ def def abc end
@@ -0,0 +1,8 @@
1
+ case abc
2
+ when 'a'
3
+ puts 'a'
4
+ when 'b'
5
+ puts 'b'
6
+ else
7
+ puts 'c'
8
+ end
@@ -0,0 +1,3 @@
1
+ def abc end
2
+
3
+ def def abc end end
data/test/test_unit.rb CHANGED
@@ -4,31 +4,29 @@ require 'pp'
4
4
  class TestLazibi < Test::Unit::TestCase
5
5
  attr :fixtures, :expected
6
6
 
7
- include Lazibi
8
-
9
7
  def setup
10
-
8
+
11
9
  # load fixtures
12
10
  @meta = {}
13
11
  @real = {}
14
12
 
15
13
  fixture_dir = File.dirname(__FILE__) + '/fixtures/meta'
16
-
14
+
17
15
  Dir.open(fixture_dir).each do |fn|
18
16
  next unless fn =~ /[.]txt$/
19
17
  @meta[fn.scan(/(.*)[.]/).to_s.to_sym] = File.read(fixture_dir + "/#{fn}")
20
18
  end
21
-
19
+
22
20
  expected_dir = File.dirname(__FILE__) + '/fixtures/real'
23
21
  Dir.open(expected_dir).each do |fn|
24
22
  next unless fn =~ /[.]txt$/
25
23
  @real[fn.scan(/(.*)[.]/).to_s.to_sym] = File.read(expected_dir + "/#{fn}")
26
24
  end
27
-
28
- @r = Lazibi.new
25
+
26
+ @r = Lazibi::Runner.new
29
27
  end
30
-
31
-
28
+
29
+
32
30
  def test_start_anchor?
33
31
  assert @r.start_anchor?( 'class' )
34
32
  assert @r.start_anchor?( 'do |abc| ')
@@ -36,13 +34,13 @@ class TestLazibi < Test::Unit::TestCase
36
34
  assert !@r.start_anchor?( '"abc do "')
37
35
  assert !@r.start_anchor?( '"abc do |"')
38
36
  end
39
-
37
+
40
38
  def test_middle_anchor?
41
39
  assert !@r.middle_anchor?( '' )
42
40
  assert @r.middle_anchor?( 'rescue' )
43
41
  end
44
-
45
- def test_find_
42
+
43
+ def test_find_end
46
44
  assert_find :basic_class, 0, 0
47
45
  assert_find :class_with_def, 0, 1
48
46
  assert_find :class_with_def, 0, 1
@@ -52,47 +50,47 @@ class TestLazibi < Test::Unit::TestCase
52
50
  assert_find :partial_method, 2, 0
53
51
  assert_find :middle, 0, 1
54
52
  end
55
-
53
+
56
54
  def test_convert_path
57
55
  assert @r.convert_path( 'meta/abc.py.rb' ) == 'real/abc.rb', @r.convert_path('meta/abc.rb')
58
56
  assert @r.convert_path( 'real/abc.rb' ) == 'meta/abc.py.rb'
59
57
  assert @r.convert_path( 'meta/lib/abc.py.rb' ) == 'real/lib/abc.rb'
60
58
  end
61
-
59
+
62
60
  def test_convert_content
63
61
  @meta.keys.reject{|k| ['partial_method', 'inline_end'].include? k.to_s }.each do |k|
64
62
  assert_convert k
65
63
  end
66
64
  end
67
-
65
+
68
66
  def test_to_rb
69
67
  assert_to_rb :partial_method
70
68
  end
71
-
72
- def test_to_py
69
+
70
+ def test_to_py
73
71
  assert_to_py :inline_end
74
72
  end
75
-
76
-
73
+
74
+
77
75
  private
78
- def assert_find( name, indent, end_i )
79
- assert_equal @r.find_end(@meta[name].split("\n"), indent), end_i
80
- end
81
-
82
- def assert_to_rb( name )
83
- assert_equal @r.to_rb( @meta[name]), @real[name], name
84
- end
85
-
86
- def assert_to_py( name )
87
- assert_equal @r.to_py( @real[name]), @meta[name], name
88
- end
89
-
90
- def assert_convert( name )
91
- assert_to_rb(name)
92
- assert_to_py(name)
93
- end
94
-
95
- def assert_identity( s )
96
- assert_equal @r.to_rb( @r.to_py( s ) ), s
97
- end
76
+ def assert_find( name, indent, end_i )
77
+ assert_equal @r.find_end(@meta[name].split("\n"), indent), end_i
78
+ end
79
+
80
+ def assert_to_rb( name )
81
+ assert_equal @r.to_rb( @meta[name]), @real[name], name
82
+ end
83
+
84
+ def assert_to_py( name )
85
+ assert_equal @r.to_py( @real[name]), @meta[name], name
86
+ end
87
+
88
+ def assert_convert( name )
89
+ assert_to_rb(name)
90
+ assert_to_py(name)
91
+ end
92
+
93
+ def assert_identity( s )
94
+ assert_equal @r.to_rb( @r.to_py( s ) ), s
95
+ end
98
96
  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.4</a>
36
+ <a href="http://rubyforge.org/projects/lazibi" class="numbers">0.1.5</a>
37
37
  </div>
38
38
  <p>
39
39
  Lazibi is a meta language which allows you to use Python like syntax (
@@ -109,23 +109,13 @@ Make sure everything still works
109
109
  rake test / autotest
110
110
  </pre>
111
111
  <p>
112
- Start hacking ruby/python :/
112
+ Start hacking ruby/python in meta :/
113
113
  </p>
114
114
  <pre>
115
115
  cd shiny_project
116
116
  $your_editor meta
117
117
  </pre>
118
118
  <h2>Tips</h2>
119
- <h3>Rails fix</h3>
120
- <p>
121
- After bootstrap, edit config/boot.py.rb in meta
122
- </p>
123
- <pre>
124
- STDERR.puts %(Cannot find gem for Rails ~&gt;#{version}.0:
125
- Install the missing gem with 'gem install -v=#{version} rails', or
126
- change environment.rb to define RAILS_GEM_VERSION with your desired version.
127
- )
128
- </pre>
129
119
  <h3>Manually create meta files</h3>
130
120
  <ul>
131
121
  <li>Bootstrap your project as usual, just don&#8217;t run lazibi
@@ -144,6 +134,18 @@ After bootstrap, edit config/boot.py.rb in meta
144
134
  <li>create .py.rb files in corresponding directories inside &#8216;meta&#8217;,
145
135
  .rb files will be created and updated in &#8216;real&#8217; as usual
146
136
 
137
+ </li>
138
+ </ul>
139
+ <h3>Prevent certain directories from being parsed during bootstrap ( default is ^vendor )</h3>
140
+ <ul>
141
+ <li>Create .lazibi in project/real path
142
+
143
+ <pre>
144
+ exclude:
145
+ - pattern_1
146
+ - pattern_2
147
+ - for_example_^vendor
148
+ </pre>
147
149
  </li>
148
150
  </ul>
149
151
  <h2>Known issues</h2>
@@ -174,7 +176,7 @@ Released under the MIT license (included)
174
176
  </p>
175
177
 
176
178
  <p class="coda">
177
- <a href="mailto:nfjinjing@gmail.com">Jinjing</a>, 15th June 2007<br>
179
+ <a href="mailto:nfjinjing@gmail.com">Jinjing</a>, 16th June 2007<br>
178
180
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
179
181
  </p>
180
182
  </div>
data/website/index.txt CHANGED
@@ -63,22 +63,13 @@ Make sure everything still works
63
63
  cd shiny_project/real
64
64
  rake test / autotest
65
65
 
66
- Start hacking ruby/python :/
66
+ Start hacking ruby/python in meta :/
67
67
 
68
68
  cd shiny_project
69
69
  $your_editor meta
70
70
 
71
71
  == Tips
72
72
 
73
- === Rails fix
74
-
75
- After bootstrap, edit config/boot.py.rb in meta
76
-
77
- STDERR.puts %(Cannot find gem for Rails ~>#{version}.0:
78
- Install the missing gem with 'gem install -v=#{version} rails', or
79
- change environment.rb to define RAILS_GEM_VERSION with your desired version.
80
- )
81
-
82
73
  === Manually create meta files
83
74
 
84
75
  * Bootstrap your project as usual, just don't run lazibi
@@ -92,6 +83,14 @@ After bootstrap, edit config/boot.py.rb in meta
92
83
 
93
84
  * create .py.rb files in corresponding directories inside 'meta', .rb files will be created and updated in 'real' as usual
94
85
 
86
+ === Prevent certain directories from being parsed during bootstrap ( default is ^vendor )
87
+
88
+ * Create .lazibi in project/real path
89
+
90
+ exclude:
91
+ - pattern_1
92
+ - pattern_2
93
+ - for_example_^vendor
95
94
 
96
95
  == Known issues
97
96
 
@@ -1,21 +1,22 @@
1
1
  body {
2
- background-color: #E1D1F1;
2
+ background-color: #fff; color: #333;
3
3
  font-family: "Georgia", sans-serif;
4
4
  font-size: 16px;
5
5
  line-height: 1.6em;
6
6
  padding: 1.6em 0 0 0;
7
- color: #333;
8
7
  }
9
8
  h1, h2, h3, h4, h5, h6 {
10
- color: #444;
11
9
  }
10
+
12
11
  h1 {
12
+ background: #eef;
13
13
  font-family: sans-serif;
14
14
  font-weight: normal;
15
15
  font-size: 4em;
16
16
  line-height: 0.8em;
17
17
  letter-spacing: -0.1ex;
18
18
  margin: 5px;
19
+ padding: 20px 20px 10px 20px;
19
20
  }
20
21
  li {
21
22
  padding: 0;
@@ -23,11 +24,12 @@ li {
23
24
  list-style-type: square;
24
25
  }
25
26
  a {
26
- color: #5E5AFF;
27
- background-color: #DAC;
28
27
  font-weight: normal;
29
28
  text-decoration: underline;
30
29
  }
30
+
31
+ a { color: #000; }
32
+
31
33
  blockquote {
32
34
  font-size: 90%;
33
35
  font-style: italic;
@@ -79,11 +81,11 @@ td {
79
81
  }
80
82
  pre, code {
81
83
  font-family: monospace;
84
+ background: #eee;
82
85
  font-size: 90%;
83
86
  line-height: 1.4em;
84
- color: #ff8;
85
- background-color: #111;
86
87
  padding: 2px 10px 2px 10px;
88
+ # border: 1px solid;
87
89
  }
88
90
  .comment { color: #aaa; font-style: italic; }
89
91
  .keyword { color: #eff; font-weight: bold; }
@@ -101,8 +103,8 @@ pre, code {
101
103
  text-align: right;
102
104
  font-family: sans-serif;
103
105
  font-weight: normal;
104
- background-color: #B3ABFF;
105
- color: #141331;
106
+ # background-color: #B3ABFF;
107
+ # color: #141331;
106
108
  padding: 15px 20px 10px 20px;
107
109
  margin: 0 auto;
108
110
  margin-top: 15px;
@@ -119,16 +121,16 @@ pre, code {
119
121
 
120
122
  #version p {
121
123
  text-decoration: none;
122
- color: #141331;
123
- background-color: #B3ABFF;
124
+ # color: #141331;
125
+ # background-color: #B3ABFF;
124
126
  margin: 0;
125
127
  padding: 0;
126
128
  }
127
129
 
128
130
  #version a {
129
131
  text-decoration: none;
130
- color: #141331;
131
- background-color: #B3ABFF;
132
+ # color: #141331;
133
+ # background-color: #B3ABFF;
132
134
  }
133
135
 
134
136
  .clickable {
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.4
7
- date: 2007-06-15 00:00:00 +08:00
6
+ version: 0.1.5
7
+ date: 2007-06-16 00:00:00 +08:00
8
8
  summary: Python like syntax for Ruby
9
9
  require_paths:
10
10
  - lib
@@ -35,19 +35,29 @@ files:
35
35
  - README.txt
36
36
  - Rakefile
37
37
  - bin/lazibi
38
+ - lib/helper/parser_helper.rb
39
+ - lib/helper/task_helper.rb
38
40
  - lib/lazibi.rb
39
41
  - lib/lazibi/version.rb
42
+ - lib/parser.rb
43
+ - lib/task.rb
44
+ - lib/vendor/beautifier.rb
45
+ - scripts/rdoc2html
40
46
  - scripts/txt2html
41
47
  - test/fixtures/meta/basic_class.txt
48
+ - test/fixtures/meta/case.txt
42
49
  - test/fixtures/meta/class_with_def.txt
43
50
  - test/fixtures/meta/comment.txt
51
+ - test/fixtures/meta/inline_end.txt
44
52
  - test/fixtures/meta/middle.txt
45
53
  - test/fixtures/meta/nested_comment.txt
46
54
  - test/fixtures/meta/partial_method.txt
47
55
  - test/fixtures/meta/two_methods.txt
48
56
  - test/fixtures/real/basic_class.txt
57
+ - test/fixtures/real/case.txt
49
58
  - test/fixtures/real/class_with_def.txt
50
59
  - test/fixtures/real/comment.txt
60
+ - test/fixtures/real/inline_end.txt
51
61
  - test/fixtures/real/middle.txt
52
62
  - test/fixtures/real/nested_comment.txt
53
63
  - test/fixtures/real/partial_method.txt
@@ -71,15 +81,19 @@ extra_rdoc_files:
71
81
  - Manifest.txt
72
82
  - README.txt
73
83
  - test/fixtures/meta/basic_class.txt
84
+ - test/fixtures/meta/case.txt
74
85
  - test/fixtures/meta/class_with_def.txt
75
86
  - test/fixtures/meta/comment.txt
87
+ - test/fixtures/meta/inline_end.txt
76
88
  - test/fixtures/meta/middle.txt
77
89
  - test/fixtures/meta/nested_comment.txt
78
90
  - test/fixtures/meta/partial_method.txt
79
91
  - test/fixtures/meta/two_methods.txt
80
92
  - test/fixtures/real/basic_class.txt
93
+ - test/fixtures/real/case.txt
81
94
  - test/fixtures/real/class_with_def.txt
82
95
  - test/fixtures/real/comment.txt
96
+ - test/fixtures/real/inline_end.txt
83
97
  - test/fixtures/real/middle.txt
84
98
  - test/fixtures/real/nested_comment.txt
85
99
  - test/fixtures/real/partial_method.txt