Module: Ronn::Server
- Defined in:
- lib/ronn/server.rb
Overview
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
Class Method Summary collapse
Class Method Details
.new(files, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ronn/server.rb', line 15 def self.new(files, ={}) files = Dir[files] if files.respond_to?(:to_str) raise ArgumentError, "no files" if files.empty? Sinatra.new do set :show_exceptions, true set :public, File.(__FILE__, '../templates') set :static, false set :views, File.(__FILE__, '../templates') get '/' do files.map do |f| base = File.basename(f, '.ronn') "<li><a href='./#{base}.html'>#{escape_html(base)}</a></li>" end end def styles params[:styles] ||= params[:style] case when params[:styles].respond_to?(:to_ary) params[:styles] when params[:styles] params[:styles].split(/[, ]+/) else [] end end files.each do |file| basename = File.basename(file, '.ronn') get "/#{basename}.html" do = .merge(:styles => styles) %w[date manual organization].each do |attribute| next if !params[attribute] [attribute] = params[attribute] end Ronn::Document.new(file, ).to_html end get "/#{basename}.roff" do content_type 'text/plain+roff' Ronn::Document.new(file, .dup).to_roff end end end end |
.run(files, options = {}) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/ronn/server.rb', line 62 def self.run(files, ={}) new(files, ).run!( :server => %w[mongrel thin webrick], :port => 1207, :logging => true ) end |