osteele-ropenlaszlo 0.5.1
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/CHANGES +41 -0
- data/MIT-LICENSE +21 -0
- data/README.rdoc +61 -0
- data/TODO +21 -0
- data/lib/compiler.rb +255 -0
- data/lib/ropenlaszlo.rb +5 -0
- data/test/compilation-error.lzx +2 -0
- data/test/compilation-warning.lzx +1 -0
- data/test/compiler_test.rb +144 -0
- data/test/test.lzx +1 -0
- data/test/test_utils.rb +25 -0
- metadata +71 -0
data/CHANGES
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
= Change Log
|
2
|
+
|
3
|
+
== Version 0.5.1 (2009/03/22)
|
4
|
+
* update for compatibility with OpenLaszlo 4.x
|
5
|
+
* move to github
|
6
|
+
|
7
|
+
== Version 0.5 (2009/03/22)
|
8
|
+
* update for compatibility with OpenLaszlo 4.x
|
9
|
+
* move to github
|
10
|
+
|
11
|
+
== Version 0.4.1 (2006/01/25)
|
12
|
+
* bug fix: don't use popen on Windows
|
13
|
+
* bug fix: default LPS_HOME from OPENLASZLO_HOME
|
14
|
+
* added note about OpenLaszlo windows bug
|
15
|
+
|
16
|
+
== Version 0.4.0 (2006/01/19)
|
17
|
+
* new feature: command-line compiler detects compilation warnings
|
18
|
+
* bug fix: command-line compilation in qualified directory places object in same directory
|
19
|
+
* improve rdoc
|
20
|
+
* refactored unit tests
|
21
|
+
|
22
|
+
== Version 0.3.0 (2006/01/16)
|
23
|
+
* New feature: compilation errors and warnings
|
24
|
+
* Bug fix: --output doesn't exist; --dir does
|
25
|
+
* refactored test case setup
|
26
|
+
* fixed test case directory
|
27
|
+
* Rakefile: added rdoc task
|
28
|
+
* Updated installation instructions
|
29
|
+
* Fixed rdoc formatting errors
|
30
|
+
|
31
|
+
== Version 0.2.0 (2006/01/11)
|
32
|
+
* Released as gem
|
33
|
+
* Moved to rubyforge
|
34
|
+
* Added doc directory
|
35
|
+
* Added test directory
|
36
|
+
* Added examples directory
|
37
|
+
|
38
|
+
== Version 0.1.0 (2006/01/04)
|
39
|
+
* Initial release
|
40
|
+
* Published to osteele.com
|
41
|
+
* Announced on weblog.openlaszlo.org
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2006-2009 by Oliver Steele
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
= ROpenLaszlo: Interface to the OpenLaszlo compiler
|
2
|
+
|
3
|
+
ROpenLaszo is a Ruby interface to the OpenLaszlo[openlaszlo.org] compiler. It allows you to compile Open<tt></tt>Laszlo programs from within Ruby, in order to integrate Open<tt></tt>Laszlo development into Rake or Rails applications.
|
4
|
+
|
5
|
+
If you are using Open<tt></tt>Laszlo with Ruby on Rails, you probably want the {OpenLaszlo Rails plugin}[laszlo-plugin.rubyforge.org] as well.
|
6
|
+
|
7
|
+
OpenLaszlo[openlaszlo.org] programs are written in XML with embedded JavaScript, and compiled into Flash (swf) binary files, or DHTML. (As of this writing, the DHTML target is in pre-beta form.) The APIs in this library make it easy for Ruby code to invoke the Open<tt></tt>Laszlo compiler. For example, if hello.lzx contains the following text:
|
8
|
+
<canvas>
|
9
|
+
<window>
|
10
|
+
<button>Hello, World!</button>
|
11
|
+
</window>
|
12
|
+
</canvas>
|
13
|
+
then the following Ruby code can be used to create a file 'hello.swf' which can be executed in a browser or placed on a web site:
|
14
|
+
require 'rubygems'
|
15
|
+
require 'ropenlaszlo'
|
16
|
+
OpenLaszlo::compile 'hello.lzx'
|
17
|
+
|
18
|
+
You can turn this snippet into a Rake task that will compile any Open<tt></tt>Laszlo source file:
|
19
|
+
rule '.swf' => '.lzx' do |t|
|
20
|
+
puts "Compiling #{t.source} => #{t.name}" if verbose
|
21
|
+
OpenLaszlo::compile t.source, :output => t.name
|
22
|
+
end
|
23
|
+
|
24
|
+
== Requirements
|
25
|
+
|
26
|
+
* {OpenLaszlo 3.1 or later}[openlaszlo.org]
|
27
|
+
* Ruby -v 1.8.2 or later (untested in earlier versions)
|
28
|
+
* RubyGems[rubygems.rubyforge.org]
|
29
|
+
|
30
|
+
== Installation
|
31
|
+
|
32
|
+
0:: Download and install the {OpenLaszlo SDK}[openlaszlo.org]
|
33
|
+
|
34
|
+
1: Install this gem
|
35
|
+
$ gem install osteele-ropenlaszlo -s http://gems.github.com
|
36
|
+
|
37
|
+
2:: Set your +OPENLASZLO_HOME+ environment variable to the directory that contains the {OpenLaszlo SDK}[openlaszlo.org]. If the following prints something, you've got it right:
|
38
|
+
grep Laszlo "$OPENLASZLO_HOME/README.txt"
|
39
|
+
|
40
|
+
3:: (Optional) Set your +OPENLASZLO_URL+ environment variable to the web location of the Open<tt></tt>Laszlo server; for example, <tt>http</tt><tt>://localhost:8080/lps-3.1</tt>. If you omit this step, the module will use the command line compiler, which is slower but is not limited to compiling files inside of +OPENLASZLO_HOME+.
|
41
|
+
|
42
|
+
<b>Note:</b> The command-line compiler is broken in the Windows version of Open<tt></tt>Laszlo 3.1.1. If you are running Windows, step (3) is required. ({OpenLaszlo bug 1428}[http://www.openlaszlo.org/jira/browse/LPP-1428])
|
43
|
+
|
44
|
+
== Additional Resources
|
45
|
+
|
46
|
+
* The {OpenLaszlo web site}[openlaszlo.org] is a rich source of information about the Open<tt></tt>Laszlo platform. It includes links to the wiki, mailing lists, and forums.
|
47
|
+
|
48
|
+
* The {Laszlo on Rails}[groups.google.com/group/laszlo-on-rails] news group discusses the integration of Open<tt></tt>Laszlo with Ruby on Rails.
|
49
|
+
|
50
|
+
* The {OpenLaszlo Rails plugin}[laszlo-plugin.rubyforge.org] provides generators and scaffolding for using Open<tt></tt>Laszlo with Ruby on Rails.
|
51
|
+
|
52
|
+
* {This OpenLaszlo Blog entry}[weblog.openlaszlo.org/archives/2006/01/deploying-openlaszlo-applications-with-rake/] has additional information and some examples of using ROpenLaszlo in a Rakefile.
|
53
|
+
|
54
|
+
* The RubyForge project page is here[http://rubyforge.org/projects/ropenlaszlo/].
|
55
|
+
|
56
|
+
== License
|
57
|
+
|
58
|
+
ROpenLaszlo is copyright (c) 2006 - 2009 by Oliver Steele. It is
|
59
|
+
open-source software, and may be redistributed under the terms of the
|
60
|
+
MIT license. The text of this licence is included in the ROpenLaszlo
|
61
|
+
distribution.
|
data/TODO
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
= ROpenLaszlo Project -- To Do List
|
2
|
+
|
3
|
+
== Features
|
4
|
+
* Add rake task file
|
5
|
+
* Compile server: allow use of proxy?
|
6
|
+
* Compile server: temporarily copy files into webapp directory
|
7
|
+
* compile_string
|
8
|
+
* Dependency tracking
|
9
|
+
* query compiler version
|
10
|
+
|
11
|
+
== Unit Tests
|
12
|
+
* Compiler parameters
|
13
|
+
* Missing source file
|
14
|
+
* Unreachable server
|
15
|
+
* Invalid OPENLASZLO_HOME
|
16
|
+
|
17
|
+
== Corners
|
18
|
+
* invalid parameters
|
19
|
+
* server isn't running
|
20
|
+
* thinks lps-dev/foo is in lps/ directory
|
21
|
+
|
data/lib/compiler.rb
ADDED
@@ -0,0 +1,255 @@
|
|
1
|
+
# Author:: Oliver Steele
|
2
|
+
# Copyright:: Copyright (c) 2005-2006 Oliver Steele. All rights reserved.
|
3
|
+
# License:: Ruby License.
|
4
|
+
|
5
|
+
# == module OpenLaszlo
|
6
|
+
#
|
7
|
+
# This module contains utility methods for compiling
|
8
|
+
# OpenLaszlo[openlaszlo.org] programs.
|
9
|
+
#
|
10
|
+
# Example:
|
11
|
+
# # Set up the environment to use the compile server. The OpenLaszlo server
|
12
|
+
# # must be running in order at this location in order for this to work.
|
13
|
+
# ENV['OPENLASZLO_HOME'] = '/Applications/OpenLaszlo Server 3.1'
|
14
|
+
# ENV['OPENLASZLO_URL'] = 'http://localhost:8080/lps-3.1'
|
15
|
+
#
|
16
|
+
# require 'openlaszlo'
|
17
|
+
# # Create a file 'hello.swf' in the current directory:
|
18
|
+
# OpenLaszlo::compile 'hello.lzx'
|
19
|
+
#
|
20
|
+
# See OpenLaszlo.compile for additional documentation.
|
21
|
+
#
|
22
|
+
module OpenLaszlo
|
23
|
+
class CompilationError < StandardError; end
|
24
|
+
|
25
|
+
# This class implements a bridge to the compile server.
|
26
|
+
#
|
27
|
+
# If you don't need multiple compilers, you can use the methods in
|
28
|
+
# the OpenLaszlo module instead.
|
29
|
+
#
|
30
|
+
# CompileServer is faster than CommandLineCompiler, but can only compile
|
31
|
+
# files in the same directory as the Open<tt></tt>Laszlo SDK.
|
32
|
+
class CompileServer
|
33
|
+
# Options:
|
34
|
+
# * <tt>:openlaszlo_home</tt> - filesystem location of the Open<tt></tt>Laszlo SDK. Defaults to ENV['OPENLASZLO_HOME']
|
35
|
+
# * <tt>:server_uri</tt> - the URI of the server. Defaults to ENV['OPENLASZLO_URL'] if this is specified, otherwise to 'http://localhost:8080/lps-dev'.
|
36
|
+
def initialize(options={})
|
37
|
+
@home = options[:home] || ENV['OPENLASZLO_HOME']
|
38
|
+
dirs = Dir[File.join(@home, 'Server', 'lps-*', 'WEB-INF')]
|
39
|
+
@home = File.dirname(dirs.first) if dirs.any?
|
40
|
+
@base_url = options[:server_uri] || ENV['OPENLASZLO_URL'] || 'http://localhost:8080/lps-dev'
|
41
|
+
end
|
42
|
+
|
43
|
+
# Invokes the Open<tt></tt>Laszlo server-based compiler on
|
44
|
+
# +source_file+. +source_file+ must be inside the home directory
|
45
|
+
# of the server.
|
46
|
+
#
|
47
|
+
# Options:
|
48
|
+
# * <tt>:format</tt> - request type (default 'swf')
|
49
|
+
# See OpenLaszlo.compile for a description of +options+.
|
50
|
+
def compile(source_file, options={})
|
51
|
+
mtime = File.mtime source_file
|
52
|
+
runtime = options[:runtime] || 'swf8'
|
53
|
+
output = options[:output] || "#{File.expand_path(File.join(File.dirname(source_file), File.basename(source_file, '.lzx')))}.lzr=#{runtime}.swf"
|
54
|
+
compile_object(source_file, output, options)
|
55
|
+
results = request_metadata_for(source_file, options)
|
56
|
+
raise "Race condition: #{source_file} was modified during compilation" if mtime != File.mtime(source_file)
|
57
|
+
results[:output] = output
|
58
|
+
raise CompilationError.new(results[:error]) if results[:error]
|
59
|
+
return results
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
def compile_object(source_file, object, options={})
|
64
|
+
options = {}.update(options).update(:output => object)
|
65
|
+
request(source_file, options)
|
66
|
+
end
|
67
|
+
|
68
|
+
def request_metadata_for(source_file, options={})
|
69
|
+
results = {}
|
70
|
+
options = {}.update(options).update(:format => 'canvas-xml', :output => nil)
|
71
|
+
text = request(source_file, options)
|
72
|
+
if text =~ %r{<warnings>(.*?)</warnings>}m
|
73
|
+
results[:warnings] = $1.scan(%r{<error>\s*(.*?)\s*</error>}m).map{|w|w.first}
|
74
|
+
elsif text !~ %r{<canvas>} && text =~ %r{<pre>Error:\s*(.*?)\s*</pre>}m
|
75
|
+
results[:error] = $1
|
76
|
+
end
|
77
|
+
return results
|
78
|
+
end
|
79
|
+
|
80
|
+
def request(source_file, options={})
|
81
|
+
output = options[:output]
|
82
|
+
require 'net/http'
|
83
|
+
require 'uri'
|
84
|
+
# assert that pathname is relative to LPS home:
|
85
|
+
absolute_path = File.expand_path(source_file)
|
86
|
+
raise "#{absolute_path} isn't inside #{@home}" unless absolute_path.index(@home) == 0
|
87
|
+
server_relative_path = absolute_path[@home.length..-1]
|
88
|
+
# FIXME: this doesn't handle quoting; use recursive File.split instead
|
89
|
+
# FIXME: should encode the url, for filenames that include '/'
|
90
|
+
server_relative_path.gsub(File::Separator, '/')
|
91
|
+
options = {
|
92
|
+
:lzr => options[:runtime],
|
93
|
+
:debug => options[:debug],
|
94
|
+
:lzproxied => options.fetch(:proxied, false),
|
95
|
+
:lzt => options[:format] || 'swf'}
|
96
|
+
query = options.map{|k,v|"#{k}=#{v}" unless v.nil?}.compact.join('&')
|
97
|
+
url = "#{@base_url}#{server_relative_path}"
|
98
|
+
url += "?#{query}" unless query.empty?
|
99
|
+
Net::HTTP.get_response URI.parse(url) do |response|
|
100
|
+
case response
|
101
|
+
when Net::HTTPOK
|
102
|
+
if output
|
103
|
+
File.open(output, 'w') do |f|
|
104
|
+
response.read_body do |segment|
|
105
|
+
f << segment
|
106
|
+
end
|
107
|
+
end
|
108
|
+
else
|
109
|
+
return response.body
|
110
|
+
end
|
111
|
+
else
|
112
|
+
response.value # for effect: raises error
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# This class implements a bridge to the command-line compiler.
|
119
|
+
#
|
120
|
+
# If you don't need multiple compilers, you can use the methods in
|
121
|
+
# the OpenLaszlo module instead.
|
122
|
+
#
|
123
|
+
# CommandLineCompiler is slower than CompileServer, but,
|
124
|
+
# unlike the server, it can compile files in any location.
|
125
|
+
class CommandLineCompiler
|
126
|
+
# Creates a new compiler.
|
127
|
+
#
|
128
|
+
# Options are:
|
129
|
+
# * <tt>:compiler_script</tt> - the path to the shell script that
|
130
|
+
# invokes the compiler. This defaults to a standard location inside
|
131
|
+
# the value specified by :home.
|
132
|
+
# * <tt>:openlaszlo_home</tt> - the home directory of the Open<tt></tt>Laszlo SDK.
|
133
|
+
# This defaults to ENV['OPENLASZLO_HOME'].
|
134
|
+
def initialize(options={})
|
135
|
+
@lzc = options[:compiler_script]
|
136
|
+
unless @lzc
|
137
|
+
home = options[:openlaszlo_home] || ENV['OPENLASZLO_HOME']
|
138
|
+
raise ":compiler_script or :openlaszlo_home must be specified" unless home
|
139
|
+
search = bin_directories.map{|f| File.join(home, f, 'lzc')}
|
140
|
+
found = search.select{|f| File.exists? f}
|
141
|
+
raise "couldn't find bin/lzc in #{bin_directories.join(' or ')}" if found.empty?
|
142
|
+
@lzc = found.first
|
143
|
+
@lzc += '.bat' if windows?
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# Invokes the OpenLaszlo command-line compiler on +source_file+.
|
148
|
+
#
|
149
|
+
# See OpenLaszlo.compile for a description of +options+.
|
150
|
+
def compile(source_file, options={})
|
151
|
+
runtime = options[:runtime] || 'swf8'
|
152
|
+
output_suffix = ".lzr=#{runtime}.swf"
|
153
|
+
default_output = File.join(File.dirname(source_file),
|
154
|
+
File.basename(source_file, '.lzx') + output_suffix)
|
155
|
+
output = options[:output] || default_output
|
156
|
+
raise "#{source_file} and #{output} do not have the same basename." unless File.basename(source_file, '.lzx') == File.basename(output, output_suffix)
|
157
|
+
args = []
|
158
|
+
args << '--runtime=#{options[:runtime]}' if options[:runtime]
|
159
|
+
args << '--debug' if options[:debug]
|
160
|
+
args << '--profile' if options[:profile]
|
161
|
+
args << "--dir '#{File.dirname output}'" unless File.dirname(source_file) == File.dirname(output)
|
162
|
+
args << source_file
|
163
|
+
command = "\"#{@lzc}\" #{args.join(' ')}"
|
164
|
+
ENV['LPS_HOME'] ||= ENV['OPENLASZLO_HOME']
|
165
|
+
begin
|
166
|
+
#raise NotImplementedError --- for testing Windows
|
167
|
+
require "open3"
|
168
|
+
# The compiler writes errors to stdout, warnings to stderr
|
169
|
+
stdin, stdout, stderr = Open3.popen3(command)
|
170
|
+
errors = stdout.read
|
171
|
+
warnings = stderr.readlines
|
172
|
+
warnings.shift if warnings.first and warnings.first =~ /^Compiling:/
|
173
|
+
rescue NotImplementedError
|
174
|
+
# Windows doesn't have popen
|
175
|
+
errors = `#{command}`
|
176
|
+
warnings = []
|
177
|
+
end
|
178
|
+
errors.gsub!(/^\d+\s+/, '') # work around a bug in OpenLaszlo 3.1
|
179
|
+
if errors =~ /^Compilation errors occurred:\n/
|
180
|
+
raise CompilationError.new($'.strip)
|
181
|
+
end
|
182
|
+
results = {:output => output, :warnings => warnings}
|
183
|
+
return results
|
184
|
+
end
|
185
|
+
|
186
|
+
private
|
187
|
+
|
188
|
+
# Locations in which to look for the lzc script, relative to OPENLASZLO_HOME
|
189
|
+
def bin_directories
|
190
|
+
[# binary distro location
|
191
|
+
'bin',
|
192
|
+
# source distro location
|
193
|
+
'WEB-INF/lps/server/bin'
|
194
|
+
]
|
195
|
+
end
|
196
|
+
|
197
|
+
def windows?
|
198
|
+
RUBY_PLATFORM =~ /win/ and not RUBY_PLATFORM =~ /darwin/
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
# Returns the default compiler. Use the server-based compiler if it's
|
203
|
+
# available, since it's so much faster.
|
204
|
+
def self.compiler
|
205
|
+
return @compiler if @compiler
|
206
|
+
return @compiler = CompileServer.new if ENV['OPENLASZLO_URL'] and ENV['OPENLASZLO_HOME']
|
207
|
+
return @compiler = CommandLineCompiler.new if ENV['OPENLASZLO_HOME']
|
208
|
+
raise <<EOF
|
209
|
+
Couldn\'t find an OpenLaszlo compiler.
|
210
|
+
|
211
|
+
To use the compile server (recommended), set ENV['OPENLASZLO_URL'] and ENV['OPENLASZLO_HOME'].
|
212
|
+
|
213
|
+
To use the command-line compiler, set ENV['OPENLASZLO_HOME'].
|
214
|
+
EOF
|
215
|
+
end
|
216
|
+
|
217
|
+
# Sets the default compiler for future invocations of OpenLaszlo.compile.
|
218
|
+
def self.compiler=(compiler)
|
219
|
+
@compiler = compiler
|
220
|
+
end
|
221
|
+
|
222
|
+
# Compile an OpenLaszlo source file.
|
223
|
+
#
|
224
|
+
# Examples:
|
225
|
+
# require 'openlaszlo'
|
226
|
+
# OpenLaszlo::compile 'hello.lzx'
|
227
|
+
# OpenLaszlo::compile 'hello.lzx', :debug => true
|
228
|
+
# OpenLaszlo::compile 'hello.lzx', :runtime => 'swf8'
|
229
|
+
# OpenLaszlo::compile 'hello.lzx', {:runtime => 'swf8', :debug => true}
|
230
|
+
# OpenLaszlo::compile 'hello.lzx', :output => 'hello-world.swf'
|
231
|
+
#
|
232
|
+
# Options are:
|
233
|
+
# * <tt>:debug</tt> - debug mode (default false)
|
234
|
+
# * <tt>:output</tt> - specify the name and location for the output file (default = <tt>input_file.sub(/\.lzx$/, '.swf')</tt>)
|
235
|
+
# * <tt>:proxied</tt> - is application proxied (default true)
|
236
|
+
# * <tt>:runtime</tt> - runtime (default swf7)
|
237
|
+
#
|
238
|
+
# See CompileServer.compile and CommandLineCompiler.compile for
|
239
|
+
# additional options that are specific to the compilation methods in
|
240
|
+
# those classes.
|
241
|
+
def self.compile(source_file, options={})
|
242
|
+
return compiler.compile source_file, options
|
243
|
+
end
|
244
|
+
|
245
|
+
def self.make_html(source_file, options={}) #:nodoc:
|
246
|
+
raise 'not really supported, for now'
|
247
|
+
options = {
|
248
|
+
:format => 'html-object',
|
249
|
+
:output => File.basename(source_file, '.lzx')+'.html'}.update(options)
|
250
|
+
compiler.compile(source_file, options)
|
251
|
+
source_file = options[:output]
|
252
|
+
s = open(source_file).read
|
253
|
+
open(source_file, 'w') {|f| f.write s.gsub!(/\.lzx\?lzt=swf&/, '.lzx.swf?')}
|
254
|
+
end
|
255
|
+
end
|
data/lib/ropenlaszlo.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<canvas unknown-attribute="value"/>
|
@@ -0,0 +1,144 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__) + "/../lib"
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'ropenlaszlo'
|
5
|
+
require 'fileutils'
|
6
|
+
require File.join(File.dirname(__FILE__), 'test_utils.rb')
|
7
|
+
|
8
|
+
include FileUtils
|
9
|
+
|
10
|
+
REQUIRED_ENV_VALUES = %w{OPENLASZLO_HOME OPENLASZLO_HOME}
|
11
|
+
unless REQUIRED_ENV_VALUES.reject {|w| ENV[w]}.empty?
|
12
|
+
raise "These environment variables must be set: #{REQUIRED_ENV_VALUES}.join(', ')"
|
13
|
+
end
|
14
|
+
|
15
|
+
module CompilerTestHelper
|
16
|
+
def self.included(base)
|
17
|
+
base.send(:include, InstanceMethods)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def testfile_pathname(file)
|
22
|
+
return File.expand_path(file, File.dirname(__FILE__))
|
23
|
+
end
|
24
|
+
|
25
|
+
def assert_same_file(a, b)
|
26
|
+
assert_equal File.expand_path(a), File.expand_path(b)
|
27
|
+
end
|
28
|
+
|
29
|
+
def compile(file, output=nil, options={})
|
30
|
+
file = testfile_pathname(file)
|
31
|
+
output ||= File.join(File.dirname(file), File.basename(file, '.lzx')+'.lzr=swf8.swf')
|
32
|
+
rm_f output
|
33
|
+
raise "Unable to remove output file: #{output}" if File.exists?(output)
|
34
|
+
begin
|
35
|
+
result = OpenLaszlo::compile(file, *options)
|
36
|
+
assert_same_file output, result[:output]
|
37
|
+
assert File.exists?(output), "#{output} does not exist"
|
38
|
+
return result
|
39
|
+
ensure
|
40
|
+
rm_f output
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Tests that are shared between CompilerServerTest and
|
45
|
+
# CommandLineCompilerTest.
|
46
|
+
module InstanceMethods
|
47
|
+
def test_compilation
|
48
|
+
result = compile 'test.lzx'
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_compilation_warning
|
52
|
+
result = compile 'compilation-warning.lzx'
|
53
|
+
assert_instance_of Array, result[:warnings]
|
54
|
+
assert_equal 1, result[:warnings].length
|
55
|
+
assert_match /^compilation-warning.lzx:1:36/, result[:warnings].first
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_compilation_error
|
59
|
+
ex = (compile 'compilation-error.lzx' rescue $!)
|
60
|
+
assert_instance_of OpenLaszlo::CompilationError, ex
|
61
|
+
assert_match /^compilation-error.lzx:3:1: XML document structures must start and end within the same entity\./, ex.message
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class CompileServerTest < Test::Unit::TestCase
|
67
|
+
include CompilerTestHelper
|
68
|
+
|
69
|
+
def setup
|
70
|
+
OpenLaszlo::compiler = nil
|
71
|
+
home = ENV['OPENLASZLO_HOME']
|
72
|
+
dirs = Dir[File.join(home, 'Server', 'lps-*', 'WEB-INF')]
|
73
|
+
home = File.dirname(dirs.first) if dirs.any?
|
74
|
+
@test_dir = File.join(home, 'tmp/ropenlaszlo-tests')
|
75
|
+
mkdir_p @test_dir
|
76
|
+
end
|
77
|
+
|
78
|
+
def teardown
|
79
|
+
OpenLaszlo::compiler = nil
|
80
|
+
rm_rf @test_dir
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
alias :saved_compile :compile
|
85
|
+
|
86
|
+
def compile(file, output=nil, options={})
|
87
|
+
raise "unimplemented" if output
|
88
|
+
file = testfile_pathname file
|
89
|
+
server_local_file = File.join(@test_dir, File.basename(file))
|
90
|
+
cp file, server_local_file
|
91
|
+
begin
|
92
|
+
saved_compile(server_local_file, output, options)
|
93
|
+
ensure
|
94
|
+
rm_f server_local_file
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class CommandLineCompilerTest < Test::Unit::TestCase
|
100
|
+
include CompilerTestHelper
|
101
|
+
|
102
|
+
def setup
|
103
|
+
OpenLaszlo::compiler = nil
|
104
|
+
callcc do |exit|
|
105
|
+
resume = nil
|
106
|
+
ENV.with_bindings 'OPENLASZLO_URL' => nil do
|
107
|
+
resume = callcc do |continue|
|
108
|
+
@teardown = continue
|
109
|
+
exit.call
|
110
|
+
end
|
111
|
+
end
|
112
|
+
resume.call
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def teardown
|
117
|
+
OpenLaszlo::compiler = nil
|
118
|
+
callcc do |continue| @teardown.call(continue) end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
class CompilerFacadeTest < Test::Unit::TestCase
|
123
|
+
def setup
|
124
|
+
raise "ENV['OPENLASZLO_URL'] must be set" unless ENV['OPENLASZLO_URL']
|
125
|
+
raise "ENV['OPENLASZLO_HOME'] must be set" unless ENV['OPENLASZLO_HOME']
|
126
|
+
OpenLaszlo::compiler = nil
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_select_server
|
130
|
+
assert_instance_of OpenLaszlo::CompileServer, OpenLaszlo::compiler
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_select_commandline
|
134
|
+
ENV.with_bindings 'OPENLASZLO_URL' => nil do
|
135
|
+
assert_instance_of OpenLaszlo::CommandLineCompiler, OpenLaszlo::compiler
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_missing_home
|
140
|
+
ENV.with_bindings 'OPENLASZLO_HOME' => nil do
|
141
|
+
assert_raise(RuntimeError) do OpenLaszlo::compiler end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
data/test/test.lzx
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<canvas/>
|
data/test/test_utils.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Author:: Oliver Steele
|
2
|
+
# Copyright:: Copyright (c) 2005-2006 Oliver Steele. All rights reserved.
|
3
|
+
# License:: Ruby License.
|
4
|
+
|
5
|
+
class << ENV
|
6
|
+
# Execute a block, restoring the bindings for +keys+ at the end.
|
7
|
+
# NOT thread-safe!
|
8
|
+
def with_saved_bindings keys, &block
|
9
|
+
saved_bindings = Hash[*keys.map {|k| [k, ENV[k]]}.flatten]
|
10
|
+
begin
|
11
|
+
block.call
|
12
|
+
ensure
|
13
|
+
ENV.update saved_bindings
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Execute a block with the temporary bindings in +bindings+.
|
18
|
+
# Doesn't remove keys; simply sets them to nil.
|
19
|
+
def with_bindings bindings, &block
|
20
|
+
with_saved_bindings bindings.keys do
|
21
|
+
ENV.update bindings
|
22
|
+
return block.call
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: osteele-ropenlaszlo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oliver Steele
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-22 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: ROpenLaszlo is an interface to the OpenLaszlo compiler.
|
17
|
+
email: steele@osteele.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
- MIT-LICENSE
|
25
|
+
- CHANGES
|
26
|
+
- TODO
|
27
|
+
files:
|
28
|
+
- lib/compiler.rb
|
29
|
+
- lib/ropenlaszlo.rb
|
30
|
+
- test/compilation-error.lzx
|
31
|
+
- test/compilation-warning.lzx
|
32
|
+
- test/compiler_test.rb
|
33
|
+
- test/test.lzx
|
34
|
+
- test/test_utils.rb
|
35
|
+
- README.rdoc
|
36
|
+
- MIT-LICENSE
|
37
|
+
- CHANGES
|
38
|
+
- TODO
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/osteele/ropenlaszlo
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options:
|
43
|
+
- --title
|
44
|
+
- "ROpenLaszlo: Ruby interface to the OpenLaszlo compiler"
|
45
|
+
- --exclude
|
46
|
+
- test/.*
|
47
|
+
- --inline-source
|
48
|
+
- --charset=UTF-8
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project: ropenlaszlo
|
66
|
+
rubygems_version: 1.2.0
|
67
|
+
signing_key:
|
68
|
+
specification_version: 2
|
69
|
+
summary: Ruby interface to the OpenLaszlo compiler.
|
70
|
+
test_files: []
|
71
|
+
|