| Class | OpenLaszlo::Rails::Applet |
| In: |
lib/openlaszlo_build_support.rb
|
| Parent: | Object |
| name | [R] | |
| options | [R] | |
| source_dir | [R] | |
| target | [R] |
# File lib/openlaszlo_build_support.rb, line 17 def self.from_target(target) self.new(source_dir_for_target(target), target, options_from_target(target)) end
An applet is any LZX file in app/applets/*/*.lzx whose name matches one of the names below, where {dirname} is the name of the directory that contains the file.
# File lib/openlaszlo_build_support.rb, line 11 def self.main_file_names; %w{main canvas applet application {dirname}}; end
# File lib/openlaszlo_build_support.rb, line 38 def initialize(source, target=nil, options={}) @name = File.basename(source) source = File.dirname(source) if File.ftype(source) == 'file' target ||= File.join(RAILS_ROOT, 'public/applets', File.basename(source, '.lzx')+'.swf') @source_dir = source @target = target @options = options end
# File lib/openlaszlo_build_support.rb, line 28 def self.options_from_target(target) options = {} options[:debug] = true if target =~ /-debug(\.swf)/ options end
# File lib/openlaszlo_build_support.rb, line 21 def self.source_dir_for_target(target) target = target.sub(/-debug(\.swf)/, '\1') relative = File.expand_path(target).sub(File.expand_path(RAILS_ROOT), '') name = relative.sub(/^\/public\/applets\//, '').sub(/(\.swf)?(\?\d+)?$/, '') return File.join(RAILS_ROOT, 'app/applets', name) end
# File lib/openlaszlo_build_support.rb, line 64 def compile FileUtils::mkdir_p File.dirname(target) compilation_options = options.clone compilation_options[:output] = target results = OpenLaszlo::compile(source, compilation_options) which_compiler = case results[:compiler] when OpenLaszlo::CompileServer when OpenLaszlo::CommandLineCompiler then " with the command-line compiler" end ActiveRecord::Base.logger.info "Compiled #{name} applet#{which_compiler}" rescue nil if results[:warnings] and results[:warnings].any? ActiveRecord::Base.logger.warn "Warnings:" rescue puts "Warnings:" results[:warnings].each do |warning| ActiveRecord::Base.logger.warn warning rescue puts warning end end end
# File lib/openlaszlo_build_support.rb, line 48 def source self.class.main_file_names.map { |name| name = name.sub(/^\{dirname\}$/, File.basename(source_dir)) pathname = File.join(source_dir, name) + '.lzx' pathname if File.exists?(pathname) }.compact.first or raise "No main file in #{source_dir}" end