wbzyl-sinatra-rdiscount 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/app.rb +15 -0
- data/examples/config.ru +9 -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 +32 -0
- data/sinatra-rdiscount.gemspec +14 -3
- data/test/spec_sinatra_rdiscount.rb +0 -0
- metadata +9 -1
data/examples/app.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'sinatra'
|
5
|
+
require 'sinatra/rdiscount'
|
6
|
+
|
7
|
+
get "/hello" do
|
8
|
+
@name = "RDiscount"
|
9
|
+
rdiscount :hello, :layout => false
|
10
|
+
end
|
11
|
+
|
12
|
+
get "/hello2" do
|
13
|
+
@name = "RDiscount"
|
14
|
+
rdiscount :hello2, :layout => :layout2
|
15
|
+
end
|
data/examples/config.ru
ADDED
@@ -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,32 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
|
3
|
+
module Sinatra
|
4
|
+
module RDiscountTemplate
|
5
|
+
|
6
|
+
def rdiscount(template, options={}, locals={})
|
7
|
+
require 'erubis' unless defined? ::Erubis::Eruby
|
8
|
+
require 'rdiscount' unless defined? ::RDiscount
|
9
|
+
render :rdiscount, template, options, locals
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def render_rdiscount(template, data, options, locals, &block)
|
15
|
+
if block_given?
|
16
|
+
# render layout
|
17
|
+
instance = ::Erubis::Eruby.new(data)
|
18
|
+
else
|
19
|
+
# render template
|
20
|
+
markdown = ::RDiscount.new(data)
|
21
|
+
html = markdown.to_html
|
22
|
+
instance = ::Erubis::Eruby.new(html, :pattern => '\{% %\}')
|
23
|
+
end
|
24
|
+
locals_assigns = locals.to_a.collect { |k,v| "#{k} = locals[:#{k}]" }
|
25
|
+
src = "#{locals_assigns.join("\n")}\n#{instance.src}"
|
26
|
+
eval src, binding, '(__ERB__)', locals_assigns.length + 1
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
helpers RDiscountTemplate
|
32
|
+
end
|
data/sinatra-rdiscount.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "sinatra-rdiscount"
|
5
|
-
s.version = '0.0.
|
5
|
+
s.version = '0.0.6'
|
6
6
|
s.date = '2009-03-31'
|
7
7
|
|
8
8
|
s.summary = "RDiscount templates for Sinatra applications"
|
@@ -10,8 +10,19 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = "http://github.com/wbzyl/sinatra-rdiscount"
|
11
11
|
s.description = "RDiscount templates for Sinatra applications"
|
12
12
|
s.authors = ["Włodek Bzyl"]
|
13
|
-
s.files =
|
14
|
-
|
13
|
+
s.files = %w{.gitignore
|
14
|
+
sinatra-rdiscount.gemspec
|
15
|
+
Rakefile
|
16
|
+
README.markdown
|
17
|
+
LICENSE
|
18
|
+
lib/sinatra/rdiscount.rb
|
19
|
+
test/spec_sinatra_rdiscount.rb
|
20
|
+
examples/app.rb
|
21
|
+
examples/config.ru
|
22
|
+
examples/views/layout2.rdiscount
|
23
|
+
examples/views/hello2.rdiscount
|
24
|
+
examples/views/hello.rdiscount
|
25
|
+
examples/public/stylesheets/application.css}
|
15
26
|
|
16
27
|
s.add_dependency 'sinatra', '>=0.9.1'
|
17
28
|
s.add_dependency 'rdiscount', '>=1.3.4'
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wbzyl-sinatra-rdiscount
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "W\xC5\x82odek Bzyl"
|
@@ -56,6 +56,14 @@ files:
|
|
56
56
|
- Rakefile
|
57
57
|
- README.markdown
|
58
58
|
- LICENSE
|
59
|
+
- lib/sinatra/rdiscount.rb
|
60
|
+
- test/spec_sinatra_rdiscount.rb
|
61
|
+
- examples/app.rb
|
62
|
+
- examples/config.ru
|
63
|
+
- examples/views/layout2.rdiscount
|
64
|
+
- examples/views/hello2.rdiscount
|
65
|
+
- examples/views/hello.rdiscount
|
66
|
+
- examples/public/stylesheets/application.css
|
59
67
|
has_rdoc: false
|
60
68
|
homepage: http://github.com/wbzyl/sinatra-rdiscount
|
61
69
|
post_install_message:
|