Permalink
Browse files

rake tasks to build a simple website

  • Loading branch information...
1 parent d8a0242 commit fe1ed270d0042c53da2a1963d4eceed696933684 @sr sr committed with rtomayko Nov 2, 2008
Showing with 68 additions and 17 deletions.
  1. +3 −3 .gitignore
  2. +46 −14 Rakefile
  3. BIN doc/sinatra-logo.gif
  4. +19 −0 doc/template.haml
View
@@ -1,6 +1,6 @@
-doc/api
-doc/website/index.html
-doc/website/tmp/*
*.log
.DS_Store
/dist
+/doc/website
+/doc/book
+/doc/api
View
@@ -57,7 +57,7 @@ end
# Rubyforge Release / Publish Tasks ==================================
-desc 'Publish API docs to rubyforge'
+desc 'Publish website to rubyforge'
task 'publish:doc' => 'doc/api/index.html' do
sh 'scp -rp doc/* rubyforge.org:/var/www/gforge-projects/sinatra/'
end
@@ -69,6 +69,46 @@ task 'publish:gem' => [package('.gem'), package('.tar.gz')] do |t|
end
end
+# Website ============================================================
+def rdoc_to_html(file_name)
+ require 'rdoc/markup/to_html'
+ rdoc = RDoc::Markup::ToHtml.new
+ rdoc.convert(File.read(file_name))
+end
+
+def haml(locals={})
+ require 'haml'
+ template = File.read('doc/template.haml')
+ haml = Haml::Engine.new(template, :format => :html4, :attr_wrapper => '"')
+ haml.render(Object.new, locals)
+end
+
+directory 'doc/website'
+
+desc 'Build website'
+task :website => ['doc/website/book.html', 'doc/website/index.html', :doc]
+
+file 'doc/website/index.html' => 'doc/website' do |file|
+ File.open(file.name, 'w') do |file|
+ file << haml(:title => 'Sinatra', :content => rdoc_to_html('README.rdoc'))
+ end
+end
+
+file 'doc/website/book.html' => ['doc/website', :build_book] do |file|
+ File.open(file.name, 'w') do |file|
+ book_content = File.read('doc/book/output/sinatra-book.html')
+ file << haml(:title => 'Sinatra Book', :content => book_content)
+ end
+end
+
+task :build_book do
+ unless File.directory?('doc/book')
+ sh 'git clone git://github.com/cschneid/sinatra-book.git doc/book'
+ end
+ sh 'cd doc/book && git fetch origin && git rebase origin/master'
+ sh 'cd doc/book && thor book:build'
+end
+
# Gemspec Helpers ====================================================
file 'sinatra.gemspec' => FileList['{lib,test,images}/**','Rakefile'] do |f|
@@ -81,6 +121,7 @@ file 'sinatra.gemspec' => FileList['{lib,test,images}/**','Rakefile'] do |f|
split("\n").
sort.
reject{ |file| file =~ /^\./ }.
+ reject { |file| file =~ /^doc/ }.
map{ |file| " #{file}" }.
join("\n")
# piece file back together and write...
@@ -96,29 +137,20 @@ end
# gem install mislav-hanna --source=http://gems.github.com
desc 'Generate Hanna RDoc under doc/api'
-task :doc => ['doc/api/index.html']
+task :doc => ['doc/website/api/index.html']
-file 'doc/api/index.html' => FileList['lib/**/*.rb','README.rdoc'] do |f|
+file 'doc/website/api/index.html' => FileList['lib/**/*.rb','README.rdoc'] do |f|
rb_files = f.prerequisites
sh((<<-end).gsub(/\s+/, ' '))
rdoc --charset utf8 \
--fmt html \
--inline-source \
--line-numbers \
--main README.rdoc \
- --op doc/api \
+ --op doc/website/api \
--title 'Sinatra API Documentation' \
#{rb_files.join(' ')}
end
end
-CLEAN.include 'doc/api'
-desc "Generate simple website"
-task :website do
- `rdoc --force-update -o doc/website/tmp README.rdoc`
- readme = Hpricot( open("doc/website/tmp/files/README_rdoc.html") ).at('#bodyContent').inner_html
- # Replace placeholder with Readme content
- html = File.read("doc/website/index.tpl").sub(Regexp.new(Regexp.escape("{{REPLACE}}")), readme)
- # TODO: Fix RDoc links
- File.open( "doc/website/index.html", 'w+' ) { |f| f << html }
-end
+CLEAN.include 'doc/website'
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,19 @@
+!!! strict
+%html
+ %head
+ %title= title
+ %link{ :media => 'screen', :type => 'text/css', :href => '/sinatra.css', :rel => 'stylesheet' }
+ %body
+ #page
+ %h1
+ %a{ :href => '/'}= 'Sinatra'
+ %ul#navigation
+ %li
+ %a{ :href => '/' } The Hat
+ %li
+ %a{ :href => '/book' } The Book
+ %li
+ %a{ :href => '/api' } The API
+ %li
+ %a{ :href => 'http://github.com/bmizerany/sinatra' } The Source
+ #content= content

0 comments on commit fe1ed27

Please sign in to comment.