mirror of
/repos/Prototyper.git
synced 2025-12-30 06:31:32 +01:00
add preview button
This commit is contained in:
parent
a6f71b6203
commit
fddb5012d4
@ -6,15 +6,16 @@ Change the mongo url to your mongodb
|
||||
|
||||
npm start
|
||||
|
||||
http://localhost:8000/index.html
|
||||
[/index.html](http://localhost:8000/index.html)
|
||||
|
||||
Import content defined in index.html into db:
|
||||
|
||||
http://localhost:8000/importer/index.html
|
||||
[/importer/index.html](http://localhost:8000/importer/index.html)
|
||||
|
||||
|
||||
Dogfood viewing of index.html from db:
|
||||
|
||||
http://localhost:8000/page/app/main.index.html
|
||||
[/page/app/main.index.html](http://localhost:8000/page/app/main.index.html)
|
||||
|
||||
|
||||
# Features:
|
||||
|
||||
@ -174,13 +174,14 @@ module.exports = function (config, mongoDataInstance) {
|
||||
var attribute = {
|
||||
collection: parts[1],
|
||||
name: parts[2],
|
||||
attribute: parts[3]
|
||||
attribute: parts[3],
|
||||
query: { name: parts[2] }
|
||||
};
|
||||
return mongoDataInstance.getMongoAttribute(attribute, function handleMarkdownContent(err, markdown_result) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
var html = markdown.toHTML(markdown_result[options.attribute]);
|
||||
var html = markdown.toHTML(markdown_result[attribute.attribute]);
|
||||
return callback(null, {
|
||||
regExp: new RegExp(result, 'gmi'),
|
||||
value: html
|
||||
|
||||
@ -55,6 +55,7 @@
|
||||
</div>
|
||||
<!-- /ko -->
|
||||
</div>
|
||||
<button class="btn pull-right" title="preview" data-bind="enable: $root._chosenAttributeId, click: $root._previewAttribute"><i class="icon-eye-open"></i></button>
|
||||
<!--<ul class="nav pull-right"><li>-->
|
||||
<div class="nav navbar-form pull-right">
|
||||
<input type="text" class="span2"
|
||||
@ -198,8 +199,20 @@ function addComputed(doc) {
|
||||
});
|
||||
}
|
||||
|
||||
function getExtensionForAttribute(attribute) {
|
||||
var mode = getModeForAttribute(attribute);
|
||||
if (mode && mode.ace() == 'markdown') {
|
||||
return '.md';
|
||||
} else {
|
||||
return '.html';
|
||||
}
|
||||
}
|
||||
|
||||
function getModeForChosenAttribute() {
|
||||
var attribute = viewModel._chosenAttributeId();
|
||||
return getModeForAttribute(attribute)
|
||||
}
|
||||
function getModeForAttribute(attribute) {
|
||||
if (!attribute) {
|
||||
return null;
|
||||
}
|
||||
@ -226,6 +239,10 @@ function updateSelectedMode() {
|
||||
}
|
||||
}
|
||||
|
||||
function open_in_new_tab(url) {
|
||||
var win = window.open(url, '_blank');
|
||||
win.focus();
|
||||
}
|
||||
|
||||
function initViewModel(doc) {
|
||||
viewModel_updating = true;
|
||||
@ -253,6 +270,16 @@ function initViewModel(doc) {
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
viewModel._previewAttribute = function () {
|
||||
var id = viewModel._chosenAttributeId();
|
||||
if (id) {
|
||||
var ext = getExtensionForAttribute(id);
|
||||
var url = '/page/app/main.'+id+ext;
|
||||
open_in_new_tab(url);
|
||||
}
|
||||
|
||||
}
|
||||
viewModel._getMode = ko.computed(function () {
|
||||
var id = viewModel._chosenAttributeId();
|
||||
return id && viewModel[id].mode;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
var mimetypes = {
|
||||
'js': 'application/javascript',
|
||||
'html': 'text/html',
|
||||
'md': 'text/html',
|
||||
'text': 'text/plain',
|
||||
'css': 'text/css',
|
||||
'less': 'text/css'
|
||||
@ -21,7 +22,7 @@ module.exports = function (options, res, next) {
|
||||
if (/Data not found*/.test(err.message)) {
|
||||
res.status(404);
|
||||
}
|
||||
return next(err.message);
|
||||
return next(JSON.stringify( err));
|
||||
}
|
||||
var contentType = getMimeType(options.ext);
|
||||
res.setHeader('Content-Type', contentType);
|
||||
|
||||
15
routes.js
15
routes.js
@ -282,10 +282,10 @@ module.exports = function (app, db, config) {
|
||||
|
||||
var previewInstance = preview(config, mongoDataInstance);
|
||||
|
||||
route = config.api.preview + '/:collection/:name.:ext(html)';
|
||||
route = config.api.preview + '/:collection/:name.:ext(html|md)';
|
||||
app.get(route,
|
||||
function getPreviewContent(req, res, next) {
|
||||
config.debug && console.log('/page/:collection/:name.:ext(html)');
|
||||
config.debug && console.log('/page/:collection/:name.:ext(html|md)');
|
||||
var options = {
|
||||
collection: req.params.collection,
|
||||
ext: req.params.ext,
|
||||
@ -294,7 +294,16 @@ module.exports = function (app, db, config) {
|
||||
headers: req.headers
|
||||
}
|
||||
};
|
||||
mongoDataInstance.getMongoContent(options, function handleResult(err, result) {
|
||||
if(options.ext == 'md') {
|
||||
var attribute_parts = options.query.name.split('.');
|
||||
var markdownTag='markdown__'+options.collection+'_'+attribute_parts[0]+'_'+attribute_parts[1];
|
||||
//var markdownDocument=helpers.marker_prefix + markdownTag + helpers.marker_postfix;
|
||||
var markdownDocument='<!-- @@' + markdownTag + ' -->';
|
||||
return previewInstance.getPreviewHTML(markdownDocument, { req:options.req },
|
||||
responder(options, res, next)
|
||||
);
|
||||
}
|
||||
return mongoDataInstance.getMongoContent(options, function handleResult(err, result) {
|
||||
if (err) {
|
||||
return responder(options, res, next)(err, result);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user