ron 0.1 → 0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,34 +2,87 @@ require 'contest'
2
2
  require 'ron/document'
3
3
 
4
4
  class DocumentTest < Test::Unit::TestCase
5
- SIMPLE_FILE = "#{File.dirname(__FILE__)}/simple.ron"
6
- HELLO_DATA = "# hello(1) -- hello world"
5
+ SIMPLE_FILE = "#{File.dirname(__FILE__)}/basic_document.ron"
7
6
 
8
- test "creating with a file" do
7
+ test "new with path" do
9
8
  doc = Ron::Document.new(SIMPLE_FILE)
10
9
  assert_equal File.read(SIMPLE_FILE), doc.data
11
10
  end
12
11
 
13
- test "creating with a string and a file" do
14
- doc = Ron::Document.new('hello.1.ron') { HELLO_DATA }
15
- assert_equal HELLO_DATA, doc.data
12
+ test "new with path and block" do
13
+ doc = Ron::Document.new('hello.1.ron') { "# hello(1) -- hello world" }
14
+ assert_equal "# hello(1) -- hello world", doc.data
16
15
  end
17
16
 
18
- context "Document" do
17
+ test "new with path and block but missing name section" do
18
+ doc = Ron::Document.new('foo.7.ron') { '' }
19
+ assert_equal 'foo', doc.name
20
+ assert_equal '7', doc.section
21
+ end
22
+
23
+ test "new with non conventional path and missing name section" do
24
+ doc = Ron::Document.new('bar.ron') { '' }
25
+ assert_equal 'bar', doc.name
26
+ assert_equal nil, doc.section
27
+ assert_equal "./bar.html", doc.path_for('html')
28
+ assert_equal "./bar", doc.path_for('roff')
29
+ assert_equal "./bar", doc.path_for('')
30
+ assert_equal "./bar", doc.path_for(nil)
31
+ end
32
+
33
+ test "new with path and name section mismatch" do
34
+ doc = Ron::Document.new('foo/rick.7.ron') { "# randy(3) -- I'm confused." }
35
+ assert_equal 'randy', doc.name
36
+ assert_equal 'rick', doc.path_name
37
+ assert_equal '3', doc.section
38
+ assert_equal '7', doc.path_section
39
+ assert_equal 'rick.7', doc.basename
40
+ assert_equal 'foo/rick.7.bar', doc.path_for(:bar)
41
+ end
42
+
43
+ test "new with no path and a name section" do
44
+ doc = Ron::Document.new { "# brandy(5) -- wootderitis" }
45
+ assert_equal nil, doc.path_name
46
+ assert_equal nil, doc.path_section
47
+ assert_equal 'brandy', doc.name
48
+ assert_equal '5', doc.section
49
+ assert_equal 'brandy.5', doc.basename
50
+ assert_equal 'brandy.5.foo', doc.path_for(:foo)
51
+ end
52
+
53
+ context "simple conventionally named document" do
19
54
  setup do
20
- @doc = Ron::Document.new('hello.1.ron') { HELLO_DATA }
55
+ @doc = Ron::Document.new('hello.1.ron') { "# hello(1) -- hello world" }
21
56
  end
22
57
 
23
58
  should "load data" do
24
- assert_equal HELLO_DATA, @doc.data
59
+ assert_equal "# hello(1) -- hello world", @doc.data
25
60
  end
26
61
 
27
- should "extract the name" do
62
+ should "extract the manual page name from the filename or document" do
28
63
  assert_equal 'hello', @doc.name
29
64
  end
30
65
 
31
- should "extract the section" do
66
+ should "extract the manual page section from the filename or document" do
32
67
  assert_equal '1', @doc.section
33
68
  end
69
+
70
+ should "convert to an HTML fragment" do
71
+ assert_equal %[<h2 id='NAME'>NAME</h2>\n<p><code>hello</code> -- hello world</p>\n],
72
+ @doc.to_html_fragment
73
+ end
74
+
75
+ should "convert to HTML with a layout" do
76
+ assert_match %r{^<!DOCTYPE html.*}m, @doc.to_html
77
+ assert_match %[<h2 id='NAME'>NAME</h2>\n<p><code>hello</code> -- hello world</p>],
78
+ @doc.to_html
79
+ end
80
+
81
+ should "construct a path to related documents" do
82
+ assert_equal "./hello.1.html", @doc.path_for(:html)
83
+ assert_equal "./hello.1", @doc.path_for(:roff)
84
+ assert_equal "./hello.1", @doc.path_for('')
85
+ assert_equal "./hello.1", @doc.path_for(nil)
86
+ end
34
87
  end
35
88
  end
data/test/ron_test.rb CHANGED
@@ -1,21 +1,27 @@
1
1
  require 'contest'
2
2
 
3
- # ron command tests
4
3
  class RonTest < Test::Unit::TestCase
5
4
  testdir = File.dirname(__FILE__)
