osteele-ropenlaszlo 0.5.1 → 0.6.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/CHANGES CHANGED
@@ -1,25 +1,33 @@
1
1
  = Change Log
2
2
 
3
- == Version 0.5.1 (2009/03/22)
4
- * update for compatibility with OpenLaszlo 4.x
5
- * move to github
3
+ == Version 0.6 (2009-03-23)
4
+ * follow symbolic links
5
+ * reorganize directory structure
6
+ * new rake task file
7
+ * fall back to cmd-line compiler if source file is not in web path
8
+ * raise error when lzc is not executable
9
+ * change default runtime to swf8
6
10
 
7
- == Version 0.5 (2009/03/22)
11
+
12
+ == Version 0.5 (2009-03-22)
8
13
  * update for compatibility with OpenLaszlo 4.x
9
14
  * move to github
10
15
 
11
- == Version 0.4.1 (2006/01/25)
16
+
17
+ == Version 0.4.1 (2006-01-25)
12
18
  * bug fix: don't use popen on Windows
13
19
  * bug fix: default LPS_HOME from OPENLASZLO_HOME
14
20
  * added note about OpenLaszlo windows bug
15
21
 
16
- == Version 0.4.0 (2006/01/19)
22
+
23
+ == Version 0.4.0 (2006-01-19)
17
24
  * new feature: command-line compiler detects compilation warnings
18
25
  * bug fix: command-line compilation in qualified directory places object in same directory
19
26
  * improve rdoc
20
27
  * refactored unit tests
21
28
 
22
- == Version 0.3.0 (2006/01/16)
29
+
30
+ == Version 0.3.0 (2006-01-16)
23
31
  * New feature: compilation errors and warnings
24
32
  * Bug fix: --output doesn't exist; --dir does
25
33
  * refactored test case setup
@@ -28,14 +36,16 @@
28
36
  * Updated installation instructions
29
37
  * Fixed rdoc formatting errors
30
38
 
31
- == Version 0.2.0 (2006/01/11)
39
+
40
+ == Version 0.2.0 (2006-01-11)
32
41
  * Released as gem
33
42
  * Moved to rubyforge
34
43
  * Added doc directory
35
44
  * Added test directory
36
45
  * Added examples directory
37
46
 
38
- == Version 0.1.0 (2006/01/04)
47
+
48
+ == Version 0.1.0 (2006-01-04)
39
49
  * Initial release
40
50
  * Published to osteele.com
41
51
  * Announced on weblog.openlaszlo.org
data/README.rdoc CHANGED
@@ -12,8 +12,8 @@ OpenLaszlo[openlaszlo.org] programs are written in XML with embedded JavaScript,
12
12
  </canvas>
13
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
14
  require 'rubygems'
15
- require 'ropenlaszlo'
16
- OpenLaszlo::compile 'hello.lzx'
15
+ require 'openlaszlo'
16
+ OpenLaszlo::compile 'hello.lzx' # creates hello.swf
17
17
 
18
18
  You can turn this snippet into a Rake task that will compile any Open<tt></tt>Laszlo source file:
19
19
  rule '.swf' => '.lzx' do |t|
@@ -21,6 +21,11 @@ You can turn this snippet into a Rake task that will compile any Open<tt></tt>La
21
21
  OpenLaszlo::compile t.source, :output => t.name
22
22
  end
23
23
 
24
+ The following includes such a task:
25
+ require 'openlaszlo'
26
+ load 'tasks/openlaszlo.rake'
27
+ # defines a pattern *.lzx -> *.swf
28
+
24
29
  == Requirements
25
30
 
26
31
  * {OpenLaszlo 3.1 or later}[openlaszlo.org]
@@ -53,6 +58,13 @@ You can turn this snippet into a Rake task that will compile any Open<tt></tt>La
53
58
 
