ropenlaszlo 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/CHANGES +9 -0
- data/doc/README +9 -6
- data/doc/TODO +3 -4
- data/lib/compiler.rb +52 -8
- data/test/compilation-error.lzx +2 -0
- data/test/compilation-warning.lzx +1 -0
- data/test/compiler_test.rb +46 -8
- data/test/utils.rb +22 -0
- metadata +6 -3
data/doc/CHANGES
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
= Change Log
|
2
2
|
|
3
|
+
== Version 0.3.0 (2006/01/16)
|
4
|
+
* compilation errors and warnings
|
5
|
+
* refactored test case setup
|
6
|
+
* fixed test case directory
|
7
|
+
* added rdoc task
|
8
|
+
* --output doesn't exist; --dir does
|
9
|
+
* Updated installation instructions
|
10
|
+
* Fixed rdoc formatting errors
|
11
|
+
|
3
12
|
== Version 0.2.0 (2006/01/11)
|
4
13
|
* Released as gem
|
5
14
|
* Published to rubyforge
|
data/doc/README
CHANGED
@@ -15,20 +15,23 @@ then the following Ruby code can be used to create a file 'hello.swf' which can
|
|
15
15
|
|
16
16
|
== Requirements
|
17
17
|
|
18
|
-
* {OpenLaszlo 3.1}[http://openlaszlo.org]
|
18
|
+
* {OpenLaszlo 3.1 or later}[http://openlaszlo.org]
|
19
19
|
* Ruby -v 1.8.2 or later (untested in earlier versions)
|
20
|
+
* RubyGems[http://rubygems.rubyforge.org]
|
20
21
|
|
21
|
-
==
|
22
|
+
== Installation
|
22
23
|
|
23
|
-
|
24
|
+
0:: Download and install {OpenLaszlo}[http://openlaszlo.org]
|
24
25
|
|
25
|
-
|
26
|
+
1: Install this gem
|
27
|
+
> gem install ropenlaszlo
|
26
28
|
|
27
|
-
|
29
|
+
2:: Set your +OPENLASZLO_HOME+ environment variable to the directory that contains the {OpenLaszlo SDK}[http://openlaszlo.org]. If the following prints something, you've got it right:
|
30
|
+
> grep Laszlo "$OPENLASZLO_HOME/README.txt"
|
28
31
|
|
29
32
|
== Documentation
|
30
33
|
|
31
|
-
{This OpenLaszlo Blog entry}[http://weblog.openlaszlo.org/archives/2006/01/deploying-openlaszlo-applications-with-rake/] has additional information and some examples of using ROpenLaszlo in a Rakefile.
|
34
|
+
{This OpenLaszlo Blog entry}[http://weblog.openlaszlo.org/archives/2006/01/deploying-openlaszlo-applications-with-rake/] has additional information and some examples of using ROpenLaszlo in a Rakefile.
|
32
35
|
|
33
36
|
== License
|
34
37
|
|
data/doc/TODO
CHANGED
@@ -2,17 +2,16 @@
|
|
2
2
|
|
3
3
|
== Compiler
|
4
4
|
* Dependency tracking
|
5
|
-
*
|
6
|
-
*
|
5
|
+
* Compile server: allow use of proxy
|
6
|
+
* Compile server: temporarily copy files into webapp directory
|
7
|
+
* Command line: detect compilation warnings
|
7
8
|
|
8
9
|
== Unit Tests
|
9
10
|
* Compiler parameters
|
10
11
|
* Missing source file
|
11
|
-
* Syntax error
|
12
12
|
* Unreachable server
|
13
13
|
* Invalid OPENLASZLO_HOME
|
14
14
|
|
15
15
|
== Packaging
|
16
16
|
* Add rake task file
|
17
17
|
* Add unit testing, doc generation to rakefile
|
18
|
-
|
data/lib/compiler.rb
CHANGED
@@ -42,6 +42,8 @@
|
|
42
42
|
# See OpenLaszlo.compile for additional documentation.
|
43
43
|
#
|
44
44
|
module OpenLaszlo
|
45
|
+
class CompilationError < StandardError; end
|
46
|
+
|
45
47
|
# This class implements a bridge to the compile server.
|
46
48
|
#
|
47
49
|
# If you don't need multiple compilers, you can use the methods in
|
@@ -65,6 +67,35 @@ module OpenLaszlo
|
|
65
67
|
# Additional options:
|
66
68
|
# * <tt>:format</tt> - request type (default 'swf')
|
67
69
|
def compile source_file, params={}
|
70
|
+
mtime = File.mtime source_file
|
71
|
+
output = params[:output] || "#{File.basename source_file, '.lzx'}.swf"
|
72
|
+
compile_object source_file, output, params
|
73
|
+
results = request_metadata_for source_file, params
|
74
|
+
raise "Race condition: #{source_file} was modified during compilation" if mtime != File.mtime(source_file)
|
75
|
+
results[:output] = output
|
76
|
+
raise CompilationError.new(results[:error]) if results[:error]
|
77
|
+
return results
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
def compile_object source_file, object, params={}
|
82
|
+
params = {}.update(params).update(:output => object)
|
83
|
+
request source_file, params
|
84
|
+
end
|
85
|
+
|
86
|
+
def request_metadata_for source_file, params={}
|
87
|
+
results = {}
|
88
|
+
params = {}.update(params).update(:format => 'canvas-xml', :output => nil)
|
89
|
+
text = request source_file, params
|
90
|
+
if text =~ %r{<warnings>(.*?)</warnings>}m
|
91
|
+
results[:warnings] = $1.scan(%r{<error>\s*(.*?)\s*</error>}m).map{|w|w.first}
|
92
|
+
elsif text !~ %r{<canvas>} && text =~ %r{<pre>Error:\s*(.*?)\s*</pre>}m
|
93
|
+
results[:error] = $1
|
94
|
+
end
|
95
|
+
return results
|
96
|
+
end
|
97
|
+
|
98
|
+
def request source_file, params={}
|
68
99
|
require 'net/http'
|
69
100
|
require 'uri'
|
70
101
|
# assert that pathname is relative to LPS home:
|
@@ -74,7 +105,7 @@ module OpenLaszlo
|
|
74
105
|
# FIXME: this doesn't handle quoting; use recursive File.split instead
|
75
106
|
# FIXME: should encode the url, for filenames that include '/'
|
76
107
|
server_relative_path.gsub(File::Separator, '/')
|
77
|
-
output = params[:output]
|
108
|
+
output = params[:output]
|
78
109
|
options = {
|
79
110
|
:lzr => params[:runtime],
|
80
111
|
:debug => params[:debug],
|
@@ -86,16 +117,19 @@ module OpenLaszlo
|
|
86
117
|
Net::HTTP.get_response URI.parse(url) do |response|
|
87
118
|
case response
|
88
119
|
when Net::HTTPOK
|
89
|
-
|
90
|
-
|
91
|
-
|
120
|
+
if output
|
121
|
+
File.open(output, 'w') do |f|
|
122
|
+
response.read_body do |segment|
|
123
|
+
f << segment
|
124
|
+
end
|
92
125
|
end
|
126
|
+
else
|
127
|
+
return response.body
|
93
128
|
end
|
94
129
|
else
|
95
130
|
response.value # raises error
|
96
131
|
end
|
97
132
|
end
|
98
|
-
return output
|
99
133
|
end
|
100
134
|
end
|
101
135
|
|
@@ -142,8 +176,18 @@ module OpenLaszlo
|
|
142
176
|
args << '--runtime=#{params[:runtime]}' if params[:runtime]
|
143
177
|
args << '--debug' if params[:debug]
|
144
178
|
args << '--profile' if params[:profile]
|
145
|
-
args << "--
|
146
|
-
|
179
|
+
args << "--dir '#{File.dirname output}'" unless File.dirname(source_file) == File.dirname(output)
|
180
|
+
args << source_file
|
181
|
+
text = `#{@lzc} #{args.join(' ')}`
|
182
|
+
text.gsub!(/^\d+\s+/, '') # work around a bug in OpenLaszlo 3.1
|
183
|
+
results = {:output => output}
|
184
|
+
if text =~ /^Compilation errors occurred:\n/
|
185
|
+
raise CompilationError.new($'.strip)
|
186
|
+
else
|
187
|
+
# FIXME: doesn't work because lzc prints errors to stderr
|
188
|
+
results[:warnings] = text.split("\n")
|
189
|
+
end
|
190
|
+
return results
|
147
191
|
end
|
148
192
|
|
149
193
|
private
|
@@ -169,7 +213,7 @@ module OpenLaszlo
|
|
169
213
|
return @compiler = CompileServer.new if ENV['OPENLASZLO_URL'] and ENV['OPENLASZLO_HOME']
|
170
214
|
return @compiler = CommandLineCompiler.new if ENV['OPENLASZLO_HOME']
|
171
215
|
raise <<EOF
|
172
|
-
Couldn't find an OpenLaszlo compiler.
|
216
|
+
Couldn\'t find an OpenLaszlo compiler.
|
173
217
|
|
174
218
|
To use the compile server (recommended), set ENV['OPENLASZLO_URL'] and ENV['OPENLASZLO_HOME'].
|
175
219
|
|
@@ -0,0 +1 @@
|
|
1
|
+
<canvas unknown-attribute="value"/>
|
data/test/compiler_test.rb
CHANGED
@@ -37,19 +37,26 @@ class << ENV
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
# FIXME: should be able to put the test methods in here too
|
40
41
|
module CompilerTestHelper
|
41
42
|
def super_setup
|
42
43
|
OpenLaszlo::compiler = nil
|
43
|
-
cd File.dirname(__FILE__)
|
44
|
+
#cd File.expand_path(File.dirname(__FILE__))
|
44
45
|
end
|
45
46
|
|
46
47
|
private
|
48
|
+
def testfile_pathname file
|
49
|
+
File.expand_path file, File.dirname(__FILE__)
|
50
|
+
end
|
51
|
+
|
47
52
|
def compile file, output=nil, options={}
|
53
|
+
file = testfile_pathname file
|
48
54
|
output = File.basename(file, '.lzx')+'.swf'
|
49
55
|
rm_f output
|
50
56
|
begin
|
51
|
-
OpenLaszlo::compile file, *options
|
57
|
+
result = OpenLaszlo::compile file, *options
|
52
58
|
assert File.exists?(output), "#{output} does not exist"
|
59
|
+
return result
|
53
60
|
ensure
|
54
61
|
rm_f output
|
55
62
|
end
|
@@ -70,13 +77,30 @@ class CompileServerTest < Test::Unit::TestCase
|
|
70
77
|
end
|
71
78
|
|
72
79
|
def test_compilation
|
73
|
-
compile 'test.lzx'
|
80
|
+
result = compile 'test.lzx'
|
81
|
+
assert_equal 'test.swf', result[:output]
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_compilation_error
|
85
|
+
#assert_raise(OpenLaszlo::CompilationError) {compile 'compilation-error.lzx'}
|
86
|
+
ex = (compile 'compilation-error.lzx' rescue $!)
|
87
|
+
assert_instance_of OpenLaszlo::CompilationError, ex
|
88
|
+
assert_match /^compilation-error.lzx:3:1: XML document structures must start and end within the same entity./, ex.message
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_compilation_warning
|
92
|
+
result = compile 'compilation-warning.lzx'
|
93
|
+
assert_equal 'compilation-warning.swf', result[:output]
|
94
|
+
assert_instance_of Array, result[:warnings]
|
95
|
+
assert_equal 2, result[:warnings].length
|
96
|
+
assert_match /^compilation-warning.lzx:1:36/, result[:warnings].first
|
74
97
|
end
|
75
98
|
|
76
99
|
private
|
77
100
|
alias :saved_compile :compile
|
78
101
|
|
79
102
|
def compile file, output=nil, options={}
|
103
|
+
file = testfile_pathname file
|
80
104
|
server_local_file = File.join @test_dir, File.basename(file)
|
81
105
|
cp file, server_local_file
|
82
106
|
begin
|
@@ -91,18 +115,32 @@ class CommandLineCompilerTest < Test::Unit::TestCase
|
|
91
115
|
include CompilerTestHelper
|
92
116
|
|
93
117
|
def setup
|
94
|
-
bindings = {'OPENLASZLO_URL' => nil}
|
95
|
-
@saved_bindings = Hash[*bindings.keys.map{|k|[k,ENV[k]]}.flatten]
|
96
|
-
ENV.update bindings
|
97
118
|
super_setup
|
119
|
+
callcc do |exit|
|
120
|
+
resume = nil
|
121
|
+
ENV.with_bindings 'OPENLASZLO_URL' => nil do
|
122
|
+
resume = callcc do |continue|
|
123
|
+
@teardown = continue
|
124
|
+
exit.call
|
125
|
+
end
|
126
|
+
end
|
127
|
+
resume.call
|
128
|
+
end
|
98
129
|
end
|
99
130
|
|
100
131
|
def teardown
|
101
|
-
|
132
|
+
callcc do |continue| @teardown.call(continue) end
|
102
133
|
end
|
103
134
|
|
104
135
|
def test_compilation
|
105
|
-
compile 'test.lzx'
|
136
|
+
result = compile 'test.lzx'
|
137
|
+
assert_equal 'test.swf', result[:output]
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_compilation_error
|
141
|
+
ex = (compile 'compilation-error.lzx' rescue $!)
|
142
|
+
assert_instance_of OpenLaszlo::CompilationError, ex
|
143
|
+
assert_match /^compilation-error.lzx:3:1: XML document structures must start and end within the same entity./, ex.message
|
106
144
|
end
|
107
145
|
end
|
108
146
|
|
data/test/utils.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
class << ENV
|
2
|
+
# Execute a block, restoring the bindings for +keys+ at the end.
|
3
|
+
# NOT thread-safe!
|
4
|
+
def with_saved_bindings keys, &block
|
5
|
+
saved_bindings = Hash[*keys.map {|k| [k, ENV[k]]}.flatten]
|
6
|
+
begin
|
7
|
+
block.call
|
8
|
+
ensure
|
9
|
+
ENV.update saved_bindings
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Execute a block with the temporary bindings in +bindings+.
|
14
|
+
# Doesn't remove keys; simply sets them to nil.
|
15
|
+
def with_bindings bindings, &block
|
16
|
+
with_saved_bindings bindings.keys do
|
17
|
+
ENV.update bindings
|
18
|
+
return block.call
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ropenlaszlo
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2006-01-
|
6
|
+
version: 0.3.0
|
7
|
+
date: 2006-01-16 00:00:00 -05:00
|
8
8
|
summary: Ruby interface to OpenLaszlo.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -34,13 +34,16 @@ files:
|
|
34
34
|
- doc/MIT-LICENSE
|
35
35
|
- doc/README
|
36
36
|
- doc/TODO
|
37
|
+
- test/compilation-error.lzx
|
38
|
+
- test/compilation-warning.lzx
|
37
39
|
- test/compiler_test.rb
|
38
40
|
- test/test.lzx
|
41
|
+
- test/utils.rb
|
39
42
|
test_files: []
|
40
43
|
|
41
44
|
rdoc_options:
|
42
45
|
- --title
|
43
|
-
- ROpenLaszlo
|
46
|
+
- "ROpenLaszlo: Ruby interface to OpenLaszlo."
|
44
47
|
- --main
|
45
48
|
- doc/README
|
46
49
|
extra_rdoc_files:
|