Class OpenLaszlo::Rails::Applet
In: lib/openlaszlo_build_support.rb
Parent: Object

Methods

Attributes

name  [R] 
options  [R] 
source_dir  [R] 
target  [R] 

Public Class methods

[Source]

# File lib/openlaszlo_build_support.rb, line 13
      def self.from_source(source)
        self.new(source)
      end

[Source]

# 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.

[Source]

# File lib/openlaszlo_build_support.rb, line 11
      def self.main_file_names; %w{main canvas applet application {dirname}}; end

[Source]

# 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

[Source]

# File lib/openlaszlo_build_support.rb, line 28
      def self.options_from_target(target)
        options = {}
        options[:debug] = true if target =~ /-debug(\.swf)/
        options
      end

[Source]

# 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

Public Instance methods

[Source]

# 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

[Source]

# 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

[Source]

# File lib/openlaszlo_build_support.rb, line 83
      def update
        compile unless uptodate?
      end

[Source]

# File lib/openlaszlo_build_support.rb, line 56
      def uptodate?
        return false unless File.exists?(target)
        source_files = Dir[File.join(source_dir, '**/*')] +
          Dir[File.join(RAILS_ROOT, 'lib/**/*')]
        return File.mtime(target) >= source_files.map { |f|
          File.mtime(f) rescue nil }.compact.max
      end

[Validate]