Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 6ceacc4c129be999552d8bf33849026c454b5714 @joshbuddy joshbuddy committed Dec 1, 2011
@@ -0,0 +1,5 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
+.DS_Store
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in gitdocs.gemspec
+gemspec
@@ -0,0 +1,67 @@
+# Gitdocs
+
+Collaborate on files and docs through a shared git repository. gitdocs will automatically push changes to the repo as well as pull in changes.
+This allows any git repo to be used as a collaborative task list or wiki for a team.
+
+You can also start a web front-end allowing the repo to be viewed through the browser.
+
+## Installation
+
+Install the gem:
+
+```
+gem install gitdocs
+```
+
+If you have Growl installed, you'll probably want to run `brew install growlnotify` to enable Growl support.
+
+## Usage
+
+First add the doc folders to watch:
+
+```
+gitdocs add my/path/to/watch
+```
+
+You can remove and clear paths as well:
+
+```
+gitdocs rm my/path/to/watch
+# or gitdocs clear
+```
+
+You need to startup gitdocs:
+
+```
+gitdocs start
+```
+
+You can also `stop` and `restart` gitdocs as needed. Run
+
+```
+gitdocs status
+```
+
+for a helpful listing of the current state. Once gitdocs is started, simply start editing or adding files to your
+designated git repository. Changes will be automatically pushed and pulled to your local repo.
+
+You can also have gitdocs fetch a remote repository with:
+
+```
+gitdocs create my/path/for/doc git@github.com:user/some_docs.git
+```
+
+This will clone the repo and add the path to your watched docs. Be sure to restart gitdocs
+to have path changes update:
+
+```
+gitdocs restart
+```
+
+To view the docs in your browser with file formatting:
+
+```
+gitdocs serve
+```
+
+and then visit `http://localhost:8888` for access to all your docs in the browser.
@@ -0,0 +1,8 @@
+require "bundler/gem_tasks"
+require 'rake/testtask'
+
+Rake::TestTask.new do |t|
+ t.libs.push "lib"
+ t.test_files = FileList[File.expand_path('../test/**/*_test.rb', __FILE__)]
+ t.verbose = true
+end
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+
+require 'gitdocs'
+
+Gitdocs::Cli.start(ARGV)
@@ -0,0 +1,34 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "gitdocs/version"
+
+Gem::Specification.new do |s|
+ s.name = "gitdocs"
+ s.version = Gitdocs::VERSION
+ s.authors = ["Josh Hull"]
+ s.email = ["joshbuddy@gmail.com"]
+ s.homepage = ""
+ s.summary = %q{Docs + git = gitdocs}
+ s.description = %q{Docs + git = gitdocs.}
+
+ s.rubyforge_project = "gitdocs"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ s.add_dependency 'rb-fsevent', '~> 0.4.3.1'
+ s.add_dependency 'thin'
+ s.add_dependency 'renee', '~> 0.3.6'
+ s.add_dependency 'redcarpet'
+ s.add_dependency 'thor'
+ s.add_dependency 'dante', '~> 0.0.4'
+ s.add_dependency 'growl', '~> 1.0.3'
+ s.add_dependency 'yajl-ruby'
+
+ s.add_development_dependency 'minitest', "~> 2.6.1"
+ s.add_development_dependency 'rake'
+ s.add_development_dependency 'mocha'
+ s.add_development_dependency 'fakeweb'
+end
@@ -0,0 +1,25 @@
+require 'gitdocs/version'
+require 'gitdocs/configuration'
+require 'gitdocs/runner'
+require 'gitdocs/server'
+require 'gitdocs/cli'
+require 'thread'
+require 'rb-fsevent'
+require 'growl'
+require 'yajl'
+require 'dante'
+
+module Gitdocs
+ def self.run(config_root = nil)
+ loop do
+ @config = Configuration.new(config_root)
+ @threads = @config.paths.map do |path|
+ t = Thread.new { Runner.new(path).run }
+ t.abort_on_exception = true
+ t
+ end
+ @threads.each(&:join)
+ sleep(60)
+ end
+ end
+end
@@ -0,0 +1,110 @@
+module Gitdocs
+ require 'thor'
+
+ class Cli < Thor
+ include Thor::Actions
+
+ def self.source_root; File.expand_path('../../', __FILE__); end
+
+ desc "start", "Starts a daemonized gitdocs process"
+ def start
+ if !self.running?
+ self.runner(:daemonize => true, :pid_path => self.pid_path).execute { Gitdocs.run }
+ say "Started gitdocs", :green
+ else
+ say "Gitdocs is already running, please use restart", :red
+ end
+ end
+
+ desc "stop", "Stops the gitdocs process"
+ def stop
+ self.runner(:kill => true, :pid_path => self.pid_path).execute
+ say "Stopped gitdocs", :red
+ end
+
+ desc "restart", "Restarts the gitdocs process"
+ def restart
+ self.stop
+ sleep(1)
+ self.start
+ end
+
+ desc "add PATH", "Adds a path to gitdocs"
+ def add(path)
+ self.config.add_path(path)
+ say "Added path #{path} to doc list"
+ self.restart if self.running?
+ end
+
+ desc "rm PATH", "Removes a path from gitdocs"
+ def rm(path)
+ self.config.remove_path(path)
+ say "Removed path #{path} from doc list"
+ self.restart if self.running?
+ end
+
+ desc "clear", "Clears all paths from gitdocs"
+ def clear
+ self.config.paths = []
+ say "Cleared paths from gitdocs"
+ end
+
+ desc "create PATH REMOTE", "Creates a new gitdoc root based on an existing remote"
+ def create(path, remote)
+ path = self.config.normalize_path(path)
+ FileUtils.mkdir_p(File.dirname(path))
+ system("git clone -q #{remote} #{path}") or raise "Unable to clone into #{path}"
+ self.add(path)
+ say "Created & added path #{path} to doc list"
+ end
+
+ desc "status", "Retrieve gitdocs status"
+ def status
+ say "GitDoc v#{VERSION}"
+ say "Running: #{self.running?}"
+ say "Watching paths:"
+ say self.config.paths.map { |p| " - #{p}" }.join("\n")
+ end
+
+ desc "serve", "Serves web frontend for files"
+ def serve
+ puts "Serving docs..."
+ Gitdocs::Server.new(*self.config.paths.map{|p| Gitdocs::Runner.new(p)}).start
+ end
+
+ desc "config", "Configuration options for gitdocs"
+ def config
+ # TODO make this work
+ end
+
+ desc "help", "Prints out the help"
+ def help(task = nil, subcommand = false)
+ say "\nGitdocs: Collaborate with ease.\n\n"
+ task ? self.class.task_help(shell, task) : self.class.help(shell, subcommand)
+ end
+
+ # Helpers for thor
+ no_tasks do
+ def runner(options={})
+ Dante::Runner.new('gitdocs', options)
+ end
+
+ def config
+ @config ||= Configuration.new
+ end
+
+ def running?
+ return false unless File.exist?(pid_path)
+ Process.kill 0, File.read(pid_path).to_i
+ true
+ rescue Errno::ESRCH
+ false
+ end
+
+ def pid_path
+ "/tmp/gitdocs.pid"
+ end
+ end
+
+ end
+end
@@ -0,0 +1,52 @@
+module Gitdocs
+ class Configuration
+ attr_reader :config_root
+
+ def initialize(config_root = nil)
+ @config_root = config_root || File.expand_path(".gitdocs", ENV["HOME"])
+ FileUtils.mkdir_p(@config_root)
+ end
+
+ # @config.paths => ['my/path/1', 'my/path/2']
+ def paths
+ self.read_file('paths').split("\n")
+ end
+
+ def paths=(paths)
+ self.write_file('paths', paths.uniq.join("\n"))
+ end
+
+ # @config.add_path('my/path/1')
+ def add_path(path)
+ path = normalize_path(path)
+ self.paths += [path]
+ path
+ end
+
+ # @config.remove_path('my/path/1')
+ def remove_path(path)
+ path = normalize_path(path)
+ self.paths -= [path]
+ path
+ end
+
+ def normalize_path(path)
+ File.expand_path(path, Dir.pwd)
+ end
+
+ protected
+
+ # Read file from gitdocs repo
+ # @config.read_file('paths')
+ def read_file(name)
+ full_path = File.expand_path(name, @config_root)
+ File.exist?(full_path) ? File.read(full_path) : ''
+ end
+
+ # Writes configuration file
+ # @config.write_file('paths', '...')
+ def write_file(name, content)
+ File.open(File.expand_path(name, @config_root), 'w') { |f| f.puts content }
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 6ceacc4

Please sign in to comment.