ropenlaszlo 0.2.0

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/doc/CHANGES ADDED
@@ -0,0 +1,13 @@
1
+ = Change Log
2
+
3
+ == Version 0.2.0 (2006/01/11)
4
+ * Released as gem
5
+ * Published to rubyforge
6
+ * Added doc directory
7
+ * Added test directory
8
+ * Added examples directory
9
+
10
+ == Version 0.1.0 (2006/01/04)
11
+ * Initial release
12
+ * Published to osteele.com
13
+ * Announced on weblog.openlaszlo.org
data/doc/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2003, 2004 Jim Weirich
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/doc/README ADDED
@@ -0,0 +1,37 @@
1
+ = ROpenLaszlo Interface to the OpenLaszlo Platform
2
+
3
+ ROpenLaszo is a Ruby interface to the OpenLaszlo[http://openlaszlo.org] platform for creating rich internet applicatons. It allows you to compile OpenLaszlo[http://openlaszlo.org] programs from within Ruby, in order to integrate OpenLaszlo[http://openlaszlo.org] development into Rake or Rails applications.
4
+
5
+ OpenLaszlo[http://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 OpenLaszlo[http://openlaszlo.org] compiler. For example, if hello.lzx contains the following text:
6
+ <canvas>
7
+ <window>
8
+ <button>Hello, World!</button>
9
+ </window>
10
+ </canvas>
11
+ 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:
12
+ require 'rubygems'
13
+ require 'ropenlaszlo'
14
+ OpenLaszlo::compile 'hello.lzx'
15
+
16
+ == Requirements
17
+
18
+ * {OpenLaszlo 3.1}[http://openlaszlo.org]
19
+ * Ruby -v 1.8.2 or later (untested in earlier versions)
20
+
21
+ == Downloading and Installation
22
+
23
+ ROpenLaszlo is distributed as a RubyGem. You may download it from ROpenLaszlo's {RubyForge project}[http://rubyforge.org/projects/ropenlaszlo].
24
+
25
+ Installation of ROpenLaszlo requires that you have RubyGems[http://rubygems.rubyforge.org] installed. In that case, you can download the ROpenLaszlo .gem to your local file system, and execute:
26
+
27
+ gem install ropenlaszlo
28
+
29
+ == Documentation
30
+
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. Where that entry says to download +openlaszlo.rb+ and require +openlaszlo+, you should instead install this ropenlaszlo gem and require +ropenlaszlo+.)
32
+
33
+ == License
34
+
35
+ ROpenLaszlo is copyright (c) 2006 Oliver Steele. It is open-source software, and may be redistributed
36
+ under the terms of the MIT license. The text of this licences is included in the
37
+ ROpenLaszlo distribution, under the +doc+ subdirectory.
data/doc/TODO ADDED
@@ -0,0 +1,18 @@
1
+ = ROpenLaszlo Project -- To Do List
2
+
3
+ == Compiler
4
+ * Dependency tracking
5
+ * Detect when file is not present
6
+ * Class for compiler configuration errors
7
+
8
+ == Unit Tests
9
+ * Compiler parameters
10
+ * Missing source file
11
+ * Syntax error
12
+ * Unreachable server
13
+ * Invalid OPENLASZLO_HOME
14
+
15
+ == Packaging
16
+ * Add rake task file
17
+ * Add unit testing, doc generation to rakefile
18
+
data/lib/compiler.rb ADDED
@@ -0,0 +1,217 @@
1
+ # Author:: Oliver Steele
2
+ # Copyright:: Copyright (c) 2005-2006 Oliver Steele. All rights reserved.
3
+ # License:: Ruby License.
4
+ #
5
+ # This module contains utility methods for compiling OpenLaszlo[http://openlaszlo.org] programs. See the OpenLaszlo module documentation for usage information.
6
+ #
7
+ #--
8
+ # Bugs:
9
+ # - syntax error compiles swf anyway
10
+ #
11
+ # Todo:
12
+ # - unit tests
13
+ # - doc :profile
14
+ #
15
+ # Wishlist:
16
+ # - compile_string
17
+ # - detect compiler version
18
+ # - select compiler based on file location; or, copy files
19
+ # - retrieve dependencies
20
+ # - retrieve compiler warnings
21
+ #
22
+ # Corners:
23
+ # - detect invalid parameters
24
+ # - server isn't running
25
+ # - lps-dev/foo isn't inside lps
26
+
27
+
28
+ # == module OpenLaszlo
29
+ #
30
+ # This module contains utility methods for compiling OpenLaszlo[http://openlaszlo.org] programs.
31
+ #
32
+ # Example:
33
+ # # Set up the environment to use the compile server. The OpenLaszlo server
34
+ # # must be running in order at this location in order for this to work.
35
+ # ENV['OPENLASZLO_HOME'] = '/Applications/OpenLaszlo Server 3.1'
36
+ # ENV['OPENLASZLO_URL'] = 'http://localhost:8080/lps-3.1'
37
+ #
38
+ # require 'openlaszlo'
39
+ # # Create a file 'hello.swf' in the current directory:
40
+ # OpenLaszlo::compile 'hello.lzx'
41
+ #
42
+ # See OpenLaszlo.compile for additional documentation.
43
+ #
44
+ module OpenLaszlo
45
+ # This class implements a bridge to the compile server.
46
+ #
47
+ # If you don't need multiple compilers, you can use the methods in
48
+ # the OpenLaszlo module instead.
49
+ #
50
+ # The compile server is faster than CommandLineCompiler, but can only compile
51
+ # files in the same directory as the {OpenLaszlo SDK}[http://openlaszlo.org].
52
+ class CompileServer
53
+ # Options:
54
+ # * <tt>:openlaszlo_home</tt> - filesystem location of the OpenLaszlo SDK. Defaults to EVN['OPENLASZLO_HOME']
55
+ # * <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'.
56
+ def initialize params={}
57
+ @home = params[:home] || ENV['OPENLASZLO_HOME']
58
+ @base_url = params[:server_uri] || ENV['OPENLASZLO_URL'] || 'http://localhost:8080/lps-dev'
59
+ end
60
+
61
+ # Invokes the OpenLaszlo server-based compiler on +source_file+.
62
+ # +source_file+ must be inside the home directory of the server.
63
+ # See OpenLaszlo.compile for a description of the +params+.
64
+ #
65
+ # Additional options:
66
+ # * <tt>:format</tt> - request type (default 'swf')
67
+ def compile source_file, params={}
68
+ require 'net/http'
69
+ require 'uri'
70
+ # assert that pathname is relative to LPS home:
71
+ absolute_path = File.expand_path source_file
72
+ raise "#{absolute_path} isn't inside #{@home}" unless absolute_path.index(@home) == 0
73
+ server_relative_path = absolute_path[@home.length..-1]
74
+ # FIXME: this doesn't handle quoting; use recursive File.split instead
75
+ # FIXME: should encode the url, for filenames that include '/'
76
+ server_relative_path.gsub(File::Separator, '/')
77
+ output = params[:output] || "#{File.basename source_file, '.lzx'}.swf"
78
+ options = {
79
+ :lzr => params[:runtime],
80
+ :debug => params[:debug],
81
+ :lzproxied => params[:proxied] == nil ? params[:proxied] : false,
82
+ :lzt => params[:format] || 'swf'}
83
+ query = options.map{|k,v|"#{k}=#{v}" unless v.nil?}.compact.join('&')
84
+ url = "#{@base_url}#{server_relative_path}"
85
+ url += "?#{query}" unless query.empty?
86
+ Net::HTTP.get_response URI.parse(url) do |response|
87
+ case response
88
+ when Net::HTTPOK
89
+ File.open(output, 'w') do |f|
90
+ response.read_body do |segment|
91
+ f << segment
92
+ end
93
+ end
94
+ else
95
+ response.value # raises error
96
+ end
97
+ end
98
+ return output
99
+ end
100
+ end
101
+
102
+ # This class implements a bridge to the command-line compiler.
103
+ #
104
+ # If you don't need multiple compilers, you can use the methods in
105
+ # the OpenLaszlo module instead.
106
+ #
107
+ # The command-line compiler is slower than CompileServer, but,
108
+ # unlike the server, it can compile files in any location.
109
+ class CommandLineCompiler
110
+ # Creates a new compiler.
111
+ #
112
+ # Options are:
113
+ # * <tt>:compiler_script</tt> - the path to the shell script that
114
+ # invokes the compiler. This defaults to a standard location inside
115
+ # the value specified by :home.
116
+ # * <tt>:openlaszlo_home</tt> - the home directory of the OpenLaszlo SDK.
117
+ # This defaults to ENV['OPENLASZLO_HOME'].
118
+ def initialize params={}
119
+ @lzc = params[:compiler_script]
120
+ unless @lzc
121
+ home = params[:openlaszlo_home] || ENV['OPENLASZLO_HOME']
122
+ raise ":compiler_script or :openlaszlo_home must be specified" unless home
123
+ search = lzc_directories.map{|f| File.join(home, f, 'lzc')}
124
+ found = search.select{|f| File.exists? f}
125
+ raise "couldn't find bin/lzc in #{search.join(' or ')}" if found.empty?
126
+ @lzc = found.first
127
+ # Adjust the name for Windows
128
+ @lzc += '.bat' if windows?
129
+ end
130
+ end
131
+
132
+ # Invokes the OpenLaszlo command-line compiler on +source_file+.
133
+ #
134
+ # See OpenLaszlo.compile for a description of the +params+.
135
+ def compile source_file, params={}
136
+ default_output = File.basename(source_file, '.lzx') + '.swf'
137
+ output = params[:output] || default_output
138
+ # TODO: could handle this case by compiling to a temporary directory and
139
+ # renaming from there
140
+ raise "#{source_file} and #{output} do not have the same basename." unless File.basename(source_file, '.lzx') == File.basename(output, '.swf')
141
+ args = []
142
+ args << '--runtime=#{params[:runtime]}' if params[:runtime]
143
+ args << '--debug' if params[:debug]
144
+ args << '--profile' if params[:profile]
145
+ args << "--output '#{File.basename output}'" unless File.dirname(source_file) == File.dirname(output)
146
+ `#{@lzc} #{args.join(' ')} '#{source_file}'`
147
+ end
148
+
149
+ private
150
+
151
+ # Locations in which to look for the lzc script, relative to OPENLASZLO_HOME
152
+ def lzc_directories
153
+ [# binary distro location
154
+ 'bin',
155
+ # binary distro location
156
+ 'WEB-INF/lps/server/bin'
157
+ ]
158
+ end
159
+
160
+ def windows?
161
+ RUBY_PLATFORM =~ /win/ and not RUBY_PLATFORM =~ /darwin/
162
+ end
163
+ end
164
+
165
+ # Returns the default compiler. Use the server-based compiler if it's
166
+ # available, since it's so much faster.
167
+ def self.compiler
168
+ return @compiler if @compiler
169
+ return @compiler = CompileServer.new if ENV['OPENLASZLO_URL'] and ENV['OPENLASZLO_HOME']
170
+ return @compiler = CommandLineCompiler.new if ENV['OPENLASZLO_HOME']
171
+ raise <<EOF
172
+ Couldn't find an OpenLaszlo compiler.
173
+
174
+ To use the compile server (recommended), set ENV['OPENLASZLO_URL'] and ENV['OPENLASZLO_HOME'].
175
+
176
+ To use the command-line compiler, set ENV['OPENLASZLO_HOME'].
177
+ EOF
178
+ end
179
+
180
+ # Sets the default compiler for future invocations of OpenLaszlo.compile.
181
+ def self.compiler= compiler
182
+ @compiler = compiler
183
+ end
184
+
185
+ # Compile an OpenLaszlo[http://openlaszlo.org] source file.
186
+ #
187
+ # Examples:
188
+ # require 'openlaszlo'
189
+ # OpenLaszlo::compile 'hello.lzx'
190
+ # OpenLaszlo::compile 'hello.lzx', :debug => true
191
+ # OpenLaszlo::compile 'hello.lzx', :runtime => 'swf8'
192
+ # OpenLaszlo::compile 'hello.lzx', {:runtime => 'swf8', :debug => true}
193
+ # OpenLaszlo::compile 'hello.lzx', :output => 'hello-world.swf' # server only
194
+ #
195
+ # Options are:
196
+ # * <tt>:debug</tt> - debug mode (default false)
197
+ # * <tt>:output</tt> - specify the name and location for the output file (default = input_file.sub(/\.lzx$/, '.swf'))
198
+ # * <tt>:proxied</tt> - is application proxied (default true)
199
+ # * <tt>:runtime</tt> - runtime (default swf7)
200
+ #
201
+ # See CompileServer.compile and CommandLineCompiler.compile for additional options
202
+ # that are specific to these compilers.
203
+ def self.compile source_file, params={}
204
+ compiler.compile source_file, params
205
+ end
206
+
207
+ def self.make_html source_file, params={} #:nodoc:
208
+ raise 'not really supported, for now'
209
+ params = {
210
+ :format => 'html-object',
211
+ :output => File.basename(source_file, '.lzx')+'.html'}.update(params)
212
+ compiler.compile source_file, params
213
+ source_file = params[:output]
214
+ s = open(source_file).read
215
+ open(source_file, 'w') {|f| f.write s.gsub!(/\.lzx\?lzt=swf&amp;/, '.lzx.swf?')}
216
+ end
217
+ end
@@ -0,0 +1,5 @@
1
+ # Author:: Oliver Steele
2
+ # Copyright:: Copyright (c) 2005-2006 Oliver Steele. All rights reserved.
3
+ # License:: Ruby License.
4
+
5
+ require 'compiler'
@@ -0,0 +1,131 @@
1
+ # Author:: Oliver Steele
2
+ # Copyright:: Copyright (c) 2005-2006 Oliver Steele. All rights reserved.
3
+ # License:: Ruby License.
4
+
5
+ $:.unshift File.dirname(__FILE__) + "/../lib"
6
+
7
+ require 'test/unit'
8
+ require 'ropenlaszlo'
9
+ require 'fileutils'
10
+
11
+ include FileUtils
12
+
13
+ REQUIRED_ENV_VALUES = %w{OPENLASZLO_HOME OPENLASZLO_HOME}
14
+ unless REQUIRED_ENV_VALUES.reject {|w| ENV[w]}.empty?
15
+ raise "These environment variables must be set: #{REQUIRED_ENV_VALUES}.join(', ')"
16
+ end
17
+
18
+ class << ENV
19
+ # Execute a block, restoring the bindings for +keys+ at the end.
20
+ # NOT thread-safe!
21
+ def with_saved_bindings keys, &block
22
+ saved_bindings = Hash[*keys.map {|k| [k, ENV[k]]}.flatten]
23
+ begin
24
+ block.call
25
+ ensure
26
+ ENV.update saved_bindings
27
+ end
28
+ end
29
+
30
+ # Execute a block with the temporary bindings in +bindings+.
31
+ # Doesn't remove keys; simply sets them to nil.
32
+ def with_bindings bindings, &block
33
+ with_saved_bindings bindings.keys do
34
+ ENV.update bindings
35
+ return block.call
36
+ end
37
+ end
38
+ end
39
+
40
+ module CompilerTestHelper
41
+ def super_setup
42
+ OpenLaszlo::compiler = nil
43
+ cd File.dirname(__FILE__)
44
+ end
45
+
46
+ private
47
+ def compile file, output=nil, options={}
48
+ output = File.basename(file, '.lzx')+'.swf'
49
+ rm_f output
50
+ begin
51
+ OpenLaszlo::compile file, *options
52
+ assert File.exists?(output), "#{output} does not exist"
53
+ ensure
54
+ rm_f output
55
+ end
56
+ end
57
+ end
58
+
59
+ class CompileServerTest < Test::Unit::TestCase
60
+ include CompilerTestHelper
61
+
62
+ def setup
63
+ @test_dir = File.join(ENV['OPENLASZLO_HOME'], 'ropenlaszlo-tests')
64
+ mkdir @test_dir
65
+ super_setup
66
+ end
67
+
68
+ def teardown
69
+ rm_rf @test_dir
70
+ end
71
+
72
+ def test_compilation
73
+ compile 'test.lzx'
74
+ end
75
+
76
+ private
77
+ alias :saved_compile :compile
78
+
79
+ def compile file, output=nil, options={}
80
+ server_local_file = File.join @test_dir, File.basename(file)
81
+ cp file, server_local_file
82
+ begin
83
+ saved_compile server_local_file, output, options
84
+ ensure
85
+ rm_f server_local_file
86
+ end
87
+ end
88
+ end
89
+
90
+ class CommandLineCompilerTest < Test::Unit::TestCase
91
+ include CompilerTestHelper
92
+
93
+ def setup
94
+ bindings = {'OPENLASZLO_URL' => nil}
95
+ @saved_bindings = Hash[*bindings.keys.map{|k|[k,ENV[k]]}.flatten]
96
+ ENV.update bindings
97
+ super_setup
98
+ end
99
+
100
+ def teardown
101
+ ENV.update @saved_bindings
102
+ end
103
+
104
+ def test_compilation
105
+ compile 'test.lzx'
106
+ end
107
+ end
108
+
109
+ class CompilerFacadeTest < Test::Unit::TestCase
110
+ def setup
111
+ raise "ENV['OPENLASZLO_URL'] must be set" unless ENV['OPENLASZLO_URL']
112
+ raise "ENV['OPENLASZLO_HOME'] must be set" unless ENV['OPENLASZLO_HOME']
113
+ OpenLaszlo::compiler = nil
114
+ end
115
+
116
+ def test_select_server
117
+ assert_instance_of OpenLaszlo::CompileServer, OpenLaszlo::compiler
118
+ end
119
+
120
+ def test_select_commandline
121
+ ENV.with_bindings 'OPENLASZLO_URL' => nil do
122
+ assert_instance_of OpenLaszlo::CommandLineCompiler, OpenLaszlo::compiler
123
+ end
124
+ end
125
+
126
+ def test_missing_home
127
+ ENV.with_bindings 'OPENLASZLO_HOME' => nil do
128
+ assert_raise(RuntimeError) do OpenLaszlo::compiler end
129
+ end
130
+ end
131
+ end
data/test/test.lzx ADDED
@@ -0,0 +1 @@
1
+ <canvas/>
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: ropenlaszlo
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.2.0
7
+ date: 2006-01-11 00:00:00 -05:00
8
+ summary: Ruby interface to OpenLaszlo.
9
+ require_paths:
10
+ - lib
11
+ email: steele@osteele.com
12
+ homepage: http://ropenlaszlo.rubyforge.org
13
+ rubyforge_project: ropenlaszlo
14
+ description: ROpenLaszlo is an interface to the OpenLaszlo compiler.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - Oliver Steele
30
+ files:
31
+ - lib/compiler.rb
32
+ - lib/ropenlaszlo.rb
33
+ - doc/CHANGES
34
+ - doc/MIT-LICENSE
35
+ - doc/README
36
+ - doc/TODO
37
+ - test/compiler_test.rb
38
+ - test/test.lzx
39
+ test_files: []
40
+
41
+ rdoc_options:
42
+ - --title
43
+ - ROpenLaszlo -- Ruby interface to OpenLaszlo
44
+ - --main
45
+ - doc/README
46
+ extra_rdoc_files:
47
+ - doc/CHANGES
48
+ - doc/MIT-LICENSE
49
+ - doc/README
50
+ - doc/TODO
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ requirements: []
56
+
57
+ dependencies: []
58
+