Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmarr-ft committed Jun 1, 2015
1 parent a3ea4b6 commit 3274fd2
Show file tree
Hide file tree
Showing 49 changed files with 1,304 additions and 1,096 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This module adds display advertising functionality to your product. Using this m
standard demographic targeting functionality, behavioural tracking features, useful custom targeting attributes, it is also
aligned to the standard FT Advertising Technology stack so co-ordination with Ad Operations should be a breeze.

Having a sales model is important! See this document for pre-requisite steps required for adding advertising to your product:
Having a sales model is important! See this document for pre-requisite steps required for adding advertising to your product:
https://docs.google.com/a/ft.com/document/d/1a9Dyi-4VzN_gzhYn6scVLgKICEP1AEPR7A7-shefklU/edit

## Browser support <div id="title2"></div>
Expand Down
150 changes: 103 additions & 47 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
/* jshint node: true */

'use strict';

printAscii();
var path = require('path');
var gulp = require('gulp');
var obt = require('origami-build-tools');
var git = require('gulp-git');
var bump = require('gulp-bump');
var filter = require('gulp-filter');
var plato = require('gulp-plato');
var tag_version = require('gulp-tag-version');
var tagVersion = require('gulp-tag-version');
var ssg = require('gulp-ssg');
var rename = require('gulp-rename');
var data = require('gulp-data');
var matter = require('gray-matter');
var markdown = require('gulp-markdown');
var wrap = require('gulp-wrap');

var sequence = require('run-sequence');
var clean = require('rimraf');

var config = {
origami: require('./origami.json'),
bower: require('./bower.json'),
jshint: require('./node_modules/origami-build-tools/config/jshint.json')
docs: {
filters: {
js: filter('**/*.js'),
md: filter('**/*.md')
},
templates: {
main: path.join(__dirname, './docs/templates/o-tech.html'),
js: path.join(__dirname, './docs/templates/src.html')
}
},
reports: {
plato: {
dest: './build/reports/plato',
options: {
jshint: {
options: require('./node_modules/origami-build-tools/config/jshint.json')
},
complexity: {
trycatch: true
}
}
}
}
};

/**
Expand All @@ -38,88 +61,121 @@ var config = {
* introduced a feature or made a backwards-incompatible release.
*/

