Skip to content

Commit

Permalink
[Version - v0.3.10]
Browse files Browse the repository at this point in the history
  • Loading branch information
vinaygopinath committed Sep 20, 2016
1 parent b7d8e20 commit 730bbed
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#Changelog

## [v0.3.10](https://github.com/vinaygopinath/ngMeta/releases/tag/v0.3.10)

##### Features

* [#15](https://github.com/vinaygopinath/ngMeta/issues/15) New 'setDefaultTag` function to dynamically update default values (Thanks [@xon88](https://github.com/xon88))

## [v0.3.9](https://github.com/vinaygopinath/ngMeta/releases/tag/v0.3.9)

##### Bugfixes
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,18 @@ angular.module('YourApp')
.controller(function(ngMeta) {
//These examples assume useTitleSuffix is enabled,
//and default titleSuffix is set to 'Playlist'
//Custom title and titleSuffix
ngMeta.setTitle('Eluvium', ' | Spotify'); //Title = Eluvium | Spotify
//default titleSuffix
ngMeta.setTitle('Eluvium'); //Title = Eluvium | Playlist
//Clear the default titleSuffix
ngMeta.setTitle('Eluvium',''); //Title = Eluvium
ngMeta.setTag('author', 'Matthew Cooper');
ngMeta.setTag('image', 'http://placeholder.com/abc.jpg');
ngMeta.setDefaultTag('author', 'Default author');
});
```

Expand All @@ -155,6 +157,7 @@ Note: Please use `setTitle` to modify the title and/or titleSuffix and `setTag`
| ------ | ------- | ------- |
| **setTitle(String title, String titleSuffix)** | Sets the current title based on the given params. When `useTitleSuffix` is enabled and titleSuffix is not provided, it uses the default titleSuffix. | ngMeta.setTitle('Title', ' - TitleSuffix')<br/><br/>ngMeta.setTitle('Title with default titleSuffix')<br/><br/>ngMeta.setTitle('Title with no titleSuffix','') |
| **setTag(String tagName, String value)** | Sets the value of an arbitrary tag, using the default value of the tag when the second param is missing. The value is accessible as {{ngMeta.tagName}} from HTML. Calling setTag with `title` or `titleSuffix` as `tagName` results in an error. Title must be modified using `setTitle` instead.|ngMeta.setTag('author', 'John Smith')<br/><br/>ngMeta.setTag('ogImage', 'http://url.com/image.png')|
| **setDefaultTag(String tagName, String value)** | Sets the default value of an arbitrary tag, overwriting previously set default values, but not the value set dynamically (using `setTitle`/`setTag`) or by the route/state. `title` and `titleSuffix` are accepted values.|ngMeta.setDefaultTag('image', 'http://default-image-url.com');<br/><br/>ngMeta.setDefaultTag('title','Default title');|

### Setting tags with custom data resolved by ui-router

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngMeta",
"version": "0.3.9",
"version": "0.3.10",
"authors": [
"Vinay Gopinath <[email protected]>"
],
Expand Down
37 changes: 34 additions & 3 deletions dist/ngMeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@
if (!$rootScope.ngMeta) {
throw new Error('Cannot call setTitle when ngMeta is undefined. Did you forget to call ngMeta.init() in the run block? \nRefer: https://github.com/vinaygopinath/ngMeta#getting-started');
}
$rootScope.ngMeta.title = angular.isDefined(title) ? title : defaults.title;

$rootScope.ngMeta.title = angular.isDefined(title) ? title : (defaults.title || '');
if (config.useTitleSuffix) {
$rootScope.ngMeta.title += angular.isDefined(titleSuffix) ? titleSuffix : defaults.titleSuffix;
$rootScope.ngMeta.title += angular.isDefined(titleSuffix) ? titleSuffix : (defaults.titleSuffix || '');
}
return this;
};
Expand All @@ -86,10 +87,39 @@
if (tag === 'title' || tag === 'titleSuffix') {
throw new Error('Attempt to set \'' + tag + '\' through \'setTag\': \'title\' and \'titleSuffix\' are reserved tag names. Please use \'ngMeta.setTitle\' instead');
}

$rootScope.ngMeta[tag] = angular.isDefined(value) ? value : defaults[tag];
return this;
};

/**
* @ngdoc method
* @name ngMeta#setDefaultTag
* @description
* Sets the default tag for all routes that are missing a custom
* `tag` property in their meta objects.
*
* @example
* ngMeta.setDefaultTag('titleSuffix', ' | Tagline of the site');
*
* @returns {Object} self
*/
var setDefaultTag = function(tag, value) {
if (!$rootScope.ngMeta) {
throw new Error('Cannot call setDefaultTag when ngMeta is undefined. Did you forget to call ngMeta.init() in the run block? \nRefer: https://github.com/vinaygopinath/ngMeta#getting-started');
}

defaults[tag] = value;

if (tag === 'title' || tag === 'titleSuffix') {
this.setTitle($rootScope.ngMeta.title, $rootScope.ngMeta.titleSuffix);
} else {
this.setTag(tag, $rootScope.ngMeta[tag]);
}

return this;
};

/**
* @ngdoc method
* @name readRouteMeta
Expand Down Expand Up @@ -165,7 +195,8 @@
return {
'init': init,
'setTitle': setTitle,
'setTag': setTag
'setTag': setTag,
'setDefaultTag': setDefaultTag
};
}

Expand Down
4 changes: 2 additions & 2 deletions dist/ngMeta.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-meta",
"version": "0.3.9",
"version": "0.3.10",
"description": "Meta tags support for AngularJS single page applications (SPA)",
"main": "dist/ngMeta.js",
"directories": {
Expand Down

0 comments on commit 730bbed

Please sign in to comment.