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

Support syntax highlighting for multiple languages #110

Merged
merged 15 commits into from
Dec 17, 2014
Merged

Conversation

kattrali
Copy link
Contributor

@kattrali kattrali commented Dec 9, 2014

Add an optional language argument to pygmentize, doing a dumb guess as to a file's language. Default language remains objc.

@@ -122,7 +122,7 @@ def format_failures(failures_per_suite)
def format_failure(f)
" #{f[:test_case]}, #{red(f[:reason])}\n #{cyan(f[:file_path])}\n" +
" ```\n" +
Syntax.highlight(Snippet.from_filepath(f[:file_path])) +
Syntax.highlight(Snippet.from_filepath(f[:file_path]), nil, File.basename(f[:file_path])) +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [97/80]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kattrali what if we reorder options and filetype, then you wouldn't have to pass explicit nil?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kattrali on the side note, i think Snippet shouldn't be a String. This was a quick hack I've done before, but if it was a better object, it'd remember the file_path when you initialize it.

The usage:

snippet = Snippet.from_filepath(f[:file_path])
snippet.contents #=> String
snippet.file_path #=> String  /Users/..../file.m:234

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that seems much cleaner, then we don't need an extra parameter at all.

@supermarin
Copy link
Contributor

@kattrali thanks for working on this!

I'd appreciate if you add tests for it, I can do the refactors if you want

@kattrali
Copy link
Contributor Author

kattrali commented Dec 9, 2014

@supermarin sounds good, wanted to make sure it was the right direction first 👍

RUBY = 'ruby'
RUBY_EXTENSIONS = ['.ruby','.rb']

def self.highlight(code, options="", filename="")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surrounding space missing in default value assignment.
Prefer single-quoted strings when you don't need string interpolation or special symbols.

RUBY = 'ruby'
RUBY_EXTENSIONS = ['.ruby', '.rb']

def self.highlight(snippet, options = "")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer single-quoted strings when you don't need string interpolation or special symbols.


it 'highlights dylan code by filename' do
snippet = Snippet.new(
'define method write-end-array (serializer :: <json-serializer>)',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WHERE

Marin Usalj and others added 2 commits December 16, 2014 18:52
ext = File.extname(filename)
@filetypes[ext] || 'objc'
end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at body end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hush you

end
end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 trailing blank lines detected.

@supermarin
Copy link
Contributor

@kattrali shouldn't we enforce a trailing line on EOF?

@kattrali
Copy link
Contributor Author

@supermarin yeah, I think so

Marin Usalj and others added 5 commits December 17, 2014 02:49
Previously, we were basically testing the behavior of Pygments.
Now we're just testing if Pygments are being called with the right
arguments.
end
end
end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 trailing blank lines detected.

@supermarin
Copy link
Contributor

It's time.

:shipit:

supermarin added a commit that referenced this pull request Dec 17, 2014
Support syntax highlighting for multiple languages
@supermarin supermarin merged commit 51350b3 into master Dec 17, 2014
@supermarin supermarin deleted the lang-swap branch December 17, 2014 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants