Skip to content
This repository was archived by the owner on Nov 17, 2017. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],
"dependencies": {
"generator-git-init": "^1.1.1",
"lodash": "^3.10.1",
"lodash": "^4.5.0",
"yeoman-generator": "^0.20.3"
},
"devDependencies": {
Expand Down
14 changes: 14 additions & 0 deletions src/generators/app/templates/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
<% if (generateApi) { %>import exampleRoute from './server/routes/example';<% } %>

import fs from 'fs';
import path from 'path';

function getAll(type) {
try {
return fs.readdirSync(path.join(__dirname, 'public', type)).map(file => {
return `plugins/<%= name %>/${type}/${file.replace(/\.js$/, '')}`;
});
} catch (e) {
return [];
}
}

export default function (kibana) {
return new kibana.Plugin({
require: ['elasticsearch'],

uiExports: {
fieldFormats: getAll('field_formats'),
<% if (generateApp) { %>
app: {
title: '<%= title %>',
Expand Down
41 changes: 41 additions & 0 deletions src/generators/field-format/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';
import * as yeoman from 'yeoman-generator';
import _ from 'lodash';

module.exports = yeoman.generators.Base.extend({
prompting: function () {
var done = this.async();

var prompts = [{
type: 'input',
name: 'name',
message: 'Enter the titel of the field format I should create?'
},{
type: 'checkbox',
name: 'fieldTypes',
message: 'For which field types will this formatter work?',
choices: ['string', 'number', 'boolean', 'date', 'ip', 'attachment', 'geo_point', 'geo_shape', 'murmur3', 'unknown'],
validate: (value) => {
return value.length ? true : "You have to specify at least one type.";
}
}];

this.prompt(prompts, (props) => {
this.props = props;
done();
});
},

writing: function () {
this.fs.copyTpl(
this.templatePath('field_format.js'),
this.destinationPath(`public/field_formats/${_.snakeCase(this.props.name)}.js`),
{
...this.props,
className: _.upperFirst(_.camelCase(this.props.name)),
id: _.camelCase(this.props.name)
}
);
}

});
28 changes: 28 additions & 0 deletions src/generators/field-format/templates/field_format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import fieldFormatRegistry from 'ui/registry/field_formats';
import FieldFormat from 'ui/index_patterns/_field_format/FieldFormat';
import _ from 'lodash';

fieldFormatRegistry.register((Private) => {
_.class(<%= className %>).inherits(Private(FieldFormat));
function <%= className %>(params) {
<%= className %>.Super.call(this, params);
}

<%= className %>.id = '<%= id %>';
<%= className %>.title = '<%= name %>';

<%= className %>.fieldType = <%- JSON.stringify(fieldTypes) %>;

<%= className %>.prototype._convert = {
text: function (value) {
// This method must return a textual representation of the value (no HTML).
return value;
},
html: function (value) {
// This method can return HTML to represent the value.
return value;
}
};

return <%= className %>;
});