tortoise 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
+ output.html
2
+ test.html
1
3
  *.swp
2
4
  .DS_Store
3
5
  *.gem
data/README.markdown CHANGED
@@ -110,20 +110,28 @@ Command Line Usage
110
110
  Tortoise can be used on the command line to render logo command files. The
111
111
  output is rendered to standard out.
112
112
 
113
- Usage: tortoise [FILE]
113
+ Usage: tortoise [OPTIONS] [FILE]
114
114
 
115
- For example, if you'd like to render `drawing.logo` to `drawing.txt`:
115
+ Options:
116
+ --ascii Render ascii output (default)
117
+ --html Render html output
118
+
119
+ For example, if you'd like to render `drawing.logo` to `drawing.txt` as ascii:
116
120
 
117
121
  $ tortoise drawing.logo > drawing.txt
118
122
 
123
+ Or as html:
124
+
125
+ $ tortoise --html drawing.logo > drawing.html
126
+
119
127
  Rendering The Canvas
120
128
  --------------------
121
- Tortoise can currently render its canvas to a string. Html export is planned
122
- soon (which will allow a very high resolution canvas). To get a string
123
- representation of the current canvas:
129
+ Tortoise can currently render its canvas as ascii or as html.
124
130
 
125
131
  interpreter = Tortoise::Interpreter.new(5)
126
- interpreter.to_s
132
+
133
+ interpreter.to_ascii #=> return ascii
134
+ interpreter.to_html #=> return html
127
135
 
128
136
  Supported Commands
129
137
  ------------------
data/bin/tortoise CHANGED
@@ -2,10 +2,38 @@
2
2
  $:.push File.expand_path("../../lib", __FILE__)
3
3
  require 'tortoise/interpreter'
4
4
 
5
- if ARGV.size < 1
6
- puts "Usage: tortoise [FILE]"
7
- raise Exception.new("Missing filename")
5
+ def print_usage
6
+ puts "Usage: tortoise [OPTIONS] [FILE]\n\n"
7
+ puts "Options:"
8
+ puts " --ascii Render ascii output (default)"
9
+ puts " --html Render html output"
10
+ exit(1)
8
11
  end
9
12
 
10
- commands = File.new(ARGV.first).read
11
- puts Tortoise::Interpreter.new(commands).to_s
13
+ format = '--ascii'
14
+ filname = nil
15
+
16
+ case ARGV.size
17
+ when 1
18
+ filename = ARGV.pop
19
+ when 2
20
+ filename = ARGV.pop
21
+ format = ARGV.pop
22
+ else
23
+ print_usage
24
+ end
25
+
26
+ commands = File.new(filename).read
27
+ interpreter = Tortoise::Interpreter.new(commands)
28
+ output = ''
29
+
30
+ case format
31
+ when '--ascii'
32
+ output = interpreter.to_ascii
33
+ when '--html'
34
+ output = interpreter.to_html
35
+ else
36
+ print_usage
37
+ end
38
+
39
+ puts output
@@ -35,7 +35,7 @@ module Tortoise
35
35
  commands.each { |command| execute(command) }
36
36
  end
37
37
 
38
- def to_s
38
+ def to_ascii
39
39
  s = ''
40
40
  oriented_canvas.each do |column|
41
41
  column.each do |pixel|
@@ -47,6 +47,18 @@ module Tortoise
47
47
  s
48
48
  end
49
49
 
50
+ def to_html
51
+ <<-HTML
52
+ <!DOCTYPE html>
53
+ <html>
54
+ #{html_head}
55
+ <body>
56
+ #{html_canvas}
57
+ </body>
58
+ </html>
59
+ HTML
60
+ end
61
+
50
62
  private
51
63
 
52
64
  def new_canvas
@@ -119,5 +131,56 @@ module Tortoise
119
131
  end
120
132
  oriented
121
133
  end
134
+
135
+ def html_head
136
+ pixel_size = 8
137
+ <<-HTML
138
+ <head>
139
+ <title>Tortoise</title>
140
+ <style type="text/css">
141
+ * { margin: 0; padding: 0; }
142
+
143
+ body { background: #555; }
144
+
145
+ #canvas {
146
+ overflow: hidden;
147
+ border: #{pixel_size}px solid #000;
148
+ width: #{@size * pixel_size}px;
149
+ margin: 50px auto 10px auto;
150
+ }
151
+
152
+ .column {
153
+ float: left;
154
+ }
155
+
156
+ .pixel {
157
+ width: #{pixel_size}px;
158
+ height: #{pixel_size}px;
159
+ }
160
+
161
+ .empty {
162
+ background: #ddd;
163
+ }
164
+
165
+ .filled {
166
+ background: #111;
167
+ }
168
+ </style>
169
+ </head>
170
+ HTML
171
+ end
172
+
173
+ def html_canvas
174
+ html = "<div id='canvas'>"
175
+ @canvas.each do |column|
176
+ html += "<div class='column'>"
177
+ column.reverse.each do |pixel|
178
+ pixel_class = pixel ? 'filled' : 'empty'
179
+ html += "<div class='pixel #{pixel_class}'></div>"
180
+ end
181
+ html += "</div>"
182
+ end
183
+ html += "</div>"
184
+ end
122
185
  end
123
186
  end
@@ -1,3 +1,3 @@
1
1
  module Tortoise
2
- VERSION = "0.8.0"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -1,10 +1,10 @@
1
1
  require 'tortoise'
2
2
 
3
3
  describe Tortoise::Interpreter do
4
- it 'produces the expected string output' do
4
+ it 'produces the expected ascii output' do
5
5
  input = File.new('./spec/data/simple.logo').read
6
6
  output = File.new('./spec/data/simple_out.txt').read
7
7
 
8
- Tortoise::Interpreter.new(input).to_s.should == output
8
+ Tortoise::Interpreter.new(input).to_ascii.should == output
9
9
  end
10
10
  end
@@ -80,8 +80,8 @@ describe Tortoise::Interpreter do
80
80
  end
81
81
  end
82
82
 
83
- describe '#to_s' do
84
- it 'renders canvas to string' do
83
+ describe '#to_ascii' do
84
+ it 'renders canvas to ascii' do
85
85
  tortoise = Tortoise::Interpreter.new(5)
86
86
  tortoise.draw <<-STEPS
87
87
  RT 90
@@ -94,7 +94,7 @@ describe Tortoise::Interpreter do
94
94
  FD 2
95
95
  STEPS
96
96
 
97
- tortoise.to_s.should == "" +
97
+ tortoise.to_ascii.should == "" +
98
98
  ". . . . .\n" +
99
99
  ". . . . .\n" +
100
100
  ". . X X .\n" +
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tortoise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-22 00:00:00.000000000 Z
12
+ date: 2012-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70316818801540 !ruby/object:Gem::Requirement
16
+ requirement: &70219246665200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70316818801540
24
+ version_requirements: *70219246665200
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70316818793360 !ruby/object:Gem::Requirement
27
+ requirement: &70219246663560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70316818793360
35
+ version_requirements: *70219246663560
36
36
  description: Tortoise is a Logo interpreter for ruby.
37
37
  email:
38
38
  - huntca@gmail.com