Skip to content
Browse files

Move Raddocs::App into subfolder

  • Loading branch information...
1 parent d333ee9 commit f58aec858a522405ce5d308e878d139cdcd59517 @oestrich committed Jun 1, 2012
Showing with 43 additions and 40 deletions.
  1. +1 −40 lib/raddocs.rb
  2. +42 −0 lib/raddocs/app.rb
View
41 lib/raddocs.rb
@@ -1,48 +1,9 @@
require 'sinatra'
require 'json'
require 'raddocs/configuration'
+require 'raddocs/app'
module Raddocs
- class App < Sinatra::Base
- set :haml, :format => :html5
-
- get "/" do
- index = JSON.parse(File.read("#{docs_dir}/index.json"))
- haml :index, :locals => { :index => index }
- end
-
- get "/*" do
- file = "#{docs_dir}/#{params[:splat][0]}.json"
-
- if !File.exists?(file)
- raise Sinatra::NotFound
- end
-
- file_content = File.read(file)
-
- example = JSON.parse(file_content)
- haml :example, :locals => { :example => example }
- end
-
- not_found do
- "Example does not exist"
- end
-
- helpers do
- def link_to(name, link)
- %{<a href="#{request.env["SCRIPT_NAME"]}#{link}">#{name}</a>}
- end
-
- def url_location
- request.env["SCRIPT_NAME"]
- end
- end
-
- def docs_dir
- Raddocs.configuration.docs_dir
- end
- end
-
def self.configuration
@configuration ||= Configuration.new
end
View
42 lib/raddocs/app.rb
@@ -0,0 +1,42 @@
+module Raddocs
+ class App < Sinatra::Base
+ set :haml, :format => :html5
+ set :root, File.join(File.dirname(__FILE__), "..")
+
+ get "/" do
+ index = JSON.parse(File.read("#{docs_dir}/index.json"))
+ haml :index, :locals => { :index => index }
+ end
+
+ get "/*" do
+ file = "#{docs_dir}/#{params[:splat][0]}.json"
+
+ if !File.exists?(file)
+ raise Sinatra::NotFound
+ end
+
+ file_content = File.read(file)
+
+ example = JSON.parse(file_content)
+ haml :example, :locals => { :example => example }
+ end
+
+ not_found do
+ "Example does not exist"
+ end
+
+ helpers do
+ def link_to(name, link)
+ %{<a href="#{request.env["SCRIPT_NAME"]}#{link}">#{name}</a>}
+ end
+
+ def url_location
+ request.env["SCRIPT_NAME"]
+ end
+ end
+
+ def docs_dir
+ Raddocs.configuration.docs_dir
+ end
+ end
+end

0 comments on commit f58aec8

Please sign in to comment.
Something went wrong with that request. Please try again.