Module | Ronn::Server |
In: |
lib/ronn/server.rb
|
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
# File lib/ronn/server.rb, line 15 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
# File lib/ronn/server.rb, line 62 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