Skip to content

JSON to HTML and viceversa for Sir Trevor

License

Notifications You must be signed in to change notification settings

Upplication/sir-trevor-adapter

Repository files navigation

Sir Trevor Adapter

Sir Trevor Adapter allows to use Sir Trevor like a common html wysiwyg and work only with html like ckeditor, tinymce and others. Given a Sir Trevor result data as JSON with this adapter we can get a valid html. Also we can revert the process and regenerate the JSON with the html generated by the Sir Trevor Adapter

Installation

Clone this repo and install the dependencies:

  • Install node dependencies npm install
  • Install project dependencies -- bower install

Usage

Run the tests

You can run the test suite with the command: npm test

Example of use

// create a instance
var adapter = new SirTrevorAdapter();
// get the html initial data of sir trevor, transform in a correct json and save the data in it.
var $textarea =  $('.js-st-instance');
var data = adapter.toJSON($textarea.val());
$textarea.val(JSON.stringify( { data: data } ));
// create a sir trevor instance and attach to a textarea
var sirtrevor = new SirTrevor.Editor({ el: $textarea});

// on submit you can send the html to the server instead of the json structure
$form.submit(function(e){
    var dataJson = $textarea.val();
    var dataHtml = this.adapter.toHTML(JSON.parse(dataJson));
    // save the data in a hidden field
    var $data = $("<input>").attr("type", "hidden").val(dataHtml);
    $(this).append($data)
});

Development

  • gulp doc generate the jsdocs and store in the doc folder
  • gulp compile-dev generate new compile results of the adapter: sir-trevor-adapter.js
  • gulp compile-prod generate new compile results of the adapter: sir-trevor-adapter.js & sir-trevor-adapter.min.js
  • gulp patch compile and generate a new tag in the git repository incrementing the pacth version
  • gulp feature compile and generate a new tag in the git repository incrementing the feature version
  • gulp release compile and generate a new tag in the git repository incrementing the major version

About

JSON to HTML and viceversa for Sir Trevor

http://www.upplication.com

Resources

License

Stars

Watchers

Forks

Packages

No packages published