Skip to content

Commit

Permalink
Merge b05d340 into 41befae
Browse files Browse the repository at this point in the history
  • Loading branch information
olamothe committed Jan 27, 2017
2 parents 41befae + b05d340 commit d8dd544
Show file tree
Hide file tree
Showing 74 changed files with 1,394 additions and 1,159 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ script:
- npm run build
- npm run minimize
- npm run test
- npm run uploadCoverage
after_success:
- npm run doc
- if [ "x$TRAVIS_TAG" != "x" ]; then bash ./deploy.doc.sh ; fi
Expand Down
5 changes: 4 additions & 1 deletion gulpTasks/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ gulp.task('dev', ['setup', 'prepareSass'], (done)=> {
let server = new WebpackDevServer(compiler, {
contentBase: 'bin/',
publicPath: '/js/',
compress: true
compress: true,
headers: {
'Content-Security-Policy': "script-src 'self' 'unsafe-inline'"
}
});
server.listen(8080, 'localhost', ()=> {
});
Expand Down
132 changes: 61 additions & 71 deletions gulpTasks/templatesParser.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
var fs = require('fs');
var path = require('path');
var Q = require('q');
var fsReaddir = Q.denodeify(fs.readdir);
var fsWriteFile = Q.denodeify(fs.writeFile);
var fsStat = Q.denodeify(fs.stat);
const Promise = require('bluebird');
const fs = Promise.promisifyAll(require('fs'));

function createDirectory(directory) {
if (!fs.existsSync(directory)) {
Expand All @@ -15,65 +12,55 @@ function createDirectory(directory) {
}
}

function findTemplates(directory, callback) {
fsReaddir(directory).then(function (files) {
Q.all(files.map(function (file) {
var filePath = path.join(directory, file);
var extname = path.extname(file);
var deferred = Q.defer();
fsStat(filePath).then(function (stat) {
if (stat.isDirectory()) {
findTemplates(filePath, function (subTemplates) {
deferred.resolve(subTemplates);
});
} else if (stat.isFile() && (extname == '.ejs' || extname == '.html')) {
deferred.resolve([filePath]);
} else {
deferred.resolve([]);
}
});
return deferred.promise;
})).then(function (results) {
var templates = [];
results.forEach(function (file) {
templates = templates.concat(file)
});
callback(templates)
});
});
function isTemplateFile(file) {
const extname = path.extname(file);
return (extname == '.ejs' || extname == '.html');
}

function readDirectory(directory) {
return fs.readdirAsync(directory).map(fileName => {
const fullPath = path.join(directory, fileName);
return fs.statAsync(fullPath).then(stat => stat.isDirectory() ? readDirectory(fullPath) : fullPath);
})
.reduce((a, b) => a.concat(b), [])
.filter(path => isTemplateFile(path));
}

function parseDirectory(directory, conditions, callback) {
findTemplates(directory, function (templates) {
callback(templates.map(function (template) {
var extname = path.extname(template);
var name = path.basename(template, extname);
var subtemplate = (name.indexOf("_") == 0);
name = subtemplate ? name.substr(1) : name;
var condition = conditions[name];
var content = fs.readFileSync(template).toString();
var templateObj = {
name: name,
type: (extname == '.html' ? 'HtmlTemplate' : 'UnderscoreTemplate'),
condition: condition,
subtemplate: subtemplate,
path: path.dirname(path.relative(directory, template)),
content: content,
priority: condition != null ? condition.priority || 0 : -1
};
buildRegisterTemplate(templateObj);
buildTemplateHtml(templateObj);
return templateObj;
}).sort(function (a, b) {
return a.priority < b.priority ? 1 : -1;
}));
});
function parseDirectory(directory, conditions) {
return readDirectory(directory).map(template => {
var extname = path.extname(template);
var name = path.basename(template, extname);
var subtemplate = (name.indexOf("_") == 0);
name = subtemplate ? name.substr(1) : name;
var condition = conditions[name];
var content = fs.readFileSync(template).toString();
var templateObj = {
name: name,
type: 'HtmlTemplate',
condition: condition || {},
subtemplate: subtemplate,
path: path.dirname(path.relative(directory, template)),
content: content,
priority: condition != null ? condition.priority || 0 : -1
};
buildRegisterTemplate(templateObj);
buildTemplateHtml(templateObj);
return templateObj;
}).then(templates => templates.sort((a, b) => a.priority < b.priority ? 1 : -1));
}

function buildRegisterTemplate(template) {
template.js = 'Coveo.TemplateCache.registerTemplate(' + [
JSON.stringify(template.name),
'Coveo.' + template.type + '.fromString(' + JSON.stringify(template.content) + (template.condition != null ? ', ' + JSON.stringify(template.condition.value) : '') + ')',
`Coveo.${template.type}.fromString(`
+ JSON.stringify(template.content) + ','
+ JSON.stringify({
'condition': addToJsonIfNotNull(template, 'value'),
'layout': addToJsonIfNotNull(template, 'layout'),
'fieldsToMatch': addToJsonIfNotNull(template, 'fieldsToMatch'),
'mobile': addToJsonIfNotNull(template, 'mobile')
}) + '),'
+
(!template.subtemplate).toString(),
(!template.subtemplate).toString()
].join(', ') + ')';
Expand All @@ -88,29 +75,32 @@ function buildTemplateHtml(template) {

function compileTemplates(directory, destination, fileName, conditions, done) {
createDirectory(destination);
parseDirectory(directory, conditions, function (templates) {
var groupedTemplates = {};
parseDirectory(directory, conditions).then(templates => {
let groupedTemplates = {};
groupedTemplates[fileName] = [];
templates.forEach(function (template) {
templates.forEach(template => {
if (groupedTemplates[template.path] == null) {
groupedTemplates[template.path] = [];
}
groupedTemplates[template.path].push(template.js);
groupedTemplates[fileName].push(template.js);
});
Q.all(Object.keys(groupedTemplates).map(function (key) {
return fsWriteFile(path.join(destination, key + '.js'), groupedTemplates[key].join('\n'));
}))
.catch(function (e) {
done(e)
})
.then(function () {
done()
});
})
return groupedTemplates;
}).then(groupedTemplates => {
Object.keys(groupedTemplates).forEach(key => {
fs.writeFileAsync(path.join(destination, key + '.js'), groupedTemplates[key].join('\n'));
})
}).catch(e => done(e));
}

function addToJsonIfNotNull(template, key) {
if (template.condition && template.condition[key]) {
return template.condition[key]
}
return null;
}

module.exports = {
parseDirectory: parseDirectory,
compileTemplates: compileTemplates
};
};
2 changes: 1 addition & 1 deletion gulpTasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ gulp.task('setupTests', function () {
).pipe(event_stream.wait())
});

gulp.task('coverage', ['lcovCoverage' , 'uploadCoverage']);
gulp.task('coverage', ['lcovCoverage']);

gulp.task('test', ['setupTests', 'buildTest'], function (done) {
new TestServer({
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"injectTag": "gulp injectTag",
"heroku-postbuild": "npm run build",
"start": "node index.js",
"zipForGitReleases": "gulp zip"
"zipForGitReleases": "gulp zip",
"uploadCoverage" : "gulp uploadCoverage"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -52,6 +53,7 @@
},
"devDependencies": {
"@salesforce-ux/design-system": "2.0.3",
"bluebird": "^3.4.7",
"cheerio": "^0.20.0",
"circular-dependency-plugin": "^1.1.0",
"colors": "^1.1.2",
Expand Down Expand Up @@ -131,4 +133,4 @@
"pikaday": "^1.4.0",
"underscore": "^1.8.3"
}
}
}
2 changes: 1 addition & 1 deletion pages/People.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<script src="js/templates/templatesNew.js"></script>
<link rel="stylesheet" href="css/CoveoFullSearchNewDesign.css" />
<script>
document.addEventListener('DOMContentLoaded', function(){
document.addEventListener('DOMContentLoaded', function() {
Coveo.SearchEndpoint.configureSampleEndpointV2();
Coveo.init(document.body);
})
Expand Down
12 changes: 9 additions & 3 deletions sass/_Result.scss
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,27 @@
}
}

.coveo-list-layout > .CoveoResult {
.coveo-list-layout.CoveoResult {
border-bottom: $default-border;
margin: 20px 0px 20px 20px;
}

.coveo-card-layout {
margin-right: -20px;
> .CoveoResult {
&.CoveoResult {
overflow: hidden;

font-size: 0.9em;

width: 300px;
@include flex-grow(1);
& + .CoveoResult {

}
margin: 0 20px 20px 0;
@include mediaSelector(480) {
margin: 0 0 20px 0;
}
@include defaultRoundedBorder();

&.coveo-clickable {
Expand Down Expand Up @@ -210,4 +216,4 @@

.coveo-card-overlay a {
@include clickable($dark-background: true);
}
}
4 changes: 2 additions & 2 deletions sass/_ResultList.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
}

.coveo-card-layout {
.coveo-card-layout-container {
@include display(flex);
@include flex-wrap(wrap);
}
Expand All @@ -30,4 +30,4 @@
margin-left: 10px;
margin-right: 10px;
}
}
}
3 changes: 2 additions & 1 deletion src/models/QueryStateModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Model, IModelSetOptions} from './Model';
import {Assert} from '../misc/Assert';
import {IStringMap} from '../rest/GenericParam';
import {Utils} from '../utils/Utils';
import {defaultLayout} from '../ui/ResultLayout/ResultLayout';

export const QUERY_STATE_ATTRIBUTES = {
Q: 'q',
Expand Down Expand Up @@ -47,7 +48,7 @@ export class QueryStateModel extends Model {
hd: '',
hq: '',
sort: '',
layout: 'list',
layout: defaultLayout,
tg: '',
quickview: ''
};
Expand Down
30 changes: 28 additions & 2 deletions src/ui/AnalyticsSuggestions/AnalyticsSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {analyticsActionCauseList, IAnalyticsTopSuggestionMeta} from '../Analytic
import {Initialization} from '../Base/Initialization';
import {$$} from '../../utils/Dom';
import {StandaloneSearchInterface} from '../SearchInterface/SearchInterface';
import {IStringMap} from '../../rest/GenericParam';

export interface IAnalyticsSuggestionsOptions extends ISuggestionForOmniboxOptions {
}
Expand Down Expand Up @@ -88,7 +89,16 @@ export class AnalyticsSuggestions extends Component {

this.options = ComponentOptions.initComponentOptions(element, AnalyticsSuggestions, this.options);

let rowTemplate = _.template(`<div class='magic-box-suggestion coveo-omnibox-selectable coveo-top-analytics-suggestion-row'><%= data %></div>`);
let rowTemplate = (toRender: IStringMap<any>) => {
let rowElement = $$('div', {
className: 'magic-box-suggestion coveo-omnibox-selectable coveo-top-analytics-suggestion-row'
});
if (toRender['data']) {
rowElement.el.innerHTML = toRender['data'];
}
return rowElement.el.outerHTML;
};

this.options.onSelect = this.options.onSelect || this.onRowSelection;

let suggestionStructure: ISuggestionForOmniboxTemplate;
Expand All @@ -97,7 +107,23 @@ export class AnalyticsSuggestions extends Component {
row: rowTemplate
};
} else {
let headerTemplate = _.template(`<div class='coveo-top-analytics-suggestion-header'><span class='coveo-icon-top-analytics'></span><span class='coveo-caption'><%= headerTitle %></span></div>`);
let headerTemplate = () => {
let headerElement = $$('div', {
className: 'coveo-top-analytics-suggestion-header'
});
let iconElement = $$('span', {
className: 'coveo-icon-top-analytics'
});
let captionElement = $$('span', {
className: 'coveo-caption'
});
if (this.options.headerTitle) {
captionElement.text(this.options.headerTitle);
}
headerElement.append(iconElement.el);
headerElement.append(captionElement.el);
return headerElement.el.outerHTML;
};
suggestionStructure = {
header: { template: headerTemplate, title: this.options.headerTitle },
row: rowTemplate
Expand Down
4 changes: 2 additions & 2 deletions src/ui/Base/ComponentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,9 @@ export class ComponentOptions {
' ' + HtmlTemplate.mimeTypes.toString();
Assert.check(Utils.isNonEmptyString(type), mimeTypes);

if (_.indexOf(UnderscoreTemplate.mimeTypes, type) != -1) {
if (_.indexOf(UnderscoreTemplate.mimeTypes, type.toLowerCase()) != -1) {
return UnderscoreTemplate.create(element);
} else if (_.indexOf(HtmlTemplate.mimeTypes, type) != -1) {
} else if (_.indexOf(HtmlTemplate.mimeTypes, type.toLowerCase()) != -1) {
return new HtmlTemplate(element);
} else {
Assert.fail('Cannot guess template type from attribute: ' + type + '. Valid values are ' + mimeTypes);
Expand Down
6 changes: 3 additions & 3 deletions src/ui/Debug/Debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export class Debug extends RootComponent {
jElement.toggleClass('coveo-search-submatch', submatch);
return match || submatch;
} else {
if (element['value'].indexOf(value) != -1) {
if (element['values'].indexOf(value) != -1) {
this.highlightSearch(element['valueDom'], value);
match = true;
} else {
Expand Down Expand Up @@ -523,7 +523,7 @@ export class Debug extends RootComponent {
} else {
valueContainer.innerHTML = '{}';
}
dom['value'] = '';
dom['values'] = '';
}
dom['label'] = label != null ? label.toLowerCase() : '';
dom.appendChild(valueContainer);
Expand Down Expand Up @@ -578,7 +578,7 @@ export class Debug extends RootComponent {
valueDom.className = className.join(' ');

dom['label'] = label != null ? label.toLowerCase() : '';
dom['value'] = stringValue.toLowerCase();
dom['values'] = stringValue.toLowerCase();
return dom;
}

Expand Down
Loading

0 comments on commit d8dd544

Please sign in to comment.