littlewiki

Check-in [fd74213d0d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:First commit. Don't vendor Rum.
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA1:fd74213d0d732d69ccb30d3b16a4138ca7c9beb2
User & Date: christian 2012-03-16 02:44:06
Context
2012-03-16
02:44
First commit. Don't vendor Rum. Leaf check-in: fd74213d0d user: christian tags: trunk
02:43
initial empty check-in check-in: 17b7bfe52e user: christian tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added LICENSE.















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Copyright (c) 2012 Christian Koch.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

  * Redistributions of source code must retain the above copyright notice,
    this list of conditions and the following disclaimer.

  * Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Added config.ru.































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#
# Little Wiki
# config.ru
#
# Christian Koch <cfkoch@sdf.lonestar.org>
#
# -----
#
# Little Wiki is a simple wiki-ish web application based on Christian
# Neukirchen's own mini-framework, Rum. All of your site's content is written in
# Markdown, save the layout, which is written in HTML/ERB. The directory
# heirarchy of Little Wiki is very similar to that of Sinatra:
#
#   lib/
#     rum.rb
#   public/
#     css/
#     jpg/
#   views/
#     index.md
#     layout.erb
#     posts/
#       index.md
#       20120209.md
#       20120315.md
#
# If a client requests a directory, then the file called "index.md" will be
# served if it exists in that directory, otherwise the server will return 404
# Not Found. All other requests should point directly to the desired view, but
# without the .md extension. For example, to read the March 15 post, request for
# http://example.com/posts/20120315. (This means that any Markdown content must
# be stored in a file with a .md extension.)
#
# Two variables are exposed to layout.erb:
#   @mtime       represents the modification time of the requested view
#   @inner_text  contains the HTML result of the requested Markdown content
#                (just like <%= yield %> in Sinatra)
#
# That's pretty much all there is to it. Little Wiki was designed to be tiny,
# fast, and would require one to SSH into the server in order to make changes.
#
# TODO:
#   * Automatically set the HTML <title> of each page to something meaningful.
#

THIS_DIR   = File.dirname(__FILE__)
VIEWS_DIR  = File.join(THIS_DIR, 'views')
LIB_DIR    = File.join(THIS_DIR, 'lib')
PUBLIC_DIR = File.join(THIS_DIR, 'public')

$LOAD_PATH.unshift LIB_DIR
require 'rubygems'
require 'rum'
require 'erb'
require 'rdiscount'

use Rack::CommonLogger
use Rack::ShowExceptions
use Rack::ShowStatus

# This makes the application aware of public dirs *only once* -- therefore, if
# you add a new public dir then you still need to reboot the server.
public_dirs = Dir.glob("#{PUBLIC_DIR}/*").map { |d| "/" + File.basename(d) }
use Rack::Static, :urls => public_dirs, :root => 'public'

#####

LittleWiki = Rum.new do
  def render(template)
    @inner_text = RDiscount.new(
      File.read(File.join(VIEWS_DIR, "#{template}.md")),
      :smart
    ).to_html

    @mtime = File.mtime(File.join(VIEWS_DIR, "#{template}.md"))

    result = ERB.new(File.read(File.join(VIEWS_DIR, 'layout.erb'))).
      result(binding)
    puts result  
  end

  on get, path(/.*/) do |_, slug|
    begin
      if File.file?(File.join(VIEWS_DIR, slug, "index.md"))
        render "#{slug}/index"
      else
        render slug
      end
    rescue
      res.status = 404
    end
  end
end

run LittleWiki