function inc(importance, callback) {
function inc(type, callback) {

// make sure we're on the master branch, otherwise the release could end up on the wrong branch or worse an orphaned head
git.checkout('master', function (err) {
git.checkout('master', function(err) {
if (err) throw err;
// get all the files to bump version in

gulp.src(['./package.json', './bower.json'])
// bump the version number in those files
.pipe(bump({type: importance}))
// save it back to filesystem
.pipe(bump({type: type}))
.pipe(gulp.dest('./'))
// commit the changed version number
.pipe(git.commit('bumps package version'))
// read only one file to get the version number
.pipe(filter('bower.json'))
// **tag it in the repository**
.pipe(tag_version({prefix:""}))
.on('end', function () {
git.push('origin', 'master', function (err) {
.pipe(tagVersion({prefix: ''}))
.on('end', function() {
git.push('origin', 'master', function(err) {
if (err) throw err;
git.push('origin', '--tag', function (err) {
git.push('origin', '--tag', function(err) {
if (err) throw err;
callback();
});
});
});
});

}

gulp.task('release:patch', function(callback) { inc('patch', callback); });
gulp.task('release:minor', function(callback) { inc('minor', callback); });
gulp.task('release:major', function(callback) { inc('major', callback); });

gulp.task('report:plato', function() {
var conf = config.reports.plato;
gulp.src(['./main.js', './src/js/**/*.js'])
.pipe(plato(conf.dest, conf.options));
});

gulp.task('report:plato', function(){
var dest = './reports/plato';
gulp.src(['./main.js', './src/js/*.js']).pipe(plato(dest, {
jshint: {
options: config.jshint
},
complexity: {
trycatch: true
}
}));
gulp.task('build', function() {
obt.build(gulp, {
sourcemaps: true
});
});

gulp.task('build', function () {
gulp.task('report:qunit', function() {
obt.build(gulp, {
files: ['test/qunit/setup.js', 'test/qunit/*.test.js'],
sourcemaps: true
});
});

gulp.task('reports', ['build', 'report:plato']);

gulp.task('docs:otech', function () {
return gulp.src('./docs/*.md')
gulp.task('docs:build', function() {
var filters = config.docs.filters;
var templates = config.docs.templates;
return gulp.src(['./docs/**/*.md', './src/js/**/*.js'])
.pipe(filters.md)
.pipe(data(function(file) {
var m = matter(String(file.contents));
file.matter = matter.stringify('', m.data);
file.contents = new Buffer(m.content);
return m.data;
}))
.pipe(markdown())
.pipe(filters.md.restore())
.pipe(filters.js)
.pipe(data(function(file) {
var data = {
title: path.parse(file.path).name
};
file.matter = matter.stringify('', data);
return data;
}))
.pipe(wrap({ src: templates.js }, {}, { engine: 'hogan' }))
.pipe(rename(function(file) {
file.dirname = path.join('developer-guide/src/', file.dirname);
}))
.pipe(filters.js.restore())
.pipe(wrap('{{file.matter}}{{{contents}}}', {}, { engine: 'hogan' }))
.pipe(rename({ extname: '.html' }))
.pipe(gulp.dest('./build/site/base'));
});

gulp.task('docs:gh', function() {
var templates = config.docs.templates;

return gulp.src('./build/site/base/**/*.html')
.pipe(data(function(file) {
console.log(file);
var m = matter(String(file.contents));
file.contents = new Buffer(m.content);
return m.data;
}))
.pipe(markdown())
.pipe(rename({ extname: '.html' }))
.pipe(ssg())
.pipe(wrap(
{ src: './docs/templates/basic.html' },
{ siteTitle: 'Example Website'},
{ src: templates.main },
{ siteTitle: config.origami.description},
{ engine: 'hogan' }
))
.pipe(gulp.dest('./docs/o-tech/'));
.pipe(gulp.dest('./build/site/gh'));
});

gulp.task('clean:docs', function(cb) {
clean('build/site', cb);
});

gulp.task('docs', function() {
sequence('clean:docs', 'docs:build', 'docs:gh');
});

function printAscii() {
console.log(" __ ");
console.log(" / | ");
console.log(" ______ ______ ____$$ | _______ ");
console.log(" / \\ ______ / \\ / $$ | / |");
console.log("/$$$$$$ |/ |$$$$$$ |/$$$$$$$ |/$$$$$$$/ ");
console.log("$$ | $$ |$$$$$$/ / $$ |$$ | $$ |$$ \\ ");
console.log("$$ \\__$$ | /$$$$$$$ |$$ \\__$$ | $$$$$$ |");
console.log("$$ $$/ $$ $$ |$$ $$ |/ $$/ ");
console.log("$$$$$$/ $$$$$$$/ $$$$$$$/ $$$$$$$/");
console.log("");
console.log(' __ ');
console.log(' / | ');
console.log(' ______ ______ ____$$ | _______ ');
console.log(' / \\ ______ / \\ / $$ | / |');
console.log('/$$$$$$ |/ |$$$$$$ |/$$$$$$$ |/$$$$$$$/ ');
console.log('$$ | $$ |$$$$$$/ / $$ |$$ | $$ |$$ \\ ');
console.log('$$ \\__$$ | /$$$$$$$ |$$ \\__$$ | $$$$$$ |');
console.log('$$ $$/ $$ $$ |$$ $$ |/ $$/ ');
console.log('$$$$$$/ $$$$$$$/ $$$$$$$/ $$$$$$$/');
console.log('');
}
1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var options = {
frameworks: ['browserify', 'qunit'],
files: [
'test/qunit/styles.css',
'build/main.css',
'node_modules/qunitjs/qunit/qunit.css',
'bower_components/jquery-1.7.2.min/index.js',
'bower_components/jquery.cookie/index.js',
Expand Down
14 changes: 11 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* Represents an instance of the o-ads on the page.
* All sub modules are available from the prototype
* @constructor
*/
function Ads() {
Expand All @@ -26,7 +27,12 @@ Ads.prototype.version = require('./src/js/version');
Ads.prototype.buildURLForVideo = require('./src/js/video');
Ads.prototype.utils = require('./src/js/utils');

Ads.prototype.init = function (config){
/**
* Initialises the ads library and all sub modules
* @param config {object} a JSON object containing configuration for the current page
*/

Ads.prototype.init = function(config) {
// use `this` as our internal namespace
// it's passed into each module so we can to maintain state in each module
this.config.init();
Expand All @@ -43,19 +49,21 @@ Ads.prototype.init = function (config){
var ads = new Ads();
var initAll = function() {
var metas = document.getElementsByTagName('meta');
for (i=0; i<metas.length; i++) {
for (i = 0; i < metas.length; i++) {
if (metas[i].getAttribute("property") === "o-ads-declarative-init") {
return false;
}
}

ads.init();
var slots = document.querySelectorAll(".o-ads, [data-o-ads-name]");
for (var i = 0; i < slots.length; i++) {
var name = slots[i].getAttribute('data-o-ads-name');
if (name){
if (name) {
ads.slots.initSlot(name);
}
}

document.documentElement.removeEventListener('o.DOMContentLoaded', initAll);
};

Expand Down
2 changes: 1 addition & 1 deletion main.mustache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div id="{{pos}}" class="advertising {{classes}}" {{{o-ads-data-attr}}}></div>
<div data-o-ads-name="{{name}}" class=".o-ads {{classes}}" {{{o-ads-data-attr}}}></div>
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
"gulp-markdown": "^1.0.0",
"gulp-plato": "^1.0.2",
"gulp-rename": "^1.2.2",
"gulp-sourcemaps": "^1.5.2",
"gulp-ssg": "^2.0.0",
"gulp-tag-version": "^1.1.0",
"gulp-util": "^3.0.4",
"gulp-wrap": "^0.11.0",
"hogan.js": "^3.0.2",
"karma": "^0.12.31",
"karma-browserify": "^1.0.0",
"karma-chrome-launcher": "^0.1.5",
Expand All @@ -41,7 +44,11 @@
"karma-qunit": "~0.1.1",
"karma-safari-launcher": "~0.1.1",
"karma-webdriver-launcher": "^1.0.1",
"origami-build-tools": "^2.13.0"
"origami-build-tools": "^2.13.0",
"rimraf": "^2.3.3",
"run-sequence": "^1.1.0",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
},
"browserify-swap": {
"@packages": [
Expand Down
6 changes: 3 additions & 3 deletions src/js/ad-servers/gpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,15 @@ var slotMethods = {
gptSlot = gptSlot || this.gpt.slot;
var canonical = config('canonical');
if (canonical) {
gptSlot.set("page_url", canonical || utils.getLocation());
gptSlot.set('page_url', canonical || utils.getLocation());
}

return this;
},

/**
* Adds key values from a given object to the slot targeting
*/
* Adds key values from a given object to the slot targeting
*/
setTargeting: function(gptSlot) {
gptSlot = gptSlot || this.gpt.slot;
if (utils.isPlainObject(this.targeting)) {
Expand Down
Loading

0 comments on commit 3274fd2

Please sign in to comment.