qdoc 0.0.22 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/qdoc.rb +79 -73
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59b6ef3449df0454bfa9313eb121ffbace6679cf
4
- data.tar.gz: eb7b2affec88066b4db7cef3d7d86899cbc967b8
3
+ metadata.gz: 8d15f985461e6968951af4faa1cd89f97e176a6a
4
+ data.tar.gz: 800dbc887390648b3a60f7a403b41b5dd2c8f863
5
5
  SHA512:
6
- metadata.gz: a6230718eddf17992f06e34d66cfb0ae4c07490ead8c0f93224922780c32227c9202b867e225f8bdb9de8db71094b8980c180e9b3fae547550d1e723e56bfdc3
7
- data.tar.gz: 4d426858a2ec112af37cb1fe8adc22ece458c79e2e4283de344ae306caa5ed09e907a49ea01baa120d6dd152395769d52edd4e9bfb72d005759b5350c29cb222
6
+ metadata.gz: fc7674660a98508ec3b4cc10cbe49a71e4702fac92774f9bac0cd0592c8f90e79b4a4dc7cb949938e74b97c9ec85b1b89f9ac1e311f2bd83b018f8ae4e29549f
7
+ data.tar.gz: 2f89b14f7ade0106202a65389b3a5c6a6d05fe2e1193f5e046f9490e2e5aca1c30f0e278019a7d4e1b3e04bd07cefb405cd87b536b6105c1617f9400d1cb3f9c
@@ -2,100 +2,106 @@
2
2
  require 'redcarpet'
3
3
  require 'kramdown'
4
4
  require 'fileutils'
5
+ require 'cgi'
5
6
 
6
7
  class QDoc
7
-
8
- def initialize
9
- @documents = [ { file: "index.html", title: "index", file: "index.html", content: "Choose from the left nav.", directory: "", parse: false } ]
10
- # @locations = [ "accomplishments", "cio-staff", "one-on-one", "team-staff"]
8
+
9
+ def initialize( options = {} )
10
+ defaults = { output_directory: "doc", index_content: "Choose from the left nav." }
11
+ options = defaults.merge options
12
+ @out_dir = options[:output_directory]
13
+
14
+ @index = { file: "index.html", title: "index", extension: "html", content: options[:index_content], directory: nil, output_file: "index.html", parse: false }
15
+
16
+ @documents = Array.new
11
17
  @locations = Array.new
12
- @out_dir = "doc"
13
18
  @redcarpet = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
14
19
  end
15
-
20
+
16
21
  def run
17
- search_for_files
18
- stage_files( @locations )
22
+ @locations = identify_locations
23
+ @documents = stage_files( @locations )
19
24
  nav = create_nav( @documents )
20
- index = nil
25
+ # index = nil
21
26
  make_doc_directory
22
27
  @documents.each do |doc|
23
- index = doc if doc[:title] == "index"
24
- next if !doc[:parse]
25
- doc[:content] = parse_file( "#{doc[:directory]}/#{doc[:filename]}")
26
- write_file( "#{@out_dir}/#{doc[:directory]}-#{doc[:file]}", create_page(nav, doc[:content]) )
27
- # write_file( "#{@out_dir}/#{doc[:file]}", create_page(nav, doc[:content]) )
28
+ doc[:content] = parse_document( doc ) if doc[:parse] #"#{doc[:directory]}/#{doc[:filename]}")
29
+ write_file( "#{@out_dir}/#{doc[:output_file]}", create_page(nav, doc[:content]) )
28
30
  end
29
- write_file( "#{@out_dir}/#{index[:file]}", create_page(nav, create_index))
30
31
  copy_bootstrap
31
- # create_custom_css
32
32
  end
33
-
33
+
34
34
  private
35
-
35
+
36
36
  def make_doc_directory
37
37
  if !File.directory?(@out_dir)
38
38
  FileUtils.mkdir_p(@out_dir)
39
39
  end
40
40
  end
41
-
42
- def search_for_files
43
- @locations << "" # Current directory
44
- Dir.foreach('./') do |leaf|
45
- next if leaf =~ /\A\./ || leaf == @out_dir || leaf =~ /\.rb\z/
46
- @locations << leaf if File.directory?(leaf)
41
+
42
+ def identify_locations
43
+ locations = [""] # Current directory
44
+ Dir.foreach('./') do |node|
45
+ next if node =~ /\A\./ || node == @out_dir # || leaf =~ /\.rb\z/
46
+ locations << node if File.directory?(node)
47
47
  end
48
+ locations
48
49
  end
49
-
50
+
50
51
  def create_index
51
52
  page = "<div class='col-md-8'><p>Choose from the left navigation to select a document</p>" + \
52
- "<p>#{@documents.count-1} files parsed from the following locations:<p>" + \
53
- "<table class='table table-striped'><tbody>"
53
+ "<p>#{@documents.count-1} files parsed from the following locations:<p>" + \
54
+ "<table class='table table-striped'><tbody>"
54
55
  @locations.each do |l|
55
56
  l = "Current Dir" if l == ""
56
57
  page += "<tr><td>#{l}</td></tr>"
57
58
  end
58
59
  page += "</tbody></table></div>"
59
60
  end
60
-
61
+
61
62
  def stage_files( locations )
