Forked from groovehunter/bundle_gems_overview_table
Created
February 23, 2012 16:24
-
-
Save Raven24/1893525 to your computer and use it in GitHub Desktop.
Display table with all gems in a bundle, each with ie. summary and description, render in MediaWiki table
This file contains hidden or 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
require "rubygems" | |
require "bundler" | |
dia = '/home/florian/src/diaspora' | |
Dir.chdir dia | |
def allm obj | |
obj.methods.sort.each { |m| | |
puts m | |
} | |
end | |
class MediaWikiTable | |
def initialize(headers, data, maxwidth) | |
@headers = headers | |
@data = data | |
@maxwidth = maxwidth | |
end | |
def tbl_start | |
puts "{|" | |
end | |
def tbl_end | |
puts "|}" | |
end | |
def render_header | |
puts "!" + @headers.join( "\n!") | |
puts "|-" | |
end | |
def render_body | |
@data.each do |row| | |
puts "|" + row.map{ |cell| | |
dotdot = (cell.length > @maxwidth) ? "..." : "" | |
cell[0..@maxwidth].gsub(/[\n\s]+/, " ") + dotdot | |
}.join( "\n|") | |
puts "|-" | |
end | |
end | |
def render | |
tbl_start | |
render_header | |
render_body | |
tbl_end | |
end | |
end | |
def readgems | |
data = [] | |
Bundler.rubygems.all_specs.each { |spec| | |
line = [ | |
spec.name.to_s, | |
spec.version.to_s, | |
spec.description.to_s, | |
] | |
data.push line | |
} | |
headers = ['Name', 'Version', 'Description'] | |
t = MediaWikiTable.new(headers, data, 120) | |
t.render | |
end | |
readgems | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment