docubot 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/docubot +36 -0
- data/lib/docubot.rb +14 -0
- data/lib/docubot/converter.rb +21 -0
- data/lib/docubot/converters/markdown.rb +6 -0
- data/lib/docubot/generator.rb +35 -0
- data/lib/docubot/page.rb +33 -0
- data/lib/docubot/section.rb +16 -0
- data/lib/docubot/snippet.rb +17 -0
- data/lib/docubot/snippets/glossary.rb +4 -0
- data/lib/docubot/template.rb +13 -0
- data/lib/docubot/templates/default/page.haml +0 -0
- data/lib/docubot/templates/default/section.haml +0 -0
- data/test/all.rb +6 -0
- data/test/site1/A Slight Change of Heart/1 Ze First Page in Ze Section.md +1 -0
- data/test/site1/A Slight Change of Heart/2 Another Page in the Section.md +1 -0
- data/test/site1/A Slight Change of Heart/3_more_crap.md +5 -0
- data/test/site1/headers.md +10 -0
- data/test/site1/raw.md +3 -0
- metadata +94 -0
data/bin/docubot
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'docubot'
|
5
|
+
|
6
|
+
USAGE = <<ENDUSAGE
|
7
|
+
Usage:
|
8
|
+
docubot [-t template_name] directory
|
9
|
+
ENDUSAGE
|
10
|
+
|
11
|
+
ARGS = { :template=>'default' }
|
12
|
+
UNFLAGGED_ARGS = [ :directory ]
|
13
|
+
next_arg = UNFLAGGED_ARGS.first
|
14
|
+
ARGV.each{ |arg|
|
15
|
+
case arg
|
16
|
+
when '-h','--help'
|
17
|
+
ARGS[:help] = true
|
18
|
+
when '-t','--template'
|
19
|
+
next_arg = :template
|
20
|
+
else
|
21
|
+
if next_arg
|
22
|
+
ARGS[next_arg] = arg
|
23
|
+
UNFLAGGED_ARGS.delete( next_arg )
|
24
|
+
end
|
25
|
+
next_arg = UNFLAGGED_ARGS.first
|
26
|
+
end
|
27
|
+
}
|
28
|
+
|
29
|
+
if ARGS[:help] or !ARGS[:directory]
|
30
|
+
puts USAGE
|
31
|
+
#puts EXAMPLES if ARGS[:help]
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
|
35
|
+
DocuBot.generate( ARGS[:directory], ARGS )
|
36
|
+
|
data/lib/docubot.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module DocuBot
|
2
|
+
VERSION = '0.0.1'
|
3
|
+
DIR = File.dirname( __FILE__ )
|
4
|
+
def self.name( file_path )
|
5
|
+
no_extension = File.basename( file_path ).sub( /\.[^.]+$/, '' )
|
6
|
+
no_ordering = no_extension.sub( /^\d*\s/, '' )
|
7
|
+
end
|
8
|
+
end
|
9
|
+
require 'docubot/converter'
|
10
|
+
require 'docubot/section'
|
11
|
+
require 'docubot/page'
|
12
|
+
require 'docubot/template'
|
13
|
+
require 'docubot/snippet'
|
14
|
+
require 'docubot/generator'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module DocuBot
|
2
|
+
module Converter
|
3
|
+
@@by_type = {}
|
4
|
+
def converts_for( *types )
|
5
|
+
types.each{ |type| @@by_type[type.to_s] = self }
|
6
|
+
end
|
7
|
+
def self.by_type
|
8
|
+
@@by_type
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.convert_to_html( source, type )
|
13
|
+
converter = DocuBot::Converter.by_type[ type.to_s ]
|
14
|
+
raise "No converter found for type #{type}" unless converter
|
15
|
+
converter.new( source ).to_html
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Dir[ File.join( DocuBot::DIR, 'docubot/converters/*.rb' ) ].each do |converter|
|
20
|
+
require converter
|
21
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module DocuBot
|
2
|
+
GENERATOR_DEFAULTS = {
|
3
|
+
:template => 'default'
|
4
|
+
}
|
5
|
+
def self.generate( directory, options={} )
|
6
|
+
options = GENERATOR_DEFAULTS.merge( options )
|
7
|
+
|
8
|
+
if !File.exists?( directory )
|
9
|
+
raise "DocuBot cannot find directory #{File.expand_path(directory)}. Exiting."
|
10
|
+
end
|
11
|
+
|
12
|
+
use_template( options[:template] )
|
13
|
+
|
14
|
+
@toc = DocuBot::Section.new( 'Table of Contents' )
|
15
|
+
sections_by_path = {}
|
16
|
+
|
17
|
+
Dir[ File.join( directory, '**/*' ) ].each do |item|
|
18
|
+
parent = sections_by_path[ File.dirname( item ) ] || @toc
|
19
|
+
if File.directory?( item )
|
20
|
+
section = DocuBot::Section.new( DocuBot.name( item ) )
|
21
|
+
sections_by_path[ item ] = section
|
22
|
+
parent << section
|
23
|
+
else
|
24
|
+
parent << DocuBot::Page.from_file( item )
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
puts @toc
|
29
|
+
|
30
|
+
output = "#{directory}_html"
|
31
|
+
Dir.mkdir(output) unless File.exists?(output)
|
32
|
+
|
33
|
+
# TODO: CHM the results
|
34
|
+
end
|
35
|
+
end
|
data/lib/docubot/page.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
class DocuBot::Page
|
3
|
+
META_SEPARATOR = /^\+\+\+$/ # Sort of like +++ATH0
|
4
|
+
|
5
|
+
attr_reader :html
|
6
|
+
|
7
|
+
def self.from_file( filename, title=nil, type=:md )
|
8
|
+
title ||= DocuBot.name( filename )
|
9
|
+
type ||= File.extname( filename )[ 1..-1 ]
|
10
|
+
new( File.read(filename), title, type )
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize( source, title=nil, type=:md )
|
14
|
+
parts = source.split( META_SEPARATOR, 2 )
|
15
|
+
@meta = { 'title'=>title }
|
16
|
+
@meta.merge!( YAML.load( parts.first ) ) if parts.length > 1
|
17
|
+
@html = DocuBot::convert_to_html( parts.last, type )
|
18
|
+
@html = DocuBot::process_snippets( @html )
|
19
|
+
end
|
20
|
+
|
21
|
+
def method_missing( method, *args )
|
22
|
+
key=method.to_s
|
23
|
+
case key[-1..-1]
|
24
|
+
when '?' then @meta.has_key?( key[0..-2] )
|
25
|
+
when '!', '=' then super
|
26
|
+
else @meta[ key ]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s( depth=0 )
|
31
|
+
"#{' '*depth}#{@meta['title']}"
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class DocuBot::Section
|
2
|
+
attr_reader :entries, :title
|
3
|
+
def initialize( title )
|
4
|
+
@entries = []
|
5
|
+
@title = title
|
6
|
+
end
|
7
|
+
def sub_sections
|
8
|
+
@entries.select{ |e| e.is_a?( DocuBot::Section ) }
|
9
|
+
end
|
10
|
+
def <<( entry )
|
11
|
+
@entries << entry
|
12
|
+
end
|
13
|
+
def to_s( depth=0 )
|
14
|
+
(["#{' '*depth}#@title"] + @entries.map{ |e| e.to_s(depth+1) }).join("\n")
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module DocuBot
|
2
|
+
@snippets = {}
|
3
|
+
|
4
|
+
def self.handle_snippet( regexp, &handler )
|
5
|
+
@snippets[ regexp ] = handler
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.process_snippets( html )
|
9
|
+
@snippets.inject(html){ |html,regexp,handler| html.gsub( regexp, &handler ) }
|
10
|
+
end
|
11
|
+
|
12
|
+
Dir[ File.join( DocuBot::DIR, 'docubot/snippets/*.rb' ) ].each do |snippet|
|
13
|
+
require snippet
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module DocuBot
|
2
|
+
TEMPLATE_DIR = File.expand_path( File.join( DocuBot::DIR, 'docubot/templates' ) )
|
3
|
+
Dir.chdir TEMPLATE_DIR do
|
4
|
+
@available_templates = Dir[ '*' ]
|
5
|
+
end
|
6
|
+
def self.use_template( template_name )
|
7
|
+
@template = template_name
|
8
|
+
unless @available_templates.include?( template_name )
|
9
|
+
warn "No template named '#{template_name}' exists in #{TEMPLATE_DIR}; using 'default' instead."
|
10
|
+
use 'default' unless template_name=='default'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
File without changes
|
File without changes
|
data/test/all.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
The title of this should be "Ze First Page in Ze Section"
|
@@ -0,0 +1 @@
|
|
1
|
+
The title of this page should be "Another Page in the Section".
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# I like Chicken, I like Liver
|
2
|
+
MeowMix MeowMix, please deliver.
|
3
|
+
|
4
|
+
## Delivery Options
|
5
|
+
You could just put it in my bowl. Or you could:
|
6
|
+
|
7
|
+
* Put it on a fancy plate.
|
8
|
+
* Let me eat it out of your hand.
|
9
|
+
* Just dump it all over the floor and let me lick up dust
|
10
|
+
at the same time as I scarf the food.
|
data/test/site1/raw.md
ADDED
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: docubot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gavin Kistner
|
8
|
+
- Harold Hausman
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2010-01-05 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bluecloth
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
version:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: haml
|
28
|
+
type: :runtime
|
29
|
+
version_requirement:
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
version:
|
36
|
+
description: Create CHM documentation from a simple hierarchy of text files.
|
37
|
+
email: gavin@phrogz.net
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- bin/docubot
|
46
|
+
- lib/docubot/converter.rb
|
47
|
+
- lib/docubot/converters/markdown.rb
|
48
|
+
- lib/docubot/generator.rb
|
49
|
+
- lib/docubot/page.rb
|
50
|
+
- lib/docubot/section.rb
|
51
|
+
- lib/docubot/snippet.rb
|
52
|
+
- lib/docubot/snippets/glossary.rb
|
53
|
+
- lib/docubot/template.rb
|
54
|
+
- lib/docubot/templates/default/page.haml
|
55
|
+
- lib/docubot/templates/default/section.haml
|
56
|
+
- lib/docubot.rb
|
57
|
+
- test/all.rb
|
58
|
+
- test/site1/A Slight Change of Heart/1 Ze First Page in Ze Section.md
|
59
|
+
- test/site1/A Slight Change of Heart/2 Another Page in the Section.md
|
60
|
+
- test/site1/A Slight Change of Heart/3_more_crap.md
|
61
|
+
- test/site1/headers.md
|
62
|
+
- test/site1/raw.md
|
63
|
+
has_rdoc: true
|
64
|
+
homepage: http://github.com/Phrogz/docubot
|
65
|
+
licenses: []
|
66
|
+
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
version:
|
84
|
+
requirements:
|
85
|
+
- Windows with HTML Help Workshop installed.
|
86
|
+
- BlueCloth gem for Markdown conversion.
|
87
|
+
- Haml gem for template interpretation.
|
88
|
+
rubyforge_project: docubot
|
89
|
+
rubygems_version: 1.3.5
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: Create CHM documentation from a simple hierarchy of text files.
|
93
|
+
test_files:
|
94
|
+
- test/all.rb
|