forked from vinaygopinath/ngMeta
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added ng-annotate to avoid DI issues after minification * Added editorconfig and formatted all files
- Loading branch information
1 parent
bd89b23
commit e1ee56f
Showing
7 changed files
with
198 additions
and
44 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = false | ||
trim_trailing_whitespace = true |
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,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']); | ||
}; |
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,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" | ||
} | ||
} |
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 |
---|---|---|
@@ -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); | ||
}]; | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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