[ create a new paste ] login | about

Link: http://codepad.org/BFggyhf2    [ raw code | fork | 5 comments ]

apotheon - Plain Text, pasted on Mar 28:
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="main.css" />
    <title>Foo</title>
  </head>
  <body>
    <%
      require 'bluecloth'
      require 'cgi'

      cgi = CGI.new
      content = cgi.params['page']

      path = File.join(File.dirname(__FILE__), 'content')

      list_start = '<li><a href="'

      puts '<ul class="menu">'

      Dir.open(path) do |dir|
        dir.sort.each do |file|
          if file.match(/.txt$/)
            file_title = file.sub(/.txt$/, '').split('_').map do |word|
              word.capitalize
            end

            address = file == 'index.txt' ? './' : "?page=#{file.sub(/.txt$/, '')}"

            puts "#{list_start}#{address + '"'}>#{file_title}</a></li>"
          end
        end
      end

      puts '</ul>'

      file_contents = if content.length < 1
        File.open(File.join path, 'index.txt').read
      else
        File.open(File.join path, content.to_s + '.txt').read
      end

      puts BlueCloth.new(file_contents).to_html
    %>
  </body>
</html>


Create a new paste based on this one


Comments:
posted by apotheon on Mar 28
CMMS: Content Management Micro-System

You may distribute this under the terms of the Nietzsche Public License:

http://copyfree.org/licenses/nietzschepl/license.txt
reply
posted by apotheon on Mar 28
You need eruby and the BlueCloth gem to use this as written.

Wherever you stick this on your server, create a directory there called "content".

Put all your content files into the "content" directory.

Format text in the content files using Markdown syntax.

The rest should handle itself.

You may want to change the page title from "Foo" to something else.

reply
posted by apotheon on Mar 28
This was created in a few spare minutes for the purpose of making a point here:

http://www.techrepublic.com/forum/discussions/102-390300-3656482

reply
posted by apotheon on Mar 28
You may need to copy-and-paste that TechRepublic URI if you want to see the page. For some reason, the link target contains extra characters in at least some browsers.
reply
posted by apotheon on Apr 10
For Ruby 1.8.x, you should add a line that reads "require 'rubygems'" before the other require statements.
reply