describe('mergeModeConfig', function() {
	'use strict';

	var snooze = require('snooze');
	var should = require('should');

	require('../main.js');
	snooze.module('myApp', ['snooze-baselib']);

	it('should merge the development mode config', function() {
		snooze.module('myApp').snoozeConfig = {
			foo: 'bar',
			modes: {
				development: {
					foo: 'baz'
				}
			}
		};

		snooze.module('myApp').preprocessConfig();

		snooze.module('myApp').snoozeConfig.foo.should.equal('bar');

		snooze.module('myApp').snoozeConfig.mode = 'development';

		snooze.module('myApp').preprocessConfig();

		snooze.module('myApp').snoozeConfig.foo.should.equal('baz');
	});
});
Beispiel #2
0
(function() {
  "use strict";

  var snooze = require('snooze');
  var us = require('underscore');

  snooze
    .module("formatter")
    .service("Formatter", function factory(PdfKitFormatter) {

      function Formatter(model) {
        console.log("Formatter model before: ", model);
        model = us.map(model, function(m) {
          // return ComponentFactory.create(model.type);
          return m;
        })
        return new PdfKitFormatter(model);
      }


      return Formatter;

    })

}());
Beispiel #3
0
(function() {
	"use strict";

	var snooze = require('snooze');

	snooze
		.module("formatter", ["snooze-baselib", "formatter-pdfkit",
			"formatter-components"
		])
		.registerEntitiesFromPath('lib/formatter/*.js')

}());
	it('should merge the development mode config', function() {
		snooze.module('myApp').snoozeConfig = {
			foo: 'bar',
			modes: {
				development: {
					foo: 'baz'
				}
			}
		};

		snooze.module('myApp').preprocessConfig();

		snooze.module('myApp').snoozeConfig.foo.should.equal('bar');

		snooze.module('myApp').snoozeConfig.mode = 'development';

		snooze.module('myApp').preprocessConfig();

		snooze.module('myApp').snoozeConfig.foo.should.equal('baz');
	});
Beispiel #5
0
var snooze = require('snooze');
require('snooze-stdlib');

snooze.module('HelloServer', ['snooze-stdlib'])
		.libs(['controllers', 'services', 'validators', 'dtos', 'routes'])
		.setPort(8000);

snooze.module('HelloServer').wakeup();
var snooze = require('snooze');

snooze.module('snooze-notify').dto('$NotifyMessage', {
	message: {
		type: 'string',
		description: 'simple text message'
	},
	deviceType: {
		type: 'string',
		description: 'android or ios. case insensitive',
		example: 'iOS'
	},
	deviceId: {
		type: 'string',
		description: 'id of device'
	},
	sound: {
		type: 'string',
		description: 'path of sound file or default',
		default: 'default'
	},
	iOS: {
		type: '@$iOSNotifyMessageDTO',
		description: 'iOS specific message data'
	},
	android: {
		type: '@$AndroidNotifyMessageDTO',
		description: 'android specific message data'
	}
});
(function() {
  "use strict";

  var snooze = require('snooze');
  var expect = require('expect');
  var Stream = require('stream');
  var us = require('underscore');
  var fse = require('fs-extra');

  var app = snooze.module("formatter-pdfkit", ["snooze-baselib"]);
  app.registerEntitiesFromPath("lib/**/*.js");

  app.service('Component', function() {

    function Component(model) {
      this._model = model;
    }

    Component.prototype.render = function(doc) {
      throw new Error("Test not implemented");
    };

    Component.prototype.getType = function() {
      return this._model.type;
    };

    Component.prototype.getModel = function() {
      return this._model;
    };

    return Component;

  })

  app.service('testModel1', function() {

    var testModel = {
      type: "text",
      value: "Hello World",
      options: {
        fillColor: "green",
        moveDown: "5"
      }
    };

    return testModel;
  })

  app.service('testModel2', function() {

    var testModel = {
      type: "text",
      value: "Hello World 2",
      options: {
        fillColor: "blue",
        moveDown: "10",
      }
    };

    return testModel;
  })



  beforeEach(function() {
    snooze.clear();
    app.runs.length = 0;
    app.configs.length = 0;
  })

  var target = null;

  describe("Test formatter", function() {

    it(" - format()", function(done) {

      app
        .run(function(PdfKitFormatter, testModel1, testModel2,
          Component,
          TargetResolver) {

          var target = new TargetResolver("output.pdf").resolve();

          var comp1 = new Component(testModel1);
          var comp2 = new Component(testModel2);

          var model = [comp1, comp2];
          var formatter = new PdfKitFormatter(model);

          formatter.format()
            .then(function(stream) {
              expect(stream).toExist();
              expect(stream).toBeA(Stream);
            })
            .then(function() {
              fse.removeSync(target);
              done();
            })

        })
        .wakeup();

    })

  })

}());
Beispiel #8
0
var snooze = require('snooze');
var _ = require('lodash');

