I am using GrapesJS to build a simple webpage.
I included the script in the following way inside head part :
for Q3 you can use a "frontend option" like this:
NOTE 1: i'm using angularJS
NOTE 2: $scope.editor is my grapesJs instance
Function to get HTML+CSS inline
$scope.getHtmlCss = function(){
var html = $scope.editor.runCommand('gjs-get-inlined-html');
$log.log("-----> HTML & INLINED CSS: ", html);
return html;
}
In your GrapesJs editor add an new option for "Donwload HTML file"
$scope.editor.Panels.addButton('options', [
{ id: 'save',
className: 'fa fa-file-code-o',
command: function(editor1, sender) {
if($scope.getHtmlCss()){
$scope.generateFile($scope.getHtmlCss());
}
},
attributes: { title: 'Download HMTL file' }
}, ]);
function to generate HTML file:
$scope.generateFile = function(code){
$(function()
{
console.log( "ready!" );
// Check for the various File API support.
if (window.File && window.FileReader && window.FileList && window.Blob)
{
saveText(code, 'text/html;charset=utf-8', 'mailing.html');
}
else
{
alert('The File APIs are not fully supported in this browser.');
}
}
);
function saveText(text, mime, file)
{
var blob = new Blob([text], {type: mime});
saveAs(blob, file);
return false;
}
function handleFileSelect(code, mimeType)
{
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (
function(theFile)
{
return function(e)
{
target.html( e.target.result );
};
}
)(file);
// Read in the image file as a data URL.
reader.readAsText(file);
}
}