cohitre-perro 0.6.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.
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2008-08-26
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,9 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/perro.rb
6
+ lib/perro/haml_handler.rb
7
+ lib/perro/proxy_handler.rb
8
+ lib/perro/sass_handler.rb
9
+ test/test_perro.rb
@@ -0,0 +1,72 @@
1
+ = perro
2
+
3
+ http://code.cohitre.com
4
+
5
+ == DESCRIPTION:
6
+
7
+ Perro is a light server built on top of mongrel that helps at least
8
+ one developer be happy. If it had been designed as production server
9
+ it would have a cooler name. Like "Dinosaur" or "Freckle".
10
+
11
+ The Internet is a global system of interconnected computer networks.
12
+ Developer creates files that are served through this global system.
13
+ Developer may be tempted to develop such files by creating a folder,
14
+ moving the files to such folder, double clicking them and watching
15
+ what happens on the browser whose address bar reads
16
+ "file:///Users/cohitre/development/my-project/index.html".
17
+
18
+ Perro helps developer be happy by helping overcome temptation.
19
+
20
+ == FEATURES/PROBLEMS:
21
+
22
+ Developer wants file "guaca.haml" served on route "mayo". Perro can
23
+ help with that if asked nicely.
24
+
25
+ == SYNOPSIS:
26
+
27
+ require "rubygems"
28
+ require "perro"
29
+
30
+ HOME_FOLDER = File.expand_path( "~" )
31
+
32
+ server = Perro::Server.new(3001)
33
+ server.static( "/javascripts" , "#{HOME_FOLDER}/libs/javascript")
34
+ server.sass( "/stylesheets" , "#{HOME_FOLDER}/libs/sass")
35
+ server.proxy( "/service" , "http://example.com" )
36
+ server.haml( "/" , "#{File.expand_path(".")}/" )
37
+ server.start
38
+
39
+ == REQUIREMENTS:
40
+
41
+ mongrel
42
+ haml
43
+
44
+
45
+ == INSTALL:
46
+
47
+ "sudo gem install perro" may work...
48
+
49
+ == LICENSE:
50
+
51
+ (The MIT License)
52
+
53
+ Copyright (c) 2008 Carlos Rodriguez
54
+
55
+ Permission is hereby granted, free of charge, to any person obtaining
56
+ a copy of this software and associated documentation files (the
57
+ 'Software'), to deal in the Software without restriction, including
58
+ without limitation the rights to use, copy, modify, merge, publish,
59
+ distribute, sublicense, and/or sell copies of the Software, and to
60
+ permit persons to whom the Software is furnished to do so, subject to
61
+ the following conditions:
62
+
63
+ The above copyright notice and this permission notice shall be
64
+ included in all copies or substantial portions of the Software.
65
+
66
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
67
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
68
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
69
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
70
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
71
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
72
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'hoe'
3
+ require './lib/perro.rb'
4
+
5
+ Hoe.new('perro', Perro::VERSION) do |p|
6
+ p.name = "perro"
7
+ p.developer('carlos', 'carlosrr@gmail.com')
8
+ p.summary = "A quick and dirty solution for serving files easily."
9
+ p.extra_deps = [ ["mongrel", ">= 1.1.4"], ["haml" , ">= 2.0.2"] ]
10
+ end
@@ -0,0 +1,67 @@
1
+ begin
2
+ require 'action_controller'
3
+ rescue
4
+ puts "It appears that you don't have action_controller."
5
+ puts "`sudo gem install rails` might help you with that."
6
+ end
7
+
8
+ require "open-uri"
9
+ require "mongrel"
10
+
11
+ ActionView::Base.helper_modules.each {|m| include m }
12
+
13
+ module Perro
14
+ VERSION = '0.6.0'
15
+
16
+ class Server
17
+ attr_reader :routes
18
+ @@route_keys = {}
19
+
20
+
21
+ def self.route_manager key , handler
22
+ @@route_keys[key] = handler
23
+ end
24
+
25
+ def initialize port=3000
26
+ @routes_manager = {}
27
+ @port = port
28
+ end
29
+
30
+ def route key , uri , file
31
+ @routes_manager[key] ||= []
32
+ r = { :route => uri , :resource => file }
33
+ @routes_manager[key].push( r )
34
+ end
35
+
36
+ def static uri , file
37
+ route( :static , uri , file )
38
+ end
39
+
40
+ def start
41
+ routes = @routes_manager
42
+ port = @port
43
+ config = Mongrel::Configurator.new :host => "0.0.0.0" do
44
+ listener :port => port do
45
+ routes.each do |k,v|
46
+ v.each do |r|
47
+ uri( r[:route] , :handler => @@route_keys[k].new( r[:resource]) )
48
+ end
49
+ end
50
+ end
51
+ run
52
+ end
53
+ puts '** Perro Server Started'
54
+ puts '** Woof Woof'
55
+ puts "** Listening to port #{@port}"
56
+ puts '** Use CTRL-C to stop.'
57
+
58
+ config.join
59
+ end
60
+ end
61
+
62
+ Server.route_manager( :static , Mongrel::DirHandler )
63
+ end
64
+
65
+ require "#{File.expand_path( __FILE__+"/.." )}/perro/haml_handler.rb"
66
+ require "#{File.expand_path( __FILE__+"/.." )}/perro/proxy_handler.rb"
67
+ require "#{File.expand_path( __FILE__+"/.." )}/perro/sass_handler.rb"
@@ -0,0 +1,34 @@
1
+ require "haml"
2
+
3
+ module Perro
4
+
5
+ class HAMLHandler < Mongrel::HttpHandler
6
+ def initialize file
7
+ super()
8
+ @file = file
9
+ end
10
+
11
+ def process request , response
12
+ filename = request.params['PATH_INFO'].empty? ? "#{@file}/index.haml" : @file+request.params["PATH_INFO"]
13
+ if ( !File.exists?( filename) )
14
+ response.start(404) do |head,out|
15
+ out.write( "404 Error : File #{filename} was not found" )
16
+ end
17
+ else
18
+ response.start(200) do |head,out|
19
+ head['Content-Type'] = 'text/html'
20
+ engine = Haml::Engine.new( open(filename).read )
21
+ out.write( engine.render )
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ class Server
28
+ def haml uri , file
29
+ route( :haml , uri , file )
30
+ end
31
+ end
32
+
33
+ Server.route_manager( :haml , HAMLHandler )
34
+ end
@@ -0,0 +1,23 @@
1
+ module Perro
2
+
3
+ class ProxyHandler < Mongrel::HttpHandler
4
+ def initialize url
5
+ super()
6
+ @url = url
7
+ end
8
+
9
+ def process request , response
10
+ response.start(200) do |head,out|
11
+ head['Content-Type'] = 'text/html'
12
+ out.write( open(@url + request.params["PATH_INFO"]).read )
13
+ end
14
+ end
15
+ end
16
+
17
+ class Server
18
+ def proxy uri , file
19
+ route( :proxy , uri , file )
20
+ end
21
+ end
22
+ Server.route_manager( :proxy , ProxyHandler )
23
+ end
@@ -0,0 +1,28 @@
1
+ require "sass"
2
+
3
+ module Perro
4
+
5
+ class SASSHandler < Mongrel::HttpHandler
6
+ def initialize path
7
+ super()
8
+ @path = path
9
+ end
10
+
11
+ def process request , response
12
+ response.start(200) do |head,out|
13
+ head['Content-Type'] = 'text/css'
14
+
15
+ engine = Sass::Engine.new( open("#{@path}#{request.params["PATH_INFO"]}").read )
16
+
17
+ out.write( engine.render )
18
+ end
19
+ end
20
+ end
21
+
22
+ class Server
23
+ def sass uri , file
24
+ route( :sass , uri , file )
25
+ end
26
+ end
27
+ Server.route_manager( :sass , SASSHandler )
28
+ end
@@ -0,0 +1 @@
1
+ # Imagine that there is very good test coverage.
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cohitre-perro
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - carlos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-10 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mongrel
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.1.4
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: haml
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 2.0.2
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: hoe
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.7.0
41
+ version:
42
+ description: Perro is a light server built on top of mongrel that helps at least one developer be happy. If it had been designed as production server it would have a cooler name. Like "Dinosaur" or "Freckle". The Internet is a global system of interconnected computer networks. Developer creates files that are served through this global system. Developer may be tempted to develop such files by creating a folder, moving the files to such folder, double clicking them and watching what happens on the browser whose address bar reads "file:///Users/cohitre/development/my-project/index.html". Perro helps developer be happy by helping overcome temptation.
43
+ email:
44
+ - carlosrr@gmail.com
45
+ executables: []
46
+
47
+ extensions: []
48
+
49
+ extra_rdoc_files:
50
+ - History.txt
51
+ - Manifest.txt
52
+ - README.txt
53
+ files:
54
+ - History.txt
55
+ - Manifest.txt
56
+ - README.txt
57
+ - Rakefile
58
+ - lib/perro.rb
59
+ - lib/perro/haml_handler.rb
60
+ - lib/perro/proxy_handler.rb
61
+ - lib/perro/sass_handler.rb
62
+ - test/test_perro.rb
63
+ has_rdoc: true
64
+ homepage: http://code.cohitre.com
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --main
68
+ - README.txt
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ requirements: []
84
+
85
+ rubyforge_project: perro
86
+ rubygems_version: 1.2.0
87
+ signing_key:
88
+ specification_version: 2
89
+ summary: A quick and dirty solution for serving files easily.
90
+ test_files:
91
+ - test/test_perro.rb