sinatra-rdiscount 0.9.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/LICENSE +22 -0
- data/README.markdown +100 -0
- data/Rakefile +33 -0
- data/VERSION.yml +5 -0
- data/examples/app.rb +14 -0
- data/examples/config.ru +4 -0
- data/examples/mapp.rb +16 -0
- data/examples/public/stylesheets/application.css +29 -0
- data/examples/views/hello.rdiscount +4 -0
- data/examples/views/hello2.rdiscount +305 -0
- data/examples/views/layout2.rdiscount +15 -0
- data/lib/sinatra/rdiscount.rb +33 -0
- data/sinatra-rdiscount.gemspec +76 -0
- data/test/sinatra_rdiscount_test.rb +91 -0
- data/test/test_helper.rb +22 -0
- data/test/views/hello.rdiscount +1 -0
- data/test/views/layout2.rdiscount +2 -0
- metadata +125 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2009 Wlodek Bzyl
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# Sinatra RDiscount Extension for Sinatra v0.9.4
|
2
|
+
|
3
|
+
The *sinatra-rdiscount* extension provides `rdiscount` helper method
|
4
|
+
for rendering RDiscount templates.
|
5
|
+
|
6
|
+
To install it, run:
|
7
|
+
|
8
|
+
sudo gem install -v0.9.4.0 sinatra-rdiscount -s http://gemcutter.com
|
9
|
+
|
10
|
+
To test it, create a simple Sinatra application:
|
11
|
+
|
12
|
+
# app.rb
|
13
|
+
require 'rubygems'
|
14
|
+
require 'sinatra'
|
15
|
+
|
16
|
+
require 'sinatra/rdiscount'
|
17
|
+
|
18
|
+
get "/" do
|
19
|
+
rdiscount "# Hello RDiscount"
|
20
|
+
end
|
21
|
+
|
22
|
+
and run it with:
|
23
|
+
|
24
|
+
ruby app.rb
|
25
|
+
|
26
|
+
The result could be seen at *http://localhost:4567*.
|
27
|
+
|
28
|
+
Another example could be find in the *examples* directory. Run it with:
|
29
|
+
|
30
|
+
rackup -p 4567 config.ru
|
31
|
+
|
32
|
+
|
33
|
+
## Template Languages (*update to The Sinatra Book*)
|
34
|
+
|
35
|
+
One important thing to remember is that you always have to reference
|
36
|
+
templates and layouts with **symbols**, even if they’re in a subdirectory,
|
37
|
+
for example `:'subdir/template'`.
|
38
|
+
Rendering methods will render any strings passed to them directly.
|
39
|
+
|
40
|
+
|
41
|
+
### RDiscount Templates
|
42
|
+
|
43
|
+
The following gems are required to render RDiscount templates:
|
44
|
+
*rdiscount*, *erubis*.
|
45
|
+
|
46
|
+
This helper method:
|
47
|
+
|
48
|
+
get '/' do
|
49
|
+
rdiscount :index
|
50
|
+
end
|
51
|
+
|
52
|
+
renders template *./views/index.rdiscount*.
|
53
|
+
|
54
|
+
If a layout named *layout.rdiscount* exists, it will be used each time
|
55
|
+
a template is rendered.
|
56
|
+
|
57
|
+
You can disable layouts by passing `:layout => false`
|
58
|
+
to *rdiscount* helper. For example
|
59
|
+
|
60
|
+
get '/' do
|
61
|
+
rdiscount :index, :layout => false
|
62
|
+
end
|
63
|
+
|
64
|
+
You can set a different layout from the default one with:
|
65
|
+
|
66
|
+
get '/' do
|
67
|
+
rdiscount :index, :layout => :application
|
68
|
+
end
|
69
|
+
|
70
|
+
This renders *./views/index.rdiscount* template
|
71
|
+
within *./views/application.rdiscount* layout.
|
72
|
+
|
73
|
+
|
74
|
+
## Important Info
|
75
|
+
|
76
|
+
Layouts are **RHTML** — not RDiscount — files.
|
77
|
+
Layout example:
|
78
|
+
|
79
|
+
<!DOCTYPE html>
|
80
|
+
<html>
|
81
|
+
<head>
|
82
|
+
<title><%= @title || "My Sinatra App" %></title>
|
83
|
+
</head>
|
84
|
+
<body>
|
85
|
+
<%= yield %>
|
86
|
+
</body>
|
87
|
+
</html>
|
88
|
+
|
89
|
+
Templates are **Markdown** files with ERB insertions delimited
|
90
|
+
by `'{% %}'`. Template example:
|
91
|
+
|
92
|
+
# Hello {%= @name %}
|
93
|
+
|
94
|
+
Such a change in embedded code pattern was necessary,
|
95
|
+
to avoid messing with RDiscount engine,
|
96
|
+
which converts bare `<` to `&lt;`.
|
97
|
+
Also I think that there is no way for RDiscount renderer
|
98
|
+
to generate that line:
|
99
|
+
|
100
|
+
<!DOCTYPE html>
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require "rake/clean"
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "sinatra-rdiscount"
|
9
|
+
gem.summary = "Sinatra extension providing RDiscount templates for Sinatra application."
|
10
|
+
gem.email = "matwb@univ.gda.pl"
|
11
|
+
gem.homepage = "http://github.com/wbzyl/sinatra-rdiscount"
|
12
|
+
gem.description = gem.summary
|
13
|
+
gem.authors = ["Wlodek Bzyl"]
|
14
|
+
|
15
|
+
gem.add_runtime_dependency 'sinatra', '=0.9.4'
|
16
|
+
gem.add_runtime_dependency 'erubis', '>=2.6.5'
|
17
|
+
gem.add_runtime_dependency 'rdiscount', '>=1.5.8'
|
18
|
+
|
19
|
+
gem.add_development_dependency 'rack', '>=1.1.0'
|
20
|
+
gem.add_development_dependency 'rack-test', '>=0.5.3'
|
21
|
+
end
|
22
|
+
Jeweler::GemcutterTasks.new
|
23
|
+
rescue LoadError
|
24
|
+
puts "Jeweler not available."
|
25
|
+
puts "Install it with:"
|
26
|
+
puts " sudo gem install jeweler"
|
27
|
+
end
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'lib' << 'test'
|
31
|
+
t.pattern = 'test/**/*_test.rb'
|
32
|
+
t.verbose = false
|
33
|
+
end
|
data/VERSION.yml
ADDED
data/examples/app.rb
ADDED
data/examples/config.ru
ADDED
data/examples/mapp.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'rack'
|
4
|
+
require 'sinatra/base'
|
5
|
+
|
6
|
+
require 'sinatra/rdiscount'
|
7
|
+
|
8
|
+
class MApp < Sinatra::Base
|
9
|
+
helpers Sinatra::RDiscount
|
10
|
+
|
11
|
+
get '/?' do
|
12
|
+
rdiscount "## hello form modular app"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Rack::Handler::Thin.run MApp.new, :Port => 4567
|
@@ -0,0 +1,29 @@
|
|
1
|
+
html {
|
2
|
+
margin: 0;
|
3
|
+
padding: 0;
|
4
|
+
background-color: #0C7D85;
|
5
|
+
line-height: 1.6;
|
6
|
+
}
|
7
|
+
|
8
|
+
body {
|
9
|
+
margin: 1em auto 1em auto;
|
10
|
+
padding: 1em 2em 2em 1em;
|
11
|
+
width: 760px;
|
12
|
+
border: 1px solid black;
|
13
|
+
background-color: #E8DDCB;
|
14
|
+
}
|
15
|
+
|
16
|
+
pre {
|
17
|
+
padding: 0.5em 0 0.5em 2em;
|
18
|
+
background-color: #D7D3C1;
|
19
|
+
}
|
20
|
+
|
21
|
+
h1, h2, h3 {
|
22
|
+
color: #0C7D85;
|
23
|
+
}
|
24
|
+
|
25
|
+
/* rdiscount comments */
|
26
|
+
|
27
|
+
h6 {
|
28
|
+
display: none;
|
29
|
+
}
|
@@ -0,0 +1,305 @@
|
|
1
|
+
###### {% @title = "Sinatra is Awesome!" %}
|
2
|
+
|
3
|
+
Hello {%= @name %}: Markdown Basics
|
4
|
+
===================================
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
|
8
|
+
<li><a class="selected" title="Markdown Basics">Basics</a></li>
|
9
|
+
<li><a href="/projects/markdown/syntax" title="Markdown Syntax Documentation">Syntax</a></li>
|
10
|
+
<li><a href="/projects/markdown/license" title="Pricing and License Information">License</a></li>
|
11
|
+
<li><a href="/projects/markdown/dingus" title="Online Markdown Web Form">Dingus</a></li>
|
12
|
+
</ul>
|
13
|
+
|
14
|
+
|
15
|
+
Getting the Gist of Markdown's Formatting Syntax
|
16
|
+
------------------------------------------------
|
17
|
+
|
18
|
+
This page offers a brief overview of what it's like to use Markdown.
|
19
|
+
The [syntax page] [s] provides complete, detailed documentation for
|
20
|
+
every feature, but Markdown should be very easy to pick up simply by
|
21
|
+
looking at a few examples of it in action. The examples on this page
|
22
|
+
are written in a before/after style, showing example syntax and the
|
23
|
+
HTML output produced by Markdown.
|
24
|
+
|
25
|
+
It's also helpful to simply try Markdown out; the [Dingus] [d] is a
|
26
|
+
web application that allows you type your own Markdown-formatted text
|
27
|
+
and translate it to XHTML.
|
28
|
+
|
29
|
+
[s]: /projects/markdown/syntax "Markdown Syntax"
|
30
|
+
[d]: /projects/markdown/dingus "Markdown Dingus"
|
31
|
+
[src]: /projects/markdown/basics.text
|
32
|
+
|
33
|
+
|
34
|
+
## Paragraphs, Headers, Blockquotes ##
|
35
|
+
|
36
|
+
A paragraph is simply one or more consecutive lines of text, separated
|
37
|
+
by one or more blank lines. (A blank line is any line that looks like a
|
38
|
+
blank line -- a line containing nothing spaces or tabs is considered
|
39
|
+
blank.) Normal paragraphs should not be intended with spaces or tabs.
|
40
|
+
|
41
|
+
Markdown offers two styles of headers: *Setext* and *atx*.
|
42
|
+
Setext-style headers for `<h1>` and `<h2>` are created by
|
43
|
+
"underlining" with equal signs (`=`) and hyphens (`-`), respectively.
|
44
|
+
To create an atx-style header, you put 1-6 hash marks (`#`) at the
|
45
|
+
beginning of the line -- the number of hashes equals the resulting
|
46
|
+
HTML header level.
|
47
|
+
|
48
|
+
Blockquotes are indicated using email-style '`>`' angle brackets.
|
49
|
+
|
50
|
+
Markdown:
|
51
|
+
|
52
|
+
A First Level Header
|
53
|
+
====================
|
54
|
+
|
55
|
+
A Second Level Header
|
56
|
+
---------------------
|
57
|
+
|
58
|
+
Now is the time for all good men to come to
|
59
|
+
the aid of their country. This is just a
|
60
|
+
regular paragraph.
|
61
|
+
|
62
|
+
The quick brown fox jumped over the lazy
|
63
|
+
dog's back.
|
64
|
+
|
65
|
+
### Header 3
|
66
|
+
|
67
|
+
> This is a blockquote.
|
68
|
+
>
|
69
|
+
> This is the second paragraph in the blockquote.
|
70
|
+
>
|
71
|
+
> ## This is an H2 in a blockquote
|
72
|
+
|
73
|
+
|
74
|
+
Output:
|
75
|
+
|
76
|
+
<h1>A First Level Header</h1>
|
77
|
+
|
78
|
+
<h2>A Second Level Header</h2>
|
79
|
+
|
80
|
+
<p>Now is the time for all good men to come to
|
81
|
+
the aid of their country. This is just a
|
82
|
+
regular paragraph.</p>
|
83
|
+
|
84
|
+
<p>The quick brown fox jumped over the lazy
|
85
|
+
dog's back.</p>
|
86
|
+
|
87
|
+
<h3>Header 3</h3>
|
88
|
+
|
89
|
+
<blockquote>
|
90
|
+
<p>This is a blockquote.</p>
|
91
|
+
|
92
|
+
<p>This is the second paragraph in the blockquote.</p>
|
93
|
+
|
94
|
+
<h2>This is an H2 in a blockquote</h2>
|
95
|
+
</blockquote>
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
### Phrase Emphasis ###
|
100
|
+
|
101
|
+
Markdown uses asterisks and underscores to indicate spans of emphasis.
|
102
|
+
|
103
|
+
Markdown:
|
104
|
+
|
105
|
+
Some of these words *are emphasized*.
|
106
|
+
Some of these words _are emphasized also_.
|
107
|
+
|
108
|
+
Use two asterisks for **strong emphasis**.
|
109
|
+
Or, if you prefer, __use two underscores instead__.
|
110
|
+
|
111
|
+
Output:
|
112
|
+
|
113
|
+
<p>Some of these words <em>are emphasized</em>.
|
114
|
+
Some of these words <em>are emphasized also</em>.</p>
|
115
|
+
|
116
|
+
<p>Use two asterisks for <strong>strong emphasis</strong>.
|
117
|
+
Or, if you prefer, <strong>use two underscores instead</strong>.</p>
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
## Lists ##
|
122
|
+
|
123
|
+
Unordered (bulleted) lists use asterisks, pluses, and hyphens (`*`,
|
124
|
+
`+`, and `-`) as list markers. These three markers are
|
125
|
+
interchangable; this:
|
126
|
+
|
127
|
+
* Candy.
|
128
|
+
* Gum.
|
129
|
+
* Booze.
|
130
|
+
|
131
|
+
this:
|
132
|
+
|
133
|
+
+ Candy.
|
134
|
+
+ Gum.
|
135
|
+
+ Booze.
|
136
|
+
|
137
|
+
and this:
|
138
|
+
|
139
|
+
- Candy.
|
140
|
+
- Gum.
|
141
|
+
- Booze.
|
142
|
+
|
143
|
+
all produce the same output:
|
144
|
+
|
145
|
+
<ul>
|
146
|
+
<li>Candy.</li>
|
147
|
+
<li>Gum.</li>
|
148
|
+
<li>Booze.</li>
|
149
|
+
</ul>
|
150
|
+
|
151
|
+
Ordered (numbered) lists use regular numbers, followed by periods, as
|
152
|
+
list markers:
|
153
|
+
|
154
|
+
1. Red
|
155
|
+
2. Green
|
156
|
+
3. Blue
|
157
|
+
|
158
|
+
Output:
|
159
|
+
|
160
|
+
<ol>
|
161
|
+
<li>Red</li>
|
162
|
+
<li>Green</li>
|
163
|
+
<li>Blue</li>
|
164
|
+
</ol>
|
165
|
+
|
166
|
+
If you put blank lines between items, you'll get `<p>` tags for the
|
167
|
+
list item text. You can create multi-paragraph list items by indenting
|
168
|
+
the paragraphs by 4 spaces or 1 tab:
|
169
|
+
|
170
|
+
* A list item.
|
171
|
+
|
172
|
+
With multiple paragraphs.
|
173
|
+
|
174
|
+
* Another item in the list.
|
175
|
+
|
176
|
+
Output:
|
177
|
+
|
178
|
+
<ul>
|
179
|
+
<li><p>A list item.</p>
|
180
|
+
<p>With multiple paragraphs.</p></li>
|
181
|
+
<li><p>Another item in the list.</p></li>
|
182
|
+
</ul>
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
### Links ###
|
187
|
+
|
188
|
+
Markdown supports two styles for creating links: *inline* and
|
189
|
+
*reference*. With both styles, you use square brackets to delimit the
|
190
|
+
text you want to turn into a link.
|
191
|
+
|
192
|
+
Inline-style links use parentheses immediately after the link text.
|
193
|
+
For example:
|
194
|
+
|
195
|
+
This is an [example link](http://example.com/).
|
196
|
+
|
197
|
+
Output:
|
198
|
+
|
199
|
+
<p>This is an <a href="http://example.com/">
|
200
|
+
example link</a>.</p>
|
201
|
+
|
202
|
+
Optionally, you may include a title attribute in the parentheses:
|
203
|
+
|
204
|
+
This is an [example link](http://example.com/ "With a Title").
|
205
|
+
|
206
|
+
Output:
|
207
|
+
|
208
|
+
<p>This is an <a href="http://example.com/" title="With a Title">
|
209
|
+
example link</a>.</p>
|
210
|
+
|
211
|
+
Reference-style links allow you to refer to your links by names, which
|
212
|
+
you define elsewhere in your document:
|
213
|
+
|
214
|
+
I get 10 times more traffic from [Google][1] than from
|
215
|
+
[Yahoo][2] or [MSN][3].
|
216
|
+
|
217
|
+
[1]: http://google.com/ "Google"
|
218
|
+
[2]: http://search.yahoo.com/ "Yahoo Search"
|
219
|
+
[3]: http://search.msn.com/ "MSN Search"
|
220
|
+
|
221
|
+
Output:
|
222
|
+
|
223
|
+
<p>I get 10 times more traffic from <a href="http://google.com/"
|
224
|
+
title="Google">Google</a> than from <a href="http://search.yahoo.com/"
|
225
|
+
title="Yahoo Search">Yahoo</a> or <a href="http://search.msn.com/"
|
226
|
+
title="MSN Search">MSN</a>.</p>
|
227
|
+
|
228
|
+
The title attribute is optional. Link names may contain letters,
|
229
|
+
numbers and spaces, but are *not* case sensitive:
|
230
|
+
|
231
|
+
I start my morning with a cup of coffee and
|
232
|
+
[The New York Times][NY Times].
|
233
|
+
|
234
|
+
[ny times]: http://www.nytimes.com/
|
235
|
+
|
236
|
+
Output:
|
237
|
+
|
238
|
+
<p>I start my morning with a cup of coffee and
|
239
|
+
<a href="http://www.nytimes.com/">The New York Times</a>.</p>
|
240
|
+
|
241
|
+
|
242
|
+
### Images ###
|
243
|
+
|
244
|
+
Image syntax is very much like link syntax.
|
245
|
+
|
246
|
+
Inline (titles are optional):
|
247
|
+
|
248
|
+
![alt text](/path/to/img.jpg "Title")
|
249
|
+
|
250
|
+
Reference-style:
|
251
|
+
|
252
|
+
![alt text][id]
|
253
|
+
|
254
|
+
[id]: /path/to/img.jpg "Title"
|
255
|
+
|
256
|
+
Both of the above examples produce the same output:
|
257
|
+
|
258
|
+
<img src="/path/to/img.jpg" alt="alt text" title="Title" />
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
### Code ###
|
263
|
+
|
264
|
+
In a regular paragraph, you can create code span by wrapping text in
|
265
|
+
backtick quotes. Any ampersands (`&`) and angle brackets (`<` or
|
266
|
+
`>`) will automatically be translated into HTML entities. This makes
|
267
|
+
it easy to use Markdown to write about HTML example code:
|
268
|
+
|
269
|
+
I strongly recommend against using any `<blink>` tags.
|
270
|
+
|
271
|
+
I wish SmartyPants used named entities like `—`
|
272
|
+
instead of decimal-encoded entites like `—`.
|
273
|
+
|
274
|
+
Output:
|
275
|
+
|
276
|
+
<p>I strongly recommend against using any
|
277
|
+
<code><blink></code> tags.</p>
|
278
|
+
|
279
|
+
<p>I wish SmartyPants used named entities like
|
280
|
+
<code>&mdash;</code> instead of decimal-encoded
|
281
|
+
entites like <code>&#8212;</code>.</p>
|
282
|
+
|
283
|
+
|
284
|
+
To specify an entire block of pre-formatted code, indent every line of
|
285
|
+
the block by 4 spaces or 1 tab. Just like with code spans, `&`, `<`,
|
286
|
+
and `>` characters will be escaped automatically.
|
287
|
+
|
288
|
+
Markdown:
|
289
|
+
|
290
|
+
If you want your page to validate under XHTML 1.0 Strict,
|
291
|
+
you've got to put paragraph tags in your blockquotes:
|
292
|
+
|
293
|
+
<blockquote>
|
294
|
+
<p>For example.</p>
|
295
|
+
</blockquote>
|
296
|
+
|
297
|
+
Output:
|
298
|
+
|
299
|
+
<p>If you want your page to validate under XHTML 1.0 Strict,
|
300
|
+
you've got to put paragraph tags in your blockquotes:</p>
|
301
|
+
|
302
|
+
<pre><code><blockquote>
|
303
|
+
<p>For example.</p>
|
304
|
+
</blockquote>
|
305
|
+
</code></pre>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" http://www.w3.org/TR/html4/strict.dtd">
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
5
|
+
<link rel="stylesheet" href="/stylesheets/application.css"
|
6
|
+
type="text/css" media="screen" charset="utf-8">
|
7
|
+
<title><%= @title || "My Sinatra App" %></title>
|
8
|
+
</head>
|
9
|
+
|
10
|
+
<body>
|
11
|
+
|
12
|
+
<%= yield %>
|
13
|
+
|
14
|
+
</body>
|
15
|
+
</html>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'erubis'
|
2
|
+
require 'rdiscount'
|
3
|
+
|
4
|
+
require 'sinatra/base'
|
5
|
+
|
6
|
+
module Sinatra
|
7
|
+
module RDiscount
|
8
|
+
|
9
|
+
def rdiscount(template, options={}, locals={})
|
10
|
+
render :rdiscount, template, options, locals
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def render_rdiscount(template, data, options, locals, &block)
|
16
|
+
if block_given?
|
17
|
+
# render layout
|
18
|
+
instance = ::Erubis::Eruby.new(data)
|
19
|
+
else
|
20
|
+
# render template
|
21
|
+
markdown = ::RDiscount.new(data)
|
22
|
+
html = markdown.to_html
|
23
|
+
instance = ::Erubis::Eruby.new(html, :pattern => '\{% %\}')
|
24
|
+
end
|
25
|
+
locals_assigns = locals.to_a.collect { |k,v| "#{k} = locals[:#{k}]" }
|
26
|
+
src = "#{locals_assigns.join("\n")}\n#{instance.src}"
|
27
|
+
eval src, binding, '(__ERB__)', locals_assigns.length + 1
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
helpers RDiscount
|
33
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{sinatra-rdiscount}
|
8
|
+
s.version = "0.9.4.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Wlodek Bzyl"]
|
12
|
+
s.date = %q{2010-02-08}
|
13
|
+
s.description = %q{Sinatra extension providing RDiscount templates for Sinatra application.}
|
14
|
+
s.email = %q{matwb@univ.gda.pl}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.markdown",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION.yml",
|
25
|
+
"examples/app.rb",
|
26
|
+
"examples/config.ru",
|
27
|
+
"examples/mapp.rb",
|
28
|
+
"examples/public/stylesheets/application.css",
|
29
|
+
"examples/views/hello.rdiscount",
|
30
|
+
"examples/views/hello2.rdiscount",
|
31
|
+
"examples/views/layout2.rdiscount",
|
32
|
+
"lib/sinatra/rdiscount.rb",
|
33
|
+
"sinatra-rdiscount.gemspec",
|
34
|
+
"test/sinatra_rdiscount_test.rb",
|
35
|
+
"test/test_helper.rb",
|
36
|
+
"test/views/hello.rdiscount",
|
37
|
+
"test/views/layout2.rdiscount"
|
38
|
+
]
|
39
|
+
s.homepage = %q{http://github.com/wbzyl/sinatra-rdiscount}
|
40
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = %q{1.3.5}
|
43
|
+
s.summary = %q{Sinatra extension providing RDiscount templates for Sinatra application.}
|
44
|
+
s.test_files = [
|
45
|
+
"test/test_helper.rb",
|
46
|
+
"test/sinatra_rdiscount_test.rb",
|
47
|
+
"examples/mapp.rb",
|
48
|
+
"examples/app.rb"
|
49
|
+
]
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
53
|
+
s.specification_version = 3
|
54
|
+
|
55
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_runtime_dependency(%q<sinatra>, ["= 0.9.4"])
|
57
|
+
s.add_runtime_dependency(%q<erubis>, [">= 2.6.5"])
|
58
|
+
s.add_runtime_dependency(%q<rdiscount>, [">= 1.5.8"])
|
59
|
+
s.add_development_dependency(%q<rack>, [">= 1.1.0"])
|
60
|
+
s.add_development_dependency(%q<rack-test>, [">= 0.5.3"])
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<sinatra>, ["= 0.9.4"])
|
63
|
+
s.add_dependency(%q<erubis>, [">= 2.6.5"])
|
64
|
+
s.add_dependency(%q<rdiscount>, [">= 1.5.8"])
|
65
|
+
s.add_dependency(%q<rack>, [">= 1.1.0"])
|
66
|
+
s.add_dependency(%q<rack-test>, [">= 0.5.3"])
|
67
|
+
end
|
68
|
+
else
|
69
|
+
s.add_dependency(%q<sinatra>, ["= 0.9.4"])
|
70
|
+
s.add_dependency(%q<erubis>, [">= 2.6.5"])
|
71
|
+
s.add_dependency(%q<rdiscount>, [">= 1.5.8"])
|
72
|
+
s.add_dependency(%q<rack>, [">= 1.1.0"])
|
73
|
+
s.add_dependency(%q<rack-test>, [">= 0.5.3"])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class SinatraRDiscountTest < Test::Unit::TestCase
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
def rdiscount_app(&block)
|
7
|
+
mock_app {
|
8
|
+
set :views, File.dirname(__FILE__) + '/views'
|
9
|
+
helpers Sinatra::RDiscount
|
10
|
+
set :show_exceptions, false
|
11
|
+
get '/', &block
|
12
|
+
}
|
13
|
+
get '/'
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_renders_inline_strings
|
17
|
+
rdiscount_app { rdiscount 'hello world' }
|
18
|
+
assert last_response.ok?
|
19
|
+
assert_equal "<p>hello world</p>\n", last_response.body
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_renders_inline_erb_string
|
23
|
+
rdiscount_app { rdiscount '{%= 1 + 1 %}' }
|
24
|
+
assert last_response.ok?
|
25
|
+
assert_equal "<p>2</p>\n", last_response.body
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_renders_files_in_views_path
|
29
|
+
rdiscount_app { rdiscount :hello }
|
30
|
+
assert last_response.ok?
|
31
|
+
assert_equal "<h1>hello world</h1>\n", last_response.body
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_takes_locals_option
|
35
|
+
rdiscount_app {
|
36
|
+
locals = {:foo => 'Bar'}
|
37
|
+
rdiscount "{%= foo %}", :locals => locals
|
38
|
+
}
|
39
|
+
assert last_response.ok?
|
40
|
+
assert_equal "<p>Bar</p>\n", last_response.body
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_renders_with_inline_layouts
|
44
|
+
rdiscount_app {
|
45
|
+
rdiscount 'Sparta', :layout => 'THIS. IS. <%= yield.upcase %>'
|
46
|
+
}
|
47
|
+
assert last_response.ok?
|
48
|
+
assert_equal "THIS. IS. <P>SPARTA</P>\n", last_response.body
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_renders_with_file_layouts
|
52
|
+
rdiscount_app {
|
53
|
+
rdiscount 'hello world', :layout => :layout2
|
54
|
+
}
|
55
|
+
assert last_response.ok?
|
56
|
+
assert_equal "erb layout\n<p>hello world</p>\n\n", last_response.body
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_renders_erb_with_blocks
|
60
|
+
mock_app {
|
61
|
+
set :views, File.dirname(__FILE__) + '/views'
|
62
|
+
helpers Sinatra::RDiscount
|
63
|
+
|
64
|
+
def container
|
65
|
+
yield
|
66
|
+
end
|
67
|
+
def is;
|
68
|
+
"THIS. IS. SPARTA!"
|
69
|
+
end
|
70
|
+
|
71
|
+
get '/' do
|
72
|
+
rdiscount '{% container do %} {%= is %} {% end %}'
|
73
|
+
end
|
74
|
+
}
|
75
|
+
|
76
|
+
get '/'
|
77
|
+
assert last_response.ok?
|
78
|
+
assert_equal "<p> THIS. IS. SPARTA! </p>\n", last_response.body
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_raises_error_if_template_not_found
|
82
|
+
mock_app {
|
83
|
+
set :views, File.dirname(__FILE__) + '/views'
|
84
|
+
helpers Sinatra::RDiscount
|
85
|
+
set :show_exceptions, false
|
86
|
+
|
87
|
+
get('/') { rdiscount :no_such_template }
|
88
|
+
}
|
89
|
+
assert_raise(Errno::ENOENT) { get('/') }
|
90
|
+
end
|
91
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rack/test'
|
4
|
+
|
5
|
+
path = File.expand_path("../lib" + File.dirname(__FILE__))
|
6
|
+
$:.unshift(path) unless $:.include?(path)
|
7
|
+
|
8
|
+
require 'sinatra/rdiscount'
|
9
|
+
require 'rdiscount'
|
10
|
+
|
11
|
+
class Test::Unit::TestCase
|
12
|
+
include Rack::Test::Methods
|
13
|
+
|
14
|
+
attr_reader :app
|
15
|
+
|
16
|
+
# Sets up a Sinatra::Base subclass defined with the block
|
17
|
+
# given. Used in setup or individual spec methods to establish
|
18
|
+
# the application.
|
19
|
+
def mock_app(base=Sinatra::Base, &block)
|
20
|
+
@app = Sinatra.new(base, &block)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# hello world
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sinatra-rdiscount
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wlodek Bzyl
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-08 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: sinatra
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - "="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.9.4
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: erubis
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.6.5
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rdiscount
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.5.8
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: rack
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.1.0
|
54
|
+
version:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack-test
|
57
|
+
type: :development
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 0.5.3
|
64
|
+
version:
|
65
|
+
description: Sinatra extension providing RDiscount templates for Sinatra application.
|
66
|
+
email: matwb@univ.gda.pl
|
67
|
+
executables: []
|
68
|
+
|
69
|
+
extensions: []
|
70
|
+
|
71
|
+
extra_rdoc_files:
|
72
|
+
- LICENSE
|
73
|
+
- README.markdown
|
74
|
+
files:
|
75
|
+
- .gitignore
|
76
|
+
- LICENSE
|
77
|
+
- README.markdown
|
78
|
+
- Rakefile
|
79
|
+
- VERSION.yml
|
80
|
+
- examples/app.rb
|
81
|
+
- examples/config.ru
|
82
|
+
- examples/mapp.rb
|
83
|
+
- examples/public/stylesheets/application.css
|
84
|
+
- examples/views/hello.rdiscount
|
85
|
+
- examples/views/hello2.rdiscount
|
86
|
+
- examples/views/layout2.rdiscount
|
87
|
+
- lib/sinatra/rdiscount.rb
|
88
|
+
- sinatra-rdiscount.gemspec
|
89
|
+
- test/sinatra_rdiscount_test.rb
|
90
|
+
- test/test_helper.rb
|
91
|
+
- test/views/hello.rdiscount
|
92
|
+
- test/views/layout2.rdiscount
|
93
|
+
has_rdoc: true
|
94
|
+
homepage: http://github.com/wbzyl/sinatra-rdiscount
|
95
|
+
licenses: []
|
96
|
+
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options:
|
99
|
+
- --charset=UTF-8
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: "0"
|
107
|
+
version:
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: "0"
|
113
|
+
version:
|
114
|
+
requirements: []
|
115
|
+
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 1.3.5
|
118
|
+
signing_key:
|
119
|
+
specification_version: 3
|
120
|
+
summary: Sinatra extension providing RDiscount templates for Sinatra application.
|
121
|
+
test_files:
|
122
|
+
- test/test_helper.rb
|
123
|
+
- test/sinatra_rdiscount_test.rb
|
124
|
+
- examples/mapp.rb
|
125
|
+
- examples/app.rb
|