Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Final refactoring. #108

Merged
merged 3 commits into from

3 participants

@paulmillr
  1. Wrap lines at 80 symbols.
  2. Use .on instead of .addListener.
  3. Use less braces where appropriate.

All tested.

@paulmillr paulmillr Final refactoring.
1. Wrap lines at 80 symbols.
2. Use `.on` instead of `addListener`.
3. Use less braces where appropriate.

All tested.
993631c
@jashkenas
Owner

Fine except for the 80-char line wrap. Revert that bit, and I'll be glad to merge.

@paulmillr

okay, but why? If you write many lines with one break in markdown (text\ntext\ntext\n), it’s treated just as if it was one big line.

@jashkenas
Owner

Because it reads better in the source.

@paulmillr

doesn’t read any better for me, guess I have too small space for >80loc code, but reverted.

@jashkenas
Owner

Let's take out that isComment extraction as well...

@jashkenas jashkenas merged commit 064a5b0 into from
@michaelficarra

Fuck small screens. 120 is the new 80.

@michaelficarra say this to my setup. 120 chars just won't fit here.

It'll be interesting to see some research on optimal line width for ease of reading, btw. bookmate.com wraps stuff at 114 chars for art books.

I actually do use ~110-120 chars per line in personal projects because it fits nicely when tiling two windows side-by-side, and still reads easily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 6, 2012
  1. @paulmillr

    Final refactoring.

    paulmillr authored
    1. Wrap lines at 80 symbols.
    2. Use `.on` instead of `addListener`.
    3. Use less braces where appropriate.
    
    All tested.
  2. @paulmillr

    Revert 80LOC change.

    paulmillr authored
  3. @paulmillr
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 14 deletions.
  1. +10 −7 lib/docco.js
  2. +7 −7 src/docco.coffee
View
17 lib/docco.js
@@ -18,7 +18,7 @@
};
parse = function(source, code) {
- var codeText, docsText, hasCode, language, line, lines, save, sections, _i, _len;
+ var codeText, docsText, hasCode, isComment, language, line, lines, save, sections, _i, _len;
lines = code.split('\n');
sections = [];
language = getLanguage(source);
@@ -29,9 +29,12 @@
codeText: codeText
});
};
+ isComment = function(line) {
+ return line.match(language.commentMatcher) && !line.match(language.commentFilter);
+ };
for (_i = 0, _len = lines.length; _i < _len; _i++) {
line = lines[_i];
- if (line.match(language.commentMatcher) && !line.match(language.commentFilter)) {
+ if (isComment(line)) {
if (hasCode) {
save(docsText, codeText);
hasCode = docsText = codeText = '';
@@ -51,21 +54,21 @@
language = getLanguage(source);
pygments = spawn('pygmentize', ['-l', language.name, '-f', 'html', '-O', 'encoding=utf-8,tabsize=2']);
output = '';
- pygments.stderr.addListener('data', function(error) {
+ pygments.stderr.on('data', function(error) {
if (error) {
return console.error(error.toString());
}
});
- pygments.stdin.addListener('error', function(error) {
- console.error("Could not use Pygments to highlight the source.");
+ pygments.stdin.on('error', function(error) {
+ console.error('Could not use Pygments to highlight the source.');
return process.exit(1);
});
- pygments.stdout.addListener('data', function(result) {
+ pygments.stdout.on('data', function(result) {
if (result) {
return output += result;
}
});
- pygments.addListener('exit', function() {
+ pygments.on('exit', function() {
var fragments, i, section, _i, _len;
output = output.replace(highlightStart, '').replace(highlightEnd, '');
fragments = output.split(language.dividerHtml);
View
14 src/docco.coffee
@@ -79,7 +79,7 @@ parse = (source, code) ->
lines = code.split '\n'
sections = []
language = getLanguage source
- hasCode = docsText = codeText = ''
+ hasCode = docsText = codeText = ''
save = (docsText, codeText) ->
sections.push {docsText, codeText}
@@ -112,17 +112,17 @@ highlight = (source, sections, callback) ->
]
output = ''
- pygments.stderr.addListener 'data', (error) ->
+ pygments.stderr.on 'data', (error) ->
console.error error.toString() if error
- pygments.stdin.addListener 'error', (error) ->
- console.error "Could not use Pygments to highlight the source."
+ pygments.stdin.on 'error', (error) ->
+ console.error 'Could not use Pygments to highlight the source.'
process.exit 1
- pygments.stdout.addListener 'data', (result) ->
+ pygments.stdout.on 'data', (result) ->
output += result if result
- pygments.addListener 'exit', ->
+ pygments.on 'exit', ->
output = output.replace(highlightStart, '').replace(highlightEnd, '')
fragments = output.split language.dividerHtml
for section, i in sections
@@ -132,7 +132,7 @@ highlight = (source, sections, callback) ->
if pygments.stdin.writable
text = (section.codeText for section in sections)
- pygments.stdin.write(text.join(language.dividerText))
+ pygments.stdin.write text.join language.dividerText
pygments.stdin.end()
# Once all of the code is finished highlighting, we can generate the HTML file
Something went wrong with that request. Please try again.