-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests for launcher; clean up dist task; website
- Loading branch information
Showing
20 changed files
with
1,373 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
host: your_username@rubyforge.org | ||
remote_dir: /var/www/gforge-projects/github_badges |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'rubygems' | ||
begin | ||
require 'newgem' | ||
rescue LoadError | ||
puts "\n\nGenerating the website requires the newgem RubyGem" | ||
puts "Install: gem install newgem\n\n" | ||
exit(1) | ||
end | ||
require 'redcloth' | ||
require 'syntax/convertors/html' | ||
require 'erb' | ||
ENV['rakefile_just_config'] = "true" | ||
load File.dirname(__FILE__) + '/../Rakefile' | ||
|
||
version = APP_VERSION | ||
download = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}/" | ||
|
||
class Fixnum | ||
def ordinal | ||
# teens | ||
return 'th' if (10..19).include?(self % 100) | ||
# others | ||
case self % 10 | ||
when 1: return 'st' | ||
when 2: return 'nd' | ||
when 3: return 'rd' | ||
else return 'th' | ||
end | ||
end | ||
end | ||
|
||
class Time | ||
def pretty | ||
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}" | ||
end | ||
end | ||
|
||
def convert_syntax(syntax, source) | ||
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'') | ||
end | ||
|
||
if ARGV.length >= 1 | ||
src, template = ARGV | ||
template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb') | ||
|
||
else | ||
puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html") | ||
exit! | ||
end | ||
|
||
template = ERB.new(File.open(template).read) | ||
|
||
title = nil | ||
body = nil | ||
File.open(src) do |fsrc| | ||
title_text = fsrc.readline | ||
body_text_template = fsrc.read | ||
body_text = ERB.new(body_text_template).result(binding) | ||
syntax_items = [] | ||
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){ | ||
ident = syntax_items.length | ||
element, syntax, source = $1, $2, $3 | ||
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>" | ||
"syntax-temp-#{ident}" | ||
} | ||
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip | ||
body = RedCloth.new(body_text).to_html | ||
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] } | ||
end | ||
stat = File.stat(src) | ||
created = stat.ctime | ||
modified = stat.mtime | ||
|
||
$stdout << template.result(binding) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<%= include 'HEADER' %> | ||
|
||
var GithubBadge = { | ||
Version: '<%= APP_VERSION %>', | ||
}; | ||
|
||
<%= include 'github-badge-launcher.js' %> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'yaml' | ||
|
||
def website_config | ||
unless @website_config | ||
begin | ||
@website_config = YAML.load(File.read(File.expand_path(File.dirname(__FILE__) + "/../config/website.yml"))) | ||
rescue | ||
puts <<-EOS | ||
To upload your website to a host, you need to configure | ||
config/website.yml. See config/website.yml.sample for | ||
an example. | ||
EOS | ||
exit | ||
end | ||
end | ||
@website_config | ||
end | ||
|
||
desc 'Generate website files' | ||
task :website_generate => [:ruby_env, :dist] do | ||
(Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt| | ||
sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} } | ||
end | ||
end | ||
|
||
desc 'Upload website files to rubyforge' | ||
task :website_upload do | ||
host = website_config["host"] # "#{rubyforge_username}@rubyforge.org" | ||
remote_dir = website_config["remote_dir"] # "/var/www/gforge-projects/#{PATH}/" | ||
local_dir = 'website' | ||
sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}} | ||
end | ||
|
||
desc 'Generate and upload website files' | ||
task :website => [:website_generate, :website_upload] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | ||
<head> | ||
<title>JavaScript unit test file</title> | ||
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> | ||
<script src="../assets/jsunittest.js" type="text/javascript"></script> | ||
|
||
<link rel="stylesheet" href="../assets/unittest.css" type="text/css" /> | ||
</head> | ||
<body> | ||
|
||
<div id="content"> | ||
|
||
<div id="header"> | ||
<h1>JavaScript unit test file</h1> | ||
<p> | ||
This file tests <strong>launcher.js</strong>. | ||
</p> | ||
</div> | ||
|
||
<!-- Log output (one per Runner, via {testLog: "testlog"} option)--> | ||
<div id="testlog"></div> | ||
|
||
<script type="text/javascript" charset="utf-8"> | ||
var GitHubBadge = GitHubBadge || {}; | ||
GitHubBadge.buildUserBadgeExecuted = false; | ||
GitHubBadge.buildUserBadge = function() { | ||
GitHubBadge.buildUserBadgeExecuted = true; | ||
}; | ||
</script> | ||
<!-- Put sample/test html here --> | ||
<div id="sample"> | ||
<div id="github-badge" width="150px"></div> | ||
<script src="../../src/github-badge-launcher.js" type="text/javascript"></script> | ||
</div> | ||
</div> | ||
|
||
<script type="text/javascript"> | ||
// <![CDATA[ | ||
|
||
new Test.Unit.Runner({ | ||
"test that jQuery + jQuery.template loaded": function() { with(this) { | ||
assert(jQuery, 'jQuery not loaded'); | ||
assert(jQuery.template, 'jQuery.template not loaded'); | ||
}}, | ||
|
||
"test that badge built": function() { with(this) { | ||
assert(GitHubBadge.buildUserBadgeExecuted, 'Badge code was not executed'); | ||
}} | ||
}, {testLog: "testlog"}); | ||
// For each Test.UnitRunner instance, specify the element id where results will be | ||
// published; e.g. <div id="testlog"/> above. | ||
// That is, you can have multiple "new Test.Unit.Runner() { ... }" on this page, just | ||
// create more <div id="testlog2"></div> etc, and pass the element id to the hash above: | ||
// e.g. {testLog: "testlog2"} | ||
// ]]> | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* GitHub Badge, version 0.1.0 | ||
* (c) 2008 Dr Nic Williams | ||
* | ||
* GitHub Badge is freely distributable under | ||
* the terms of an MIT-style license. | ||
* For details, see the web site: http://github.com/drnic/github-badges/tree/master | ||
* | ||
*--------------------------------------------------------------------------*/ | ||
|
||
var GithubBadge = { | ||
Version: '0.1.0', | ||
}; | ||
|
||
var GitHubBadge = GitHubBadge || {}; | ||
GitHubBadge.buildUserBadge = function(username) { | ||
(function($){ | ||
$('#github-badge') | ||
.empty() | ||
.buildHeader("My projects", username) | ||
.buildBody(username) | ||
.buildFooter(); | ||
})(jQuery); | ||
}; | ||
|
||
GitHubBadge.loadUserInfo = function(data) { | ||
var template = $.template( | ||
"<li class='public'>" | ||
+ "<img src='http://github.com/images/icons/public.png' alt='public'>" | ||
+ "<strong><a href='${url}'>${name}</a></strong>" | ||
+"</li>" | ||
); | ||
var showMore = $("<div><a href='#' class='more'>Show more</a></div>") | ||
.find('a') | ||
.click(function(event) { | ||
$('#github-badge .body li').show(); | ||
$('#github-badge .more').hide(); | ||
return false; | ||
}); | ||
var list = $("<div class='repos'><ul id='repo_listing'></ul></div>"); | ||
$('#github-badge .body') | ||
.empty() | ||
.append(list) | ||
.append(showMore); | ||
list = list.find('ul'); | ||
orderedRepos = data.user.repositories.sort(GitHubBadge.compareRepos) | ||
$.each(orderedRepos, function(index) { | ||
list.append(template, this); | ||
}); | ||
$('#github-badge .body li:gt(9)').hide(); // hide extras | ||
}; | ||
|
||
GitHubBadge.compareRepos = function(repo1, repo2) { | ||
var properties = ['network', 'watched']; | ||
for (var i=0; i < properties.length; i++) { | ||
var comparison = GitHubBadge.compareReposProperty(repo1, repo2, properties[i]); | ||
if (comparison != 0) return comparison; | ||
}; | ||
return 0; | ||
}; | ||
|
||
GitHubBadge.compareReposProperty = function(repo1, repo2, property) { | ||
if ((property in repo1) && !(property in repo2)) return -1; | ||
if (!(property in repo1) && (property in repo2)) return 1; | ||
if ((property in repo1) && (property in repo2)) { | ||
return repo2[property] - repo1[property]; | ||
} | ||
return 0; | ||
}; | ||
|
||
(function($){ | ||
$.fn.buildBody = function() { | ||
return this.append($("<div class='body'>loading...</div>")); | ||
}; | ||
|
||
$.fn.buildHeader = function(title, username) { | ||
var template = $.template( | ||
"<legend class='header'>${title} <span>(" | ||
+ "<a href='http://github.com/${username}'>${username}</a>)" | ||
+ "</span></legend>") | ||
return this.append(template, { title: title, username: username }); | ||
}; | ||
|
||
$.fn.buildFooter = function() { | ||
return this.append($( | ||
"<div class='footer'>" | ||
+ "Powered by <a href='http://github.com'>GitHub</a> | " | ||
+ "Written by <a href='http://drnicwilliams.com'>Dr Nic</a>" | ||
+ "</div>" | ||
+ "</fieldset>" | ||
)); | ||
}; | ||
})(jQuery); |
Oops, something went wrong.