Skip to content
This repository has been archived by the owner on Jan 30, 2019. It is now read-only.

Commit

Permalink
doc shit
Browse files Browse the repository at this point in the history
  • Loading branch information
Oshuma committed May 19, 2011
1 parent cbb40d2 commit 1ccdc73
Show file tree
Hide file tree
Showing 9 changed files with 357 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.rvmrc
doc/api/
25 changes: 19 additions & 6 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,27 @@
Facebook, Twitter, email or just about anywhere. Think of it as a {TinyURL}[http://en.wikipedia.org/wiki/URL_shortening]
for songs. Powered by {Grooveshark}[http://grooveshark.com/].

There are three basic methods when dealing with the library:

* Grooveshark::TinySong#first - Returns a URL string for the first result (like Google's "I'm Feeling Lucky").
* Grooveshark::TinySong#meta - Returns a hash of meta information about the first song found.
* Grooveshark::TinySong#search - Perform a search, returning an array of result hashes.

All methods require an API key as the first argument.
You can request an API key here: {http://tinysong.com/api}[http://tinysong.com/api].


== Usage

In a nutshell:

# Return a URL string with the first search result (like Google's "I'm Feeling Lucky" button).
TinySong.first('Bad Brains') # => "http://tinysong.com/2Z5Q"
# Required to use the service.
api_key = 'YOUR_TINYSONG_API_KEY'

TinySong.first(api_key, 'Bad Brains')
# => "http://tinysong.com/2Z5Q"

# Returns a hash of meta information about the first song found.
TinySong.meta('Bad Brains')
TinySong.meta(api_key, 'Bad Brains')
# => {
"Url" => "http://tinysong.com/2Z5Q",
"SongID" => 8417130,
Expand All @@ -21,9 +35,8 @@ In a nutshell:
"AlbumName" => "Bad Brains"
}

# Perform a search, returning an array of result hashes, in the same format as returned by TinySong.meta().
# Can pass an optional limit as the 2nd arg; default limit is 5, max is (currently) 32.
TinySong.search('Bad Brains', 3)
TinySong.search(api_key, 'Bad Brains', 3)
# => [
{ "Url" => "http://tinysong.com/2Z5Q", ... },
{ "Url" => "http://tinysong.com/gRqG", ... },
Expand Down
19 changes: 19 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'bundler'
require 'rake/rdoctask'
require 'rspec/core/rake_task'

task :default => :spec
Expand All @@ -12,3 +13,21 @@ desc 'Start a console loaded with the library'
task :console do
sh "irb -I ./lib -r 'grooveshark'"
end

namespace :docs do
Rake::RDocTask.new do |rd|
rd.title = "TinySong API"
rd.main = "README.rdoc"
rd.rdoc_dir = "#{File.dirname(__FILE__)}/doc/api"
rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
rd.options << "--all"
end
end

desc 'Build the API docs'
task :docs do
Rake::Task['docs:rerdoc'].invoke
STDOUT.puts "Copying Javascript files..."
doc_root = "#{File.dirname(__FILE__)}/doc"
system("cp -r #{doc_root}/js #{doc_root}/api/")
end
116 changes: 116 additions & 0 deletions doc/js/darkfish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
*
* Darkfish Page Functions
* $Id: darkfish.js 53 2009-01-07 02:52:03Z deveiant $
*
* Author: Michael Granger <[email protected]>
*
*/

/* Provide console simulation for firebug-less environments */
if (!("console" in window) || !("firebug" in console)) {
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

window.console = {};
for (var i = 0; i < names.length; ++i)
window.console[names[i]] = function() {};
};


/**
* Unwrap the first element that matches the given @expr@ from the targets and return them.
*/
$.fn.unwrap = function( expr ) {
return this.each( function() {
$(this).parents( expr ).eq( 0 ).after( this ).remove();
});
};


function showSource( e ) {
var target = e.target;
var codeSections = $(target).
parents('.method-detail').
find('.method-source-code');

$(target).
parents('.method-detail').
find('.method-source-code').
slideToggle();
};

function hookSourceViews() {
$('.method-description,.method-heading').click( showSource );
};

function toggleDebuggingSection() {
$('.debugging-section').slideToggle();
};

function hookDebuggingToggle() {
$('#debugging-toggle img').click( toggleDebuggingSection );
};

function hookQuickSearch() {
$('.quicksearch-field').each( function() {
var searchElems = $(this).parents('.section').find( 'li' );
var toggle = $(this).parents('.section').find('h3 .search-toggle');
// console.debug( "Toggle is: %o", toggle );
var qsbox = $(this).parents('form').get( 0 );

$(this).quicksearch( this, searchElems, {
noSearchResultsIndicator: 'no-class-search-results',
focusOnLoad: false
});
$(toggle).click( function() {
// console.debug( "Toggling qsbox: %o", qsbox );
$(qsbox).toggle();
});
});
};

function highlightTarget( anchor ) {
console.debug( "Highlighting target '%s'.", anchor );

$("a[name=" + anchor + "]").each( function() {
if ( !$(this).parent().parent().hasClass('target-section') ) {
console.debug( "Wrapping the target-section" );
$('div.method-detail').unwrap( 'div.target-section' );
$(this).parent().wrap( '<div class="target-section"></div>' );
} else {
console.debug( "Already wrapped." );
}
});
};

function highlightLocationTarget() {
console.debug( "Location hash: %s", window.location.hash );
if ( ! window.location.hash || window.location.hash.length == 0 ) return;

var anchor = window.location.hash.substring(1);
console.debug( "Found anchor: %s; matching %s", anchor, "a[name=" + anchor + "]" );

highlightTarget( anchor );
};

function highlightClickTarget( event ) {
console.debug( "Highlighting click target for event %o", event.target );
try {
var anchor = $(event.target).attr( 'href' ).substring(1);
console.debug( "Found target anchor: %s", anchor );
highlightTarget( anchor );
} catch ( err ) {
console.error( "Exception while highlighting: %o", err );
};
};


$(document).ready( function() {
hookSourceViews();
hookDebuggingToggle();
hookQuickSearch();
highlightLocationTarget();

$('ul.link-list a').bind( "click", highlightClickTarget );
});
Loading

0 comments on commit 1ccdc73

Please sign in to comment.