Permalink
Browse files

dgetted

  • Loading branch information...
1 parent 6992f7a commit 6bd30d085da70621581e14caf0f5a25f3e6ba55d @nkpart committed Sep 8, 2009
View
@@ -0,0 +1,2 @@
+=== 0.0.1 / 2009-09-09
+* Some thing
View
@@ -1,13 +1,14 @@
+History.txt
Manifest.txt
-PostInstall.txt
README.rdoc
Rakefile
-features/development.feature
-features/step_definitions/common_steps.rb
-features/support/common.rb
-features/support/env.rb
-features/support/matchers.rb
-lib/gh-wiki.rb
+bin/dget
+lib/dget.rb
+lib/dget/github.html
+lib/dget/github.rb
+lib/dget/googlecode.rb
+lib/dget/utils.rb
+lib/googlecode.html
script/console
script/destroy
script/generate
View
@@ -1,4 +1,4 @@
-= gh-wiki
+= dget
* http://github.com/#{github_username}/#{project_name}
View
@@ -2,15 +2,18 @@ require 'rubygems'
gem 'hoe', '>= 2.1.0'
require 'hoe'
require 'fileutils'
-require './lib/gh-wiki'
+require './lib/dget'
Hoe.plugin :newgem
Hoe.plugin :cucumberfeatures
-$hoe = Hoe.spec 'gh-wiki' do
+puts DGet::VERSION
+$hoe = Hoe.spec 'dget' do
self.developer 'Nick Partridge', 'nkpart@gmail.com'
self.rubyforge_name = self.name # TODO this is default value
self.extra_deps = [['nokogiri','>= 0.0']] #TODO pick a version
+ self.version = DGet::VERSION
+
end
require 'newgem/tasks'
View
14 bin/dget 100644 → 100755
@@ -4,16 +4,6 @@
# Copyright (c) Nick Partridge 2009. All rights reserved.
require 'rubygems'
-require File.expand_path(File.dirname(__FILE__) + "/../lib/gh-wiki")
-
-user, project_name, file = *ARGV
-if (user && project_name) then
- file ||= "#{project_name}_#{user}.html"
- content = GhWiki.main(user, project_name)
- File.open(file, 'w') { |f| f.puts content }
-else
- puts "Usage: gw user project [file=user_project.html]"
-end
-
-
+require File.expand_path(File.dirname(__FILE__) + "/../lib/dget")
+DGet.cli($stdin, $stdout, ARGV)
View
@@ -0,0 +1,26 @@
+$:.unshift(File.dirname(__FILE__)) unless
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
+
+%w{rubygems erb nokogiri open-uri}.each { |r| require r }
+
+require "dget/utils"
+require "dget/googlecode"
+require "dget/github"
+
+module DGet
+ VERSION = '0.0.1' #unless defined? VERSION
+
+ def self.cli(stdin, stdout, args)
+ engine, project_spec, file = *args
+ if (engine && project_spec) then
+ case engine
+ when "github"
+ GitHubEngine.new.do(project_spec, file)
+ when "googlecode"
+ GoogleCodeEngine.new.do(project_spec, file)
+ end
+ else
+ stdout.puts "Usage: dget [github|googlecode] [user/project|project] [file]"
+ end
+ end
+end
File renamed without changes.
View
@@ -0,0 +1,98 @@
+$:.unshift(File.dirname(__FILE__)) unless
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
+
+require 'dget'
+module DGet
+
+ class GitHubDoc
+ include DGet
+ attr_reader :user, :project_name, :pages, :root_doc
+
+ def initialize user, project_name
+ @user = user
+ @project_name = project_name
+ end
+
+ def root_doc
+ @root_doc ||= proc {
+ doc = N('http://wiki.github.com/%s/%s' % [@user, @project_name])
+ doc.css('.main').first.fmap { |c| clean_links c }
+ doc
+ }.call
+ end
+
+ def pages
+ @pages ||= root_doc.css(".sidebar ul li b a").map do |link|
+ [
+ link.content,
+ link['href'][/#{@project_name}\/(.*)/, 1] || "home",
+ proc {
+ content = N(link['href']).css('.main').first
+ clean_links content
+ content
+ }
+ ]
+ end
+ end
+
+ private
+
+ def clean_links doc
+ # rewrites internal links to use the local navigation
+ doc.css('a').each do |some_a|
+ some_a['href'][/#{@project_name}\/(.*)/, 1].fmap { |id|
+ some_a['href'] = "javascript:go(\'#{id}\')"
+ }
+ end
+ end
+
+ end
+
+ class GitHubEngine
+ def do project_spec, file = nil
+ user, project_name = *project_spec.split('/')
+
+ gh_doc = GitHubDoc.new(user, project_name)
+ file ||= file_for(user, project_name)
+
+ content = build_content gh_doc
+ File.open(file, 'w') { |f| f.puts content }
+ end
+
+ private
+
+ def build_content gh_doc
+ build_doc(gh_doc.root_doc, gh_doc.pages, gh_doc.project_name, gh_doc.user)
+ end
+
+ def file_for user, project_name
+ "#{project_name}_#{user}.html"
+ end
+
+ def template
+ IO.read(File.dirname(__FILE__) / 'github.html')
+ end
+
+ def build_doc root, pages, project_name, user
+ # Template variables, note: project_name and user are also used in the template
+ project_description = root.css("#repository_description").first.fmap(&:content)
+ main_content = root.css('.main').first.fmap(&:inner_html)
+ page_list = sidebar(pages)
+ page_content = pages.map { |title, id, content_f|
+ "<div id=\"#{id}\">#{content_f[]}</div>"
+ }.join
+
+ ERB.new(template()).result(binding)
+ end
+
+ def sidebar pages
+ "<ul>" +
+ pages.map { |title, id, _|
+ "<li><b><a href=\"javascript:go(\'#{id}\')\""">#{title}</a></b></li>"
+ }.join +
+ "</ul>"
+ end
+
+ end
+
+end
View
@@ -0,0 +1,100 @@
+$:.unshift(File.dirname(__FILE__)) unless
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
+
+require 'dget'
+module DGet
+
+ class GoogleCodeDoc
+ include DGet
+ attr_reader :project_name, :pages, :root_doc
+
+ def initialize project_name
+ @project_name = project_name
+ end
+
+ def root_doc
+ # @root_doc ||= proc {
+ # doc = N('http://wiki.github.com/%s/%s' % [@user, @project_name])
+ # doc.css('.main').first.fmap { |c| clean_links c }
+ # doc
+ # }.call
+ end
+
+ def pages
+ @pages ||= proc {
+ p "http://code.google.com/p/#{@project_name}/w/list"
+ page_list_doc = N("http://code.google.com/p/#{@project_name}/w/list")
+ page_list_doc.css(".results tr").tail.map do |link|
+ [
+ link.css('.col_0 a').first.content.strip,
+ link['href'][/#{@project_name}\/(.*)/, 1] || "home",
+ proc {
+ content = N(link['href']).css('.main').first
+ clean_links content
+ content
+ }
+ ]
+ end
+ }.call
+ end
+
+ private
+
+ def clean_links doc
+ # rewrites internal links to use the local navigation
+ doc.css('a').each do |some_a|
+ some_a['href'][/#{@project_name}\/(.*)/, 1].fmap { |id|
+ some_a['href'] = "javascript:go(\'#{id}\')"
+ }
+ end
+ end
+
+ end
+
+ class GoogleCodeEngine
+ def do project_name, file = nil
+ doc = GoogleCodeDoc.new(project_name)
+ file ||= "#{project_name}.html"
+
+# content = build_content doc
+# File.open(file, 'w') { |f| f.puts content }
+ p doc.pages
+ end
+
+ private
+
+ def build_content gh_doc
+ build_doc(gh_doc.root_doc, gh_doc.pages, gh_doc.project_name, gh_doc.user)
+ end
+
+ def file_for user, project_name
+ "#{project_name}_#{user}.html"
+ end
+
+ def template
+ IO.read(File.dirname(__FILE__) / 'github.html')
+ end
+
+ def build_doc root, pages, project_name, user
+ # Template variables, note: project_name and user are also used in the template
+ project_description = root.css("#repository_description").first.fmap(&:content)
+ main_content = root.css('.main').first.fmap(&:inner_html)
+ page_list = sidebar(pages)
+ page_content = pages.map { |title, id, content_f|
+ "<div id=\"#{id}\">#{content_f[]}</div>"
+ }.join
+
+ ERB.new(template()).result(binding)
+ end
+
+ def sidebar pages
+ "<ul>" +
+ pages.map { |title, id, _|
+ "<li><b><a href=\"javascript:go(\'#{id}\')\""">#{title}</a></b></li>"
+ }.join +
+ "</ul>"
+ end
+
+ end
+
+end
@@ -1,6 +1,4 @@
-module GhWiki
- module_function
-
+module DGet
def N url
Nokogiri::HTML(open(url))
rescue SocketError => e
@@ -21,7 +19,22 @@ def to_proc
end
end
+module Enumerable
+ def tail
+ self[1..-1]
+ end
+end
+
class Object
+ def tap
+ yield self
+ self
+ end
+
+ def trace
+ self.tap { |x| p x }
+ end
+
def fmap &blk
if (self.respond_to? :map) then
self.map(&blk)
@@ -42,4 +55,3 @@ def filter &blk
end
end
end
-
View
@@ -1,12 +0,0 @@
-$:.unshift(File.dirname(__FILE__)) unless
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
-
-%w{rubygems erb nokogiri open-uri}.each { |r| require r }
-
-require "gh-wiki/utils"
-require "gh-wiki/googlecode"
-require "gh-wiki/github"
-
-module GhWiki
- VERSION = '0.0.1' unless defined? VERSION
-end
Oops, something went wrong.

0 comments on commit 6bd30d0

Please sign in to comment.