forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from harman-goei/upgrade-0.8-2
Upgrade 0.8 2
- Loading branch information
Showing
17 changed files
with
714 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
language: node_js | ||
|
||
node_js: | ||
- 0.12 | ||
- 0.11 | ||
- "5.1" | ||
|
||
before_install: | ||
- npm install -g gulp | ||
|
||
script: | ||
- gulp build | ||
- gulp build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,20 @@ | ||
<!-- #1 deprecated method - use preferred method below instead--> | ||
<script> | ||
try{ window.top.pbjs.renderAd(document, '%%PATTERN:hb_adid%%'); } catch(e) {/*ignore*/} | ||
</script> | ||
|
||
<!-- #2 preferred method for showing ad - handles cases when pbjs is not in the top window --> | ||
<script> | ||
var w = window; | ||
for (i = 0; i < 10; i++) { | ||
w = w.parent; | ||
if (w.pbjs) { | ||
try { | ||
w.pbjs.renderAd(document, '%%PATTERN:hb_adid%%'); | ||
break; | ||
} catch (e) { | ||
continue; | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,117 @@ | ||
/** adapterLoader | ||
* Webpack loader to insert dynamic javascript into `./src/adaptermanager.js` | ||
* This is used in `./webpack.conf.js` | ||
* */ | ||
|
||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const blockLoader = require('block-loader'); | ||
let adapters = require('../package.json').adapters; | ||
const adapters = require('../package.json').adapters; | ||
|
||
const files = fs.readdirSync('src/adapters').map((file) => file.replace(/\.[^/.]+$/, '')); | ||
const adapterNames = adapters.map(getNames).filter(getUniques); | ||
const aliases = adapters.filter(getAliases); | ||
|
||
var options = { | ||
start: '/** INSERT ADAPTERS - DO NOT EDIT OR REMOVE */', | ||
end: '/** END INSERT ADAPTERS */', | ||
process: function insertAdapters() { | ||
const files = fs.readdirSync('src/adapters').map((file) => file.replace(/\.[^/.]+$/, '')); | ||
process: insertAdapters | ||
}; | ||
|
||
if (!adapters || !adapters.length) { | ||
console.log('Prebid Warning: adapters config not found in package.json, building with all' + | ||
' adapters'); | ||
adapters = files; | ||
} | ||
/** | ||
* Returns a block of javascript statements to load adapter modules, register the adapters and | ||
* set adapter aliases | ||
* @returns {*} | ||
*/ | ||
function insertAdapters() { | ||
|
||
let inserts = adapters.filter((adapter) => { | ||
if (files.includes(adapter)) { | ||
return adapter; | ||
} else { | ||
console.log(`Prebid Warning: no adapter found for ${adapter}, continuing.`); | ||
} | ||
}); | ||
|
||
if (!inserts.length) { | ||
console.log('Prebid Warning: no matching adapters found for config, building with all' + | ||
' adapters.'); | ||
if (!adapters) { | ||
console.log('Prebid Warning: adapters config not found in package.json, no adapters will' + | ||
' be loaded'); | ||
return ''; | ||
} | ||
|
||
const inserts = adapterNames.map(name => { | ||
if (files.includes(name)) { | ||
return name; | ||
} else { | ||
console.log(`Prebid Warning: no adapter found for ${name}, continuing.`); | ||
} | ||
}); | ||
|
||
inserts = inserts.length ? inserts : files; | ||
return inserts.map((adapter) => { | ||
if (adapter === 'appnexusAst') { | ||
return `import { AppnexusAst } from './adapters/appnexusAst';\n` + | ||
`exports.registerBidAdapter(new AppnexusAst('appnexus'), 'appnexus');\n`; | ||
} | ||
|
||
return `var ${adapterName(adapter)} = require('./adapters/${adapter}.js');\n` + | ||
`exports.registerBidAdapter(new ${adapterName(adapter)}` + | ||
`${useCreateNew(adapter)}(), '${adapter}');\n`; | ||
}).join(''); | ||
if (!inserts.length) { | ||
console.log('Prebid Warning: no matching adapters found for config, no adapters will be' + | ||
' loaded.'); | ||
return ''; | ||
} | ||
}; | ||
|
||
return inserts.map(name => { | ||
if (name === 'appnexusAst') { | ||
return `import { AppnexusAst } from './adapters/appnexusAst'; | ||
exports.registerBidAdapter(new AppnexusAst('appnexus'), 'appnexus');\n`; | ||
} else { | ||
return `var ${adapterName(name)} = require('./adapters/${name}.js'); | ||
exports.registerBidAdapter(new ${adapterName(name)}${useCreateNew(name)}(), '${name}');\n`; | ||
} | ||
}) | ||
.concat(aliases.map(adapter => { | ||
const name = Object.keys(adapter)[0]; | ||
return `exports.aliasBidAdapter('${name}','${adapter[name].alias}');\n`; | ||
})) | ||
.join(''); | ||
} | ||
|
||
/** | ||
* Derive the variable name to use for the adapter | ||
* @param adapter | ||
* @returns {string} | ||
*/ | ||
function adapterName(adapter) { | ||
let result = adapter.split(''); | ||
const result = adapter.split(''); | ||
return result[0].toUpperCase() + result.join('').substr(1) + 'Adapter'; | ||
} | ||
|
||
// some adapters export an object with a `createNew` constructor so accommodate this pattern | ||
/** | ||
* Some adapters export an object with a `createNew` constructor so accommodate this pattern | ||
* @param adapter | ||
* @returns {string} | ||
*/ | ||
function useCreateNew(adapter) { | ||
return adapter === 'appnexus' ? '.createNew' : ''; | ||
} | ||
|
||
/** | ||
* Filter an array to return unique values | ||
* @param value current array element value | ||
* @param index current array element index | ||
* @param self current array | ||
* @returns {boolean} if true the current array element is returned | ||
* | ||
* http://stackoverflow.com/questions/1960473/unique-values-in-an-array | ||
*/ | ||
function getUniques(value, index, self) { | ||
return self.indexOf(value) === index; | ||
} | ||
|
||
/** | ||
* Filter to derive the adapter name from array elements as strings or objects | ||
* @param adapter | ||
* @returns {*} | ||
*/ | ||
function getNames(adapter) { | ||
// if `length` then `adapter` is a string, otherwise an object | ||
return adapter.length ? adapter : Object.keys(adapter)[0]; | ||
} | ||
|
||
/** | ||
* Return adapter objects that have an alias field | ||
* @param adapter | ||
* @returns {*} | ||
*/ | ||
function getAliases(adapter) { | ||
const name = Object.keys(adapter)[0]; | ||
return adapter && name && adapter[name].alias; | ||
} | ||
|
||
module.exports = blockLoader(options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.