ronn-ng 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/AUTHORS +8 -0
  3. data/CHANGES +184 -0
  4. data/INSTALLING +20 -0
  5. data/LICENSE.txt +11 -0
  6. data/README.md +113 -0
  7. data/Rakefile +163 -0
  8. data/bin/ronn +223 -0
  9. data/config.ru +15 -0
  10. data/lib/ronn.rb +50 -0
  11. data/lib/ronn/document.rb +495 -0
  12. data/lib/ronn/index.rb +183 -0
  13. data/lib/ronn/roff.rb +302 -0
  14. data/lib/ronn/server.rb +70 -0
  15. data/lib/ronn/template.rb +171 -0
  16. data/lib/ronn/template/80c.css +6 -0
  17. data/lib/ronn/template/dark.css +18 -0
  18. data/lib/ronn/template/darktoc.css +17 -0
  19. data/lib/ronn/template/default.html +41 -0
  20. data/lib/ronn/template/man.css +100 -0
  21. data/lib/ronn/template/print.css +5 -0
  22. data/lib/ronn/template/screen.css +105 -0
  23. data/lib/ronn/template/toc.css +27 -0
  24. data/lib/ronn/utils.rb +55 -0
  25. data/man/index.html +78 -0
  26. data/man/index.txt +15 -0
  27. data/man/ronn-format.7 +201 -0
  28. data/man/ronn-format.7.ronn +157 -0
  29. data/man/ronn.1 +325 -0
  30. data/man/ronn.1.ronn +306 -0
  31. data/ronn-ng.gemspec +97 -0
  32. data/test/angle_bracket_syntax.html +18 -0
  33. data/test/angle_bracket_syntax.ronn +12 -0
  34. data/test/basic_document.html +9 -0
  35. data/test/basic_document.ronn +4 -0
  36. data/test/contest.rb +68 -0
  37. data/test/custom_title_document.html +6 -0
  38. data/test/custom_title_document.ronn +5 -0
  39. data/test/definition_list_syntax.html +21 -0
  40. data/test/definition_list_syntax.roff +26 -0
  41. data/test/definition_list_syntax.ronn +18 -0
  42. data/test/dots_at_line_start_test.roff +10 -0
  43. data/test/dots_at_line_start_test.ronn +4 -0
  44. data/test/entity_encoding_test.html +35 -0
  45. data/test/entity_encoding_test.roff +61 -0
  46. data/test/entity_encoding_test.ronn +25 -0
  47. data/test/index.txt +8 -0
  48. data/test/markdown_syntax.html +957 -0
  49. data/test/markdown_syntax.roff +1467 -0
  50. data/test/markdown_syntax.ronn +881 -0
  51. data/test/middle_paragraph.html +15 -0
  52. data/test/middle_paragraph.roff +13 -0
  53. data/test/middle_paragraph.ronn +10 -0
  54. data/test/missing_spaces.roff +9 -0
  55. data/test/missing_spaces.ronn +2 -0
  56. data/test/pre_block_with_quotes.roff +13 -0
  57. data/test/pre_block_with_quotes.ronn +6 -0
  58. data/test/section_reference_links.html +17 -0
  59. data/test/section_reference_links.roff +10 -0
  60. data/test/section_reference_links.ronn +12 -0
  61. data/test/test_ronn.rb +110 -0
  62. data/test/test_ronn_document.rb +186 -0
  63. data/test/test_ronn_index.rb +73 -0
  64. data/test/titleless_document.html +10 -0
  65. data/test/titleless_document.ronn +3 -0
  66. data/test/underline_spacing_test.roff +21 -0
  67. data/test/underline_spacing_test.ronn +11 -0
  68. metadata +176 -0
