picombo 0.1.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/lib/bootstrap.rb +17 -0
- data/lib/classes/bench.rb +57 -0
- data/lib/classes/cache.rb +89 -0
- data/lib/classes/cache_file.rb +80 -0
- data/lib/classes/config.rb +81 -0
- data/lib/classes/cookie.rb +27 -0
- data/lib/classes/e404.rb +5 -0
- data/lib/classes/event.rb +136 -0
- data/lib/classes/html.rb +45 -0
- data/lib/classes/input.rb +59 -0
- data/lib/classes/log.rb +31 -0
- data/lib/classes/router.rb +155 -0
- data/lib/classes/security.rb +46 -0
- data/lib/classes/session.rb +21 -0
- data/lib/classes/url.rb +15 -0
- data/lib/classes/view/xml.rb +17 -0
- data/lib/classes/view.rb +80 -0
- data/lib/config/cache.yaml +3 -0
- data/lib/config/log.yaml +10 -0
- data/lib/config/mimes.yaml +210 -0
- data/lib/config/routes.yaml +1 -0
- data/lib/controllers/error_404.rb +11 -0
- data/lib/controllers/template.rb +34 -0
- data/lib/core/core.rb +234 -0
- data/lib/hooks/datamapper.rb +13 -0
- data/lib/hooks/profiler.rb +3 -0
- data/lib/views/404.rhtml +2 -0
- data/lib/views/bench/footer.rhtml +22 -0
- metadata +82 -0
data/lib/core/core.rb
ADDED
@@ -0,0 +1,234 @@
|
|
1
|
+
# Picombo MVC Web Framework
|
2
|
+
#
|
3
|
+
# Author:: Jeremy Bush
|
4
|
+
# Copyright:: Copyright (c) 2010 Jeremy Bush
|
5
|
+
# License:: See LICENSE
|
6
|
+
|
7
|
+
# Picombo is a Rack-based Ruby MVC web framework with design principles taken from the Kohana PHP Framework.
|
8
|
+
#
|
9
|
+
# It's designed to be fast, lightweight and easy to use.
|
10
|
+
|
11
|
+
module Picombo
|
12
|
+
class Core
|
13
|
+
@@extension = 'html'
|
14
|
+
|
15
|
+
def self.extension()
|
16
|
+
@@extension
|
17
|
+
end
|
18
|
+
def self.extension=(extension)
|
19
|
+
@@extension = extension
|
20
|
+
end
|
21
|
+
|
22
|
+
# Standard call function that gets invoked by Rack
|
23
|
+
def call(env)
|
24
|
+
# start system benchmark
|
25
|
+
Picombo::Bench.instance.start('application')
|
26
|
+
Picombo::Bench.instance.start('loading')
|
27
|
+
|
28
|
+
@@env = env
|
29
|
+
@@req = Rack::Request.new(env)
|
30
|
+
|
31
|
+
@@extension = File.extname(@@req.path)[1..-1]
|
32
|
+
@@extension = 'html' if @@extension.nil?
|
33
|
+
|
34
|
+
@@response = Rack::Response.new
|
35
|
+
#@@response['Content-Type'] = Picombo::Config.load('mimes.'+@@extension)[0]
|
36
|
+
@@response['Content-Type'] = 'text/html'
|
37
|
+
@@response.status = 200
|
38
|
+
@@redirect = []
|
39
|
+
|
40
|
+
# Add directory extensions to the filesystem
|
41
|
+
Picombo::Config.get('config.extensions').each do |extension|
|
42
|
+
require extension
|
43
|
+
end
|
44
|
+
$LOAD_PATH.delete(APPPATH)
|
45
|
+
$LOAD_PATH.unshift(APPPATH)
|
46
|
+
|
47
|
+
# Load hooks
|
48
|
+
Picombo::Config.get('config.hooks').each do |hook|
|
49
|
+
Picombo::Core.find_file('hooks', hook).each do |file|
|
50
|
+
require file
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
## intialize the input library
|
55
|
+
Picombo::Input.instance.set_request(@@req)
|
56
|
+
Picombo::Session.instance.init(@@req)
|
57
|
+
Picombo::Cookie.instance.init(@@req)
|
58
|
+
Picombo::Bench.instance.stop('loading')
|
59
|
+
|
60
|
+
Picombo::Log.write(:debug, 'Picombo Setup Complete')
|
61
|
+
output = Picombo::Router.new(@@req).process()
|
62
|
+
|
63
|
+
Picombo::Event.run('system.shutdown')
|
64
|
+
|
65
|
+
output
|
66
|
+
end
|
67
|
+
|
68
|
+
# Sets a system redirect
|
69
|
+
def self.redirect(location, status = 302)
|
70
|
+
# Add the base url if a relative path was requested
|
71
|
+
location = Picombo::Url.base+location unless location[0..3] == 'http'
|
72
|
+
|
73
|
+
@@redirect = [location, status]
|
74
|
+
render
|
75
|
+
end
|
76
|
+
|
77
|
+
# Adds content to the output buffer
|
78
|
+
def self.response(str, status = 200)
|
79
|
+
@@response.status = status
|
80
|
+
@@response.write(str)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Allows access to raw response object
|
84
|
+
def self.raw_response
|
85
|
+
@@response
|
86
|
+
end
|
87
|
+
|
88
|
+
# Renders the output buffer. Called by Picombo::Router only.
|
89
|
+
def self.render
|
90
|
+
if ! @@redirect.empty?
|
91
|
+
@@response.redirect(*@@redirect)
|
92
|
+
return @@response.finish
|
93
|
+
end
|
94
|
+
|
95
|
+
Picombo::Event.run('system.display')
|
96
|
+
|
97
|
+
response = @@response.finish
|
98
|
+
@@response = Rack::Response.new
|
99
|
+
response
|
100
|
+
end
|
101
|
+
|
102
|
+
# Finds a file recursively in the CFS.
|
103
|
+
#
|
104
|
+
# Searches application, then extension locations in order, then system.
|
105
|
+
#
|
106
|
+
# Returns an array of files that are found
|
107
|
+
def self.find_file(directory, file, required = false, ext = 'rb')
|
108
|
+
ext = "."+ext
|
109
|
+
|
110
|
+
files = []
|
111
|
+
$LOAD_PATH.each do |path|
|
112
|
+
if File.exist?(path+'/'+directory+'/'+file+ext)
|
113
|
+
files.unshift(path+'/'+directory+'/'+file+ext)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
raise LoadError if required and files.empty?
|
118
|
+
|
119
|
+
# reverse the array, to put application files first
|
120
|
+
return directory == 'config' ? files : files.reverse!
|
121
|
+
end
|
122
|
+
|
123
|
+
# Lists all files and directories in a resource path.
|
124
|
+
def self.list_files(directory)
|
125
|
+
files = []
|
126
|
+
|
127
|
+
$LOAD_PATH.each do |path|
|
128
|
+
if File.directory?(path+'/'+directory)
|
129
|
+
files.concat(Dir.new(path+'/'+directory).entries.collect! {|file|
|
130
|
+
unless (file == '.' or file == '..')
|
131
|
+
path+directory+'/'+file
|
132
|
+
end
|
133
|
+
})
|
134
|
+
end
|
135
|
+
end
|
136
|
+
files.delete('.')
|
137
|
+
files.delete('..')
|
138
|
+
files.compact
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Autoloader for missing Picombo classes
|
143
|
+
def Picombo.const_missing(name)
|
144
|
+
filename = name.to_s
|
145
|
+
|
146
|
+
require 'classes/'+filename
|
147
|
+
|
148
|
+
raise filename+' not found!' if ! const_defined?(name)
|
149
|
+
|
150
|
+
klass = const_get(name)
|
151
|
+
return klass if klass
|
152
|
+
raise klass+" not found!"
|
153
|
+
end
|
154
|
+
|
155
|
+
# == Model Module
|
156
|
+
#
|
157
|
+
# Models are the back end classes that handle business logic and data access. They accept input from controllers,
|
158
|
+
# and can manipulate data sources such as databases and other kinds of data.
|
159
|
+
#
|
160
|
+
# === Creating Model Files
|
161
|
+
#
|
162
|
+
# You can use any kind of modeling library to represent your models, such as DataMapper or ActiveRecord.
|
163
|
+
# You can also create "raw" models that don't use a library, and directly access a database. You will need
|
164
|
+
# to include your own database access methods in this case
|
165
|
+
#
|
166
|
+
# === Model Naming Conventions
|
167
|
+
# * Models live in the Picombo::Models namespace. They must be prefaced with these modules in the file
|
168
|
+
# * Models are placed in the /models directory
|
169
|
+
# * Model filenames must be named the same as the class name: class Foobar would live in /models/foobar.rb
|
170
|
+
# * Model filenames must be lowercase
|
171
|
+
module Models
|
172
|
+
# Autoloader for missing models
|
173
|
+
def Models.const_missing(name)
|
174
|
+
filename = name.to_s
|
175
|
+
|
176
|
+
require 'models/'+filename.downcase
|
177
|
+
|
178
|
+
raise filename+' not found!' if ! const_defined?(name)
|
179
|
+
|
180
|
+
klass = const_get(name)
|
181
|
+
return klass if klass
|
182
|
+
raise klass+" not found!"
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
# == Controller Module
|
187
|
+
#
|
188
|
+
# Controllers are the front level classes that expose your app to the web. They pass information to the model,
|
189
|
+
# retrieve information from the model, and pass data to views, which contain the final output for users.
|
190
|
+
#
|
191
|
+
# === Calling Controllers
|
192
|
+
# Controllers are called via URIs, i.e. http://example.com/foobar/baz
|
193
|
+
# * Segment #1 is the controller name
|
194
|
+
# * Segment #2 is the controller method to call
|
195
|
+
#
|
196
|
+
# Controller Naming Conventions
|
197
|
+
# * Controllers live in the Picombo::Controllers namespace. They must be prefaced with these modules in the file
|
198
|
+
# * Controllers are placed in the /controllers directory
|
199
|
+
# * Controller filenames must be named the same as the class name: class Foobar would live in /controllers/foobar.rb
|
200
|
+
# * Controller filenames must be lowercase
|
201
|
+
#
|
202
|
+
# === Controller Arguments
|
203
|
+
# Controller arguments are passed via URI segments after the second, i.e. http://example.com/foobar/baz/foo/bar
|
204
|
+
# * This would match the baz method of the foobar controller, and match the arg1 and arg2 method arguments
|
205
|
+
# * def baz(arg1, arg2)
|
206
|
+
# The arguments must match the method exactly or a 404 exception will occur
|
207
|
+
#
|
208
|
+
# === Example Controller
|
209
|
+
#
|
210
|
+
# module Picombo
|
211
|
+
# module Controllers
|
212
|
+
# class Foobar
|
213
|
+
# def index
|
214
|
+
# Picombo::Core.response('Hello World!')
|
215
|
+
# end
|
216
|
+
# end
|
217
|
+
# end
|
218
|
+
# end
|
219
|
+
# This controller and method could be called via http://example.com/foobar/index
|
220
|
+
module Controllers
|
221
|
+
# Autoloader for missing controller names
|
222
|
+
def Controllers.const_missing(name)
|
223
|
+
filename = name.to_s
|
224
|
+
|
225
|
+
require 'controllers/'+filename
|
226
|
+
|
227
|
+
raise LoadError if ! const_defined?(name)
|
228
|
+
|
229
|
+
klass = const_get(name)
|
230
|
+
return klass if klass
|
231
|
+
raise LoadError
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Set up database
|
2
|
+
DataMapper.setup(:default,
|
3
|
+
{:host => Picombo::Config.get('datamapper.default.host'),
|
4
|
+
:adapter => Picombo::Config.get('datamapper.default.driver'),
|
5
|
+
:database => Picombo::Config.get('datamapper.default.database'),
|
6
|
+
:username => Picombo::Config.get('datamapper.default.username'),
|
7
|
+
:password => Picombo::Config.get('datamapper.default.password')})
|
8
|
+
|
9
|
+
module Picombo
|
10
|
+
class Model
|
11
|
+
include DataMapper::Resource
|
12
|
+
end
|
13
|
+
end
|
data/lib/views/404.rhtml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
<table style="width: 100%">
|
2
|
+
<tr>
|
3
|
+
<th align="left">System Benchmarks</th>
|
4
|
+
<th align="right">Time</th>
|
5
|
+
</tr>
|
6
|
+
<tr>
|
7
|
+
<td>Picombo Setup</td>
|
8
|
+
<td align="right"><%= Picombo::Bench.instance.get('loading') %></td>
|
9
|
+
</tr>
|
10
|
+
<tr>
|
11
|
+
<td>Environment Setup</td>
|
12
|
+
<td align="right"><%= Picombo::Bench.instance.get('setup') %></td>
|
13
|
+
</tr>
|
14
|
+
<tr>
|
15
|
+
<td>Controller Execution</td>
|
16
|
+
<td align="right"><%= Picombo::Bench.instance.get('controller_execution') %></td>
|
17
|
+
</tr>
|
18
|
+
<tr>
|
19
|
+
<td>Total Execution</td>
|
20
|
+
<td align="right"><%= Picombo::Bench.instance.get('application') %></td>
|
21
|
+
</tr>
|
22
|
+
</table>
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: picombo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Bush
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-04-23 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Picombo is a lightweight MVC framework inspired by the Kohana PHP MVC framework.
|
17
|
+
email: contractfrombelow@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/bootstrap.rb
|
26
|
+
- lib/classes/bench.rb
|
27
|
+
- lib/classes/cache.rb
|
28
|
+
- lib/classes/cache_file.rb
|
29
|
+
- lib/classes/config.rb
|
30
|
+
- lib/classes/cookie.rb
|
31
|
+
- lib/classes/e404.rb
|
32
|
+
- lib/classes/event.rb
|
33
|
+
- lib/classes/html.rb
|
34
|
+
- lib/classes/input.rb
|
35
|
+
- lib/classes/log.rb
|
36
|
+
- lib/classes/router.rb
|
37
|
+
- lib/classes/security.rb
|
38
|
+
- lib/classes/session.rb
|
39
|
+
- lib/classes/url.rb
|
40
|
+
- lib/classes/view
|
41
|
+
- lib/classes/view/xml.rb
|
42
|
+
- lib/classes/view.rb
|
43
|
+
- lib/config/cache.yaml
|
44
|
+
- lib/config/log.yaml
|
45
|
+
- lib/config/mimes.yaml
|
46
|
+
- lib/config/routes.yaml
|
47
|
+
- lib/controllers
|
48
|
+
- lib/controllers/error_404.rb
|
49
|
+
- lib/controllers/template.rb
|
50
|
+
- lib/core/core.rb
|
51
|
+
- lib/hooks/datamapper.rb
|
52
|
+
- lib/hooks/profiler.rb
|
53
|
+
- lib/views/404.rhtml
|
54
|
+
- lib/views/bench/footer.rhtml
|
55
|
+
has_rdoc: false
|
56
|
+
homepage: http://www.picombo.net/
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.3.1
|
78
|
+
signing_key:
|
79
|
+
specification_version: 2
|
80
|
+
summary: A lightweight MVC web framework
|
81
|
+
test_files: []
|
82
|
+
|