Skip to content
This repository
Browse code

rake tasks to build a simple website

  • Loading branch information...
commit fe1ed270d0042c53da2a1963d4eceed696933684 1 parent d8a0242
Simon Rozet authored November 02, 2008 rtomayko committed November 02, 2008
6  .gitignore
... ...
@@ -1,6 +1,6 @@
1  
-doc/api
2  
-doc/website/index.html
3  
-doc/website/tmp/*
4 1
 *.log
5 2
 .DS_Store
6 3
 /dist
  4
+/doc/website
  5
+/doc/book
  6
+/doc/api
60  Rakefile
@@ -57,7 +57,7 @@ end
57 57
 
58 58
 # Rubyforge Release / Publish Tasks ==================================
59 59
 
60  
-desc 'Publish API docs to rubyforge'
  60
+desc 'Publish website to rubyforge'
61 61
 task 'publish:doc' => 'doc/api/index.html' do
62 62
   sh 'scp -rp doc/* rubyforge.org:/var/www/gforge-projects/sinatra/'
63 63
 end
@@ -69,6 +69,46 @@ task 'publish:gem' => [package('.gem'), package('.tar.gz')] do |t|
69 69
   end
70 70
 end
71 71
 
  72
+# Website ============================================================
  73
+def rdoc_to_html(file_name)
  74
+  require 'rdoc/markup/to_html'
  75
+  rdoc = RDoc::Markup::ToHtml.new
  76
+  rdoc.convert(File.read(file_name))
  77
+end
  78
+
  79
+def haml(locals={})
  80
+  require 'haml'
  81
+  template = File.read('doc/template.haml')
  82
+  haml = Haml::Engine.new(template, :format => :html4, :attr_wrapper => '"')
  83
+  haml.render(Object.new, locals)
  84
+end
  85
+
  86
+directory 'doc/website'
  87
+
  88
+desc 'Build website'
  89
+task :website => ['doc/website/book.html', 'doc/website/index.html', :doc]
  90
+
  91
+file 'doc/website/index.html' => 'doc/website' do |file|
  92
+  File.open(file.name, 'w') do |file|
  93
+    file << haml(:title => 'Sinatra', :content => rdoc_to_html('README.rdoc'))
  94
+  end
  95
+end
  96
+
  97
+file 'doc/website/book.html' => ['doc/website', :build_book] do |file|
  98
+  File.open(file.name, 'w') do |file|
  99
+    book_content = File.read('doc/book/output/sinatra-book.html')
  100
+    file << haml(:title => 'Sinatra Book', :content => book_content)
  101
+  end
  102
+end
  103
+
  104
+task :build_book do
  105
+  unless File.directory?('doc/book')
  106
+    sh 'git clone git://github.com/cschneid/sinatra-book.git doc/book'
  107
+  end
  108
+  sh 'cd doc/book && git fetch origin && git rebase origin/master'
  109
+  sh 'cd doc/book && thor book:build'
  110
+end
  111
+
72 112
 # Gemspec Helpers ====================================================
73 113
 
74 114
 file 'sinatra.gemspec' => FileList['{lib,test,images}/**','Rakefile'] do |f|
@@ -81,6 +121,7 @@ file 'sinatra.gemspec' => FileList['{lib,test,images}/**','Rakefile'] do |f|
81 121
     split("\n").
82 122
     sort.
83 123
     reject{ |file| file =~ /^\./ }.
  124
+    reject { |file| file =~ /^doc/ }.
84 125
     map{ |file| "    #{file}" }.
85 126
     join("\n")
86 127
   # piece file back together and write...
@@ -96,9 +137,9 @@ end
96 137
 #   gem install mislav-hanna --source=http://gems.github.com
97 138
 
98 139
 desc 'Generate Hanna RDoc under doc/api'
99  
-task :doc => ['doc/api/index.html']
  140
+task :doc => ['doc/website/api/index.html']
100 141
 
101  
-file 'doc/api/index.html' => FileList['lib/**/*.rb','README.rdoc'] do |f|
  142
+file 'doc/website/api/index.html' => FileList['lib/**/*.rb','README.rdoc'] do |f|
102 143
   rb_files = f.prerequisites
103 144
   sh((<<-end).gsub(/\s+/, ' '))
104 145
     rdoc --charset utf8 \
@@ -106,19 +147,10 @@ file 'doc/api/index.html' => FileList['lib/**/*.rb','README.rdoc'] do |f|
106 147
           --inline-source \
107 148
           --line-numbers \
108 149
           --main README.rdoc \
109  
-          --op doc/api \
  150
+          --op doc/website/api \
110 151
           --title 'Sinatra API Documentation' \
111 152
           #{rb_files.join(' ')}
112 153
   end
113 154
 end
114  
-CLEAN.include 'doc/api'
115 155
 
116  
-desc "Generate simple website"
117  
-task :website do
118  
-  `rdoc --force-update -o doc/website/tmp README.rdoc`
119  
-  readme = Hpricot( open("doc/website/tmp/files/README_rdoc.html") ).at('#bodyContent').inner_html
120  
-  # Replace placeholder with Readme content
121  
-  html = File.read("doc/website/index.tpl").sub(Regexp.new(Regexp.escape("{{REPLACE}}")), readme)
122  
-  # TODO: Fix RDoc links
123  
-  File.open( "doc/website/index.html", 'w+' ) { |f| f << html }
124  
-end
  156
+CLEAN.include 'doc/website'
BIN  doc/sinatra-logo.gif
19  doc/template.haml
... ...
@@ -0,0 +1,19 @@
  1
+!!! strict
  2
+%html
  3
+  %head
  4
+    %title= title
  5
+    %link{ :media => 'screen', :type => 'text/css', :href => '/sinatra.css', :rel => 'stylesheet' }
  6
+  %body
  7
+    #page
  8
+      %h1
  9
+        %a{ :href => '/'}= 'Sinatra'
  10
+      %ul#navigation
  11
+        %li
  12
+          %a{ :href => '/' } The Hat
  13
+        %li
  14
+          %a{ :href => '/book' } The Book
  15
+        %li
  16
+          %a{ :href => '/api' } The API
  17
+        %li
  18
+          %a{ :href => 'http://github.com/bmizerany/sinatra' } The Source
  19
+      #content= content

0 notes on commit fe1ed27

Please sign in to comment.
Something went wrong with that request. Please try again.