Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/0.5.3-dev' into 0.5.3-bb
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Smirnov committed May 15, 2015
2 parents 462df6b + 359805c commit 0da58a0
Show file tree
Hide file tree
Showing 22 changed files with 407 additions and 357 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.iml
*.DS_Store
node_modules
npm-debug.log

# Generated data for API
/core/api/data
Expand Down
24 changes: 19 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

var express = require('express');
var colors = require('colors');
var fs = require('fs');
var fs = require('fs-extra');
var loadOptions = require('./core/loadOptions');
var commander = require('commander');
var bodyParser = require('body-parser');
Expand All @@ -18,9 +18,9 @@ global.opts = loadOptions();

// Arguments parse */
commander
.option('-l, --log [string]', 'Log level (default: ' + global.opts.core.common.defaultLogLevel + ')', global.opts.core.common.defaultLogLevel)
.option('-p, --port [number]', 'Server port (default: ' + global.opts.core.common.port + ')', global.opts.core.common.port)
.option('--html', 'Turn on HTML parser on app start')
.option('-l, --log [string]', 'Log level (default: ' + global.opts.core.common.defaultLogLevel + ').', global.opts.core.common.defaultLogLevel)
.option('-p, --port [number]', 'Server port (default: ' + global.opts.core.common.port + ').', global.opts.core.common.port)
.option('--html', 'Turn on HTML parser on app start (requires installed and enabled parser).')
.parse(process.argv);

global.commander = commander;
Expand All @@ -36,6 +36,8 @@ global.pathToApp = __dirname.replace(/^\w:\\/, function (match) {
return match.toLowerCase();
});

global.engineVersion = fs.readJsonSync(global.pathToApp + '/package.json', {throws: false}).version;

// Default logger
var logger = require('./core/logger');
var log = logger.log;
Expand All @@ -48,6 +50,12 @@ if (commander.port) global.opts.core.common.port = parseInt(commander.port);

/* App config */

// Version
app.use(function (req, res, next) {
res.header('X-powered-by', 'SourceJS ' + global.engineVersion);
next();
});

// Optimization
global.app.use(require('compression')());

Expand Down Expand Up @@ -150,7 +158,13 @@ require('./core/routes');
require('./core/api');

global.app.use('/api/options', function(req, res){
res.jsonp(loadOptions().assets);
var options = loadOptions();
var assetsOptions = options.assets;

// TODO: https://github.com/sourcejs/Source/issues/142
assetsOptions.plugins = options.plugins;

res.jsonp(assetsOptions);
});

// User extenstions
Expand Down
4 changes: 4 additions & 0 deletions assets/css/project/footer.less
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@
line-height: 2;
}

.source_footer_version {
color: @color-aux2;
}

/* /Footer
---------------------------------------------------------------------------------- */
4 changes: 4 additions & 0 deletions assets/css/variables.less
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
@color-aux : #999;
@gray: @color-aux;

// aux level2
@color-aux2 : #696969;
@dark-gray: @color-aux2;

// utility
@color-utility: #f1f2f3;
@light-gray: @color-utility;
Expand Down
47 changes: 14 additions & 33 deletions assets/js/clarify.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,40 @@

