Skip to content
Browse files

Pridani komentaru podle jsdoc

  • Loading branch information...
1 parent f3da964 commit af909c18032676118a5215685da8ab232698e34b @JakubMrozek committed Nov 12, 2012
Showing with 90 additions and 7 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 README.md
  3. +1 −1 app.js
  4. +52 −3 app/models/Page.js
  5. +5 −0 config.js
  6. +12 −1 lib/filters/removeDiacritics.js
  7. +18 −2 lib/filters/url.js
View
1 .gitignore
@@ -13,5 +13,6 @@ lib-cov
pids
logs
results
+docs
npm-debug.log
View
1 README.md
@@ -5,6 +5,7 @@
* Coding Standards: http://nodeguide.com/style.html
* Kontrola syntaxe: příkaz "grunt" (grunt.cmd na Windows), musí být nainstalován balíček grunt globálně (-g)
* Spuštění testů: npm test
+* Generování dokumentace: doc-foundation --source ./ --target docs --ignore node_modules,docs,public,test --title "Zdrojak shop"
8. díl
======
View
2 app.js
@@ -7,7 +7,7 @@ var app = express();
config.configure(app);
config.connect(app);
-//controllery (inicializace modelu je v controllerech)
+//controllery
var PageController = require('./app/controllers/PageController');
//API stranky
View
55 app/models/Page.js
@@ -1,18 +1,67 @@
+
+/**
+ * Zavislosti modulu.
+ */
+
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
+/**
+ * Schema databaze.
+ */
+
var fields = {
- title: {type: String, required: true},
- url: {type: String, required: true},
- content: {type: String, required: true}
+ title: {
+ type: String,
+ required: true
+ },
+ url: {
+ type: String,
+ required: true
+ },
+ content: {
+ type: String,
+ required: true
+ }
};
var PageSchema = new Schema(fields);
+/**
+ * Vybere dokument podle URL.
+ *
+ * Vola metodu findOne(), ktere preda podminku pro vyber podle URL.
+ *
+ * @param {String} url
+ * @param {Function} cb
+ */
+
PageSchema.statics.findOneByUrl = function(url, cb) {
this.findOne({url: url}, cb);
};
+/**
+ * Kontroluje, zda jsou predana pole ve schema.
+ *
+ * Priklad:
+ *
+ * var fieldsObj = {
+ * url: 1,
+ * content: 1
+ * };
+ * Page.inSchema(fieldsObj); //true
+ *
+ * var fieldsObj = {
+ * url: 1,
+ * neexistuje: 1
+ * };
+ * Page.inSchema(fieldsObj); //false
+ *
+ *
+ * @param {Object} obj
+ * @return {Boolean}
+ */
+
PageSchema.statics.inSchema = function(obj) {
for (var field in obj) {
if (typeof fields[field] === 'undefined') {
View
5 config.js
@@ -1,3 +1,8 @@
+
+/**
+ * Zavislosti modulu.
+ */
+
var express = require('express');
var mongoose = require('mongoose');
View
13 lib/filters/removeDiacritics.js
@@ -1,4 +1,8 @@
-// inspired by http://lehelk.com/2011/05/06/script-to-remove-diacritics/
+
+/**
+ * @see http://lehelk.com/2011/05/06/script-to-remove-diacritics/
+ */
+
var REMOVE_DIACRITICS_MAP = [
{
base: 'A',
@@ -255,6 +259,13 @@ var REMOVE_DIACRITICS_MAP = [
}
];
+/**
+ * Odstrani z retezce diakritiku.
+ *
+ * @param {String} str
+ * @return {String}
+ */
+
function removeDiacritics(str) {
var item, i, ln, ref;
View
20 lib/filters/url.js
@@ -1,13 +1,29 @@
+
+/**
+ * Zavislosti modulu.
+ */
var removeDiacritics = require(process.cwd() + '/lib/filters/removeDiacritics');
+/**
+ * Prevede retezec na format pro URL.
+ *
+ * Provede tyto upravy:
+ * - odstrani ze zacatku a z konce mezery
+ * - bile znaky prevede na pomlcky
+ * - odstrani z retezce diakritiku
+ * - prevede retezec na mala pismena
+ * - odstrani vse mimo alfanumerickych znaku a pomlcky
+ *
+ * @param {String} str
+ * @return {String}
+ */
+
module.exports = function(str) {
var url = str || '';
-
url = url.trim();
url = url.replace(/\s+/g, '-');
url = removeDiacritics(url);
url = url.toLowerCase();
url = url.replace(/[^a-z0-9-]+/g, '');
-
return url;
};

0 comments on commit af909c1

Please sign in to comment.
Something went wrong with that request. Please try again.