Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove slugToSiteName helper #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ app.set('view engine', 'handlebars');

# Helpers

Currently **56 helpers** in **10 categories**:
Currently **55 helpers** in **10 categories**:


### arrays
Expand Down Expand Up @@ -84,7 +84,6 @@ Currently **56 helpers** in **10 categories**:
* [**extractImgWidth**](https://github.com/clay/handlebars#extractimgwidth--code--tests-) ( [code](https://github.com/clay/handlebars/blob/master/helpers/misc/extractImgWidth.js) | [tests](https://github.com/clay/handlebars/blob/master/helpers/misc/extractImgWidth.test.js) )
* [**indexOf**](https://github.com/clay/handlebars#indexof--code--tests-) ( [code](https://github.com/clay/handlebars/blob/master/helpers/misc/indexOf.js) | [tests](https://github.com/clay/handlebars/blob/master/helpers/misc/indexOf.test.js) )
* [**set**](https://github.com/clay/handlebars#set--code--tests-) ( [code](https://github.com/clay/handlebars/blob/master/helpers/misc/set.js) | [tests](https://github.com/clay/handlebars/blob/master/helpers/misc/set.test.js) )
* [**slugToSiteName**](https://github.com/clay/handlebars#slugtositename--code--tests-) ( [code](https://github.com/clay/handlebars/blob/master/helpers/misc/slugToSiteName.js) | [tests](https://github.com/clay/handlebars/blob/master/helpers/misc/slugToSiteName.test.js) )

### numbers

Expand Down Expand Up @@ -215,7 +214,7 @@ Add in article ads to list of components in an article
#### Params
* `content` _(array)_ the list of components in the article
* `articleData` _(object)_ the entire article's data, used to pull in the different ad units defined
* `afterComponent` _(string)_ the component type to insert the ad after
* `afterCmp` _(string)_ the component type to insert the ad after

**Returns** _(object)_ splash

Expand Down Expand Up @@ -572,22 +571,6 @@ set data into current context or other optional context/object<br /> _note:_ do
//=> "abc"
```

### slugToSiteName ( [code](https://github.com/clay/handlebars/blob/master/helpers/misc/slugToSiteName.js) | [tests](https://github.com/clay/handlebars/blob/master/helpers/misc/slugToSiteName.test.js) )

return comma-separated site names from comma-separated slugs

#### Params
* `slugs` _(string)_ comma-separated string of slugs

**Returns** _(string)_

#### Example

```hbs
{{ slugToSiteName (commaSeparated crosspost) }}
```

## numbers


Expand Down
11 changes: 8 additions & 3 deletions helpers/components/addInSplashAds.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,35 @@ function getComponentType(component) {
* Add in article ads to list of components in an article
* @param {array} content - the list of components in the article
* @param {object} articleData - the entire article's data, used to pull in the different ad units defined
* @param {string} afterComponent - the component type to insert the ad after
* @param {string} afterCmp - the component type to insert the ad after
* @return {object} splash
*/
module.exports = function (content, articleData, afterComponent) {
module.exports = function (content, articleData, afterCmp) {
var adUnits;

let newContent = []; // don't just replace the content (it's a sealed array), create a new array!

if (articleData) {
adUnits = articleData.inSplashDesktopAd || articleData.inSplashTabletAd || articleData.inSplashMobileAd;
}

if (adUnits) {
_forEach(content, function (component) {
const componentType = getComponentType(component);


// add the current component before any ads
newContent.push(component);
if (componentType === afterComponent) {
if (componentType === afterCmp) {
/* istanbul ignore else */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (articleData.inSplashMobileAd) {
newContent.push(articleData.inSplashMobileAd);
}
/* istanbul ignore else */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (articleData.inSplashTabletAd) {
newContent.push(articleData.inSplashTabletAd);
}
/* istanbul ignore else */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (articleData.inSplashDesktopAd) {
newContent.push(articleData.inSplashDesktopAd);
}
Expand Down
10 changes: 8 additions & 2 deletions helpers/components/addInSplashAds.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,17 @@ describe(name, function () {
});

it('returns the same content when the string passed in is not a component in the content', function () {
var result = filter([paragraph4, paragraph1, mediaplayComponent, paragraph1], { inSplashDesktopAd: desktopAd, inSplashTabletAd: tabletAd, inSplashMobileAd: mobileAd }, 'notAComponent');
var result = filter([desktopAd, paragraph1, mediaplayComponent, paragraph1], { inSplashDesktopAd: desktopAd, inSplashTabletAd: tabletAd, inSplashMobileAd: mobileAd }, 'notAComponent');

expect(result[0]).to.equal(paragraph4);
expect(result[0]).to.equal(desktopAd);
expect(result[1]).to.equal(paragraph1);
expect(result[2]).to.equal(mediaplayComponent);
expect(result[3]).to.equal(paragraph1);
});

it('should just return the content if there is no articleData', function () {
var result = filter([mobileAd, paragraph1, mediaplayComponent, paragraph1], {}, 'notAComponent');

expect(_.includes(result, mobileAd)).to.equal(true);
});
});
30 changes: 0 additions & 30 deletions helpers/misc/slugToSiteName.js

This file was deleted.

17 changes: 0 additions & 17 deletions helpers/misc/slugToSiteName.test.js

This file was deleted.

Loading