require([
"jquery",
'text!/api/options',
"sourceModules/utils",
"sourceLib/lodash",
"text!sourceTemplates/clarifyPanel.inc.html"
], function ($, u, clarifyPanelTpl){
], function ($, options, u, _, clarifyPanelTpl){

// If we have data from Clarify output
if (window.sourceClarifyData){
var $panelTemplate = $(clarifyPanelTpl);
var _options = JSON.parse(options);
var htmlParser = _options.plugins && _options.plugins.htmlParser && _options.plugins.htmlParser.enabled;

$panelTemplate.find('.js-source_clarify_return-link').attr('href', window.sourceClarifyData.specUrl);

var prepareTplList = function(){
var output = '';
var tplList = window.sourceClarifyData.tplList;

for (var i = 0; i < tplList.length; i++){
var currentTpl = tplList[i];

output += '<option data-tpl-name="'+currentTpl+'">'+currentTpl+'</option>'
}

return output;
};

var prepareSectionsList = function(){
var output = '';
var sectionsList = window.sourceClarifyData.sectionsIDList || [];

sectionsList.forEach(function(current){
output += '<option data-section="' + current.id + '">' + current.visualID + '. ' + current.header + '</option>';
});

return output;
};
var $panelTemplate = $(_.template(clarifyPanelTpl, {
htmlParser: htmlParser,
showApiTargetOption: window.sourceClarifyData.showApiTargetOption,
specUrl: window.sourceClarifyData.specUrl,
tplList: window.sourceClarifyData.tplList,
sectionsIDList: window.sourceClarifyData.sectionsIDList || []
}));

var enableCheckboxes = function(param){
if (u.getUrlParameter(param)) {
$panelTemplate.find('.js-source_clarify_panel_option-checkbox[name="'+param+'"]').attr('checked', true);
}
};

// Filing select containers
$panelTemplate.find('.js-source_clarify_panel_select-tpl').append(prepareTplList());
$panelTemplate.find('.js-source_clarify_panel_sections').append(prepareSectionsList());

// Restoring options from URL
var checkboxes = ['nojs','fromApi','apiUpdate'];

checkboxes.forEach(function(item){
enableCheckboxes(item);
});

var tepmplate = u.getUrlParameter('tpl') ? u.getUrlParameter('tpl') : 'default';
$panelTemplate.find('.js-source_clarify_panel_select-tpl').val(tepmplate);
var template = u.getUrlParameter('tpl') ? u.getUrlParameter('tpl') : 'default';
$panelTemplate.find('.js-source_clarify_panel_select-tpl').val(template);

var sections = u.getUrlParameter('sections') ? u.getUrlParameter('sections').split(',') : undefined;
if (sections) {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/enter-the-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require([
"source/load-options", // TODO: remove when all modules inherit Module()
"sourceModules/browser",
"sourceModules/moduleLoader",
'sourceModules/auth',
'sourceModules/auth'
], function ($, options, browser, Loader, Auth) {
if (options && options.modulesEnabled && options.modulesEnabled.auth === true) {
new Auth({
Expand Down
2 changes: 1 addition & 1 deletion assets/js/modules/sectionsParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* */

// TODO: wrap as requirejs module, and combine with phantom-runner.js
// TODO: wrap as requirejs module, and combine with phantomRunner.js

function SourceGetSections() {
// Defining strict inside func, because PhantomJS stops evaluating this script if it's on top
Expand Down
34 changes: 22 additions & 12 deletions assets/templates/clarifyPanel.inc.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,49 @@
<div class="source_clarify_panel_i">
<h2 class="source_clarify_panel_h2">Select sections</h2>
<select class="source_clarify_panel_sections js-source_clarify_panel_sections" multiple>
<% _.forEach(sectionsIDList, function(section) { %>
<option data-section="<%- section.id %>"><%- section.visualID %>. <%- section.header %></option>
<% }); %>
</select>
</div>
<div class="source_clarify_panel_i">
<h2 class="source_clarify_panel_h2">Select template</h2>
<label>
<select class="source_clarify_panel_select js-source_clarify_panel_select-tpl">
<% _.forEach(tplList, function(tpl) { %>
<option data-tpl-name="<%- tpl %>"><%- tpl %></option>
<% }); %>
</select>
</label>
</div>
<div class="source_clarify_panel_i">
<h2 class="source_clarify_panel_h2">Options</h2>
<div class="source_clarify_panel_options">
<ul class="source_clarify_panel_option-list">
<% if (showApiTargetOption) { %>
<li class="source_clarify_panel_option-item">
<label>
<input type="checkbox" class="source_clarify_panel_option-checkbox js-source_clarify_panel_option-checkbox" name="fromApi"> Get HTML From API
</label>
</li>
<% } %>
<% if (htmlParser) { %>
<li class="source_clarify_panel_option-item">
<label>
<input type="checkbox" class="source_clarify_panel_option-checkbox js-source_clarify_panel_option-checkbox" name="apiUpdate"> Update Spec HTML API on each Clarify call
</label>
</li>
<% } %>
<li class="source_clarify_panel_option-item">
<label>
<input type="checkbox" class="source_clarify_panel_option-checkbox js-source_clarify_panel_option-checkbox" name="fromApi"> Get HTML From API
</label>
</li>
<li class="source_clarify_panel_option-item">
<label>
<input type="checkbox" class="source_clarify_panel_option-checkbox js-source_clarify_panel_option-checkbox" name="apiUpdate"> Update Spec HTML API on each Clarify call
</label>
</li>
<li class="source_clarify_panel_option-item">
<label>
<input type="checkbox" class="source_clarify_panel_option-checkbox js-source_clarify_panel_option-checkbox" name="nojs"> Turn Off JavaScript
<input type="checkbox" class="source_clarify_panel_option-checkbox js-source_clarify_panel_option-checkbox" name="nojs"> Remove JS scripts
</label>
</li>
</ul>
</div>
</div>
<div class="source_clarify_panel_i">
<button class="source_clarify_panel_go js-source_clarify_panel_go">Update view</button>
<a class="source_clarify_panel_return-link js-source_clarify_return-link" href="">Return to Spec</a>
<a class="source_clarify_panel_return-link js-source_clarify_return-link" href="<%- specUrl %>">Return to Spec</a>
</div>
</div>
2 changes: 1 addition & 1 deletion assets/templates/footer.inc.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h2>Catalog</h2>
</ul>
</div>
<div class="source_footer_copy">
Copyright © 2013-2015 <a href="http://sourcejs.com" class="source_a_l">Sourcejs.com</a>
Copyright © 2013-2015 <a href="http://sourcejs.com" class="source_a_l">Sourcejs.com</a> <span class="source_footer_version">(v.<%- engineVersion %>)</span>
</div>
</div>
</footer>
8 changes: 4 additions & 4 deletions core/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

var express = require('express');
var path = require('path');
var parseData = require('./parseData');
var parseData = require(path.join(global.pathToApp, 'core/lib/parseData'));
var pathToApp = path.dirname(require.main.filename);
var deepExtend = require('deep-extend');
var parseHTML = require(path.join(global.pathToApp, 'core/api/parseHTML'));
var htmlTree = require(path.join(global.pathToApp, 'core/html-tree'));
var unflatten = require(path.join(global.pathToApp,'core/unflat'));

var config = {
Expand Down Expand Up @@ -145,7 +145,7 @@ var postHTML = function (req, res, dataPath) {
data = unflatten(data, { delimiter: '/', overwrite: 'root' });
}

parseHTML.writeDataFile(data, true, dataPath, function(err, finalData){
htmlTree.writeDataFile(data, true, dataPath, function(err, finalData){
if (err || !finalData) {
res.status(config.statusCodes.error).json({
message: err
Expand All @@ -171,7 +171,7 @@ var deleteHTML = function (req, res, dataPath) {
var body = req.body;
var reqID = body.id || req.query.id;

parseHTML.deleteFromDataFile(dataPath, reqID, function(err, finalData){
htmlTree.deleteFromDataFile(dataPath, reqID, function(err, finalData){
if (err || !finalData) {
res.status(config.statusCodes.error).json({
message: err
Expand Down
33 changes: 15 additions & 18 deletions core/headerFooter.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
'use strict';

var fs = require('fs');
var path = require('path');
var pathToApp = path.dirname(require.main.filename);
var ejs = require('ejs');

exports.getHeaderAndFooter = function () {
var defaultTemplatePath = pathToApp + "/assets/templates/";
var userTemplatePath = global.app.get('user') + "/assets/templates/";
var headerFile = "header.inc.html";
var footerFile = "footer.inc.html";
var defaultTemplatePath = global.pathToApp + '/assets/templates/';
var userTemplatePath = global.app.get('user') + '/assets/templates/';
var headerFile = 'header.inc.html';
var footerFile = 'footer.inc.html';

var data = {};
var output = {};

if(fs.existsSync(userTemplatePath + headerFile)) {
data.header = ejs.render(fs.readFileSync(userTemplatePath + headerFile, "utf-8"));
} else {
data.header = ejs.render(fs.readFileSync(defaultTemplatePath + headerFile, "utf-8"));
}
var userHeaderTplPath = userTemplatePath + headerFile;
var headerTplPath = fs.existsSync(userHeaderTplPath) ? userHeaderTplPath : defaultTemplatePath + headerFile;

if(fs.existsSync(userTemplatePath + footerFile)) {
data.footer = ejs.render(fs.readFileSync(userTemplatePath + footerFile, "utf-8"));
} else {
data.footer = ejs.render(fs.readFileSync(defaultTemplatePath + footerFile, "utf-8"));
}
var userFooterTplPath = userTemplatePath + footerFile;
var footerTplPath = fs.existsSync(userFooterTplPath) ? userFooterTplPath : defaultTemplatePath + footerFile;

return data;
output.header = ejs.render(fs.readFileSync(headerTplPath, 'utf-8'));
output.footer = ejs.render(fs.readFileSync(footerTplPath, 'utf-8'), {
engineVersion: global.engineVersion
});

return output;
};
Loading

0 comments on commit 0da58a0

Please sign in to comment.