margot 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +7 -0
- data/Manifest.txt +10 -0
- data/README.txt +60 -0
- data/Rakefile +18 -0
- data/bin/margot +30 -0
- data/lib/margot.rb +56 -0
- data/test/blog/index.mab +23 -0
- data/test/index.mab +1 -0
- data/test/layout.mab +6 -0
- data/test/test_margot.rb +0 -0
- metadata +74 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
= MARGOT
|
2
|
+
by: The Polymorphers
|
3
|
+
* cdcarter
|
4
|
+
* willcodeforfoo
|
5
|
+
* defunkt
|
6
|
+
|
7
|
+
== DESCRIPTION:
|
8
|
+
|
9
|
+
Margot is the missing link between Mongrel (http://mongrel.rubyforge.org) and Markaby (http://code.whytheluckystiff.net/markaby). It is a full webserver that parses and serves Markaby files, giving access to the request information and the parameters
|
10
|
+
|
11
|
+
== FEATURES/PROBLEMS:
|
12
|
+
|
13
|
+
* The query string, and POST/PUT parameters are available through the +params+ hash
|
14
|
+
* Other request data can be attained through the +request+ method
|
15
|
+
* The Markaby instance is called +mab+ (But you do not need to call it directly. The +html+ method is an alias to +mab.html+)
|
16
|
+
* Margot keeps an in memory cache of pages and their parameters!
|
17
|
+
* To clear the cache and garbage collect, just send a USR1 signal to the process
|
18
|
+
* The mongrel status information is mounted by default at /status
|
19
|
+
* A directory handler is loaded at /assets to the directory +./assets+
|
20
|
+
* There is daemonization support but it is borked at the moment
|
21
|
+
* Template and layout handling
|
22
|
+
|
23
|
+
== REQUIREMENTS:
|
24
|
+
|
25
|
+
Margot requires the following gems
|
26
|
+
* Markaby
|
27
|
+
* Mongrel
|
28
|
+
|
29
|
+
== INSTALL:
|
30
|
+
|
31
|
+
sudo gem install margot
|
32
|
+
|
33
|
+
== Usage
|
34
|
+
To use Margot you just create a directory structure, with each subdirectory, and the root containing an +index.mab+ and a +layout.mab+, and start Margot on that directory
|
35
|
+
$ margot 0.0.0.0 3000 ./sites
|
36
|
+
|
37
|
+
== LICENSE:
|
38
|
+
|
39
|
+
(The MIT License)
|
40
|
+
|
41
|
+
Copyright (c) 2006 FIX
|
42
|
+
|
43
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
44
|
+
a copy of this software and associated documentation files (the
|
45
|
+
'Software'), to deal in the Software without restriction, including
|
46
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
47
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
48
|
+
permit persons to whom the Software is furnished to do so, subject to
|
49
|
+
the following conditions:
|
50
|
+
|
51
|
+
The above copyright notice and this permission notice shall be
|
52
|
+
included in all copies or substantial portions of the Software.
|
53
|
+
|
54
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
55
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
56
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
57
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
58
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
59
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
60
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/margot.rb'
|
6
|
+
|
7
|
+
Hoe.new('margot', Margot::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'margot'
|
9
|
+
p.summary = 'The missing link between Markaby and Mongrel'
|
10
|
+
p.author = ['cdcarter','willcodeforfoo','defunkt']
|
11
|
+
p.description = p.paragraphs_of('README.txt', 2..6).join("\n\n")
|
12
|
+
p.url = "http://metacampsite.com/margot/"
|
13
|
+
p.email = "cdcarter@laundr.us"
|
14
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
15
|
+
p.extra_deps = ['markaby','>= 0'],['mongrel','>= 0.3.13.3']
|
16
|
+
end
|
17
|
+
|
18
|
+
# vim: syntax=Ruby
|
data/bin/margot
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
%w[rubygems margot daemons/daemonize].each { |f| require f }
|
2
|
+
|
3
|
+
DAEMON = !!ARGV.delete('-d')
|
4
|
+
Daemonize.daemonize('mongrel.log') if DAEMON
|
5
|
+
puts "started logging" if DAEMON
|
6
|
+
|
7
|
+
DEBUG = !!ARGV.delete('-b')
|
8
|
+
|
9
|
+
STDERR.puts("usage: margot.rb <host> <port> <mab root>") unless ARGV.length == 3
|
10
|
+
exit(1) unless ARGV.length == 3
|
11
|
+
|
12
|
+
stats = Mongrel::StatisticsFilter.new(:sample_rate => 1)
|
13
|
+
|
14
|
+
config = Mongrel::Configurator.new :host => ARGV[0], :port => ARGV[1] do
|
15
|
+
listener do
|
16
|
+
uri "/", :handler => Margot.new(ARGV[2])
|
17
|
+
uri "/", :handler => stats
|
18
|
+
uri "/assets", :handler => Mongrel::DirHandler.new("./assets")
|
19
|
+
uri "/status", :handler => Mongrel::StatusHandler.new(:stats_filter => stats)
|
20
|
+
uri "/favicon.ico", :handler => Mongrel::Error404Handler.new("")
|
21
|
+
end
|
22
|
+
|
23
|
+
trap("INT") { stop }
|
24
|
+
trap("USR1") { @@cache = {}; GC.start; puts "cached cleared" }
|
25
|
+
|
26
|
+
run
|
27
|
+
end
|
28
|
+
|
29
|
+
puts "Mongrel running on #{ARGV[0]}:#{ARGV[1]} with mab root #{ARGV[2]}. PID #{$$}"
|
30
|
+
config.join
|
data/lib/margot.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
%w[rubygems markaby mongrel/stats mongrel/configurator mongrel mongrel/cgi daemons/daemonize].each { |f| require f }
|
2
|
+
|
3
|
+
class Margot < Mongrel::HttpHandler
|
4
|
+
VERSION = '0.5.0'
|
5
|
+
|
6
|
+
@@cache = {}
|
7
|
+
|
8
|
+
def initialize(path)
|
9
|
+
@root = File.expand_path(path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def serve_file(path)
|
13
|
+
req_path = File.expand_path(File.join(@root, Mongrel::HttpRequest.unescape(path)), @root)
|
14
|
+
if File.file?(file = "#{req_path}.mab") || File.file?(file = "#{req_path}/index.mab")
|
15
|
+
File.open(file).read
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def process(request, response)
|
20
|
+
@cgi, @request = Mongrel::CGIWrapper.new(request, response), request
|
21
|
+
status, content_type, body = 404, 'text/html', "<h1>404-File Not Found</h1>"
|
22
|
+
|
23
|
+
if @@cache[cache_key = request.params['PATH_INFO'] + @cgi.params.sort.to_s]
|
24
|
+
status = 200
|
25
|
+
body = @@cache[cache_key]
|
26
|
+
elsif file = serve_file(request.params['PATH_INFO'])
|
27
|
+
status = 200
|
28
|
+
@@cache[cache_key] = (body = layout(compile(file))).dup
|
29
|
+
end
|
30
|
+
|
31
|
+
response.start status do |head, out|
|
32
|
+
head["Content-Type"] = content_type
|
33
|
+
out << body
|
34
|
+
open('log', 'w') { |f| f << "#{status} - GET: #{request.params['REQUEST_URI']}\n" }
|
35
|
+
puts "#{status} - GET: #{request.params['REQUEST_URI']}" if DEBUG
|
36
|
+
end
|
37
|
+
rescue => e
|
38
|
+
puts e.message, e.backtrace.map { |line| " " << line }
|
39
|
+
end
|
40
|
+
|
41
|
+
def compile(file, cgi = @cgi, &block)
|
42
|
+
Markaby::Builder.new do |mab|
|
43
|
+
(class << mab; self end).send(:attr_accessor, :params)
|
44
|
+
mab.params = cgi.params
|
45
|
+
return mab.instance_eval(file) unless file =~ /layout/
|
46
|
+
|
47
|
+
mab.instance_eval %[def #{layout_method = "layout_" + file.hash}() #{file} end]
|
48
|
+
send(layout_method, &block)
|
49
|
+
end.to_s
|
50
|
+
end
|
51
|
+
|
52
|
+
def layout(content)
|
53
|
+
return content unless layout = serve_file(@request.params['PATH_INFO'].split('/').join('') + 'layout')
|
54
|
+
compile(layout) { content }
|
55
|
+
end
|
56
|
+
end
|
data/test/blog/index.mab
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
html do
|
2
|
+
head { title "RubyHP!" }
|
3
|
+
body do
|
4
|
+
h1 "Ruby Rocks"
|
5
|
+
ul do
|
6
|
+
li "Easy Webpages"
|
7
|
+
li "cool libraries"
|
8
|
+
li "awesome people"
|
9
|
+
end
|
10
|
+
if params.include? "defunkt"
|
11
|
+
text "GURU!"
|
12
|
+
else
|
13
|
+
params.each do |key, value|
|
14
|
+
text "#{key}: #{value}"
|
15
|
+
br
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
if params.empty?
|
20
|
+
text "Get some params! Try adding something like ?params=rock to the end of the URI!"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/test/index.mab
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
p "This is cool!"
|
data/test/layout.mab
ADDED
data/test/test_margot.rb
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: margot
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.5.0
|
7
|
+
date: 2006-10-23 00:00:00 -05:00
|
8
|
+
summary: The missing link between Markaby and Mongrel
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
- test
|
12
|
+
email: cdcarter@laundr.us
|
13
|
+
homepage: http://metacampsite.com/margot/
|
14
|
+
rubyforge_project: margot
|
15
|
+
description: "== FEATURES/PROBLEMS: * The query string, and POST/PUT parameters are available through the +params+ hash * Other request data can be attained through the +request+ method * The Markaby instance is called +mab+ (But you do not need to call it directly. The +html+ method is an alias to +mab.html+) * Margot keeps an in memory cache of pages and their parameters! * To clear the cache and garbage collect, just send a USR1 signal to the process * The mongrel status information is mounted by default at /status * A directory handler is loaded at /assets to the directory +./assets+ * There is daemonization support but it is borked at the moment * Template and layout handling == REQUIREMENTS: Margot requires the following gems * Markaby * Mongrel == INSTALL: sudo gem install margot"
|
16
|
+
autorequire:
|
17
|
+
default_executable:
|
18
|
+
bindir: bin
|
19
|
+
has_rdoc: true
|
20
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
|
+
version:
|
26
|
+
platform: ruby
|
27
|
+
signing_key:
|
28
|
+
cert_chain:
|
29
|
+
authors:
|
30
|
+
- cdcarter
|
31
|
+
- willcodeforfoo
|
32
|
+
- defunkt
|
33
|
+
files:
|
34
|
+
- History.txt
|
35
|
+
- Manifest.txt
|
36
|
+
- README.txt
|
37
|
+
- Rakefile
|
38
|
+
- bin/margot
|
39
|
+
- lib/margot.rb
|
40
|
+
- test/test_margot.rb
|
41
|
+
- test/layout.mab
|
42
|
+
- test/index.mab
|
43
|
+
- test/blog/index.mab
|
44
|
+
test_files: []
|
45
|
+
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
extra_rdoc_files: []
|
49
|
+
|
50
|
+
executables:
|
51
|
+
- margot
|
52
|
+
extensions: []
|
53
|
+
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
dependencies:
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: markaby
|
59
|
+
version_requirement:
|
60
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: mongrel
|
68
|
+
version_requirement:
|
69
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 0.3.13.3
|
74
|
+
version:
|