54
59
  * The RubyForge project page is here[http://rubyforge.org/projects/ropenlaszlo/].
55
60
 
61
+
62
+ == Author
63
+
64
+ Oliver Steele
65
+ steele@osteele.com
66
+
67
+
56
68
  == License
57
69
 
58
70
  ROpenLaszlo is copyright (c) 2006 - 2009 by Oliver Steele. It is
data/TODO CHANGED
@@ -1,21 +1,20 @@
1
1
  = ROpenLaszlo Project -- To Do List
2
2
 
3
3
  == Features
4
- * Add rake task file
5
- * Compile server: allow use of proxy?
6
- * Compile server: temporarily copy files into webapp directory
4
+ * Compiler server: test whether allow_links=true
5
+ * Compile server: add alias to source directory
6
+ * Dependency tracking: switch to hpricot
7
7
  * compile_string
8
- * Dependency tracking
9
8
  * query compiler version
10
9
 
11
10
  == Unit Tests
11
+ * "Runtime" option
12
+ * Fallback to command-line compiler
12
13
  * Compiler parameters
13
14
  * Missing source file
14
15
  * Unreachable server
15
16
  * Invalid OPENLASZLO_HOME
16
17
 
17
18
  == Corners
18
- * invalid parameters
19
19
  * server isn't running
20
20
  * thinks lps-dev/foo is in lps/ directory
21
-
data/lib/openlaszlo.rb ADDED
@@ -0,0 +1 @@
1
+ require 'ropenlaszlo'
@@ -0,0 +1,81 @@
1
+ # Author:: Oliver Steele
2
+ # Copyright:: Copyright (c) 2005-2008 Oliver Steele. All rights reserved.
3
+ # License:: MIT License
4
+ module OpenLaszlo
5
+ class Applet
6
+ attr_reader :source
7
+
8
+ def initialize(source)
9
+ source = source + '.lzx' unless source =~ /\.lzx$/
10
+ @source = source
11
+ end
12
+
13
+ def source_dir
14
+ File.dirname(source)
15
+ end
16
+
17
+ def compile(target=nil, options={})
18
+ target ||= source + '.swf'
19
+ return if up2date?(target) unless options[:force]
20
+
21
+ puts "Compiling #{source} -> #{target}" if options[:verbose]
22
+ OpenLaszlo::compile(source, options)
23
+ end
24
+
25
+ def up2date?(target=nil)
26
+ target ||= source + '.swf'
27
+ return false unless File.exists?(target)
28
+ sources = Dir["#{source_dir}/**/*"].reject { |fname| fname =~ /\.lzx\.swf/ } -
29
+ Dir["#{source_dir}/build/**/*"]
30
+ source_mtime = sources.
31
+ # the 'rescue' ignores symbolic links without targets
32
+ map { |f| File.mtime(f) rescue nil }.
33
+ compact.
34
+ max
35
+ source_mtime < File.mtime(target)
36
+ end
37
+
38
+ def runtime_assets
39
+ dir = File.dirname(source)
40
+ includes = `grep -h http: #{dir}/*.lzx`.scan(/http:(.*?)['"]/).
41
+ map(&:first)
42
+ includes += `grep -h http: #{dir}/*/*.lzx`.scan(/http:(.*?)['"]/).
43
+ map(&:first).
44
+ map { |s| s.sub(/^\.\.\//, '') }
45
+ return includes.
46
+ uniq.
47
+ map { |f| File.join(dir, f) }.
48
+ select { |src| File.exists?(src) && File.ftype(src) != 'directory' }
49
+ end
50
+
51
+ def preprocess_to(dir, options={})
52
+ files = Dir[File.join(source_dir, '**/*.js')] - Dir[File.join(source_dir, '.hg')]
53
+ files.each do |src|
54
+ dst = File.join(dir, src.sub(source_dir, ''))
55
+ next if File.exists?(dst) and (!options[:force] and File.mtime(dst) > File.mtime(src))
56
+ puts "Copy #{src} #{dst}"
57
+ content = preprocess_string(open(src).read)
58
+ open(dst, 'w') do |fo| fo << content end
59
+ end.length
60
+ end
61
+
62
+ def preprocess_string(content)
63
+ re = /^\s*([a-zA-Z][a-zA-Z0=9]*)\.each\(function\(([a-zA-Z][a-zA-Z0-9]*)\)\{(.*?)}\);/m
64
+ content.gsub!(re) do |s|
65
+ target, var, body = s.match(re).captures
66
+ "var $0=#{target}, $1=$0.length;for(var $2=0; $1--;){var #{var}=$0[$2++];#{body}}"
67
+ end
68
+ return content
69
+ end
70
+
71
+ #
72
+ # Class methods
73
+ #
74
+
75
+ def self.compile(basename, target, options={})
76
+ source = "lzx/#{basename}"
77
+ target = "public/#{target}"
78
+ self.new(source).compile(target, options)
79
+ end
80
+ end
81
+ end
@@ -1,9 +1,9 @@
1
1
  # Author:: Oliver Steele
2
- # Copyright:: Copyright (c) 2005-2006 Oliver Steele. All rights reserved.
3
- # License:: Ruby License.
4
-
2
+ # Copyright:: Copyright (c) 2005-2008 Oliver Steele. All rights reserved.
3
+ # License:: MIT License
4
+
5
5
  # == module OpenLaszlo
6
- #
6
+ #
7
7
  # This module contains utility methods for compiling
8
8
  # OpenLaszlo[openlaszlo.org] programs.
9
9
  #
@@ -18,10 +18,11 @@
18
18
  # OpenLaszlo::compile 'hello.lzx'
19
19
  #
20
20
  # See OpenLaszlo.compile for additional documentation.
21
- #
21
+ #
22
22
  module OpenLaszlo
23
23
  class CompilationError < StandardError; end
24
-
24
+ class InvalidSourceLocation < StandardError; end
25
+
25
26
  # This class implements a bridge to the compile server.
26
27
  #
27
28
  # If you don't need multiple compilers, you can use the methods in
@@ -39,7 +40,7 @@ module OpenLaszlo
39
40
  @home = File.dirname(dirs.first) if dirs.any?
40
41
  @base_url = options[:server_uri] || ENV['OPENLASZLO_URL'] || 'http://localhost:8080/lps-dev'
41
42
  end
42
-
43
+
43
44
  # Invokes the Open<tt></tt>Laszlo server-based compiler on
44
45
  # +source_file+. +source_file+ must be inside the home directory
45
46
  # of the server.
@@ -58,7 +59,7 @@ module OpenLaszlo
58
59
  raise CompilationError.new(results[:error]) if results[:error]
59
60
  return results
60
61
  end
61
-
62
+
62
63
  private
63
64
  def compile_object(source_file, object, options={})
64
65
  options = {}.update(options).update(:output => object)
@@ -70,7 +71,7 @@ module OpenLaszlo
70
71
  options = {}.update(options).update(:format => 'canvas-xml', :output => nil)
71
72
  text = request(source_file, options)
72
73
  if text =~ %r{<warnings>(.*?)</warnings>}m
73
- results[:warnings] = $1.scan(%r{<error>\s*(.*?)\s*</error>}m).map{|w|w.first}
74
+ results[:warnings] = $1.scan(%r{<error>\s*(.*?)\s*</error>}m).map { |w| w.first }
74
75
  elsif text !~ %r{<canvas>} && text =~ %r{<pre>Error:\s*(.*?)\s*</pre>}m
75
76
  results[:error] = $1
76
77
  end
@@ -83,20 +84,32 @@ module OpenLaszlo
83
84
  require 'uri'
84
85
  # assert that pathname is relative to LPS home:
85
86
  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, '/')
87
+ server_relative_path = nil
88
+ begin
89
+ # follow links
90
+ server_relative_path = Dir[File.join(@home, '*')].map do |file|
91
+ next unless File.ftype(file) == 'link'
92
+ dir = File.readlink(file)
93
+ next unless absolute_path.index(dir) == 0
94
+ File.join('/', File.basename(file), absolute_path[dir.length..-1])
95
+ end.compact.first
96
+ end
97
+ unless server_relative_path
98
+ raise InvalidSourceLocation.new("#{absolute_path} isn't inside #{@home}") unless absolute_path.index(@home) == 0
99
+ server_relative_path = absolute_path[@home.length..-1]
100
+ # FIXME: this doesn't handle quoting; use recursive File.split instead
101
+ # FIXME: should encode the url, for filenames that include '/'
102
+ server_relative_path.gsub(File::Separator, '/')
103
+ end
91
104
  options = {
92
105
  :lzr => options[:runtime],
93
106
  :debug => options[:debug],
94
107
  :lzproxied => options.fetch(:proxied, false),
95
108
  :lzt => options[:format] || 'swf'}
96
- query = options.map{|k,v|"#{k}=#{v}" unless v.nil?}.compact.join('&')
109
+ query = options.map { |k,v| "#{k}=#{v}" unless v.nil? }.compact.join('&')
97
110
  url = "#{@base_url}#{server_relative_path}"
98
111
  url += "?#{query}" unless query.empty?
99
- Net::HTTP.get_response URI.parse(url) do |response|
112
+ Net::HTTP.get_response(URI.parse(url)) do |response|
100
113
  case response
101
114
  when Net::HTTPOK
102
115
  if output
@@ -114,7 +127,7 @@ module OpenLaszlo
114
127
  end
115
128
  end
116
129
  end
117
-
130
+
118
131
  # This class implements a bridge to the command-line compiler.
119
132
  #
120
133
  # If you don't need multiple compilers, you can use the methods in
@@ -136,14 +149,26 @@ module OpenLaszlo
136
149
  unless @lzc
137
150
  home = options[:openlaszlo_home] || ENV['OPENLASZLO_HOME']
138
151
  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}
152
+ search = bin_directories.map {|f| File.join(home, f, 'lzc')}
153
+ found = search.select {|f| File.exists? f}
141
154
  raise "couldn't find bin/lzc in #{bin_directories.join(' or ')}" if found.empty?
142
155
  @lzc = found.first
143
156
  @lzc += '.bat' if windows?
144
157
  end
145
158
  end
146
159
 
160
+ def self.executable_path(options={})
161
+ home = options[:openlaszlo_home] || ENV['OPENLASZLO_HOME']
162
+ raise ":compiler_script or OPENLASZLO_HOME must be specified" unless home
163
+ path = bin_directories.
164
+ map { |f| File.join(home, f, 'lzc') }.
165
+ select { |f| File.exists? f }.
166
+ first
167
+ raise "couldn't find bin/lzc in #{bin_directories.join(' or ')}" unless path
168
+ path += '.bat' if windows?
169
+ return path
170
+ end
171
+
147
172
  # Invokes the OpenLaszlo command-line compiler on +source_file+.
148
173
  #
149
174
  # See OpenLaszlo.compile for a description of +options+.
@@ -155,10 +180,11 @@ module OpenLaszlo
155
180
  output = options[:output] || default_output
156
181
  raise "#{source_file} and #{output} do not have the same basename." unless File.basename(source_file, '.lzx') == File.basename(output, output_suffix)
157
182
  args = []
158
- args << '--runtime=#{options[:runtime]}' if options[:runtime]
183
+ args << "--runtime=#{options[:runtime]}" if options[:runtime]
159
184
  args << '--debug' if options[:debug]
160
185
  args << '--profile' if options[:profile]
161
- args << "--dir '#{File.dirname output}'" unless File.dirname(source_file) == File.dirname(output)
186
+ args << "--dir '#{File.dirname output}'" unless
187
+ File.dirname(source_file) == File.dirname(output)
162
188
  args << source_file
163
189
  command = "\"#{@lzc}\" #{args.join(' ')}"
164
190
  ENV['LPS_HOME'] ||= ENV['OPENLASZLO_HOME']
@@ -182,9 +208,9 @@ module OpenLaszlo
182
208
  results = {:output => output, :warnings => warnings}
183
209
  return results
184
210
  end
185
-
211
+
186
212
  private
187
-
213
+
188
214
  # Locations in which to look for the lzc script, relative to OPENLASZLO_HOME
189
215
  def bin_directories
190
216
  [# binary distro location
@@ -193,12 +219,12 @@ module OpenLaszlo
193
219
  'WEB-INF/lps/server/bin'
194
220
  ]
195
221
  end
196
-
222
+
197
223
  def windows?
198
224
  RUBY_PLATFORM =~ /win/ and not RUBY_PLATFORM =~ /darwin/
199
225
  end
200
226
  end
201
-
227
+
202
228
  # Returns the default compiler. Use the server-based compiler if it's
203
229
  # available, since it's so much faster.
204
230
  def self.compiler
@@ -213,12 +239,12 @@ To use the compile server (recommended), set ENV['OPENLASZLO_URL'] and ENV['OPEN
213
239
  To use the command-line compiler, set ENV['OPENLASZLO_HOME'].
214
240
  EOF
215
241
  end
216
-
242
+
217
243
  # Sets the default compiler for future invocations of OpenLaszlo.compile.
218
244
  def self.compiler=(compiler)
219
245
  @compiler = compiler
220
246
  end
221
-
247
+
222
248
  # Compile an OpenLaszlo source file.
223
249
  #
224
250
  # Examples:
@@ -226,20 +252,24 @@ EOF
226
252
  # OpenLaszlo::compile 'hello.lzx'
227
253
  # OpenLaszlo::compile 'hello.lzx', :debug => true
228
254
  # OpenLaszlo::compile 'hello.lzx', :runtime => 'swf8'
229
- # OpenLaszlo::compile 'hello.lzx', {:runtime => 'swf8', :debug => true}
255
+ # OpenLaszlo::compile 'hello.lzx', :runtime => 'swf8', :debug => true
230
256
  # OpenLaszlo::compile 'hello.lzx', :output => 'hello-world.swf'
231
257
  #
232
258
  # Options are:
233
259
  # * <tt>:debug</tt> - debug mode (default false)
234
260
  # * <tt>:output</tt> - specify the name and location for the output file (default = <tt>input_file.sub(/\.lzx$/, '.swf')</tt>)
235
261
  # * <tt>:proxied</tt> - is application proxied (default true)
236
- # * <tt>:runtime</tt> - runtime (default swf7)
262
+ # * <tt>:runtime</tt> - runtime (default swf8)
237
263
  #
238
264
  # See CompileServer.compile and CommandLineCompiler.compile for
239
265
  # additional options that are specific to the compilation methods in
240
266
  # those classes.
241
267
  def self.compile(source_file, options={})
242
- return compiler.compile source_file, options
268
+ options = options.clone
269
+ options[:runtime] ||= 'swf8'
270
+ compiler.compile(source_file, options)
271
+ rescue InvalidSourceLocation
272
+ CommandLineCompiler.new.compile(source_file, options)
243
273
  end
244
274
 
245
275
  def self.make_html(source_file, options={}) #:nodoc:
@@ -250,6 +280,8 @@ EOF
250
280
  compiler.compile(source_file, options)
251
281
  source_file = options[:output]
252
282
  s = open(source_file).read
253
- open(source_file, 'w') {|f| f.write s.gsub!(/\.lzx\?lzt=swf&amp;/, '.lzx.swf?')}
283
+ open(source_file, 'w') do |f|
284
+ f << s.gsub!(/\.lzx\?lzt=swf&amp;/, '.lzx.swf?')
285
+ end
254
286
  end
255
287
  end
data/lib/ropenlaszlo.rb CHANGED
@@ -2,4 +2,4 @@
2
2
  # Copyright:: Copyright (c) 2005-2006 Oliver Steele. All rights reserved.
3
3
  # License:: Ruby License.
4
4
 
5
- require 'compiler'
5
+ require 'openlaszlo/compiler'
@@ -0,0 +1,6 @@
1
+ require 'openlaszlo'
2
+
3
+ rule '.swf' => '.lzx' do |t|
4
+ puts "Compiling #{t.source} => #{t.name}" if verbose
5
+ OpenLaszlo::compile t.source, :output => t.name
6
+ end
@@ -7,7 +7,7 @@ require File.join(File.dirname(__FILE__), 'test_utils.rb')
7
7
 
8
8
  include FileUtils
9
9
 
10
- REQUIRED_ENV_VALUES = %w{OPENLASZLO_HOME OPENLASZLO_HOME}
10
+ REQUIRED_ENV_VALUES = %w{OPENLASZLO_HOME OPENLASZLO_URL}
11
11
  unless REQUIRED_ENV_VALUES.reject {|w| ENV[w]}.empty?
12
12
  raise "These environment variables must be set: #{REQUIRED_ENV_VALUES}.join(', ')"
13
13
  end
@@ -0,0 +1,2 @@
1
+ require 'openlaszlo'
2
+ load 'tasks/openlaszlo.rake'
@@ -0,0 +1 @@
1
+ <canvas/>
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osteele-ropenlaszlo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Steele
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-22 00:00:00 -07:00
12
+ date: 2009-03-23 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -25,11 +25,21 @@ extra_rdoc_files:
25
25
  - CHANGES
26
26
  - TODO
27
27
  files:
28
- - lib/compiler.rb
28
+ - lib/openlaszlo
29
+ - lib/openlaszlo/applet.rb
30
+ - lib/openlaszlo/compiler.rb
31
+ - lib/openlaszlo/compiler.rb.orig
32
+ - lib/openlaszlo.rb
29
33
  - lib/ropenlaszlo.rb
34
+ - lib/tasks
35
+ - lib/tasks/openlaszlo.rake
30
36
  - test/compilation-error.lzx
31
37
  - test/compilation-warning.lzx
32
38
  - test/compiler_test.rb
39
+ - test/tasks
40
+ - test/tasks/Rakefile
41
+ - test/tasks/test.lzx
42
+ - test/tasks/test.swf
33
43
  - test/test.lzx
34
44
  - test/test_utils.rb
35
45
  - README.rdoc