Permalink
Browse files

Add Asciidoc parsing/rendering

* a mostly complete Asciidoc processor
* templates to render processed Asciidocs to HTML
* index rake task updates to save the preprocessed
  source and rendered HTML for each page
  • Loading branch information...
1 parent 8839ec5 commit 5a5edecfc2c4a1bcff86af432e062d2c6f860bed @nickh nickh committed with schacon Apr 3, 2012
View
Oops, something went wrong.
View
@@ -1,5 +1,8 @@
+require 'asciidoc'
+
# fill in the db from a local git clone
task :preindex => :environment do
+ template_dir = File.join(Rails.root, 'templates')
dir = ENV["GIT_REPO"]
Dir.chdir(dir) do
# find all tags
@@ -31,7 +34,7 @@ task :preindex => :environment do
mode, type, sha, path = e.split(' ')
[path, sha, type]
end
- tree = tree.select { |t| t.first =~ /.*\.txt/ }
+ tree = tree.select { |t| t.first =~ /^(git.*|everyday|howto-index,user-manual)\.txt/ }
puts "Found #{tree.size} entries"
@@ -40,9 +43,19 @@ task :preindex => :environment do
path = path.gsub('.txt', '').gsub('v', '')
file = DocFile.where(:name => path).first_or_create
doc = Doc.where(:blob_sha => sha).first_or_create
- if !doc.plain
+ if !doc.plain || !doc.html
content = `git cat-file blob #{sha}`.chomp
- doc.plain = content
+ asciidoc = Asciidoc::Document.new(path, content) do |inc|
+ if match = inc.match(/^\.\.\/(.*)$/)
+ git_path = match[1]
+ else
+ git_path = "Documentation/#{inc}"
+ end
+
+ `git cat-file blob #{tag}:#{git_path}`
+ end
+ doc.plain = asciidoc.source
+ doc.html = asciidoc.render(template_dir)
doc.save
end
DocVersion.where(:version_id => stag.id, :doc_id => doc.id, :doc_file_id => file.id).first_or_create
@@ -0,0 +1,4 @@
+<div class='man-page'>
+ <%= header %>
+ <%= sections %>
+</div>
@@ -0,0 +1,5 @@
+<div id="header">
+ <h1><%= doc_title %> Manual Page</h1>
+ <h2><%= name %></h2>
+ <div class="sectionbody"><%= content %></div>
+</div>
@@ -0,0 +1,8 @@
+<% if !anchor.nil? %>
+ <a name="#<%= anchor %>">
+<% end %>
+<h<%= level %> id="<%= section_id %>"><%= name %></h<%= level%>>
+<% if !anchor.nil? %>
+ </a>
+<% end %>
+<div class="sectionbody"><%= content %></div>
@@ -0,0 +1 @@
+<a name="<%= content %>"></a>
@@ -0,0 +1,10 @@
+<div class="dlist">
+ <dl>
+ <% content.each do |dt, dd| %>
+ <dt class="hdlist1"><%= dt %></dt>
+ <% unless dd.nil? || dd.empty? %>
+ <dd><%= dd %></dd>
+ <% end %>
+ <% end %>
+ </dl>
+</div>
@@ -0,0 +1,9 @@
+<div class="exampleblock">
+ <div class="content">
+ <div class="literalblock">
+ <div class="content">
+ <pre><tt><%= content %></tt></pre>
+ </div>
+ </div>
+ </div>
+</div>
@@ -0,0 +1,5 @@
+<div class="listingblock">
+ <div class="content">
+ <pre><tt><%= content %></tt></pre>
+ </div>
+</div>
@@ -0,0 +1,5 @@
+<div class="literalblock">
+ <div class="content">
+ <pre><tt><%= content %></tt></pre>
+ </div>
+</div>
@@ -0,0 +1 @@
+<%= content %>
@@ -0,0 +1,7 @@
+<div class="olist arabic">
+ <ol class="arabic">
+ <% content.each do |li| %>
+ <li><p><%= li %></p></li>
+ <% end %>
+ </ol>
+</div>
@@ -0,0 +1,3 @@
+<div class="paragraph">
+ <p><%= content %></p>
+</div>
@@ -0,0 +1,7 @@
+<div class="ulist">
+ <ul>
+ <% content.each do |li| %>
+ <li><p><%= li %></p></li>
+ <% end %>
+ </ul>
+</div>
@@ -0,0 +1,3 @@
+<div class="verseblock">
+ <pre class="content"><%= content %></pre>
+</div>

0 comments on commit 5a5edec

Please sign in to comment.