module Ronn::Server
Ronn
HTTP server. Serves a list of .ronn files as HTML. The options Hash is passed to Ronn::Document.new
on each invocation.
Use Ronn::Server.new
to create a Rack app. See the config.ru file in the root of the Ronn
distribution for example usage.
Ronn::Server.run
starts a server on port 1207.
Public Class Methods
new(files, options = {})
click to toggle source
# File lib/ronn/server.rb 14 def self.new(files, options = {}) 15 files = Dir[files] if files.respond_to?(:to_str) 16 raise ArgumentError, 'no files' if files.empty? 17 Sinatra.new do 18 set :show_exceptions, true 19 set :public_dir, File.expand_path(__FILE__, '../templates') 20 set :static, false 21 set :views, File.expand_path(__FILE__, '../templates') 22 23 get '/' do 24 files.map do |f| 25 base = File.basename(f, '.ronn') 26 "<li><a href='./#{base}.html'>#{escape_html(base)}</a></li>" 27 end 28 end 29 30 options[:styles] ||= options[:style] 31 my_styles = if options[:styles].respond_to?(:to_ary) 32 options[:styles] 33 elsif options[:styles] 34 options[:styles].split(/[, ]+/) 35 else 36 [] 37 end 38 39 files.each do |file| 40 basename = File.basename(file, '.ronn') 41 42 get "/#{basename}.html" do 43 options = options.merge(styles: my_styles) 44 %w[date manual organization].each do |attribute| 45 next unless params[attribute] 46 options[attribute] = params[attribute] 47 end 48 Ronn::Document.new(file, options).to_html 49 end 50 get "/#{basename}.roff" do 51 content_type 'text/plain+roff' 52 Ronn::Document.new(file, options.dup).to_roff 53 end 54 end 55 end 56 end
run(files, options = {})
click to toggle source
# File lib/ronn/server.rb 58 def self.run(files, options = {}) 59 port_number = options['port'] || 1207 60 new(files, options).run!( 61 server: %w[mongrel thin webrick], 62 port: port_number, 63 logging: true 64 ) 65 end