6
- bindir = File.dirname(testdir)
5
+
6
+ # setup PATH so that we execute the right ron command
7
+ bindir = File.dirname(testdir) + "/bin"
7
8
  ENV['PATH'] = "#{bindir}:#{ENV['PATH']}"
8
9
 
9
- SIMPLE_FILE = "#{File.dirname(__FILE__)}/simple.ron"
10
+ # make sure the load path is setup correctly
11
+ libdir = File.expand_path("#{testdir}/../lib")
12
+ $:.unshift(libdir) unless $:.any? { |path| File.expand_path(path) == libdir }
13
+ ENV['RUBYLIB'] = $:.join(':')
14
+
15
+ require 'ron'
10
16
 
11
17
  test "takes ron text on stdin and produces roff on stdout" do
12
- output = `echo '# hello(1) -- hello world' | ron`
18
+ output = `echo '# hello(1) -- hello world' | ron --date=2009-11-23`
13
19
  lines = output.split("\n")
14
20
  assert_equal 7, lines.size
15
- assert_equal %[.\\" generated with Ron], lines.shift
21
+ assert_equal %[.\\" generated with Ron/v#{Ron::VERSION}], lines.shift
16
22
  assert_equal %[.\\" http://github.com/rtomayko/ron/], lines.shift
17
23
  assert_equal %[.], lines.shift
18
- assert_equal %[.TH "HELLO" 1 "" "" ""], lines.shift
24
+ assert_equal %[.TH "HELLO" "1" "November 2009" "" ""], lines.shift
19
25
  assert_equal %[.], lines.shift
20
26
  assert_equal %[.SH "NAME"], lines.shift
21
27
  assert_equal %[\\fBhello\\fR \\-\\- hello world], lines.shift
@@ -24,6 +30,30 @@ class RonTest < Test::Unit::TestCase
24
30
 
25
31
  test "produces html instead of roff with the --html argument" do
26
32
  output = `echo '# hello(1) -- hello world' | ron --html`
27
- assert_match(/<h2 id="NAME">NAME<\/h2>/, output)
33
+ assert_match(/<h2 id='NAME'>NAME<\/h2>/, output)
34
+ end
35
+
36
+ test "produces html fragment with the --fragment argument" do
37
+ output = `echo '# hello(1) -- hello world' | ron --fragment`
38
+ assert_equal "<h2 id='NAME'>NAME</h2>\n<p><code>hello</code> -- hello world</p>\n",
39
+ output
40
+ end
41
+
42
+ # file based tests
43
+ Dir[testdir + '/*.ron'].each do |source|
44
+ dest = source.sub(/ron$/, 'html')
45
+ wrong = source.sub(/ron$/, "wrong")
46
+ test File.basename(source, '.ron') do
47
+ html = `ron --html --fragment #{source}`
48
+ expected = File.read(dest) rescue ''
49
+ if expected != html
50
+ File.open(wrong, 'wb') { |f| f.write(html) }
51
+ diff = `diff -u #{dest} #{wrong} 2>/dev/null`
52
+ fail "the #{dest} file does not exist" if diff.empty?
53
+ flunk diff
54
+ elsif File.exist?(wrong)
55
+ File.unlink(wrong)
56
+ end
57
+ end
28
58
  end
29
59
  end
@@ -0,0 +1,2 @@
1
+ <p>This is a document without a level 1 heading. It doesn't output
2
+ a <code>NAME</code> section or custom <code>&lt;h1&gt;</code>.</p>
@@ -0,0 +1,2 @@
1
+ This is a document without a level 1 heading. It doesn't output
2
+ a `NAME` section or custom `<h1>`.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ron
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.1"
4
+ version: "0.3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Tomayko
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-05 00:00:00 -08:00
12
+ date: 2009-12-09 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -49,24 +49,37 @@ executables:
49
49
  extensions: []
50
50
 
51
51
  extra_rdoc_files:
52
- - README
53
52
  - COPYING
54
53
  files:
55
54
  - COPYING
56
- - README
55
+ - README.md
57
56
  - Rakefile
58
57
  - bin/ron
59
58
  - lib/ron.rb
60
59
  - lib/ron/document.rb
61
60
  - lib/ron/layout.html
62
61
  - lib/ron/roff.rb
62
+ - man/markdown.5
63
63
  - man/markdown.5.ron
64
+ - man/ron.1
64
65
  - man/ron.1.ron
66
+ - man/ron.5
65
67
  - man/ron.5.ron
68
+ - man/ron.7
69
+ - man/ron.7.ron
66
70
  - ron.gemspec
71
+ - test/angle_bracket_syntax.html
72
+ - test/angle_bracket_syntax.ron
73
+ - test/basic_document.html
74
+ - test/basic_document.ron
75
+ - test/custom_title_document.html
76
+ - test/custom_title_document.ron
77
+ - test/definition_list_syntax.html
78
+ - test/definition_list_syntax.ron
67
79
  - test/document_test.rb
68
80
  - test/ron_test.rb
69
- - test/simple.ron
81
+ - test/titleless_document.html
82
+ - test/titleless_document.ron
70
83
  has_rdoc: true
71
84
  homepage: http://github.com/rtomayko/ron/
72
85
  licenses: []
data/README DELETED
@@ -1,145 +0,0 @@
1
- ron -- the opposite of roff
2
-
3
- Ron is a humane text format and toolchain for
4
- creating UNIX man pages -- and things that
5
- appear as man pages from a distance. Use it
6
- to build and install standard UNIX roff man
7
- pages or to generate nicely formatted HTML
8
- manual pages for the web.
9
-
10
- The ron file format is based on Markdown. In
11
- fact, ron files are 100% Markdown compatible
12
- but have a more rigidly defined structure and
13
- extend Markdown in some ways to provide
14
- features commonly found in man pages (e.g.,
15
- definition lists). The ron(5) manual page
16
- included with this distribution defines the
17
- format in more detail.
18
-
19
- INSTALL
20
- -------
21
-
22
- The easiest way to install ron is with
23
- rubygems:
24
-
25
- $ [sudo] gem install ron -s gems.gemcutter.org
26
-
27
- Or, clone the git repository and install from
28
- source:
29
-
30
- $ git clone git://github.com/rtomayko/ron.git
31
- $ cd ron
32
- $ rake install
33
-
34
- EXAMPLES
35
- --------
36
-
37
- The .ron files located under the repository's
38
- ./man directory show off a wide range of ron
39
- capabilities. The HTML versions of these
40
- files are available at:
41
-
42
- http://rtomayko.github.com/ron/ron.1.html
43
- http://rtomayko.github.com/ron/ron.5.html
44
- http://rtomayko.github.com/ron/markdown.5.html
45
-
46
- BASIC USAGE
47
- -----------
48
-
49
- To generate a roff man page from the included
50
- markdown.5.ron file and open it in man(1):
51
-
52
- $ ron -b man/markdown.5.ron
53
- building: man/markdown.5
54
- $ man man/markdown.5
55
-
56
- To generate a standalone HTML version:
57
-
58
- $ ron -b --html man/markdown.5.ron
59
- building: man/markdown.5.html
60
- $ open man/markdown.5.html
61
-
62
- To build roff and HTML versions of all ron
63
- files:
64
-
65
- $ ron -b --roff --html man/*.ron
66
-
67
- If you just want to view a ron file as if it
68
- were a man page without building any
69
- intermediate files:
70
-
71
- $ ron -m man/markdown.5.ron
72
-
73
- The ron(1) manual page included with this
74
- distribution includes full documentation on
75
- ron command line options.
76
-
77
- RATIONALE
78
- ---------
79
-
80
- Some people think UNIX manual pages are a
81
- poor and outdated form of documentation. I
82
- disagree.
83
-
84
- - Man pages typically follow a well defined
85
- structure that's immediately familiar and
86
- provides a useful starting point for
87
- developers documenting new tools,
88
- libraries, and formats.
89
-
90
- - Man pages get to the point. Because they're
91
- written in an inverted style, with a
92
- SYNOPSIS section followed by additional
93
- detail, prose, and finally references to
94
- other sources of information, man pages
95
- provide the best of both cheat sheet and
96
- reference style documentation.
97
-
98
- - Man pages have very limited text formatting
99
- capabilities. This is a feature. You get
100
- bold and underline, basically, and they're
101
- typically applied consistently across man
102
- pages.
103
-
104
- - Most man pages use only a single level of
105
- section hierarchy (although two levels are
106
- technically supported). Hierarchy destroys
107
- otherwise good documentation by adding
108
- unnecessary complexity. Feynman described
109
- the whole of quantum electro dynamics with
110
- only two levels of hierarchy. How can you
111
- possibly need more? Man pages force you to
112
- keep it simple.
113
-
114
- - Man pages have a simple referencing syntax;
115
- e.g., sh(1), fork(2), markdown(5). HTML
116
- versions can use this to generate links
117
- between pages.
118
-
119
- - The classical terminal man page display is
120
- typographically well thought out. Big bold
121
- section headings, justified monospaced
122
- text, nicely indented paragraphs,
123
- intelligently aligned definition lists, and
124
- an informational header and footer.
125
-
126
- All that being said, trying to figure out how
127
- to create a man page can be a really tedious
128
- process. The roff/man macro languages are
129
- highly extensible, fractured between multiple
130
- dialects, and include a bunch of stuff that's
131
- entirely irrelevant to modern man page
132
- creation. It's also horribly ugly compared to
133
- today's humane text formats or even HTML
134
- (just sayin').
135
-
136
- Ron aims to address many of the issues with
137
- man page creation while preserving the things
138
- that makes man pages a great form of
139
- documentation.
140
-
141
- COPYRIGHT
142
- ---------
143
-
144
- Ron is Copyright (C) 2009 Ryan Tomayko
145
- See the file COPYING for more information.