Skip to content

Commit

Permalink
Set path to redis-doc repository via REDIS_DOC environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
pietern committed Nov 29, 2010
1 parent 106b487 commit 59f0c35
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app.rb
Expand Up @@ -24,8 +24,12 @@
module Kernel
private

def documentation_path
@documentation_path ||= ENV["REDIS_DOC"] || "redis-doc"
end

def commands
@commands ||= Reference.new(JSON.parse(File.read("redis-doc/commands.json")))
@commands ||= Reference.new(JSON.parse(File.read(documentation_path + "/commands.json")))
end

def redis
Expand All @@ -41,7 +45,8 @@ def user

Cuba.define do
def render(path, locals = {})
return unless File.expand_path(path).start_with?(ROOT_PATH)
expanded = File.expand_path(path)
return unless expanded.start_with?(ROOT_PATH) || expanded.start_with?(documentation_path)
super(path, locals)
end

Expand Down Expand Up @@ -107,15 +112,15 @@ def gravatar_hash(email)
end

on get, path("clients") do
@clients = JSON.parse(File.read("redis-doc/clients.json"))
@clients = JSON.parse(File.read(documentation_path + "/clients.json"))

@clients_by_language = @clients.group_by { |name, info| info["language"] }.sort_by { |name, _| name.downcase }

res.write haml("clients")
end

on get, path("topics"), segment do |_, _, name|
@body = render("redis-doc/topics/#{name}.md")
@body = render(documentation_path + "/topics/#{name}.md")
@title = @body[%r{<h1>(.+?)</h1>}, 1] # Nokogiri may be overkill

res.write haml("topics/name")
Expand All @@ -135,7 +140,7 @@ def gravatar_hash(email)
on get, path(/\w+\.json/) do |_, file|
res.headers["Cache-Control"] = "public, max-age=29030400" if req.query_string =~ /[0-9]{10}/
res.headers["Content-Type"] = "application/json;charset=UTF-8"
res.write File.read("redis-doc/#{file}")
res.write File.read(documentation_path + "/#{file}")
end

on get, path("styles.css") do
Expand Down

0 comments on commit 59f0c35

Please sign in to comment.