Sha256: 62f64e92289a66679c12d69df39e132c5df78adb5e5f0e02b442c5cd43fc264c

Contents?: true

Size: 1.86 KB

Versions: 2

Compression:

Stored size: 1.86 KB

Contents

require "lanes/spec_helper"

class JavascriptProcessorTest < Lanes::TestCase

SCRIPT = <<-EOS
class NS.Baz
    constructor: ->
        alert("foo")
    alert: (msg)->
        alert(msg);

class NS.Bar extends NS.Baz
    squawk:->
        this.alert("Hello World!")

class Foo extends Bar
    constructor: ->
        this.called=true
        super
    aMethod: ->
         @squawk("howdy!")

EOS

CLEANED=<<-EOS
class NS.Baz
    constructor: ->
        alert("foo")
    alert: (msg)->
        alert(msg);

class NS.Bar
    constructor: -> super
    squawk:->
        this.alert("Hello World!")

NS.Baz.extend(NS.Bar)

class Foo
    constructor: ->
        this.called=true
        super
    aMethod: ->
         @squawk("howdy!")

Bar.extend(Foo)

EOS

JS=<<-EOS
(function(Lanes, Foo, _, window, FILE, undefined){
var Foo;

NS.Baz = (function() {
  function Baz() {
    alert("foo");
  }

  Baz.prototype.alert = function(msg) {
    return alert(msg);
  };

  return Baz;

})();

NS.Bar = (function() {
  function Bar() {
    Bar.__super__.constructor.apply(this, arguments);
  }

  Bar.prototype.squawk = function() {
    return this.alert("Hello World!");
  };

  return Bar;

})();

NS.Baz.extend(NS.Bar);

Foo = (function() {
  function Foo() {
    this.called = true;
    Foo.__super__.constructor.apply(this, arguments);
  }

  Foo.prototype.aMethod = function() {
    return this.squawk("howdy!");
  };

  return Foo;

})();

Bar.extend(Foo);

})(window.Lanes,(window.Lanes ? window.Lanes['Foo'] : null),window._, window,{namespace:(window.Lanes ? window.Lanes['Foo'] : null),extension:'Foo',file:'baz'});
EOS

Scope = Struct.new(:logical_path)

    def test_coffeescript_generation
        template = API::CoffeeScriptWrapper.new{ |t| SCRIPT }
        assert_equal CLEANED, template.cleaned
        
        
        assert_equal JS.chomp, template.render(Scope.new("foo/bar/baz"))
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lanes-0.1.0 spec/api/javascript_processor_spec.rb
lanes-0.0.8 spec/api/javascript_processor_spec.rb