npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ghembedder

v1.0.1

Published

Embed any source file (or specific lines) from any public github repo in your page, with no server-side dependencies.

Downloads

13

Readme

ghembedder

Embed any source file (or specific lines) from any public github repo in your page, with no server-side dependencies. Include google-code-prettify (prettyPrint) for pretty colors!

Getting Started

Download the production version or the development version. You may also want prettify.js and prettify.css from google-code-prettify. It is not required, but if present will allow for syntax highlighting.

<!-- probaby just before closing body tag... -->
<script src="path/to/gheembedder.min.js" type="text/javascript"></script>

<div 
	data-ghuserrepo="jquery/jquery"
	data-ghpath="src/core.js"
	data-ghlines="743-768"></div>

// somewhere after/during DOMReady
ghembedder.autoload(); // requires browser to have EITHER document.querySelectorAll OR jquery 

// OR

// single specific instance (after page load, for example)
ghembedder.load( document.querySelectorAll('div')[0] ); 

This will load lines 743-768 of src/core.js (jQuery.proxy) from the jquery repo!

Demo

See http://jsbin.com/suyela for a live working demo.

Documentation

ghembedder.autoload()

Find, read, and load all DOM nodes that have a [gh-path] attribute. Requires document.querySelectorAll or jQuery.

ghembedder.load( cfg || DOMNode )

Given a DOM node, load a Github file. The DOM node requires a few data-* attributes, which are defined in the examples below. Internally, ghembedder turns the node into the following configuration object, which can also be passed to this method:

{
	path: 'src/ghembedder.js'				// path relative to git repo root
	,userrepo: 'kirbysayshi/ghembedder'		// username/reponame
	,ref: 'master'							// ref id (sha), defaults to master
	,lineBegin: -1							// include all lines
	,lineEnd: -1							// include all lines 
	,el: el									// DOM node to embed within 
	,fileName: 'ghembedder.js'				// filename (used for anchor links internally)
	,tabSize: 4								// how many spaces a tab should equal
	,annotate: Boolean						// include link and line numbers at end of embedding
	,lang: 'lang-js'						// prettyPrint: which language to use for highlighting
	,linenos: Boolean						// prettyPrint: include line numbers
}

I recommend always using a DOM node when possible for ease of use.

Examples

All possible data-* attributes:

<div 
	data-ghpath=""			<!-- required, String: path to file, repo-relative -->
	data-ghuserrepo=""		<!-- required, String: username/reponame -->
	data-ghref=""			<!-- optional, String: provide a specific ref, defaults to master -->
	data-ghlines=""			<!-- optional, String: which lines to display (not specified == all), e.g.: 34-90 -->
	data-ghtabsize=""		<!-- optional, Number: how many spaces a tab character should occupy, defaults to 4 -->
	data-ghannotate=""		<!-- optional, Boolean: Display short filename, lines x-X, link to source -->
	data-ghlinenos=""		<!-- optional, prettyPrint, Boolean: display line numbers -->
	data-ghlang=""			<!-- optional, prettyPrint, String: which language to use for highlighting e.g.: lang-js -->
></div>

Load lines 743-768 from src/core.js of the jQuery repo @ 714b8ffd2b28af446fea8f25e369597d7c509cb4

<div 
	data-ghuserrepo="jquery/jquery"
	data-ghpath="/src/core.js"
	data-ghref="714b8ffd2b28af446fea8f25e369597d7c509cb4"
	data-ghlines="743-768"></div>

Load all lines from src/ghembedder.js:

<div 
	data-ghpath="src/ghembedder.js"
	data-ghuserrepo="kirbysayshi/ghembedder"
></div>

Load lines 340-350 from src/ghembedder.js:

<div 
	data-ghpath="src/ghembedder.js"
	data-ghuserrepo="kirbysayshi/ghembedder"
	data-ghlines="340-350"
></div>

load all lines from src/ghembedder.js, add annotation:

<div 
	data-ghpath="src/ghembedder.js"
	data-ghuserrepo="kirbysayshi/ghembedder"
	data-ghannotate="true"
></div>

load all lines from src/ghembedder.js, use line numbers (requires google-code-prettify:

<div 
	data-ghpath="src/ghembedder.js"
	data-ghuserrepo="kirbysayshi/ghembedder"
	data-ghlinenos="true"
></div>

Contributing

Please don't edit files in the "dist" subdirectory as they are generated. You'll find source code in the "src" subdirectory!

  • npm install

To run tests via zuul / phantomjs:

  • npm test

To run tests in an actual browser:

  • npm run test-debug

To build:

  • npm run dist

Release History

  • 1.0.0: Remove btoa/atob shim. Always html escape content.
  • 0.1.1: Basic html escaping if extension matches .htm|.html
  • 0.1.0: initial release

License

MIT

Thanks