62
- locations.each do |l|
63
- Dir.foreach("./#{l}") do |leaf|
64
- next if leaf !~ /(.*)\.(txt|md|rc)\z/
65
- filehead = $~.captures[0]
66
- file_ext = $~.captures[1]
67
- filename = filehead + "." + file_ext
68
- @documents << { directory: l, filename: filename, file: filehead + ".html", title: filename, content: nil, parse: true }
69
- # p @documents.last
63
+ documents = [ @index ]
64
+ locations.each do |dir|
65
+ Dir.foreach("./#{dir}") do |node|
66
+ node.match(/(?<name>.*)\.(?<ext>txt|md|rc)\z/) do |match|
67
+ filehead = match[:name]
68
+ file_ext = match[:ext]
69
+ filename = filehead + "." + file_ext
70
+ documents << { directory: dir, filename: filename, extension: file_ext, file: filehead + ".html", title: filename, content: nil, parse: true, output_file: "#{dir}-#{filename}.html" }
71
+ end
70
72
  end
71
73
  end
74
+ documents
72
75
  end
73
-
74
- def fix_tables( html )
76
+
77
+ def bootstrap_tables( html )
75
78
  html.gsub('<table>', '<table class="table">')
76
79
  end
77
80
 
78
- def parse_file( filename )
81
+ def parse_document( doc )
82
+ filename = doc[:directory] == "" ? doc[:filename] : "#{doc[:directory]}/#{doc[:filename]}"
79
83
  contents = File.open( filename, "r" ) do |c|
80
84
  c.read
81
85
  end
82
- contents = fix_hawaiian( contents )
83
- case File.extname(filename)
84
- when ".md"
85
- return Kramdown::Document.new( contents ).to_html
86
- when ".rc"
87
- return @redcarpet.render( contents )
88
- when ".txt"
89
- return @redcarpet.render( contents )
86
+ # contents = fix_hawaiian CGI::escapeHTML contents
87
+ case doc[:extension]
88
+ when "md"
89
+ return fix_hawaiian Kramdown::Document.new( CGI::escapeHTML contents ).to_html
90
+ when "rc"
91
+ return @redcarpet.render( fix_hawaiian CGI::escapeHTML contents )
92
+ when "txt"
93
+ return @redcarpet.render( fix_hawaiian CGI::escapeHTML contents )
94
+ when "html"
95
+ return contents
90
96
  else
91
97
  nil
92
98
  end
93
99
  end
94
-
100
+
95
101
  def copy_bootstrap
96
102
  FileUtils.cp( File.dirname(__FILE__) + "/bootstrap.min.css", "#{@out_dir}/bootstrap.min.css" )
97
103
  end
98
-
104
+
99
105
  def fix_hawaiian( text )
100
106
  text.gsub("ʻ", "&#8216;").gsub("ā", "&#257;").gsub("ē","&#275;").gsub("ī", "&#299;").gsub("ō","&#333;").gsub("ū", "&#363;").gsub("Ā", "&#256;").gsub("Ē","&#274;").gsub("Ī", "&#298;").gsub("Ō", "&#332;").gsub("Ū", "&#362;")
101
107
  end
@@ -103,42 +109,42 @@ class QDoc
103
109
  def create_page( nav, content )
104
110
  "<!DOCTYPE html>
105
111
  <html>
106
- <head>
107
- <title>My Documents</title>
108
- <link href='bootstrap.min.css' rel='stylesheet'>
109
- </head>
110
- <body>
111
- <div class='row'>
112
- <div class='col-md-3'>" + \
113
- nav + \
114
- "</div>
115
- <div class='col-md-9'>" + \
116
- content + \
117
- "</div>
118
- </div>
119
- </body>"
112
+ <head>
113
+ <title>My Documents</title>
114
+ <link href='bootstrap.min.css' rel='stylesheet'>
115
+ </head>
116
+ <body>
117
+ <div class='row'>
118
+ <div class='col-md-3'>" + \
119
+ nav + \
120
+ "</div>
121
+ <div class='col-md-9'>" + \
122
+ content + \
123
+ "</div>
124
+ </div>
125
+ </body>"
120
126
  end
121
127
 
122
128
  def create_nav( documents )
123
- snippet = "<table class='table'>
124
- <thead>
125
- <tr>
126
- <th>Documents</th>
127
- </tr>
128
- </thead>
129
- <tbody>"
129
+ snippet = "<table class='table table-striped'>
130
+ <thead>
131
+ <tr>
132
+ <th>Location</th><th>Document</th>
133
+ </tr>
134
+ </thead>
135
+ <tbody>"
130
136
  documents.each do |doc|
131
137
  snippet += "<tr>
132
- <td><a href='#{doc[:directory]}-#{doc[:file]}'>#{doc[:directory]} : #{doc[:title]}</a></td>
138
+ <td>#{doc[:directory]}</td><td><a href='#{doc[:output_file]}'>#{doc[:title]}</a></td>
133
139
  </tr>"
134
140
  end
135
141
  snippet += "</tbody></table>"
136
142
  snippet
137
143
  end
138
-
144
+
139
145
  def write_file( filename, content )
140
146
  File.open(filename, "w") do |o|
141
- o.write( fix_tables(content) )
147
+ o.write( bootstrap_tables(content) )
142
148
  o.close
143
149
  end
144
150
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
4
+ version: 0.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Sereno
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-23 00:00:00.000000000 Z
11
+ date: 2013-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet