Giter Club home page Giter Club logo

github-files's Introduction

github-files

A simple jQuery plugin that pulls a file from github.com and returns it.

This uses the public GitHub API (v3) over JSONP to pull a raw file from GitHub.

API:

$.getGithubFile(user, repo, sha, callback, startLineNum, endLineNum)

or

$.getGithubFileByFilePath(user, repo, filePath, callback, startLineNum, endLineNum)

Examples:

// fetch this README.md file and return all of the lines
$.getGithubFile("jamesward", "github-files", "2e7bf4aa35758d7a9cf87549d6299e924737ff05", function(contents) {
    console.log(contents)
});
    
// fetch this README.md file and return all of the lines beginning with line 6
$.getGithubFile("jamesward", "github-files", "2e7bf4aa35758d7a9cf87549d6299e924737ff05", function(contents) {
    console.log(contents)
}, 6);
    
// fetch this README.md file and return lines 6 - 15
$.getGithubFile("jamesward", "github-files", "2e7bf4aa35758d7a9cf87549d6299e924737ff05", function(contents) {
    console.log(contents)
}, 6, 15);

// fetch this README.md file and return all of the lines
$.getGithubFileByFilePath("jamesward", "github-files", "README.md", function(contents) {
    console.log(contents)
});

To get the sha for a file in git run something like:

git rev-parse HEAD:README.md

or use the $.getGithubFileByFilePath method as documented above.

github-files's People

Contributors

brntbeer avatar jamesward avatar kalisjoshua avatar stokito avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

github-files's Issues

Add getGithubFileHash Function

Add a function that allows you to get a blob's hash just by specifying a branch and a file name (for when you always want the most recent instead of a specific version of a blob).

Proposed API:

$.getGithubFileHash(user, repo, file, callback, branch)

Where branch is optional (defaulting to master/HEAD). The callback function will probably just need to have a string parameter that will contain the hash.

Does not work in IE.

Console says Object doesn't support property or method 'atob'. This is specifically a problem with IE.

Inconsistently working

I have the code implemented, but sometimes it loads the code, and sometimes it doesn't load anything.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.