snooze.module('snooze-stdlib').service('_', function() {
	return _;
});
Beispiel #9
0
var snooze = require('snooze');

snooze.module('HelloServer')
		.dto('MessageDTO', {
			message: {
				type: 'string',
				description: 'A message from the server.',
				example: '404 Error',
				required: true
			}
		});
Beispiel #10
0
(function() {
	"use strict";

	var config = require('config');
	var S = require('string');
	var snooze = require('snooze');
	var PDFDocument = require('pdfkit');
	var fs = require('fs');
	var us = require('underscore');

	var injects = {};

	function format() {

		var model = this.getModel();

		return new Promise(function(resolve, reject) {

			var doc = new PDFDocument();

			var target = config.get("target").replace("__dirname", __dirname);
			var file = new injects.TargetResolver("output.pdf").resolve();

			var stream = fs.createWriteStream(file);
			var resultStream = doc.pipe(stream);

			model.forEach(function(m) {
				m.render(doc);
			})

			doc.end();

			resultStream.on('finish', function() {
				resolve(fs.createReadStream(file));
			})

		})

	}

	function getModel() {
		return this._model;
	}

	snooze
		.module("formatter-pdfkit")
		.service("TargetResolver", function() {

			function TargetResolver(name) {
				this._target = name;
			}

			TargetResolver.prototype.resolve = function() {
				var root = config.get("target").replace("__dirname", __dirname);
				root = S(root).chompRight("/").s;
				var target = S(this._target).chompLeft("/");
				return root + "/" + target;
			};

			return TargetResolver;
		})
		.service("PdfKitFormatter", function factory(
			TargetResolver, RendererDecorator) {

			injects.TargetResolver = TargetResolver;

			function PdfKitFormatter(model) {

				model = us.map(model, function(item) {
					new RendererDecorator(item).decorate();
					return item;
				})

				this._model = model;
			}


			PdfKitFormatter.prototype.format = format;
			PdfKitFormatter.prototype.getModel = getModel;

			return PdfKitFormatter;

		})

}());
Beispiel #11
0
var snooze = require('snooze');
var apn = require('apn');

snooze.module('snooze-notify').service('$notifyAPNS', function($fs, $tls, $module) {
	var url = 'gateway.push.apple.com';
	var sandboxUrl = 'gateway.sandbox.push.apple.com';
	var port = 2195;
	var initialized = false;
	var connection = null;
	var err = '';
	var passphrase = '';
	var certFile = '';

	var _send = function($NotifyMessageDTO) {
		if(initialized === true) {
			var iOS = $NotifyMessageDTO.iOS || {};
			var android = $NotifyMessageDTO.android || {};

			var message = $NotifyMessageDTO.message;
			var type = $NotifyMessageDTO.deviceType;
			var id = $NotifyMessageDTO.deviceId;
			var sound = $NotifyMessageDTO.sound;

			var expiry = Math.floor(Date.now() / 1000) + (3600*48); // Defaults to 48 hours from now
			var badge = null;
			var alert = message;

			var note = new apn.Notification();

			if(iOS.alert) {
				alert = iOS.alert;
Beispiel #12
0
(function() {
	"use strict";

	var snooze = require('snooze');
	var us = require('underscore');

	var injects = {};

	/**
	 *
	 */
	function getTextRenderer() {

		return function textRenderer(doc) {

			var model = this.getModel()

			us.mapObject(model.options, function(val, key) {
				var method = doc[key];
				if (method) {
					var split = [];
					if (val) {
						split = val.split(",");
					}
					doc = method.apply(doc, split);
				}
			})

			doc.text(model.value);

		};

	}

	/**
	 *
	 */
	function getRenderer(type) {
		if (type.toLowerCase() === "text") {
			return getTextRenderer();
		}
		return null;
	}

	/**
	 *
	 */
	function decorate() {
		var component = this.getComponent();
		var renderer = getRenderer(component.getType());
		component.render = renderer.bind(component);
		return component;
	}

	/**
	 *
	 */
	function getComponent() {
		return this._component;
	}


	snooze
		.module("formatter-pdfkit")
		.service("RendererDecorator", function factory() {

			function RendererDecorator(component) {
				this._component = component;
			}

			RendererDecorator.prototype.decorate = decorate;
			RendererDecorator.prototype.getComponent = getComponent;

			return RendererDecorator;

		})

}());