Linguist: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(Created page with "== Description == This library is used on GitHub.com to detect blob languages, ignore binary or vendored files, suppress generated files in diffs, and generate language break...")
 
No edit summary
 
Line 11: Line 11:
Then use it in your application:
Then use it in your application:


<code>require 'rugged'
<pre>require 'rugged'
require 'linguist'
require 'linguist'


Line 17: Line 17:
project = Linguist::Repository.new(repo, repo.head.target_id)
project = Linguist::Repository.new(repo, repo.head.target_id)
project.language      #=> "Ruby"
project.language      #=> "Ruby"
project.languages      #=> { "Ruby" => 119387 }</code>
project.languages      #=> { "Ruby" => 119387 }</pre>


These stats are also printed out by the <code>linguist</code> executable. You can use the <code>--breakdown flag</code>, and the binary will also output the breakdown of files by language.
These stats are also printed out by the <code>linguist</code> executable. You can use the <code>--breakdown flag</code>, and the binary will also output the breakdown of files by language.
Line 23: Line 23:
You can try running <code>linguist</code> on the root directory in this repository itself:
You can try running <code>linguist</code> on the root directory in this repository itself:


<code>$ bundle exec linguist --breakdown
<pre>$ bundle exec linguist --breakdown


100.00% Ruby
100.00% Ruby
Line 33: Line 33:
github-linguist.gemspec
github-linguist.gemspec
lib/linguist.rb
lib/linguist.rb
…</code>
…</pre>


=== Troubleshooting ===
=== Troubleshooting ===

Latest revision as of 14:19, 17 October 2015

Description

This library is used on GitHub.com to detect blob languages, ignore binary or vendored files, suppress generated files in diffs, and generate language breakdown graphs.

Usage

Install the gem:

$ gem install github-linguist

Then use it in your application:

require 'rugged'
require 'linguist'

repo = Rugged::Repository.new('.')
project = Linguist::Repository.new(repo, repo.head.target_id)
project.language       #=> "Ruby"
project.languages      #=> { "Ruby" => 119387 }

These stats are also printed out by the linguist executable. You can use the --breakdown flag, and the binary will also output the breakdown of files by language.

You can try running linguist on the root directory in this repository itself:

$ bundle exec linguist --breakdown

100.00% Ruby

Ruby:
Gemfile
Rakefile
bin/linguist
github-linguist.gemspec
lib/linguist.rb
…

Troubleshooting

See Troubleshooting on GitHub

Links