Skip to content

Commit

Permalink
* Added support for ui-router
Browse files Browse the repository at this point in the history
* Added ng-annotate to avoid DI issues after minification
* Added editorconfig and formatted all files
  • Loading branch information
vinaygopinath committed Sep 10, 2015
1 parent bd89b23 commit e1ee56f
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 44 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = false
trim_trailing_whitespace = true
76 changes: 50 additions & 26 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,56 @@
module.exports = function (grunt) {
module.exports = function(grunt) {

'use strict';
'use strict';

grunt.initConfig({
grunt.initConfig({

jshint: {
files: ['Gruntfile.js', 'src/{,*/}*.js', 'test/{,*/}*.js'],
options: {
reporter: require('jshint-stylish'),
globals: {
angular: true,
require: true,
jasmine: true,
module: true
}
}
},
karma: {
unit: {
configFile: 'test/karma.conf.js',
singleRun: true
}
},
//Javascript code suggestions
jshint: {
files: ['Gruntfile.js', 'src/{,*/}*.js', 'test/{,*/}*.js'],
options: {
reporter: require('jshint-stylish'),
globals: {
angular: true,
require: true,
jasmine: true,
module: true
}
}
},
//Test runner
karma: {
unit: {
configFile: 'test/karma.conf.js',
singleRun: true
}
},
//Add explicit dependency injection strings
//to avoid errors after minification
ngAnnotate: {
dist: {
files: [{
expand: true,
cwd: 'src',
src: 'ngMeta.js',
dest: 'dist'
}]
}
},
//Minify the dist file
uglify: {
dist: {
files: {
'dist/ngMeta.min.js': 'dist/ngMeta.js'
}
}
}
});

});
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-ng-annotate');
grunt.loadNpmTasks('grunt-contrib-uglify');

grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-contrib-jshint');

grunt.registerTask('test', ['jshint', 'karma']);
grunt.registerTask('test', ['jshint', 'karma']);
grunt.registerTask('dist', ['ngAnnotate', 'uglify']);
};
31 changes: 16 additions & 15 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
{
"name": "ngMeta",
"version": "0.1.0",
"authors": [
"name": "ngMeta",
"version": "0.2.0",
"authors": [
"Vinay Gopinath <[email protected]>"
],
"description": "Meta tags support for AngularJS single page applications (SPA)",
"main": "ngMeta.js",
"keywords": [
"description": "Meta tags support for AngularJS single page applications (SPA)",
"main": "ngMeta.js",
"keywords": [
"angularjs",
"meta",
"title",
"open-graph",
"description",
"spa"
],
"license": "MIT",
"homepage": "https://github.com/vinaygopinath/ngMeta",
"ignore": [
"license": "MIT",
"homepage": "https://github.com/vinaygopinath/ngMeta",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"angular": ">1.2"
},
"devDependencies": {
"angular-mocks": ">1.2"
}
"dependencies": {
"angular": ">1.2"
},
"devDependencies": {
"angular-mocks": ">1.2",
"angular-route": "~1.4.5"
}
}
117 changes: 117 additions & 0 deletions dist/ngMeta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* @ngdoc service
* @name ngMeta.ngMeta
* @description
* # A metatags service for single-page applications
* that supports setting title, description, open-graph and twitter card meta tags
*/
angular.module('ngMeta', [])
.provider('ngMeta', function () {

'use strict';

var defaults = {
title: '',
titleSuffix: '',
description: '',
ogImgUrl: '',
ogTitle: '',
twCard: ''
};

var config = {
name: 'ngMeta',
useTitleSuffix: false,
ogType: 'website',
ogSiteName: '',
ogLocale: 'en_US',
};

//Constructor
function Meta($rootScope) {

var setTitle = function (title, titleSuffix) {
$rootScope[config.name].title = title || defaults.title;
if (config.useTitleSuffix) {
$rootScope[config.name].title += titleSuffix || defaults.titleSuffix;
}
};

var setDescription = function (description) {
$rootScope[config.name].description = description || defaults.description;
};

var setOgImgUrl = function (ogImgUrl) {
$rootScope[config.name].ogImgUrl = ogImgUrl || defaults.ogImgUrl;
};

var readRouteMeta = function (meta) {
meta = meta || {};
setTitle(meta.title, meta.titleSuffix);
setDescription(meta.description);
setOgImgUrl(meta.ogImgUrl);
};

var update = function (event, current) {
readRouteMeta(current.meta);
};

$rootScope[config.name] = {};
$rootScope[config.name].ogType = config.ogType;
$rootScope[config.name].ogSiteName = config.ogSiteName;
$rootScope[config.name].ogLocale = config.ogLocale;
$rootScope.$on('$routeChangeSuccess', update);
$rootScope.$on('$stateChangeSuccess', update);

return {
'setTitle': setTitle,
'setDescription': setDescription,
'setOgImgUrl': setOgImgUrl
};
}

/* Set defaults */

this.setDefaultTitle = function (titleStr) {
defaults.title = titleStr;
};

this.setDefaultTitleSuffix = function (titleSuffix) {
defaults.titleSuffix = titleSuffix;
};

this.setDefaultDescription = function (desc) {
defaults.description = desc;
};

this.setDefaultOgImgUrl = function (imgUrl) {
defaults.ogImgUrl = imgUrl;
};

/* One-time config */

this.setName = function (varName) {
config.name = varName;
};

this.useTitleSuffix = function (bool) {
config.useTitleSuffix = !!bool;
};

this.setOgType = function (type) {
config.ogType = type;
};

this.setOgSiteName = function (siteName) {
config.ogSiteName = siteName;
};

this.setOgLocale = function (locale) {
config.ogLocale = locale;
};

// Method for instantiating
this.$get = ["$rootScope", function ($rootScope) {
return new Meta($rootScope);
}];
});
1 change: 1 addition & 0 deletions dist/ngMeta.min.js

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

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngMeta",
"version": "0.1.0",
"name": "ng-meta",
"version": "0.2.0",
"description": "Meta tags support for AngularJS single page applications (SPA)",
"main": "ngMeta.js",
"directories": {
Expand Down Expand Up @@ -31,7 +31,9 @@
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-jshint": "^0.11.2",
"grunt-contrib-uglify": "^0.9.2",
"grunt-karma": "^0.12.0",
"grunt-ng-annotate": "^1.0.1",
"jasmine-core": "^2.3.4",
"jshint-stylish": "^2.0.1",
"karma": "^0.13.9",
Expand All @@ -40,4 +42,4 @@
"karma-phantomjs-launcher": "^0.2.1",
"phantomjs": "^1.9.18"
}
}
}
1 change: 1 addition & 0 deletions src/ngMeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ angular.module('ngMeta', [])
$rootScope[config.name].ogSiteName = config.ogSiteName;
$rootScope[config.name].ogLocale = config.ogLocale;
$rootScope.$on('$routeChangeSuccess', update);
$rootScope.$on('$stateChangeSuccess', update);

return {
'setTitle': setTitle,
Expand Down

0 comments on commit e1ee56f

Please sign in to comment.