Skip to content

Commit

Permalink
git tag on
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewRayCode committed Sep 10, 2011
1 parent 8a99c8f commit 6909e7e
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 51 deletions.
118 changes: 70 additions & 48 deletions builder.js
Expand Up @@ -23,7 +23,7 @@
$$('input[type="text"], input[type="checkbox"]').each(function(item) {
switch(item.type) {
case 'text':
if((val = item.value.trim())) {
if((val = item.value) && val.trim()) {
serialized.push(toQuery(item.id, val));
}
break;
Expand Down Expand Up @@ -74,6 +74,7 @@
'git-prefix': 'Add "git:" to show that you are in a Git repository.',
'git-bisect': 'Show text if bisecting (initiated by `git bisect`) and currently bisected revision.',
'git-submodule': 'Show text if in a submodule (submodule add remote, etc)',
'git-ontag': 'Show current tag, including local tags, such as `git tag 1.0` will show 1.0 in prompt`',
'submodule-text': 'Text to show if in a submodule.',

// hg options
Expand Down Expand Up @@ -110,14 +111,6 @@
$noBranchTexts;

window.addEvent('domready', function() {
// Cache our element selectors
$deltaChars = $$('.option-delta');
$conflictChars = $$('.option-conflict');
$conflictedFiles = $$('.conflicted-files');
$bisectingTexts = $$('.option-bisecting');
$submoduleTexts = $$('.option-submodule');
$noBranchTexts = $$('.option-nobranch');

// Make the body and displays noisy and tag it with webkit
document.body.noisify({
monochrome: false
Expand All @@ -133,6 +126,52 @@
stack = [],
totalLines = lines.length;

do {
var current = stack[stack.length - 1];

if(line.indexOf('# :else') > -1) {
output += '</div><div class="toggle opposite ' + current + '">';
} else if((instructionStart = line.indexOf('# :')) > -1) {
var last = line.substring(instructionStart + 3);
stack.push(last);

if(last.indexOf('option-')) {
output += '<div class="toggle ' + last + '">';
}
} else if(line.indexOf('# /') > -1) {
stack.pop();
output += '</div>';
} else {
var newLine = (line
.replace(new RegExp('^\\s{' + (stack.length * 4) + '}'), '')
.replace(/ /g, '&nbsp;')
.replace(/([a-zA-Z_]+)=/, '<span class="line-def">$1</span><span class="operator">=</span>')
.replace(/\b(if|then|fi)\b/g, '<span class="keyword">$1</span>')
.replace(/(\$[a-zA-Z_]+)/g, '<span class="variable">$1</span>')
.replace(/(#(.+|$))/, '<span class="comment">$1<br /></span>')
.replace(/#([a-zA-Z_0-9]+)#/, '<span id="$1"></span>'));

newLine += (newLine.indexOf('class="comment"') == -1 ? '<br />' : '');

if(current && !current.indexOf('option-')) {
newLine = newLine.replace(/>(['"])([^'"]+)(['"]?)<br/, '>$1<span class="configurable ' + current + '">$2</span>$3<br');
}

output += newLine;
}
line = lines[index++];
} while (line !== undefined);

$built.set('html', output).setStyle('display', 'block');

// Cache our element selectors
$deltaChars = $$('.option-delta');
$conflictChars = $$('.option-conflict');
$conflictedFiles = $$('.conflicted-files');
$bisectingTexts = $$('.option-bisecting');
$submoduleTexts = $$('.option-submodule');
$noBranchTexts = $$('.option-nobranch');

$$('.nav').addEvent('click:relay(a)', function(evt) {
evt.preventDefault();
window.scrollTo(0, $(this.get('href').substring(1)).getPosition().y);
Expand Down Expand Up @@ -174,6 +213,10 @@
change: toggleComments
});

var childClick,
parentToggle;

// Wire up change events for checkboxes
$$('input[type="checkbox"]').addEvents({
mouseover: updateDescription.bindWithEvent(this),
'fun-change': function(evt) {
Expand All @@ -183,8 +226,11 @@
$div,
toggles = $input.get('data-toggle');

if(toggles) {
// If our change event comes from child turning on master checkbox, don't toggle children
if(toggles && !childClick) {
parentToggle = true;
$$('#' + (toggles.split(' ').join(',#'))).set('checked', $input.checked).fireEvent('change');
parentToggle = false;
}

for(; $div = $divs[x++];) {
Expand All @@ -200,49 +246,25 @@
$cb.set('checked', 'checked');
}
$cb.funForm();
// Target only the child checkboxes and make them turn on parent checkbox
}).erase($('git')).erase($('hg')).erase($('svn')).addEvent('change', function(evt) {
// If our change event comes from master toggle, ignore it
if(!parentToggle) {
childClick = true;
var me = this;
$$('#git, #hg, #svn').each(function($master) {
if($master.get('data-toggle').indexOf(me.get('id')) > -1) {
$master.set('checked', 'checked').fireEvent('change');
}
});
childClick = false;
}
});

$$('input[type="text"]').addEvent('mouseover', updateDescription.bindWithEvent(this));

$$('.config label').addEvent('mouseover', updateDescription.bindWithEvent(this));

do {
var current = stack[stack.length - 1];

if(line.indexOf('# :else') > -1) {
output += '</div><div class="toggle opposite ' + current + '">';
} else if((instructionStart = line.indexOf('# :')) > -1) {
var last = line.substring(instructionStart + 3);
stack.push(last);

if(last.indexOf('option-')) {
output += '<div class="toggle ' + last + '">';
}
} else if(line.indexOf('# /') > -1) {
stack.pop();
output += '</div>';
} else {
var newLine = (line
.replace(new RegExp('^\\s{' + (stack.length * 4) + '}'), '')
.replace(/ /g, '&nbsp;')
.replace(/([a-zA-Z_]+)=/, '<span class="line-def">$1</span><span class="operator">=</span>')
.replace(/\b(if|then|fi)\b/g, '<span class="keyword">$1</span>')
.replace(/(\$[a-zA-Z_]+)/g, '<span class="variable">$1</span>')
.replace(/(#(.+|$))/, '<span class="comment">$1<br /></span>')
.replace(/#([a-zA-Z_0-9]+)#/, '<span id="$1"></span>'));

newLine += (newLine.indexOf('class="comment"') == -1 ? '<br />' : '');

if(current && !current.indexOf('option-')) {
newLine = newLine.replace(/>(['"])([^'"]+)(['"]?)<br/, '>$1<span class="configurable ' + current + '">$2</span>$3<br');
}

output += newLine;
}
line = lines[index++];
} while (line !== undefined);

$built.set('html', output).setStyle('display', 'block');

if(window.location.hash && window.location.hash.trim() != '#') {
$('options').deserialize(window.location.hash);
window.location.replace('#');
Expand Down
17 changes: 14 additions & 3 deletions index.html
Expand Up @@ -44,7 +44,7 @@ <h2 id="nav-options">Options </h2>

<div class="config config-git">
<div class="group">
<input type="checkbox" value="git" id="git" data-toggle="git-prefix git-revno git-ahead git-modified git-conflicted git-bisect" checked="checked" />
<input type="checkbox" value="git" id="git" data-toggle="git-prefix git-revno git-ahead git-modified git-conflicted git-bisect git-submodule" checked="checked" />
<label for="git">Git</label>
</div>

Expand Down Expand Up @@ -83,6 +83,11 @@ <h2 id="nav-options">Options </h2>
<input type="checkbox" value="git-submodule" id="git-submodule" checked="checked" />
<label for="git-submodule">In submodule<label>
</div>

<div class="group">
<input type="checkbox" value="git-ontag" id="git-ontag" checked="checked" />
<label for="git-ontag">Current tag<label>
</div>
</div>
</div>

Expand Down Expand Up @@ -194,7 +199,7 @@ <h2 id="preview">Preview</h2>
<div class="group git">
<label for="git-display">Git</label>
<div id="git-display" class="screen">
<span class="git-branch">(<span class="git-submodule"><span class="option-submodule">[submodule] </span></span><span class="git-prefix">git:</span>master<span class="git-revno">:f9302</span><span class="option-delta git-modified"></span>)</span><span class="git-ahead"> +1</span><span class="git-conflicted"> (<span class="option-conflict"></span><span class="conflicted-files">index.js, path/to/package.json</span>)</span> $
<span class="git-branch">(<span class="git-submodule"><span class="option-submodule">[submodule] </span></span><span class="git-prefix">git:</span>master<span class="git-revno">:f9302</span><span class="git-ontag"> "tag"</span><span class="option-delta git-modified"></span>)</span><span class="git-ahead"> +1</span><span class="git-conflicted"> (<span class="option-conflict"></span><span class="conflicted-files">index.js, path/to/package.json</span>)</span> $
</div>

<div class="sub git-bisect">
Expand Down Expand Up @@ -238,7 +243,7 @@ <h2 id="nav-code">Code</h2>
<section id="code">
<div id="function">
# This code was auto generated by with these options:
# - #auto_url#
# #auto_url#

# :option-max-conflicted-files
MAX_CONFLICTED_FILES=2
Expand Down Expand Up @@ -401,6 +406,12 @@ <h2 id="nav-code">Code</h2>
prompt=\$prompt\":\$revNo\"
fi
# /git-revno
# :git-ontag
tag=\`git describe --tags 2> /dev/null\`
if [ -n \"\$tag\" ]; then
prompt=\"\$prompt\\[\$COLOR_YELLOW\\] \\\"\$tag\\\"\\[\$COLOR_YELLOW\\]\"
fi
# /git-ontag
prompt=\$prompt\"\$gitChange)\\[\$COLOR_RESET\\]\"

# :git-ahead
Expand Down

0 comments on commit 6909e7e

Please sign in to comment.