luobo 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,4 +4,6 @@ Luobo is a simple, easy to extend code generator.
4
4
 
5
5
  When you feed <tt>tuzi</tt> (bunny) with some luobo (carrot) script, it will produce sources base on your predefined rules.
6
6
 
7
+ = Examples
7
8
 
9
+ = Build-in Drivers
data/bin/tuzi CHANGED
@@ -3,10 +3,36 @@
3
3
 
4
4
  $: << 'lib'
5
5
 
6
+ require "optparse"
6
7
  require "luobo"
7
8
 
8
- # TODO: optparser and build-in drivers.
9
+ options = Hash.new
10
+
11
+ OptionParser.new do |opt|
12
+ opt.banner = "Usage: tuzi [OPTIONS] filename"
13
+ opt.separator ""
14
+ opt.separator "Options"
15
+
16
+ opt.on("-d DRIVER","--driver DRIVER","specify a driver") do |driver|
17
+ options[:driver] = driver
18
+ end
19
+
20
+ options[:output] = STDOUT
21
+ opt.on("-o OUTPUT","--output OUTPUT","the output file or file handler") do |output|
22
+ options[:output] = output
23
+ end
24
+
25
+ opt.on("-h","--help","help") do
26
+ puts opt
27
+ exit
28
+ end
29
+ end.parse!
30
+
31
+
32
+ # ---------
9
33
  file = ARGV[0]
10
34
  out = STDOUT
11
35
 
12
- Luobo::Base.new(file, out).process
36
+ lb = Luobo::Base.new(ARGV[0], out)
37
+ lb.driver = options[:driver].new if options[:driver]
38
+ lb.process
File without changes
@@ -9,8 +9,13 @@ module Luobo
9
9
  def initialize file, output
10
10
  @source_file = file
11
11
 
12
- @output = output.is_a?(IO) ? output : File.open(output, "w")
13
-
12
+ if output.is_a?(IO)
13
+ @output = output
14
+ elsif output.is_a?(String)
15
+ @output_file = output
16
+ @output = File.open(output, "w")
17
+ end
18
+
14
19
  # initialize:
15
20
  @token_stack = Array.new
16
21
 
@@ -47,7 +52,7 @@ module Luobo
47
52
  end
48
53
 
49
54
  def dump contents
50
- @output.print contents if contents
55
+ @driver.dump(@output, contents)
51
56
  end
52
57
 
53
58
  # travel up through the token stack, close all token with
@@ -157,7 +162,7 @@ module Luobo
157
162
  # ensure first line as driver definition
158
163
  unless @driver
159
164
  if matches = /^#{regex_proc_head}DRIVER#{regex_proc_end}(?<dname_>\w+)\s*$/.match(line)
160
- @driver = Driver.create(matches["dname_"])
165
+ @driver = Driver.create(matches["dname_"])
161
166
  self.dump(@driver.setup)
162
167
  next
163
168
  else
@@ -204,7 +209,7 @@ module Luobo
204
209
  self.close_stack 0
205
210
 
206
211
  self.dump(@driver.exit)
207
- @output.close
212
+ @output.close if @output_file
208
213
  self
209
214
  end
210
215
  end
@@ -27,6 +27,10 @@ module Luobo
27
27
  end
28
28
  end
29
29
 
30
+ def dump output, contents
31
+ output.print contents if contents
32
+ end
33
+
30
34
  def exit; end
31
35
  def setup; end
32
36
 
@@ -35,7 +39,11 @@ module Luobo
35
39
  end
36
40
 
37
41
  def do__raw token
38
- indent(token) + token.line_code.gsub(/^\s*/, "") + "\n"
42
+ if token.line_code.size > 0
43
+ indent(token) + token.line_code.gsub(/^\s*/, "") + "\n"
44
+ else
45
+ ""
46
+ end
39
47
  end
40
48
 
41
49
  def do__missing token
@@ -1,4 +1,4 @@
1
1
  module Luobo
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
4
4
 
File without changes
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: luobo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-17 00:00:00.000000000 Z
12
+ date: 2013-03-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  requirements: []
93
93
  rubyforge_project:
94
- rubygems_version: 1.8.24
94
+ rubygems_version: 1.8.25
95
95
  signing_key:
96
96
  specification_version: 3
97
97
  summary: Easy to extend code generator