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

Handle categories / Fix #4 #17

Merged
merged 6 commits into from
Mar 6, 2015
Merged
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
7 changes: 4 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<!--[if lt IE 7]><p class=chromeframe>Your browser is <em>ancient!</em> <a href="http://browsehappy.com/">Upgrade to a different browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to experience this site.</p><![endif]-->
<div class="wrapper">
<section class="box box-top">
<h1>Semantic Release Notes <span class="light">v 0.3</span></h1>
<h1>Semantic Release Notes <span class="light">v 0.4-beta</span></h1>
</section>
<header>
<div class="header-inner">
Expand Down Expand Up @@ -301,12 +301,13 @@ <h3>Category</h3>
</p>
<div class="container">
<strong>Examples:</strong>
<pre class="code"> - This is a +New list item.
<pre class="code"> - This is a +new list item.
- This is a +Fix list item.
- This is a +Change list item.
- +New features are everyone's favorites.
- This is a list item for a +Developer.
- This is a +Super-Special custom list item.
- This is a +super-special custom list item.
- This is my last +DEVELOPER list item. +New
</pre>
<div class="result"></div>
<pre class="object"></pre>
Expand Down
60 changes: 49 additions & 11 deletions js/script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
/* Author:

*/

if (typeof String.prototype.endsWith !== 'function') {
String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
}

if (typeof String.prototype.titleize !== 'function') {
String.prototype.titleize = function() {
var words = this.split(' ')
var array = []
for (var i=0; i<words.length; ++i) {
array.push(words[i].charAt(0).toUpperCase() + words[i].toLowerCase().slice(1))
}
return array.join(' ')
};
}

var processSyntax = (function () {
var linkProcessor = {
pattern : /\[\[(\S+)\]\[(\S+)\]\]/i,
Expand Down Expand Up @@ -42,28 +60,40 @@ var processSyntax = (function () {
},
{
pattern : /^ [\-\+\*]|([123])\. /i,
categoryPattern : /\+([^\s]+)/i,
categoryPattern : /\+([\w-]+)/i,
test : function (input) {
return this.pattern.test(input);
},
process : function (obj, input) {
var priority = this.pattern.exec(input),
category = this.categoryPattern.exec(input),
links = linkProcessor.process(input, []),
item = {};

if (priority && !isNaN(priority[1]))
item.priority = priority[1];
input = input.replace(this.pattern, '');
if (category) {
item.category = category[1];
input = input.replace(this.categoryPattern, '');
}

if (links.length > 0) {
item.taskId = links[0];
item.teskLink = links[1];
input = input.replace(linkProcessor.pattern, '');
input = input.replace(linkProcessor.pattern, '').trim();
}

// handle categories

var category;
while(category = this.categoryPattern.exec(input)) {
if(!item.categories) {
item.categories = [];
}
item.categories.push(category[1].replace('-', ' ').titleize());
var replacement = category[1];
if(input.endsWith(category[1])) {
replacement = '';
}
input = input.replace(this.categoryPattern, replacement);
}

item.summary = input.trim();

// Store results
Expand Down Expand Up @@ -114,7 +144,7 @@ var processSyntax = (function () {
if (!matched)
lineProcessor.primary.process(result, rawLine, rawLines[+rawLineIndex + 1]);
}

return result;
};

Expand Down Expand Up @@ -173,9 +203,17 @@ var formatSyntax = (function () {
hasPriorities = true;
}
result += '<li' + attr + '>';
if (item.category)
result += ' {' + item.category + '}';

if(item.categories) {
result += '{';
for(var categoryIndex in item.categories) {
if(categoryIndex > 0) {
result += ', ';
}
result += item.categories[categoryIndex];
}
result += '}';
}

var summary = item.summary;
for (var fomatterIndex in formatHtmlParser)
summary = formatHtmlParser[fomatterIndex].process(summary);
Expand Down