Example #1
0
function generateSchemas(){
	if(argv.h){
		var schemas = ramlParser.schemas();

		var dir = path.join(argv.d, config.directory.schemas);

		console.log("Copying schemas to directory:", dir);

		utils.each(schemas, function(schema){

			var script = new file();
			var name = new String;

			// Get the resource name from the schema data
			for(k in schema){
				name = k;
			}

			console.log("Copying schema:", name);

			script.directory = dir;
			script.setName(name + ".json");

			script.addContent(schema[name]);

			script.build();
		})
	}
}
Example #2
0
/**
 * Generate Head file that connects to all Diet-RAML files
 */
function generateHeader(){
	if(!argv.n){
		console.log('Generating: Header file');
		var script = new file();

		var index = {
			errors: '',
			handler: '',
			requires: ''
		};

		script.directory = path.join(argv.d, config.directory.header);
		script.setName('header');

		utils.each(resources, function(resource){
			index.requires += "require('./" + path.join(config.directory.routes, resource.name) + "');\n";
		});

		index.errors = coder.indentCode('var methodStatus = ' + JSON.stringify(coder.parseErrors(errors, true)) + ';');
		
		index.handler = coder.loadTemplate('head_handler');

		for(code in index)
			script.addContent(index[code] + '\n\n');

		script.inFunction = true;
		script.requireErrorHandler = true;

		script.build();
	}
}
function buildRoutes(resource){
	routes = [];

	if(resource.methods.length > 0){
		utils.each(resource.methods, function(method){
			var code = dietUtils.parseUriParams(resource.completeRelativeUri);
			var route = coder.createRoute(code, method);
			routes.push(route);
		})
	}

	if(resource.childs.length > 0){
		utils.each(resource.childs, function(child){
			routes = routes.concat(buildRoutes(child));
		});
	}

	return routes;
}
Example #4
0
module.exports = function(router, model, options){

	// default options
	options = utils.defaults({}, defOptions, options);

	// required options
	if(!utils.isString(options.name))
		throw new Error("Missing name property");

	// collection route
	var colRoute = router.route('/'+options.name);
	// specific element route
	var eleRoute = router.route('/'+options.name+"/:id");

	// getting all objects
	if(options.getAll)
		colRoute.get(handlers.getAll(model, options));

	// updating all objects
	if(options.updateAll)
		colRoute.put(handlers.updateAll(model, options));

	// create
	if(options.create)
		colRoute.post(handlers.create(model, options));

	// delete all objects
	if(options.deleteAll)
		colRoute.delete(handlers.deleteAll(model, options));

	// getting one object
	if(options.getOne)
		eleRoute.get(handlers.getOne(model, options));

	// updating one object
	if(options.updateOne)
		eleRoute.get(handlers.updateOne(model, options));

	// deleting one object
	if(options.deleteOne)
		eleRoute.get(handlers.deleteOne(model, options));

};
Generator.prototype.generateHeader = function() {
	var self = this;

	// Load resource object if they are not loaded yet
	if(_.isFalsy(self._ramlResources)){
		self._ramlResources = self._ramlParser.resources();
	}

	// Load errors if they are not loaded yet
	if(_.isFalsy(self._ramlErrors)){
		self._ramlParser.resources();
		self._ramlErrors = self._ramlParser.allStatusErrors();
	}

	self.emit("start", "header");
	self.emit("start.header");

	var resources = self._ramlResources;
	var errors = self._ramlErrors;

	var script = new file();

	var index = {
		errors: '',
		handler: '',
		requires: ''
	};

	script.directory = path.join(self.getDirectory(), self.$config.directory.header);
	script.setName('header');

	utils.each(resources, function(resource){
		index.requires += "require('./../" + path.join(self.$config.directory.routes, resource.name) + "')(app);\n";
	});

	index.errors = coder.indentCode('var methodStatus = ' + JSON.stringify(coder.parseErrors(errors, true)) + ';');
	
	index.handler = coder.loadTemplate('head_handler');

	for(code in index)
		script.addContent(index[code] + '\n\n');

	script.inFunction = true;
	script.requireErrorHandler = true;

	script.build();

	script.on("done", function(){
		self.emit("done", "header");
		self.emit("done.header");
	});
};
Generator.prototype.generateSchemas = function() {
	var self = this;

	var schemas = self._ramlParser.schemas();

	var dir = path.join(self.getDirectory(), self.$config.directory.schemas);

	// Schemas not found
	if(!schemas){
		console.log("WARNING: Schemas not found in RAML");
		self.emit("done.schemas");
		self.emit("done", "schemas");
	}

	else{
		self.emit("start", "schemas");
		self.emit("start.schemas");

		utils.each(schemas, function(schema){

			var script = new file();
			var name = new String;

			// Get the resource name from the schema data
			for(k in schema){
				name = k;
			}

			self.emit("start.schemas.schema", name);

			script.directory = dir;
			script.setName(name + ".json");

			script.addContent(schema[name]);

			script.build();

			script.on("done", function(){
				self.emit("done", "schemas");
				self.emit("done.schemas");
			});
		});
	}
};
Example #7
0
	parseUriParams: function(uri){
		var str = utils.replace(uri, '{', ':');

		return utils.replace(str, '}', '');
	},
Example #8
0
  render() {
    const {
      className,
      newPitch,
      newPitch: {
        address,
        maxNumberOfPlayers,
        minNumberOfPlayers,
        name,
        type
      },
      onAddressChange,
      onMaxNumberOfPlayersChange,
      onMinNumberOfPlayersChange,
      onNameChange,
      onTypeChange,
      onSubmit
    } = this.props;
    const capacity = formatRange(minNumberOfPlayers, maxNumberOfPlayers);

    return (
      <div
        className={classNames(
          'new-pitch',
          className
        )}>
        <Form
          onSubmit={onSubmit}
          inputs={[
            {
              label: 'Name',
              displayValue: name,
              isValid: NewPitchModel.isNameValid(newPitch),
              component: (
                <EditableText
                  isEditing={true}
                  text={name}
                  onChange={onNameChange} />
              )
            },
            {
              label: 'Address',
              displayValue: address,
              isValid: NewPitchModel.isAddressValid(newPitch),
              component: (
                <EditableText
                  isEditing={true}
                  text={address}
                  onChange={onAddressChange} />
              )
            },
            {
              label: 'Pitch type',
              displayValue: PITCH_TYPE_STRING[type],
              isValid: NewPitchModel.isTypeValid(newPitch),
              component: (
                <ValuePicker
                  options={PITCH_TYPE_OPTIONS}
                  value={type}
                  onChange={onTypeChange} />
              )
            },
            {
              label: 'Capacity',
              displayValue: capacity,
              isValid: NewPitchModel.isCapacityValid(newPitch),
              component: (
                <RangePicker
                  min={minNumberOfPlayers}
                  minOptions={_.range(PITCH_MIN_CAPACITY, maxNumberOfPlayers + 1, 2)}
                  max={maxNumberOfPlayers}
                  maxOptions={_.range(minNumberOfPlayers, PITCH_MAX_CAPACITY + 1, 2)}
                  orientation="vertical"
                  separator="-"
                  onMinChange={onMinNumberOfPlayersChange}
                  onMaxChange={onMaxNumberOfPlayersChange} />
              )
            }
          ]} />
      </div>
    );
  }