| Class | OpenLaszlo::Applet |
| In: |
lib/openlaszlo/applet.rb
|
| Parent: | Object |
| source | [R] |
Class methods
# File lib/openlaszlo/applet.rb, line 75
75: def self.compile(basename, target, options={})
76: source = "lzx/#{basename}"
77: target = "public/#{target}"
78: self.new(source).compile(target, options)
79: end
# File lib/openlaszlo/applet.rb, line 8
8: def initialize(source)
9: source = source + '.lzx' unless source =~ /\.lzx$/
10: @source = source
11: end
# File lib/openlaszlo/applet.rb, line 17
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
# File lib/openlaszlo/applet.rb, line 62
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
# File lib/openlaszlo/applet.rb, line 51
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
# File lib/openlaszlo/applet.rb, line 38
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
# File lib/openlaszlo/applet.rb, line 25
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