RbST 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 William Melody
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,66 @@
1
+ # RbST
2
+
3
+ A simple Ruby wrapper for processing reStructuredText via
4
+ Python's Docutils.
5
+
6
+ ## Installation
7
+
8
+ Python 2.3+ is required.
9
+
10
+ RbST is available on gemcutter.
11
+
12
+ gem install gemcutter
13
+ gem tumble
14
+ gem install RbST
15
+
16
+ ## Usage
17
+
18
+ require 'RbST'
19
+ ...
20
+ @html = RbST.new('/some/file.rst').to_html
21
+
22
+ This takes the reStructuredText formatted file and converts it to
23
+ HTML. The first argument can be either a file or a string.
24
+
25
+ You can also use the `#convert` class method:
26
+
27
+ puts RbST.convert('/some/file.rst')
28
+
29
+ When no options are passed, the default behavior converts
30
+ reStructuredText to html. Options supported include
31
+ `:cloak_email_addresses` and `:strip_comments`, either of which can
32
+ be simply included as additional arguments.
33
+
34
+ puts RbST.convert(".. a comment", :strip_comments) # => '<div class="document">\n</div>'
35
+
36
+ Document parts can also be specified with the `:parts` option.
37
+
38
+ puts RbST.convert("hello world", :part => :fragment) # => '<p>hello world</p>'
39
+
40
+ By default, RbST uses the `html_body` part.
41
+
42
+ For more information on reStructuredText, see the
43
+ [ReST documentation](http://docutils.sourceforge.net/rst.html).
44
+
45
+ ## Caveats
46
+
47
+ - Docutils is very slow. On my 2.5 GHz Core 2 Duo it takes over
48
+ half a second to convert the test file to HTML, including about 0.2s
49
+ to start up and 0.38s to process the input data.
50
+ - This has only been tested on \*nix systems.
51
+ - Python 3 has not been tested.
52
+
53
+ ## Note on Patches/Pull Requests
54
+
55
+ - Fork the project.
56
+ - Make your feature addition or bug fix.
57
+ - Add tests for it. This is important so I don't break it in a
58
+ future version unintentionally.
59
+ - Commit, do not mess with rakefile, version, or history. (if you
60
+ want to have your own version, that is fine but bump version in a
61
+ commit by itself I can ignore when I pull)
62
+ - Send me a pull request. Bonus points for topic branches.
63
+
64
+ ## Copyright
65
+
66
+ Copyright (c) 2009 William Melody. See LICENSE for details.
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "RbST"
8
+ gem.summary = %Q{A simple Ruby wrapper for processing reStructuredText via Python's Docutils}
9
+ gem.description = %Q{A simple Ruby wrapper for processing reStructuredText via Python's Docutils}
10
+ gem.email = "wmelody@gmail.com"
11
+ gem.homepage = "http://github.com/autodata/rbst"
12
+ gem.authors = ["William Melody"]
13
+ gem.add_development_dependency "thoughtbot-shoulda"
14
+ gem.add_dependency "open4"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ if File.exist?('VERSION')
48
+ version = File.read('VERSION')
49
+ else
50
+ version = ""
51
+ end
52
+
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "RbST #{version}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
@@ -0,0 +1,60 @@
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{RbST}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["William Melody"]
12
+ s.date = %q{2009-11-01}
13
+ s.description = %q{A simple Ruby wrapper for processing reStructuredText via Python's Docutils}
14
+ s.email = %q{wmelody@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.markdown",
24
+ "Rakefile",
25
+ "RbST.gemspec",
26
+ "VERSION",
27
+ "lib/rbst.rb",
28
+ "lib/rst2parts.py",
29
+ "test/files/test.html",
30
+ "test/files/test.rst",
31
+ "test/test_helper.rb",
32
+ "test/test_rbst.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/autodata/rbst}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.5}
38
+ s.summary = %q{A simple Ruby wrapper for processing reStructuredText via Python's Docutils}
39
+ s.test_files = [
40
+ "test/test_helper.rb",
41
+ "test/test_rbst.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
50
+ s.add_runtime_dependency(%q<open4>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
53
+ s.add_dependency(%q<open4>, [">= 0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
57
+ s.add_dependency(%q<open4>, [">= 0"])
58
+ end
59
+ end
60
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,49 @@
1
+ require 'open4'
2
+
3
+ class RbST
4
+
5
+ def self.convert(*args)
6
+ new(*args).convert
7
+ end
8
+
9
+ def initialize(*args)
10
+ target = args.shift
11
+ @target = File.exists?(target) ? File.read(target) : target rescue target
12
+ @options = args
13
+ end
14
+
15
+ def convert
16
+ executable = File.join(File.dirname(__FILE__), 'rst2parts.py')
17
+ execute "python #{executable}" + convert_options
18
+ end
19
+ alias_method :to_s, :convert
20
+
21
+ def to_html
22
+ @options << {:writer_name => :html}
23
+ convert
24
+ end
25
+
26
+ private
27
+
28
+ def execute(command)
29
+ output = ''
30
+ Open4::popen4(command) do |pid, stdin, stdout, stderr|
31
+ stdin.puts @target
32
+ stdin.close
33
+ output = stdout.read.strip
34
+ end
35
+ output
36
+ end
37
+
38
+ def convert_options
39
+ @options.inject('') do |string, opt|
40
+ string + if opt.respond_to?(:each_pair)
41
+ opt.inject('') do |s, (flag, val)|
42
+ s + (flag.to_s.length == 1 ? " -#{flag} #{val}" : " --#{flag}=#{val}")
43
+ end
44
+ else
45
+ opt.to_s.length == 1 ? " -#{opt}" : " --#{opt}"
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env python
2
+
3
+ import sys
4
+ from optparse import OptionParser
5
+ from docutils.core import publish_parts
6
+
7
+ def main():
8
+ p = OptionParser()
9
+
10
+ p.add_option('--cloak_email_addresses', action="store_true", default=False)
11
+ p.add_option('--strip_comments', action="store_true", default=False)
12
+ p.add_option('--writer_name', default="html")
13
+ p.add_option('--part', default="html_body")
14
+
15
+ opts, args = p.parse_args()
16
+
17
+ settings = {
18
+ 'file_insertion_enabled': False,
19
+ 'raw_enabled': False,
20
+ 'cloak_email_addresses': opts.cloak_email_addresses,
21
+ 'strip_comments': opts.strip_comments,
22
+ }
23
+
24
+ if len(args) == 1:
25
+ try:
26
+ content = open(args[0], 'r').read()
27
+ except IOError:
28
+ content = args[0]
29
+ else:
30
+ content = sys.stdin.read()
31
+
32
+ parts = publish_parts(
33
+ source=content,
34
+ settings_overrides=settings,
35
+ writer_name=opts.writer_name,
36
+ )
37
+
38
+ if opts.part in parts:
39
+ return parts[opts.part]
40
+ return ''
41
+
42
+ if __name__ == '__main__':
43
+ print(main())
@@ -0,0 +1,335 @@
1
+ <div class="document" id="the-restructuredtext-cheat-sheet-syntax-reminders">
2
+ <h1 class="title">The <a class="reference external" href="http://docutils.sf.net/rst.html">reStructuredText</a> Cheat Sheet: Syntax Reminders</h1>
3
+ <table class="docinfo" frame="void" rules="none">
4
+ <col class="docinfo-name" />
5
+ <col class="docinfo-content" />
6
+ <tbody valign="top">
7
+ <tr class="field"><th class="docinfo-name">Info:</th><td class="field-body">See &lt;<a class="reference external" href="http://docutils.sf.net/rst.html">http://docutils.sf.net/rst.html</a>&gt; for introductory docs.</td>
8
+ </tr>
9
+ <tr><th class="docinfo-name">Author:</th>
10
+ <td>David Goodger &lt;<a class="reference external" href="mailto:goodger&#64;python.org">goodger&#64;python.org</a>&gt;</td></tr>
11
+ <tr><th class="docinfo-name">Date:</th>
12
+ <td>2006-01-23</td></tr>
13
+ <tr><th class="docinfo-name">Revision:</th>
14
+ <td>4321</td></tr>
15
+ <tr class="field"><th class="docinfo-name">Description:</th><td class="field-body">This is a &quot;docinfo block&quot;, or bibliographic field list</td>
16
+ </tr>
17
+ </tbody>
18
+ </table>
19
+ <div class="section" id="section-structure">
20
+ <h1>Section Structure</h1>
21
+ <p>Section titles are underlined or overlined &amp; underlined.</p>
22
+ </div>
23
+ <div class="section" id="body-elements">
24
+ <h1>Body Elements</h1>
25
+ <p>Grid table:</p>
26
+ <table border="1" class="docutils">
27
+ <colgroup>
28
+ <col width="48%" />
29
+ <col width="52%" />
30
+ </colgroup>
31
+ <tbody valign="top">
32
+ <tr><td><p class="first">Paragraphs are flush-left,
33
+ separated by blank lines.</p>
34
+ <blockquote class="last">
35
+ Block quotes are indented.</blockquote>
36
+ </td>
37
+ <td rowspan="2"><p class="first">Literal block, preceded by &quot;::&quot;:</p>
38
+ <pre class="literal-block">
39
+ Indented
40
+ </pre>
41
+ <p>or:</p>
42
+ <pre class="last literal-block">
43
+ &gt; Quoted
44
+ </pre>
45
+ </td>
46
+ </tr>
47
+ <tr><td><pre class="first last doctest-block">
48
+ &gt;&gt;&gt; print 'Doctest block'
49
+ Doctest block
50
+ </pre>
51
+ </td>
52
+ </tr>
53
+ <tr><td colspan="2"><div class="first last line-block">
54
+ <div class="line">Line blocks preserve line breaks &amp; indents. [new in 0.3.6]</div>
55
+ <div class="line-block">
56
+ <div class="line">Useful for addresses, verse, and adornment-free lists; long
57
+ lines can be wrapped with continuation lines.</div>
58
+ </div>
59
+ </div>
60
+ </td>
61
+ </tr>
62
+ </tbody>
63
+ </table>
64
+ <p>Simple tables:</p>
65
+ <table border="1" class="docutils">
66
+ <colgroup>
67
+ <col width="21%" />
68
+ <col width="79%" />
69
+ </colgroup>
70
+ <thead valign="bottom">
71
+ <tr><th class="head">List Type</th>
72
+ <th class="head">Examples</th>
73
+ </tr>
74
+ </thead>
75
+ <tbody valign="top">
76
+ <tr><td>Bullet list</td>
77
+ <td><ul class="first last simple">
78
+ <li>items begin with &quot;-&quot;, &quot;+&quot;, or &quot;*&quot;</li>
79
+ </ul>
80
+ </td>
81
+ </tr>
82
+ <tr><td>Enumerated list</td>
83
+ <td><ol class="first last arabic simple">
84
+ <li>items use any variation of &quot;1.&quot;, &quot;A)&quot;, and &quot;(i)&quot;</li>
85
+ <li>also auto-enumerated</li>
86
+ </ol>
87
+ </td>
88
+ </tr>
89
+ <tr><td>Definition list</td>
90
+ <td><dl class="first last docutils">
91
+ <dt>Term is flush-left <span class="classifier-delimiter">:</span> <span class="classifier">optional classifier</span></dt>
92
+ <dd>Definition is indented, no blank line between</dd>
93
+ </dl>
94
+ </td>
95
+ </tr>
96
+ <tr><td>Field list</td>
97
+ <td><table class="first last docutils field-list" frame="void" rules="none">
98
+ <col class="field-name" />
99
+ <col class="field-body" />
100
+ <tbody valign="top">
101
+ <tr class="field"><th class="field-name">field name:</th><td class="field-body">field body</td>
102
+ </tr>
103
+ </tbody>
104
+ </table>
105
+ </td>
106
+ </tr>
107
+ <tr><td>Option list</td>
108
+ <td><table class="first last docutils option-list" frame="void" rules="none">
109
+ <col class="option" />
110
+ <col class="description" />
111
+ <tbody valign="top">
112
+ <tr><td class="option-group">
113
+ <kbd><span class="option">-o</span></kbd></td>
114
+ <td>at least 2 spaces between option &amp; description</td></tr>
115
+ </tbody>
116
+ </table>
117
+ </td>
118
+ </tr>
119
+ </tbody>
120
+ </table>
121
+ <table border="1" class="docutils">
122
+ <colgroup>
123
+ <col width="21%" />
124
+ <col width="79%" />
125
+ </colgroup>
126
+ <thead valign="bottom">
127
+ <tr><th class="head">Explicit Markup</th>
128
+ <th class="head">Examples (visible in the <a class="reference external" href="cheatsheet.txt">text source</a>)</th>
129
+ </tr>
130
+ </thead>
131
+ <tbody valign="top">
132
+ <tr><td>Footnote</td>
133
+ <td><table class="first last docutils footnote" frame="void" id="id1" rules="none">
134
+ <colgroup><col class="label" /><col /></colgroup>
135
+ <tbody valign="top">
136
+ <tr><td class="label"><a class="fn-backref" href="#id3">[1]</a></td><td>Manually numbered or [#] auto-numbered
137
+ (even [#labelled]) or [*] auto-symbol</td></tr>
138
+ </tbody>
139
+ </table>
140
+ </td>
141
+ </tr>
142
+ <tr><td>Citation</td>
143
+ <td><table class="first last docutils citation" frame="void" id="cit2002" rules="none">
144
+ <colgroup><col class="label" /><col /></colgroup>
145
+ <tbody valign="top">
146
+ <tr><td class="label"><a class="fn-backref" href="#id4">[CIT2002]</a></td><td>A citation.</td></tr>
147
+ </tbody>
148
+ </table>
149
+ </td>
150
+ </tr>
151
+ <tr><td>Hyperlink Target</td>
152
+ <td></td>
153
+ </tr>
154
+ <tr id="internal-target"><td>Anonymous Target</td>
155
+ <td></td>
156
+ </tr>
157
+ <tr><td>Directive (&quot;::&quot;)</td>
158
+ <td><img alt="images/biohazard.png" class="first last" src="images/biohazard.png" />
159
+ </td>
160
+ </tr>
161
+ <tr><td>Substitution Def</td>
162
+ <td></td>
163
+ </tr>
164
+ <tr><td>Comment</td>
165
+ <td><!-- is anything else -->
166
+ </td>
167
+ </tr>
168
+ <tr><td>Empty Comment</td>
169
+ <td>(&quot;..&quot; on a line by itself, with blank lines before &amp; after,
170
+ used to separate indentation contexts)</td>
171
+ </tr>
172
+ </tbody>
173
+ </table>
174
+ </div>
175
+ <div class="section" id="inline-markup">
176
+ <h1>Inline Markup</h1>
177
+ <p><em>emphasis</em>; <strong>strong emphasis</strong>; <cite>interpreted text</cite>; <em>interpreted text
178
+ with role</em>; <tt class="docutils literal"><span class="pre">inline</span> <span class="pre">literal</span> <span class="pre">text</span></tt>; standalone hyperlink,
179
+ <a class="reference external" href="http://docutils.sourceforge.net">http://docutils.sourceforge.net</a>; named reference, <a class="reference external" href="http://docutils.sf.net/rst.html">reStructuredText</a>;
180
+ <a class="reference external" href="http://docutils.sf.net/docs/ref/rst/restructuredtext.html">anonymous reference</a>; footnote reference, <a class="footnote-reference" href="#id1" id="id3">[1]</a>; citation reference,
181
+ <a class="citation-reference" href="#cit2002" id="id4">[CIT2002]</a>; like an inline directive; <span class="target" id="inline-internal-target">inline internal target</span>.</p>
182
+ </div>
183
+ <div class="section" id="directive-quick-reference">
184
+ <h1>Directive Quick Reference</h1>
185
+ <p>See &lt;<a class="reference external" href="http://docutils.sf.net/docs/ref/rst/directives.html">http://docutils.sf.net/docs/ref/rst/directives.html</a>&gt; for full info.</p>
186
+ <table border="1" class="docutils">
187
+ <colgroup>
188
+ <col width="21%" />
189
+ <col width="79%" />
190
+ </colgroup>
191
+ <thead valign="bottom">
192
+ <tr><th class="head">Directive Name</th>
193
+ <th class="head">Description (Docutils version added to, in [brackets])</th>
194
+ </tr>
195
+ </thead>
196
+ <tbody valign="top">
197
+ <tr><td>attention</td>
198
+ <td>Specific admonition; also &quot;caution&quot;, &quot;danger&quot;,
199
+ &quot;error&quot;, &quot;hint&quot;, &quot;important&quot;, &quot;note&quot;, &quot;tip&quot;, &quot;warning&quot;</td>
200
+ </tr>
201
+ <tr><td>admonition</td>
202
+ <td>Generic titled admonition: <tt class="docutils literal"><span class="pre">..</span> <span class="pre">admonition::</span> <span class="pre">By</span> <span class="pre">The</span> <span class="pre">Way</span></tt></td>
203
+ </tr>
204
+ <tr><td>image</td>
205
+ <td><tt class="docutils literal"><span class="pre">..</span> <span class="pre">image::</span> <span class="pre">picture.png</span></tt>; many options possible</td>
206
+ </tr>
207
+ <tr><td>figure</td>
208
+ <td>Like &quot;image&quot;, but with optional caption and legend</td>
209
+ </tr>
210
+ <tr><td>topic</td>
211
+ <td><tt class="docutils literal"><span class="pre">..</span> <span class="pre">topic::</span> <span class="pre">Title</span></tt>; like a mini section</td>
212
+ </tr>
213
+ <tr><td>sidebar</td>
214
+ <td><tt class="docutils literal"><span class="pre">..</span> <span class="pre">sidebar::</span> <span class="pre">Title</span></tt>; like a mini parallel document</td>
215
+ </tr>
216
+ <tr><td>parsed-literal</td>
217
+ <td>A literal block with parsed inline markup</td>
218
+ </tr>
219
+ <tr><td>rubric</td>
220
+ <td><tt class="docutils literal"><span class="pre">..</span> <span class="pre">rubric::</span> <span class="pre">Informal</span> <span class="pre">Heading</span></tt></td>
221
+ </tr>
222
+ <tr><td>epigraph</td>
223
+ <td>Block quote with class=&quot;epigraph&quot;</td>
224
+ </tr>
225
+ <tr><td>highlights</td>
226
+ <td>Block quote with class=&quot;highlights&quot;</td>
227
+ </tr>
228
+ <tr><td>pull-quote</td>
229
+ <td>Block quote with class=&quot;pull-quote&quot;</td>
230
+ </tr>
231
+ <tr><td>compound</td>
232
+ <td>Compound paragraphs [0.3.6]</td>
233
+ </tr>
234
+ <tr><td>container</td>
235
+ <td>Generic block-level container element [0.3.10]</td>
236
+ </tr>
237
+ <tr><td>table</td>
238
+ <td>Create a titled table [0.3.1]</td>
239
+ </tr>
240
+ <tr><td>list-table</td>
241
+ <td>Create a table from a uniform two-level bullet list [0.3.8]</td>
242
+ </tr>
243
+ <tr><td>csv-table</td>
244
+ <td>Create a table from CSV data (requires Python 2.3+) [0.3.4]</td>
245
+ </tr>
246
+ <tr><td>contents</td>
247
+ <td>Generate a table of contents</td>
248
+ </tr>
249
+ <tr><td>sectnum</td>
250
+ <td>Automatically number sections, subsections, etc.</td>
251
+ </tr>
252
+ <tr><td>header, footer</td>
253
+ <td>Create document decorations [0.3.8]</td>
254
+ </tr>
255
+ <tr><td>target-notes</td>
256
+ <td>Create an explicit footnote for each external target</td>
257
+ </tr>
258
+ <tr><td>meta</td>
259
+ <td>HTML-specific metadata</td>
260
+ </tr>
261
+ <tr><td>include</td>
262
+ <td>Read an external reST file as if it were inline</td>
263
+ </tr>
264
+ <tr><td>raw</td>
265
+ <td>Non-reST data passed untouched to the Writer</td>
266
+ </tr>
267
+ <tr><td>replace</td>
268
+ <td>Replacement text for substitution definitions</td>
269
+ </tr>
270
+ <tr><td>unicode</td>
271
+ <td>Unicode character code conversion for substitution defs</td>
272
+ </tr>
273
+ <tr><td>date</td>
274
+ <td>Generates today's date; for substitution defs</td>
275
+ </tr>
276
+ <tr><td>class</td>
277
+ <td>Set a &quot;class&quot; attribute on the next element</td>
278
+ </tr>
279
+ <tr><td>role</td>
280
+ <td>Create a custom interpreted text role [0.3.2]</td>
281
+ </tr>
282
+ <tr><td>default-role</td>
283
+ <td>Set the default interpreted text role [0.3.10]</td>
284
+ </tr>
285
+ <tr><td>title</td>
286
+ <td>Set the metadata document title [0.3.10]</td>
287
+ </tr>
288
+ </tbody>
289
+ </table>
290
+ </div>
291
+ <div class="section" id="interpreted-text-role-quick-reference">
292
+ <h1>Interpreted Text Role Quick Reference</h1>
293
+ <p>See &lt;<a class="reference external" href="http://docutils.sf.net/docs/ref/rst/roles.html">http://docutils.sf.net/docs/ref/rst/roles.html</a>&gt; for full info.</p>
294
+ <table border="1" class="docutils">
295
+ <colgroup>
296
+ <col width="21%" />
297
+ <col width="79%" />
298
+ </colgroup>
299
+ <thead valign="bottom">
300
+ <tr><th class="head">Role Name</th>
301
+ <th class="head">Description</th>
302
+ </tr>
303
+ </thead>
304
+ <tbody valign="top">
305
+ <tr><td>emphasis</td>
306
+ <td>Equivalent to <em>emphasis</em></td>
307
+ </tr>
308
+ <tr><td>literal</td>
309
+ <td>Equivalent to <tt class="docutils literal"><span class="pre">literal</span></tt> but processes backslash escapes</td>
310
+ </tr>
311
+ <tr><td>PEP</td>
312
+ <td>Reference to a numbered Python Enhancement Proposal</td>
313
+ </tr>
314
+ <tr><td>RFC</td>
315
+ <td>Reference to a numbered Internet Request For Comments</td>
316
+ </tr>
317
+ <tr><td>raw</td>
318
+ <td>For non-reST data; cannot be used directly (see docs) [0.3.6]</td>
319
+ </tr>
320
+ <tr><td>strong</td>
321
+ <td>Equivalent to <strong>strong</strong></td>
322
+ </tr>
323
+ <tr><td>sub</td>
324
+ <td>Subscript</td>
325
+ </tr>
326
+ <tr><td>sup</td>
327
+ <td>Superscript</td>
328
+ </tr>
329
+ <tr><td>title</td>
330
+ <td>Title reference (book, etc.); standard default role</td>
331
+ </tr>
332
+ </tbody>
333
+ </table>
334
+ </div>
335
+ </div>
@@ -0,0 +1,127 @@
1
+ =====================================================
2
+ The reStructuredText_ Cheat Sheet: Syntax Reminders
3
+ =====================================================
4
+ :Info: See <http://docutils.sf.net/rst.html> for introductory docs.
5
+ :Author: David Goodger <goodger@python.org>
6
+ :Date: $Date: 2006-01-23 02:13:55 +0100 (Mon, 23 Jän 2006) $
7
+ :Revision: $Revision: 4321 $
8
+ :Description: This is a "docinfo block", or bibliographic field list
9
+
10
+ Section Structure
11
+ =================
12
+ Section titles are underlined or overlined & underlined.
13
+
14
+ Body Elements
15
+ =============
16
+ Grid table:
17
+
18
+ +--------------------------------+-----------------------------------+
19
+ | Paragraphs are flush-left, | Literal block, preceded by "::":: |
20
+ | separated by blank lines. | |
21
+ | | Indented |
22
+ | Block quotes are indented. | |
23
+ +--------------------------------+ or:: |
24
+ | >>> print 'Doctest block' | |
25
+ | Doctest block | > Quoted |
26
+ +--------------------------------+-----------------------------------+
27
+ | | Line blocks preserve line breaks & indents. [new in 0.3.6] |
28
+ | | Useful for addresses, verse, and adornment-free lists; long |
29
+ | lines can be wrapped with continuation lines. |
30
+ +--------------------------------------------------------------------+
31
+
32
+ Simple tables:
33
+
34
+ ================ ============================================================
35
+ List Type Examples
36
+ ================ ============================================================
37
+ Bullet list * items begin with "-", "+", or "*"
38
+ Enumerated list 1. items use any variation of "1.", "A)", and "(i)"
39
+ #. also auto-enumerated
40
+ Definition list Term is flush-left : optional classifier
41
+ Definition is indented, no blank line between
42
+ Field list :field name: field body
43
+ Option list -o at least 2 spaces between option & description
44
+ ================ ============================================================
45
+
46
+ ================ ============================================================
47
+ Explicit Markup Examples (visible in the `text source <cheatsheet.txt>`_)
48
+ ================ ============================================================
49
+ Footnote .. [1] Manually numbered or [#] auto-numbered
50
+ (even [#labelled]) or [*] auto-symbol
51
+ Citation .. [CIT2002] A citation.
52
+ Hyperlink Target .. _reStructuredText: http://docutils.sf.net/rst.html
53
+ .. _indirect target: reStructuredText_
54
+ .. _internal target:
55
+ Anonymous Target __ http://docutils.sf.net/docs/ref/rst/restructuredtext.html
56
+ Directive ("::") .. image:: images/biohazard.png
57
+ Substitution Def .. |substitution| replace:: like an inline directive
58
+ Comment .. is anything else
59
+ Empty Comment (".." on a line by itself, with blank lines before & after,
60
+ used to separate indentation contexts)
61
+ ================ ============================================================
62
+
63
+ Inline Markup
64
+ =============
65
+ *emphasis*; **strong emphasis**; `interpreted text`; `interpreted text
66
+ with role`:emphasis:; ``inline literal text``; standalone hyperlink,
67
+ http://docutils.sourceforge.net; named reference, reStructuredText_;
68
+ `anonymous reference`__; footnote reference, [1]_; citation reference,
69
+ [CIT2002]_; |substitution|; _`inline internal target`.
70
+
71
+ Directive Quick Reference
72
+ =========================
73
+ See <http://docutils.sf.net/docs/ref/rst/directives.html> for full info.
74
+
75
+ ================ ============================================================
76
+ Directive Name Description (Docutils version added to, in [brackets])
77
+ ================ ============================================================
78
+ attention Specific admonition; also "caution", "danger",
79
+ "error", "hint", "important", "note", "tip", "warning"
80
+ admonition Generic titled admonition: ``.. admonition:: By The Way``
81
+ image ``.. image:: picture.png``; many options possible
82
+ figure Like "image", but with optional caption and legend
83
+ topic ``.. topic:: Title``; like a mini section
84
+ sidebar ``.. sidebar:: Title``; like a mini parallel document
85
+ parsed-literal A literal block with parsed inline markup
86
+ rubric ``.. rubric:: Informal Heading``
87
+ epigraph Block quote with class="epigraph"
88
+ highlights Block quote with class="highlights"
89
+ pull-quote Block quote with class="pull-quote"
90
+ compound Compound paragraphs [0.3.6]
91
+ container Generic block-level container element [0.3.10]
92
+ table Create a titled table [0.3.1]
93
+ list-table Create a table from a uniform two-level bullet list [0.3.8]
94
+ csv-table Create a table from CSV data (requires Python 2.3+) [0.3.4]
95
+ contents Generate a table of contents
96
+ sectnum Automatically number sections, subsections, etc.
97
+ header, footer Create document decorations [0.3.8]
98
+ target-notes Create an explicit footnote for each external target
99
+ meta HTML-specific metadata
100
+ include Read an external reST file as if it were inline
101
+ raw Non-reST data passed untouched to the Writer
102
+ replace Replacement text for substitution definitions
103
+ unicode Unicode character code conversion for substitution defs
104
+ date Generates today's date; for substitution defs
105
+ class Set a "class" attribute on the next element
106
+ role Create a custom interpreted text role [0.3.2]
107
+ default-role Set the default interpreted text role [0.3.10]
108
+ title Set the metadata document title [0.3.10]
109
+ ================ ============================================================
110
+
111
+ Interpreted Text Role Quick Reference
112
+ =====================================
113
+ See <http://docutils.sf.net/docs/ref/rst/roles.html> for full info.
114
+
115
+ ================ ============================================================
116
+ Role Name Description
117
+ ================ ============================================================
118
+ emphasis Equivalent to *emphasis*
119
+ literal Equivalent to ``literal`` but processes backslash escapes
120
+ PEP Reference to a numbered Python Enhancement Proposal
121
+ RFC Reference to a numbered Internet Request For Comments
122
+ raw For non-reST data; cannot be used directly (see docs) [0.3.6]
123
+ strong Equivalent to **strong**
124
+ sub Subscript
125
+ sup Superscript
126
+ title Title reference (book, etc.); standard default role
127
+ ================ ============================================================
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'rbst'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,42 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require 'mocha'
3
+
4
+ class TestRbST < Test::Unit::TestCase
5
+ def setup
6
+ @rst_file = File.join(File.dirname(__FILE__), 'files', 'test.rst')
7
+ @html_file = File.join(File.dirname(__FILE__), 'files', 'test.html')
8
+ end
9
+
10
+ should "call bare rest2parts when passed no options" do
11
+ converter = RbST.new(@rst_file)
12
+ converter.expects(:execute).with('python ./test/../lib/rst2parts.py').returns(true)
13
+ assert converter.convert
14
+ end
15
+
16
+ should "convert ReST to html" do
17
+ html = RbST.new(@rst_file).to_html
18
+ assert_equal html, File.read(@html_file)
19
+ end
20
+
21
+ should "recognize strip_comments option" do
22
+ html_with_comment = RbST.convert(".. comment")
23
+ assert_equal html_with_comment, %Q{<div class="document">\n<!-- comment -->\n</div>}
24
+ html_without_comment = RbST.convert(".. comment", :strip_comments)
25
+ assert_equal html_without_comment, %Q{<div class="document">\n</div>}
26
+ end
27
+
28
+ should "recognize cloak_email_addresses option" do
29
+ html_with_uncloaked_email = RbST.convert("steve@mac.com")
30
+ assert_equal %Q{<div class="document">\n<p><a class="reference external" href="mailto:steve&#64;mac.com">steve&#64;mac.com</a></p>\n</div>}, html_with_uncloaked_email
31
+ html_with_cloaked_email = RbST.convert("steve@mac.com", :cloak_email_addresses)
32
+ assert_equal %Q{<div class="document">\n<p><a class="reference external" href="mailto:steve&#37;&#52;&#48;mac&#46;com">steve<span>&#64;</span>mac<span>&#46;</span>com</a></p>\n</div>}, html_with_cloaked_email
33
+ end
34
+
35
+ should "recognize part option" do
36
+ html_body = RbST.convert("hello world", :part => :html_body)
37
+ assert_equal %Q{<div class="document">\n<p>hello world</p>\n</div>}, html_body
38
+ fragment = RbST.convert("hello world", :part => :fragment)
39
+ assert_equal %Q{<p>hello world</p>}, fragment
40
+ end
41
+
42
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: RbST
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - William Melody
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-01 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: open4
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: A simple Ruby wrapper for processing reStructuredText via Python's Docutils
36
+ email: wmelody@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.markdown
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.markdown
49
+ - Rakefile
50
+ - RbST.gemspec
51
+ - VERSION
52
+ - lib/rbst.rb
53
+ - lib/rst2parts.py
54
+ - test/files/test.html
55
+ - test/files/test.rst
56
+ - test/test_helper.rb
57
+ - test/test_rbst.rb
58
+ has_rdoc: true
59
+ homepage: http://github.com/autodata/rbst
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.5
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: A simple Ruby wrapper for processing reStructuredText via Python's Docutils
86
+ test_files:
87
+ - test/test_helper.rb
88
+ - test/test_rbst.rb