1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

rake tasks to build a simple website

This commit is contained in:
Simon Rozet 2008-11-02 12:42:25 +01:00 committed by Ryan Tomayko
parent d8a02423e9
commit fe1ed270d0
4 changed files with 68 additions and 17 deletions

6
.gitignore vendored
View file

@ -1,6 +1,6 @@
doc/api
doc/website/index.html
doc/website/tmp/*
*.log
.DS_Store
/dist
/doc/website
/doc/book
/doc/api

View file

@ -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,9 +137,9 @@ 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 \
@ -106,19 +147,10 @@ file 'doc/api/index.html' => FileList['lib/**/*.rb','README.rdoc'] do |f|
--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'

BIN
doc/sinatra-logo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

19
doc/template.haml Normal file
View file

@ -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