Skip to content
Newer
Older
100644 197 lines (172 sloc) 4.27 KB
5d5467a @zzak init
authored Feb 24, 2011
1 require 'sinatra'
2 require 'rdiscount'
3 require 'erb'
4 require 'sass'
5
94c20a7 @rkh proper page caching, based on git commit
rkh authored Feb 26, 2011
6 configure :production do
7 sha1, date = `git log HEAD~1..HEAD --pretty=format:%h^%ci`.strip.split('^')
8
9 require 'rack/cache'
10 use Rack::Cache
11
12 before do
eedff39 @zzak add a max_age to cache_control
authored Feb 26, 2011
13 cache_control :public, :must_revalidate, :max_age=>300
94c20a7 @rkh proper page caching, based on git commit
rkh authored Feb 26, 2011
14 etag sha1
15 last_modified date
16 end
17 end
18
48c3611 @rkh use markdown helper method, switch to sinatra 1.2, prevent access to …
rkh authored Feb 26, 2011
19 set :markdown, :layout_engine => :erb
20 set :views, File.dirname(__FILE__)
21
5d5467a @zzak init
authored Feb 25, 2011
22 before do
90ec353 @zzak better menu, children menu under topic
authored Sep 11, 2012
23 @menu = Dir.glob("./*/").map do |file|
906dcbe @zzak oops, skip log too
authored Sep 11, 2012
24 next if file =~ /tmp/ or file =~ /log/
90ec353 @zzak better menu, children menu under topic
authored Sep 11, 2012
25 file.split('/')[1]
26 end.compact.sort
5d5467a @zzak init
authored Feb 25, 2011
27 end
28
29 get '/' do
48c3611 @rkh use markdown helper method, switch to sinatra 1.2, prevent access to …
rkh authored Feb 26, 2011
30 markdown :README
5d5467a @zzak init
authored Feb 25, 2011
31 end
32
33 get '/p/:topic' do
48c3611 @rkh use markdown helper method, switch to sinatra 1.2, prevent access to …
rkh authored Feb 26, 2011
34 pass if params[:topic] == '..'
90ec353 @zzak better menu, children menu under topic
authored Sep 11, 2012
35 @readme = true
36 @children = Dir.glob("./#{params[:topic]}/*.md").map do |file|
37 next if file =~ /README/
38 next if file.empty? or file.nil?
39 file.split('/')[-1].sub(/\.md$/, '')
40 end.compact.sort
97eedd4 @zzak remove javascript load_article() and permalinks so real urls can be u…
authored May 20, 2012
41 markdown :"#{params[:topic]}/README"
5d5467a @zzak init
authored Feb 25, 2011
42 end
43
44 get '/p/:topic/:article' do
48c3611 @rkh use markdown helper method, switch to sinatra 1.2, prevent access to …
rkh authored Feb 26, 2011
45 pass if params[:topic] == '..'
97eedd4 @zzak remove javascript load_article() and permalinks so real urls can be u…
authored May 20, 2012
46 markdown :"#{params[:topic]}/#{params[:article]}"
5d5467a @zzak init
authored Feb 25, 2011
47 end
48
49 get '/style.css' do
50 sass :style
51 end
52
53 __END__
54
55 @@ layout
94c20a7 @rkh proper page caching, based on git commit
rkh authored Feb 26, 2011
56 <!DOCTYPE html>
57 <html>
58 <head>
59 <meta charset='utf-8'>
5d5467a @zzak init
authored Feb 25, 2011
60 <meta http-equiv="X-UA-Compatible" content="chrome=1">
9c25adb @zzak s/book-contrib/recipes
authored Sep 17, 2011
61 <title>Sinatra Recipes</title>
5d5467a @zzak init
authored Feb 25, 2011
62 <link rel="stylesheet" type="text/css" href="/style.css" />
9284663 @zzak use favicon
authored Sep 7, 2012
63 <link rel="shortcut icon" href="https://github.com/sinatra/resources/raw/master/logo/favicon.ico">
f1139a0 @jacaetevha add placholder for Mongo models page; change formatting of Databases>…
jacaetevha authored Feb 26, 2011
64 <script
65 type='text/javascript'
66 src='https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js'>
67 </script>
5d5467a @zzak init
authored Feb 25, 2011
68 </head>
69 <body>
4a03461 @jacaetevha add an anchor to the top of the page so that articles can bounce back…
jacaetevha authored Feb 26, 2011
70 <a name='top' />
94c20a7 @rkh proper page caching, based on git commit
rkh authored Feb 26, 2011
71 <div id="header">
5d5467a @zzak init
authored Feb 25, 2011
72 <h2>Community contributed recipes and techniques</h2>
73 <h1><a href="/">
b4cc466 @zzak update logo sinatra/sinatra-recipes#28
authored May 20, 2012
74 <img src="https://github.com/sinatra/resources/raw/master/logo/sinatra-classic-156.png" />
9c25adb @zzak s/book-contrib/recipes
authored Sep 17, 2011
75 Sinatra Recipes
5d5467a @zzak init
authored Feb 25, 2011
76 </a></h1>
94c20a7 @rkh proper page caching, based on git commit
rkh authored Feb 26, 2011
77 </div>
5d5467a @zzak init
authored Feb 25, 2011
78 <div id="menu">
79 <ul>
90ec353 @zzak better menu, children menu under topic
authored Sep 11, 2012
80 <% @menu.each do |me| %>
f1139a0 @jacaetevha add placholder for Mongo models page; change formatting of Databases>…
jacaetevha authored Feb 26, 2011
81 <li>
97eedd4 @zzak remove javascript load_article() and permalinks so real urls can be u…
authored May 20, 2012
82 <a href='/p/<%= "#{me}" %>'>
90ec353 @zzak better menu, children menu under topic
authored Sep 11, 2012
83 <%= me.capitalize.sub('_', ' ') %>
f1139a0 @jacaetevha add placholder for Mongo models page; change formatting of Databases>…
jacaetevha authored Feb 26, 2011
84 </a>
90ec353 @zzak better menu, children menu under topic
authored Sep 11, 2012
85 </li>
5d5467a @zzak init
authored Feb 25, 2011
86 <% end %>
87 </ul>
88 </div>
89 <div id="content">
e6be638 @zzak dont use layout if request is xhr, on success update permalink too
authored Feb 27, 2011
90 <div id="post">
91 <%= yield %>
90ec353 @zzak better menu, children menu under topic
authored Sep 11, 2012
92 <% if @children %>
93 <div id="children">
94 <ul>
95 <% @children.each do |child| %>
96 <li>
97 <a href='/p/<%= "#{params[:topic]}/#{child}" %>'>
98 <%= child.capitalize.sub('_', ' ') %>
99 </a>
100 </li>
101 <% end %>
102 </ul>
103 </div>
104 <% end %>
105
106 <% if @readme %>
fc7dfab @zzak better formatting for children
authored Sep 11, 2012
107 <div id="footer">
108 <h2>Did we miss something?</h2>
109 <p>It's very possible we've left something out, thats why we need your help! This
110 is a community driven project after all. Feel free to fork the project and send
111 us a pull request to get your recipe or tutorial included in the book.</p>
112 <p>See the <a href="http://github.com/sinatra/recipes/blob/master/README.md">README</a> for more details.</p>
113 </div>
90ec353 @zzak better menu, children menu under topic
authored Sep 11, 2012
114 <% end %>
e6be638 @zzak dont use layout if request is xhr, on success update permalink too
authored Feb 27, 2011
115 </div>
94c20a7 @rkh proper page caching, based on git commit
rkh authored Feb 26, 2011
116 </div>
5d5467a @zzak init
authored Feb 25, 2011
117
9c25adb @zzak s/book-contrib/recipes
authored Sep 17, 2011
118 <a href="http://github.com/sinatra/sinatra-recipes">
5d5467a @zzak init
authored Feb 25, 2011
119 <img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png" alt="Fork me on GitHub" />
120 </a>
121 </body>
122 </html>
123
124 @@ style
125 body
126 font-family: 'Lucida Grande', Verdana, sans-serif
127 margin: 0 auto
128 max-width: 800px
129
130 h1, h2, h3, h4, h5
131 font-family: georgia, 'bitstream vera serif', serif
132 font-weight: normal
133 font-size: 2em
fc7dfab @zzak better formatting for children
authored Sep 11, 2012
134 line-height: 160%
5d5467a @zzak init
authored Feb 25, 2011
135
136 a:link, a:visited
137 color: #3F3F3F
138
139 a:hover, a:active
140 color: #8F8F8F
141
142 .small
143 font-size: .7em
144
145 #header
146 margin: 10px 0px
fc7dfab @zzak better formatting for children
authored Sep 11, 2012
147 a
148 text-decoration: none
149 h1
150 float: left
151 width: 250px
152 font-size: 2.65em
153 line-height: .75em
154 h2
155 text-align: right
156 font-style: oblique
157 font-size: 1em
158 float: right
159 width: 450px
160 img
161 float: left
162 width: 100px
163 margin-right: 15px
164 border: 0
9c25adb @zzak s/book-contrib/recipes
authored Sep 17, 2011
165
5d5467a @zzak init
authored Feb 25, 2011
166 #menu
94c20a7 @rkh proper page caching, based on git commit
rkh authored Feb 26, 2011
167 float: left
90ec353 @zzak better menu, children menu under topic
authored Sep 11, 2012
168 max-width: 200px
5d5467a @zzak init
authored Feb 25, 2011
169 word-wrap: break-word
170 font-size: .9em
171 clear: left
172
fc7dfab @zzak better formatting for children
authored Sep 11, 2012
173 #children
174 clear: both
175 ul li
176 float: left
177 width: 275px
178 height: 40px
179
5d5467a @zzak init
authored Feb 25, 2011
180 #content
181 float: right
90ec353 @zzak better menu, children menu under topic
authored Sep 11, 2012
182 max-width: 600px
fc7dfab @zzak better formatting for children
authored Sep 11, 2012
183 pre
184 padding: 10px
a01a8ee @zzak width for code
authored Sep 11, 2012
185 max-width: 600px
fc7dfab @zzak better formatting for children
authored Sep 11, 2012
186 overflow: auto
187 overflow-Y: hidden
188 background: #EEE
189 line-height: 100%
5d5467a @zzak init
authored Feb 25, 2011
190
98df954 @jacaetevha added a line-height to posts
jacaetevha authored Mar 5, 2011
191 #post
fc7dfab @zzak better formatting for children
authored Sep 11, 2012
192 line-height: 110%
193
194 #footer
195 clear: both
196 margin-top: 20px
Something went wrong with that request. Please try again.