@@ -0,0 +1,70 @@
1
+ require 'ronn'
2
+ require 'rack'
3
+ require 'sinatra/base'
4
+
5
+ module Ronn
6
+
7
+ # Ronn HTTP server. Serves a list of .ronn files as HTML. The options Hash is
8
+ # passed to Ronn::Document.new on each invocation.
9
+ #
10
+ # Use Ronn::Server.new to create a Rack app. See the config.ru file in the
11
+ # root of the Ronn distribution for example usage.
12
+ #
13
+ # Ronn::Server.run starts a server on port
14
+ module Server
15
+ def self.new(files, options={})
16
+ files = Dir[files] if files.respond_to?(:to_str)
17
+ raise ArgumentError, "no files" if files.empty?
18
+ Sinatra.new do
19
+ set :show_exceptions, true
20
+ set :public, File.expand_path(__FILE__, '../templates')
21
+ set :static, false
22
+ set :views, File.expand_path(__FILE__, '../templates')
23
+
24
+ get '/' do
25
+ files.map do |f|
26
+ base = File.basename(f, '.ronn')
27
+ "<li><a href='./#{base}.html'>#{escape_html(base)}</a></li>"
28
+ end
29
+ end
30
+
31
+ def styles
32
+ params[:styles] ||= params[:style]
33
+ case
34
+ when params[:styles].respond_to?(:to_ary)
35
+ params[:styles]
36
+ when params[:styles]
37
+ params[:styles].split(/[, ]+/)
38
+ else
39
+ []
40
+ end
41
+ end
42
+
43
+ files.each do |file|
44
+ basename = File.basename(file, '.ronn')
45
+
46
+ get "/#{basename}.html" do
47
+ options = options.merge(:styles => styles)
48
+ %w[date manual organization].each do |attribute|
49
+ next if !params[attribute]
50
+ options[attribute] = params[attribute]
51
+ end
52
+ Ronn::Document.new(file, options).to_html
53
+ end
54
+ get "/#{basename}.roff" do
55
+ content_type 'text/plain+roff'
56
+ Ronn::Document.new(file, options.dup).to_roff
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ def self.run(files, options={})
63
+ new(files, options).run!(
64
+ :server => %w[mongrel thin webrick],
65
+ :port => 1207,
66
+ :logging => true
67
+ )
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,171 @@
1
+ require 'mustache'
2
+
3
+ module Ronn
4
+ class Template < Mustache
5
+ self.template_path = File.dirname(__FILE__) + '/template'
6
+ self.template_extension = 'html'
7
+
8
+ def initialize(document, style_path=ENV['RONN_STYLE'].to_s.split(':'))
9
+ @document = document
10
+ @style_path = style_path + [Template.template_path]
11
+ end
12
+
13
+ def render(template='default')
14
+ super template[0,1] == '/' ? File.read(template) : partial(template)
15
+ end
16
+
17
+ ##
18
+ # Basic document attributes
19
+
20
+ def name
21
+ @document.name
22
+ end
23
+
24
+ def section
25
+ @document.section
26
+ end
27
+
28
+ def tagline
29
+ @document.tagline
30
+ end
31
+ alias tagline? tagline
32
+
33
+ def name_and_section?
34
+ name && section
35
+ end
36
+
37
+ def title
38
+ if !name_and_section? && tagline
39
+ tagline
40
+ else
41
+ [page_name, tagline].compact.join(' - ')
42
+ end
43
+ end
44
+
45
+ def custom_title?
46
+ !name_and_section? && tagline
47
+ end
48
+
49
+ def page_name
50
+ if section
51
+ "#{name}(#{section})"
52
+ else
53
+ name
54
+ end
55
+ end
56
+
57
+ def generator
58
+ "Ronn-NG/v#{Ronn.version} (http://github.com/apjanke/ronn-ng/tree/#{Ronn.revision})"
59
+ end
60
+
61
+ def manual
62
+ @document.manual
63
+ end
64
+
65
+ def organization
66
+ @document.organization
67
+ end
68
+
69
+ def date
70
+ @document.date.strftime('%B %Y')
71
+ end
72
+
73
+ def wrap_class_name
74
+ 'mp'
75
+ end
76
+
77
+ ##
78
+ # Section TOCs
79
+
80
+ def section_heads
81
+ @document.section_heads.map do |id, text|
82
+ {
83
+ :id => id,
84
+ :text => text
85
+ }
86
+ end
87
+ end
88
+
89
+ ##
90
+ # Styles
91
+
92
+ # Array of style module names as given on the command line.
93
+ def styles
94
+ @document.styles
95
+ end
96
+
97
+ # Array of stylesheet info hashes.
98
+ def stylesheets
99
+ styles.zip(style_files).map do |name, path|
100
+ base = File.basename(path, '.css')
101
+ fail "style not found: #{style.inspect}" if path.nil?
102
+ {
103
+ :name => name,
104
+ :path => path,
105
+ :base => File.basename(path, '.css'),
106
+ :media => (base =~ /(print|screen)$/) ? $1 : 'all'
107
+ }
108
+ end
109
+ end
110
+
111
+ # All embedded stylesheets.
112
+ def stylesheet_tags
113
+ stylesheets.
114
+ map { |style| inline_stylesheet(style[:path], style[:media]) }.
115
+ join("\n ")
116
+ end
117
+
118
+ attr_accessor :style_path
119
+
120
+ # Array of expanded stylesheet file names. If a file cannot be found, the
121
+ # resulting array will include nil elements in positions corresponding to
122
+ # the stylesheets array.
123
+ def style_files
124
+ styles.map do |name|
125
+ next name if name.include?('/')
126
+ style_path.
127
+ reject { |p| p.strip.empty? }.
128
+ map { |p| File.join(p, "#{name}.css") }.
129
+ detect { |file| File.exist?(file) }
130
+ end
131
+ end
132
+
133
+ # Array of style names for which no file could be found.
134
+ def missing_styles
135
+ style_files.
136
+ zip(files).
137
+ select { |style, file| file.nil? }.
138
+ map { |style, file| style }
139
+ end
140
+
141
+ ##
142
+ # TEMPLATE CSS LOADING
143
+
144
+ def inline_stylesheet(path, media='all')
145
+ data = File.read(path)
146
+ data.gsub!(%r|/\*.+?\*/|m, '') # comments
147
+ data.gsub!(/([;{,]) *\n/m, '\1') # end-of-line whitespace
148
+ data.gsub!(/\n{2,}/m, "\n") # collapse lines
149
+ data.gsub!(/[; ]+\}/, '}') # superfluous trailing semi-colons
150
+ data.gsub!(/([{;,+])[ ]+/, '\1') # whitespace around things
151
+ data.gsub!(/[ \t]+/m, ' ') # coalescing whitespace elsewhere
152
+ data.gsub!(/^/, ' ') # indent
153
+ data.strip!
154
+ [
155
+ "<style type='text/css' media='#{media}'>",
156
+ "/* style: #{File.basename(path, '.css')} */",
157
+ data,
158
+ "</style>"
159
+ ].join("\n ")
160
+ end
161
+
162
+ def remote_stylesheet(name, media='all')
163
+ path = File.expand_path("../template/#{name}.css", __FILE__)
164
+ "<link rel='stylesheet' type='text/css' media='#{media}' href='#{path}'>"
165
+ end
166
+
167
+ def stylesheet(path, media='all')
168
+ inline_stylesheet(name, media)
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,6 @@
1
+ /* 80c.css - condense width to emulate a classical 80 character terminal */
2
+
3
+ .mp { max-width:86ex }
4
+
5
+ /* .mp width + padding */
6
+ .man-navigation { left:101ex }
@@ -0,0 +1,18 @@
1
+ .mp, body#manpage {
2
+ background:#080706;
3
+ color:#888;
4
+ }
5
+ .mp, .mp code, .mp pre,
6
+ .mp pre code, .mp tt, .mp kbd,
7
+ .mp samp { color:#aaa }
8
+ .mp h1, .mp h2, .mp h3, .mp h4 { color:#fff }
9
+ .man-decor, .man-decor ol li { color:#666 }
10
+ .mp code, .mp strong, .mp b { color:#fff }
11
+
12
+ .mp em, .mp var, .mp u { color:#ddd }
13
+
14
+ .mp pre code { color:#ddd }
15
+
16
+ .mp a, .mp a:link, .mp a:hover,
17
+ .mp a code, .mp a pre, .mp a tt,
18
+ .mp a kbd, .mp a samp { color:#fff }
@@ -0,0 +1,17 @@
1
+ /* darktoc.css - enable table of contents */
2
+
3
+ .man-navigation {
4
+ border-left:2px solid #222;
5
+ background-color:#131211;
6
+ }
7
+ .man-navigation a,
8
+ .man-navigation a:hover,
9
+ .man-navigation a:link,
10
+ .man-navigation a:visited {
11
+ color:#777;
12
+ text-decoration:none;
13
+ }
14
+ .man-navigation a:hover {
15
+ color:#fff;
16
+ text-decoration:underline;
17
+ }
@@ -0,0 +1,41 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv='content-type' content='text/html;charset=utf8'>
5
+ <meta name='generator' content='{{ generator }}'>
6
+ <title>{{ title }}</title>
7
+ {{{ stylesheet_tags }}}
8
+ </head>
9
+ <!--
10
+ The following styles are deprecated and will be removed at some point:
11
+ div#man, div#man ol.man, div#man ol.head, div#man ol.man.
12
+
13
+ The .man-page, .man-decor, .man-head, .man-foot, .man-title, and
14
+ .man-navigation should be used instead.
15
+ -->
16
+ <body id='manpage'>
17
+ <div class='mp' id='man'>
18
+
19
+ <div class='man-navigation' style='display:none'>
20
+ {{#section_heads}}
21
+ <a href="#{{id}}">{{text}}</a>
22
+ {{/section_heads}}
23
+ </div>
24
+
25
+ <ol class='man-decor man-head man head'>
26
+ <li class='tl'>{{ page_name }}</li>
27
+ <li class='tc'>{{ manual }}</li>
28
+ <li class='tr'>{{ page_name }}</li>
29
+ </ol>
30
+
31
+ {{{ html }}}
32
+
33
+ <ol class='man-decor man-foot man foot'>
34
+ <li class='tl'>{{ organization }}</li>
35
+ <li class='tc'>{{ date }}</li>
36
+ <li class='tr'>{{ page_name }}</li>
37
+ </ol>
38
+
39
+ </div>
40
+ </body>
41
+ </html>
@@ -0,0 +1,100 @@
1
+ /* man.css - core manpage styles */
2
+
3
+ /* STRUCTURE, INDENT, MARGINS */
4
+
5
+ body#manpage { margin:0 }
6
+ .mp {
7
+ max-width:100ex;
8
+ padding:0 9ex 1ex 4ex;
9
+ }
10
+
11
+ .mp p, .mp pre,
12
+ .mp ul, .mp ol, .mp dl { margin:0 0 20px 0 }
13
+ .mp h2 { margin:10px 0 0 0 }
14
+
15
+ .mp > p, .mp > pre, .mp > ul,
16
+ .mp > ol, .mp > dl { margin-left:8ex }
17
+ .mp h3 { margin:0 0 0 4ex }
18
+
19
+ .mp dt { margin:0; clear:left }
20
+ .mp dt.flush { float:left; width:8ex }
21
+ .mp dd { margin:0 0 0 9ex }
22
+ .mp h1, .mp h2, .mp h3, .mp h4 { clear:left }
23
+
24
+ .mp pre { margin-bottom:20px }
25
+ .mp pre+h2, .mp pre+h3 { margin-top:22px }
26
+ .mp h2+pre, .mp h3+pre { margin-top:5px }
27
+
28
+ .mp img { display:block;margin:auto }
29
+ .mp h1.man-title { display:none }
30
+
31
+ /* FONTS */
32
+
33
+ .mp, .mp code, .mp pre, .mp tt,
34
+ .mp kbd, .mp samp, .mp h3, .mp h4 {
35
+ font-family:monospace;
36
+ font-size:14px;
37
+ line-height:1.42857142857143;
38
+ }
39
+ .mp h2 {
40
+ font-size:16px;
41
+ line-height:1.25;
42
+ }
43
+ .mp h1 {
44
+ font-size:20px;
45
+ line-height:2;
46
+ }
47
+
48
+ /* TEXT STYLES */
49
+
50
+ .mp {
51
+ text-align:justify;
52
+ background:#fff;
53
+ }
54
+ .mp, .mp code, .mp pre,
55
+ .mp pre code, .mp tt, .mp kbd,
56
+ .mp samp { color:#131211 }
57
+ .mp h1, .mp h2, .mp h3, .mp h4 { color:#030201 }
58
+ .mp u { text-decoration:underline; }
59
+
60
+ .mp code, .mp strong, .mp b {
61
+ font-weight:bold;
62
+ color:#131211;
63
+ }
64
+
65
+ .mp em, .mp var {
66
+ font-style:italic;
67
+ color:#232221;
68
+ text-decoration:none;
69
+ }
70
+
71
+ /* LINKS */
72
+
73
+ .mp a, .mp a:link, .mp a:hover,
74
+ .mp a code, .mp a pre, .mp a tt,
75
+ .mp a kbd, .mp a samp { color:#0000ff }
76
+
77
+ .mp b.man-ref { font-weight:normal;color:#434241 }
78
+
79
+ /* PREFORMATTED BLOCKS */
80
+
81
+ .mp pre { padding:0 4ex }
82
+ .mp pre code { font-weight:normal;color:#434241 }
83
+ .mp h2+pre, h3+pre { padding-left:0 }
84
+
85
+ /* DOCUMENT HEADER AND FOOTER AREAS */
86
+
87
+ ol.man-decor, ol.man-decor li {
88
+ margin:3px 0 10px 0;
89
+ padding:0;
90
+ float:left;
91
+ width:33%;
92
+ list-style-type:none;
93
+ text-transform:uppercase;
94
+ color:#999;
95
+ letter-spacing:1px;
96
+ }
97
+ ol.man-decor { width:100% }
98
+ ol.man-decor li.tl { text-align:left }
99
+ ol.man-decor li.tc { text-align:center; letter-spacing:4px }
100
+ ol.man-decor li.tr { text-align:right; float:right }
@@ -0,0 +1,5 @@
1
+ .mp { max-width:none }
2
+ .man-navigation { display:none !important }
3
+ .mp a[href]:not([href^="#"]):not([data-bare-link]):after {
4
+ content:" " attr(href);
5
+ }
@@ -0,0 +1,105 @@
1
+ /* STRUCTURE, INDENT, MARGINS */
2
+
3
+ body { margin:0 }
4
+ #man { max-width:88ex; padding:0 2ex 1ex 2ex }
5
+
6
+ #man p, #man pre,
7
+ #man ul, #man ol, #man dl { margin:0 0 20px 0 }
8
+ #man h2 { margin:10px 0 0 0 }
9
+
10
+ #man > p, #man > pre,
11
+ #man > ul, #man > ol, #man > dl { margin-left:8ex }
12
+ #man h3 { margin:0 0 0 4ex }
13
+
14
+ #man dt { margin:0; clear:left }
15
+ #man dt.flush { float:left; width:8ex }
16
+ #man dd { margin:0 0 0 9ex }
17
+ #man h1, #man h2, #man h3, #man h4 { clear:left }
18
+
19
+ #man pre { margin-bottom:20px }
20
+ #man pre+h2, #man pre+h3 { margin-top:22px }
21
+ #man h2+pre, #man h3+pre { margin-top:5px }
22
+
23
+ #man img { display:block;margin:auto }
24
+ #man h1.man-title { display:none }
25
+
26
+ /* FONTS */
27
+
28
+ #man, #man code, #man pre,
29
+ #man tt, #man kbd, #man samp,
30
+ #man h3, #man h4 {
31
+ font-family:monospace;
32
+ font-size:14px;
33
+ line-height:1.42857142857143;
34
+ }
35
+ #man h2, #man ol.man {
36
+ font-size:16px;
37
+ line-height:1.25
38
+ }
39
+ #man h1 {
40
+ font-size:20px;
41
+ line-height:2;
42
+ }
43
+
44
+ /* TEXT STYLES */
45
+
46
+ #man {
47
+ text-align:justify;
48
+ background:#fff;
49
+ }
50
+ #man, #man code, #man pre, #man pre code,
51
+ #man tt, #man kbd, #man samp { color:#131211 }
52
+ #man h1, #man h2, #man h3, #man h4 { color:#030201 }
53
+ #man ol.man, #man ol.man li { color:#636261 }
54
+
55
+ #man code, #man strong, #man b {
56
+ font-weight:bold;
57
+ color:#131211;
58
+ }
59
+
60
+ #man em, #man var, #man u {
61
+ font-style:italic;
62
+ color:#434241;
63
+ text-decoration:none;
64
+ }
65
+
66
+ #man pre {
67
+ background:#edeceb;
68
+ padding:5px 1ex;
69
+ border-left:1ex solid #ddd;
70
+ }
71
+ #man pre code {
72
+ font-weight:normal;
73
+ background:inherit;
74
+ }
75
+
76
+ /* DOCUMENT HEADER AND FOOTER AREAS */
77
+
78
+ #man ol.man, #man ol.man li {
79
+ margin:3px 0 10px 0;
80
+ padding:0;
81
+ float:left;
82
+ width:33%;
83
+ list-style-type:none;
84
+ text-transform:uppercase;
85
+ color:#999;
86
+ letter-spacing:1px;
87
+ }
88
+ #man ol.man { width:100% }
89
+ #man ol.man li.tl { text-align:left }
90
+ #man ol.man li.tc { text-align:center; letter-spacing:4px }
91
+ #man ol.man li.tr { text-align:right; float:right }
92
+
93
+ /* SECTION TOC NAVIGATION */
94
+
95
+ #man div.man-navigation {
96
+ position:fixed;
97
+ top:0;
98
+ left:96ex;
99
+ height:100%;
100
+ width:100%;
101
+ padding:1ex 0 0 2ex;
102
+ border-left:0.25ex solid #DCDCDC;
103
+ background-color: #F5F5F5;
104
+ }
105
+ #man div.man-navigation a { display:block; margin-bottom:1.5ex }