diff options
-rw-r--r-- | db/migrate/20120417220111_change_doc_sha_to_string.rb | 9 | ||||
-rw-r--r-- | db/schema.rb | 2 | ||||
-rwxr-xr-x | lib/asciidoc.rb | 10 | ||||
-rw-r--r-- | lib/tasks/index.rake | 54 | ||||
-rw-r--r-- | templates/section_note.html.erb | 8 |
5 files changed, 58 insertions, 25 deletions
diff --git a/db/migrate/20120417220111_change_doc_sha_to_string.rb b/db/migrate/20120417220111_change_doc_sha_to_string.rb new file mode 100644 index 00000000..8a272494 --- /dev/null +++ b/db/migrate/20120417220111_change_doc_sha_to_string.rb @@ -0,0 +1,9 @@ +class ChangeDocShaToString < ActiveRecord::Migration + def up + change_column :docs, :blob_sha, :string + end + + def down + change_column :docs, :blob_sha, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 4fe5c07e..cf55e750 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -47,7 +47,7 @@ ActiveRecord::Schema.define(:version => 20120417224143) do end create_table "docs", :force => true do |t| - t.text "blob_sha" + t.string "blob_sha" t.text "plain" t.text "html" t.timestamp "created_at", :null => false diff --git a/lib/asciidoc.rb b/lib/asciidoc.rb index 012a62ca..56974e24 100755 --- a/lib/asciidoc.rb +++ b/lib/asciidoc.rb @@ -48,6 +48,7 @@ module Asciidoc :name => /^([A-Za-z].*)\s*$/, :line => /^([=\-~^\+])+\s*$/, :verse => /^\[verse\]\s*$/, + :note => /^\[NOTE\]\s*$/, :dlist => /^(.*)(::|;;)\s*$/, :olist => /^(\d+\.|\. )(.*)$/, :ulist => /^\s*[\*\-]\s+(.*)$/, @@ -864,6 +865,15 @@ module Asciidoc end block = Block.new(parent, :verse, buffer) + elsif this_line.match(REGEXP[:note]) + # note is an admonition preceded by [NOTE] and lasts until a blank line + this_line = lines.shift + while !this_line.nil? && !this_line.strip.empty? + buffer << this_line + this_line = lines.shift + end + + block = Block.new(parent, :note, buffer) elsif this_line.match(REGEXP[:listing]) # listing is surrounded by '----' (3 or more dashes) lines this_line = lines.shift diff --git a/lib/tasks/index.rake b/lib/tasks/index.rake index 33423e94..0aa4d29d 100644 --- a/lib/tasks/index.rake +++ b/lib/tasks/index.rake @@ -1,13 +1,21 @@ require 'asciidoc' require 'octokit' require 'time' +require 'digest/sha1' # fill in the db from a local git clone task :preindex => :environment do + ActiveRecord::Base.logger.level = Logger::WARN + template_dir = File.join(Rails.root, 'templates') repo = ENV['GIT_REPO'] || 'git/git' rerun = false + blob_content = Hash.new do |blobs, sha| + content = Base64.decode64( Octokit.blob( repo, sha, :encoding => 'base64' ).content ) + blobs[sha] = content.encode( 'utf-8', :undef => :replace ) + end + # find all tags tags = Octokit.tags( repo ).select { |tag| tag.name =~ /^v1[\d\.]+$/ } # just get release tags @@ -25,7 +33,7 @@ task :preindex => :environment do commit_info = Octokit.commit( repo, tag.name ) commit_sha = commit_info.sha tree_sha = commit_info.commit.tree.sha - ts = Time.parse( commit_info.commit.committer.date ).to_i + ts = Time.parse( commit_info.commit.committer.date ) # save metadata puts "#{tag.name}: #{ts}, #{commit_sha[0, 8]}, #{tree_sha[0, 8]}" @@ -41,11 +49,6 @@ task :preindex => :environment do puts "Found #{doc_files.size} entries" - blob_content = Hash.new do |docs, sha| - content = Base64.decode64( Octokit.blob( repo, sha, :encoding => 'base64' ).content ) - content.encode( 'utf-8', :undef => :replace ) - end - # Generate this tag's command list for includes if cmd_file = tag_files.detect { |ent| ent.path == 'command-list.txt' } commands = blob_content[cmd_file.sha] @@ -77,28 +80,31 @@ task :preindex => :environment do doc_files.each do |entry| path = File.basename( entry.path, '.txt' ) file = DocFile.where(:name => path).first_or_create - doc = Doc.where(:blob_sha => entry.sha).first_or_create - if !doc.plain || !doc.html - content = blob_content[entry.sha] - asciidoc = Asciidoc::Document.new(path, content) do |inc| - if categories.has_key?(inc) - categories[inc] + + content = blob_content[entry.sha] + asciidoc = Asciidoc::Document.new(path, content) do |inc| + if categories.has_key?(inc) + categories[inc] + else + if match = inc.match(/^\.\.\/(.*)$/) + git_path = match[1] else - if match = inc.match(/^\.\.\/(.*)$/) - git_path = match[1] - else - git_path = "Documentation/#{inc}" - end - - if inc_file = tag_files.detect { |f| f.path == git_path } - blob_content[inc_file.sha] - else - '' - end + git_path = "Documentation/#{inc}" + end + + if inc_file = tag_files.detect { |f| f.path == git_path } + blob_content[inc_file.sha] + else + '' end end + end + asciidoc_sha = Digest::SHA1.hexdigest( asciidoc.source ) + + doc = Doc.where( :blob_sha => asciidoc_sha ).first_or_create + if !doc.plain || !doc.html doc.plain = asciidoc.source - doc.html = asciidoc.render(template_dir) + 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 diff --git a/templates/section_note.html.erb b/templates/section_note.html.erb new file mode 100644 index 00000000..1a3ec74d --- /dev/null +++ b/templates/section_note.html.erb @@ -0,0 +1,8 @@ +<div class="admonitionblock"> + <table> + <tr> + <td class="icon"><div class="title">Note</div></td> + <td class="content"><%= content %></td> + </tr> + </table> +</div> |