Sha256: 43e7263db92e2db54117923488ca54b704b49fa33a6bf8764c22db8a392f5a92

Contents?: true

Size: 1023 Bytes

Versions: 5

Compression:

Stored size: 1023 Bytes

Contents

require 'sprockets'

module BPM

  # A processor that will invoke a JavaScript-based plugin provided by a
  # package in the system.  The passed method name will be invoked on the
  # plugin.
  class PluginProcessor < Tilt::Template

    def self.with_plugin(plugin_opts, method_name)
      ret = Class.new(self)
      ret.instance_eval do
        @method_name  = method_name
        @plugin_opts  = plugin_opts
      end
      ret
    end

    def self.method_name
      @method_name
    end

    def self.plugin_name
      @plugin_opts["main"]
    end

    def prepare
    end

    def evaluate(context, locals, &block)
      ctx = context.environment.plugin_context_for self.class.plugin_name
      project = context.environment.project
      pkg, module_id = project.package_and_module_from_path file

      filepath   = file.to_s

      ctx["DATA"]  = data
      ctx["CTX"]   = BPM::PluginContext.new(pkg, module_id)
      ctx.eval("BPM_PLUGIN.#{self.class.method_name}(DATA, CTX, '#{filepath}');")
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bpm-1.0.0.beta.13 lib/bpm/pipeline/plugin_processor.rb
bpm-1.0.0.beta.12 lib/bpm/pipeline/plugin_processor.rb
bpm-1.0.0.beta.11 lib/bpm/pipeline/plugin_processor.rb
bpm-1.0.0.beta.10 lib/bpm/pipeline/plugin_processor.rb
bpm-1.0.0.beta.9 lib/bpm/pipeline/plugin_processor.rb