picombo 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,20 @@
1
1
  module Picombo
2
+ # == Cache_File Class
3
+ #
4
+ # Handles driver level logic for file based caching.
5
+ #
6
+ # Not used by end users. Should only be called from main cache class
2
7
  class Cache_File
3
8
  @@config = nil
4
9
 
10
+ # Constructor.
5
11
  def initialize(config)
6
12
  @@config = config
7
13
  raise "Cache directory does not exist: "+APPPATH+'cache' unless File.directory?(APPPATH+'cache/')
8
14
  raise "Cache directory not writable: "+APPPATH+'cache' unless File.writable?(APPPATH+'cache/')
9
15
  end
10
16
 
17
+ # Finds an array of files that exist for a specified key
11
18
  def exists(keys)
12
19
  return Dir.glob(APPPATH+'cache/*~*') if keys == true
13
20
 
@@ -21,6 +28,7 @@ module Picombo
21
28
  paths.uniq
22
29
  end
23
30
 
31
+ # Writes a config value to a file
24
32
  def set(items, lifetime)
25
33
  lifetime+=Time.now.to_i
26
34
 
@@ -35,6 +43,7 @@ module Picombo
35
43
  return true
36
44
  end
37
45
 
46
+ # Retreives a cached item or items
38
47
  def get(keys, single = false)
39
48
  items = []
40
49
 
@@ -60,18 +69,21 @@ module Picombo
60
69
  end
61
70
  end
62
71
 
72
+ # Deletes a cache entry
63
73
  def delete(keys)
64
74
  exists(keys).each do |file|
65
75
  File.unlink(file)
66
76
  end
67
77
  end
68
78
 
79
+ # Deletes all cache entries
69
80
  def delete_all
70
81
  exists(true).each do |file|
71
82
  File.unlink(file)
72
83
  end
73
84
  end
74
85
 
86
+ # Determines if a cache entry is expired or not
75
87
  def expired(file)
76
88
  expires = file[file.index('~') + 1, file.length]
77
89
  return (expires != 0 and expires.to_i <= Time.now.to_i);
@@ -1,4 +1,40 @@
1
+ require 'yaml'
2
+
1
3
  module Picombo
4
+ # == Config Class
5
+ #
6
+ # Handles retreiving of key value storage items
7
+ #
8
+ # Picombo uses config items internally to keep track of common or long term configuration values. These settings are stored in yaml files.
9
+ #
10
+ # === Overview
11
+ # There are several built in config file types:
12
+ # * config.yaml
13
+ # * datamapper.yaml
14
+ # * cache.yaml
15
+ # * log.yaml
16
+ # * mimes.yaml
17
+ #
18
+ # The only file required to be in your application directory is config.yaml. The rest of the files are defined in the system location.
19
+ # You can change/overwrite the system values by creating the file in your application directory and specifying your application values there.
20
+ # Please refer to the source system files for examples.
21
+ #
22
+ # === Usage
23
+ # To call config values, use the Picombo::Config.get method. The first parameter is the path of your config value, using dot notation. With dot notation, the first part is the filename, and everything after that is the path inside the file.
24
+ #
25
+ # ==== Example
26
+ # For the following file (datamapper.yaml):
27
+ #
28
+ # default:
29
+ # driver: mysql
30
+ # host: localhost
31
+ # database: picom_db
32
+ # username: picom_u
33
+ # password: picom_p
34
+ #
35
+ # You can get the database config value like:
36
+ #
37
+ # Picombo::Config.get('datamapper.default.database')
2
38
  class Config
3
39
  include Enumerable
4
40
 
@@ -1,4 +1,17 @@
1
1
  module Picombo
2
+ # == Cookie handling class
3
+ #
4
+ # In essense, a proxy to the rack cookie handling methods.
5
+ #
6
+ # == Example usage
7
+ # Writing cookie values
8
+ # Picombo::Cookie.set(:sample, 'this is the content of the cookie')
9
+ #
10
+ # Getting cookie values
11
+ # Picombo::Cookie.get(:sample)
12
+ #
13
+ # Deleting a cookie
14
+ # Picombo::Cookie.delete(:sample)
2
15
  class Cookie
3
16
  include Singleton
4
17
 
data/lib/classes/e404.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  module Picombo
2
+ # == Main 404 exception class. Used to detect 404 errors in the app
2
3
  class E404 < Exception
3
4
 
4
5
  end
data/lib/classes/event.rb CHANGED
@@ -76,8 +76,8 @@ module Picombo
76
76
  #
77
77
  # Remove one or all of the callbacks from a given event.
78
78
  #
79
- def self.clear!(name, callback = nil)
80
- return false unless @@events.include?(name)
79
+ def self.clear!(name = nil, callback = nil)
80
+ @@events = {} if name.nil?
81
81
 
82
82
  if callback.nil?
83
83
  @@events[name] = []
data/lib/classes/html.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  module Picombo
2
2
 
3
3
  # Helper class to generate HTML
4
-
5
4
  class Html
6
5
  include Singleton
7
6
 
@@ -16,6 +15,7 @@ module Picombo
16
15
  safe.join
17
16
  end
18
17
 
18
+ # Returns a html link tag for +css+
19
19
  def self.style(css)
20
20
  unless css.is_a? Array
21
21
  return '<link type="text/css" href="'+Picombo::Url.base()+css+'" rel="stylesheet" />'
@@ -29,6 +29,7 @@ module Picombo
29
29
  to_return
30
30
  end
31
31
 
32
+ # Returns a html script tag for +js+
32
33
  def self.script(js)
33
34
  unless js.is_a? Array
34
35
  return '<script type="text/javascript" src="'+Url.base()+js+'"></script>'
data/lib/classes/log.rb CHANGED
@@ -16,7 +16,7 @@ module Picombo
16
16
  class Log
17
17
  include Singleton
18
18
 
19
- # Writes log entry with level +type+:: with +message+::
19
+ # Writes log entry with level +type+ with +message+
20
20
  def self.write(type, message)
21
21
  types = {:none => 0, :info => 1, :warning => 2, :notice => 3, :debug => 4}
22
22
 
@@ -3,52 +3,68 @@ module Picombo
3
3
  # Processes the URI to route requests to proper controller
4
4
  #
5
5
  # == Using Routes
6
- # Routes are defined in the +config/routes.yaml+:: config file.
6
+ # Routes are defined in the +config/routes.rb+ config file.
7
7
  #
8
- # There should always be a 'default' route, which is the route that applies when there are no uri segments. ex: +default: controller/method+::
8
+ # There should always be a '_default' route, which is the route that applies when there are no uri segments. ex: +Picombo::Router.add('_default', 'controller/method')+
9
9
  #
10
- # The first kind of route is an exact match route. This will look for a URI match in the keys of the routes file. ex: +foobar/baz: controller/method+::
10
+ # The first kind of route is an exact match route. This will look for a URI match in the keys of the routes file. ex: +Picombo::Router.add('foobar/baz', 'controller/method')+
11
11
  #
12
12
  # You can also use regex routes for more powerful routing:
13
- # * A catch-all route: .+: controller/method
14
- # * Routing all second URI segments to the index method: foobar/(.+): foobar/index
15
- # * ([a-z]{2}): chamber/video/\1
13
+ # * A catch-all route: Picombo::Router.add(Regexp.new(/(.+)/), 'controller/method')
14
+ # * Routing all second URI segments to the index method: Picombo::Router.add(Regexp.new(/foobar\/(.+)/), 'foobar/index')
15
+ # * Picombo::Router.add(Regexp.new(/([a-z]{2})/), 'chamber/video/\1')
16
+ #
17
+ # === Using lambdas for routes
18
+ # You can use lamba methods for complex routing schemes that rely on extra logic. The first parameter to the lambda method is the source uri as a string
19
+ #
20
+ # Picombo::Route.add('my complex route', lambda{ |path|
21
+ # if Regexp.new('(complex|foobar)/([a-z]{2})/(.+)').match(path)
22
+ # {:controller => 'city', :method => 'index', :params => Regexp.last_match[2,3]}
23
+ # end
24
+ # })
16
25
 
17
26
  class Router
18
27
  @@req = nil
28
+ @@routes = {}
19
29
 
20
- # Data writer.
21
- def self.routes=(routes)
22
- @@routes = routes
23
- end
30
+ # Assigns the current uri of the request
24
31
  def self.current_uri=(current_uri)
25
32
  @@current_uri = current_uri
26
33
  end
34
+ # Reads the current uri of the request
27
35
  def self.current_uri
28
36
  @@current_uri
29
37
  end
38
+ # Assigns the current segments of the request
30
39
  def self.segments=(segments)
31
40
  @@segments = segments
32
41
  end
42
+ # Reads the current segments of the request
33
43
  def self.segments
34
44
  @@segments
35
45
  end
46
+ # Assigns the current rsegments of the request
36
47
  def self.rsegments=(rsegments)
37
48
  @@rsegments = rsegments
38
49
  end
50
+ # Assigns the current controller of the request
39
51
  def self.controller=(controller)
40
52
  @@controller = controller
41
53
  end
54
+ # Reads the current controller of the request
42
55
  def self.controller
43
56
  @@controller
44
57
  end
58
+ # Assigns the current method of the request
45
59
  def self.method=(method)
46
60
  @@method = method
47
61
  end
62
+ # Reads the current method of the request
48
63
  def self.method
49
64
  @@method
50
65
  end
51
66
 
67
+ # Initializes the request
52
68
  def initialize(req)
53
69
  @@req = req
54
70
  end
@@ -60,8 +76,7 @@ module Picombo
60
76
  Picombo::Event.run('system.pre_router')
61
77
  # Find the controller and method
62
78
  uri = @@req.path
63
- path = uri[0..-(File.extname(uri).length+1)]
64
- uri = Picombo::Router.process_uri(path)
79
+ uri = Picombo::Router.process_uri(uri)
65
80
 
66
81
  # Let events have the ability to modify the uri array
67
82
  Picombo::Event.run('system.post_router', uri)
@@ -94,7 +109,7 @@ module Picombo
94
109
  return Picombo::Controllers::Error_404.new.run_error(@@req.path)
95
110
  end
96
111
  else
97
- return Picombo::Controllers::Error_404.new.run_error(uri.inspect)
112
+ return Picombo::Controllers::Error_404.new.run_error(@@req.path)
98
113
  end
99
114
  Picombo::Event.run('system.post_controller')
100
115
 
@@ -104,27 +119,56 @@ module Picombo
104
119
  Picombo::Core.render
105
120
  end
106
121
 
122
+ # Adds a route to the router
123
+ #
124
+ # * key - the name of the route (optionally the source URI for simple routes)
125
+ # * val - the destination of the route (optionally a lambda for complex routes)
126
+ def self.add(key, val, style = nil)
127
+ @@routes[key] = {:val => val, :generate => style}
128
+ end
129
+
130
+ # Generates a routed URI based on paramaters
131
+ def self.generate(key, params = [])
132
+ raise ArgumentError.new('The route: "'+key+'" doesn\'t exist!') if ! @@routes.key?(key)
133
+ route = @@routes[key]
134
+
135
+ routing_string = route[:generate]
136
+
137
+ params.each do |key, value|
138
+ routing_string.gsub!('{'+key.to_s+'}', value)
139
+ end
140
+
141
+ routing_string
142
+ end
143
+
107
144
  # Takes a uri path string and determines the controller, method and any get parameters
108
145
  # Uses the routes config file for translation
109
146
  def self.process_uri(path)
110
- router_parts = path == '/' ? ('/'+Picombo::Config.get('routes._default')).split('/') : path.split('/')
147
+
148
+ # Load routes
149
+ Picombo::Core.find_file('config', 'routes').each do |file|
150
+ require file
151
+ end
152
+
153
+ router_parts = path == '/' ? ('/'+@@routes['_default'][:val]).split('/') : path.split('/')
111
154
  @@current_uri = path.split('?').at(0)
112
155
  @@segments = @@current_uri.split('/')[1..-1]
113
156
  @@rsegments = router_parts[1..-1]
114
157
  routed_uri = @@current_uri
115
158
 
116
- # Load routes
117
- routes = Picombo::Config.load('routes')
118
-
119
159
  # Try and find a direct match
120
- if routes.key?(@@current_uri)
121
- routed_uri = routes[@@current_uri]
160
+ if @@routes.key?(@@current_uri)
161
+ routed_uri = @@routes[@@current_uri][:val]
122
162
  @@rsegments = routed_uri.split('/')
123
163
  else
124
- routes.each do |route, destination|
125
- if route != '_default'
126
- if Regexp.new(route).match(@@current_uri)
127
- routed_uri.gsub!(Regexp.new(route), destination)
164
+ @@routes.each do |route, destination|
165
+ if destination[:val].is_a?(Proc)
166
+ route = destination[:val].call(@@current_uri)
167
+ return route if ! route.nil?
168
+ elsif route.is_a?(Regexp)
169
+ match = route.match(@@current_uri)
170
+ if ! match.nil? and match.length > 1
171
+ routed_uri.gsub!(Regexp.new(route), destination[:val])
128
172
  @@rsegments = routed_uri.split('/')[1..-1]
129
173
  end
130
174
  end
@@ -145,11 +189,11 @@ module Picombo
145
189
  if ! @@rsegments[1].nil?
146
190
  @@rsegments[1] = @@rsegments[1].split('?').at(0)
147
191
  else
148
- @@rsegments[1] = ('/'+Picombo::Config.get('routes._default')).split('/').at(2)
192
+ @@rsegments[1] = ('/'+@@routes['_default'][:val]).split('/').at(2)
149
193
  end
150
194
 
151
195
  # make sure to remove the GET from any of the parameters
152
- {:controller => @@rsegments[0].split('?').at(0), :method => @@rsegments[1], :params => params}
196
+ {:controller => @@rsegments[0].split('?').at(0).gsub('.', '').downcase, :method => @@rsegments[1], :params => params}
153
197
  end
154
198
  end
155
199
  end
@@ -1,11 +1,24 @@
1
1
  module Picombo
2
+ # == Session handling class
3
+ #
4
+ # In essense, a proxy to the rack session handling methods.
5
+ #
6
+ # == Example usage
7
+ # Writing cookie values
8
+ # Picombo::Session.set(:sample, 'this is the content of the session var')
9
+ #
10
+ # Getting cookie values
11
+ # Picombo::Session.get(:sample)
2
12
  class Session
3
13
  include Singleton
4
14
 
15
+ # Initializes the request for cookies
5
16
  def init(req)
6
17
  @@req = req
7
18
  end
8
19
 
20
+ # Retrieves a session item defined by key, returns default if item doesn't exist
21
+ # You can retreive the entire session by omiting the key paramter
9
22
  def get(key = nil, default = nil)
10
23
  return @@req.session if key.nil?
11
24
 
@@ -14,8 +27,14 @@ module Picombo
14
27
  return result.nil? ? default : result
15
28
  end
16
29
 
30
+ # Sets a session item defined by key to val
17
31
  def set(key, val)
18
32
  @@req.session[key] = val
19
33
  end
34
+
35
+ # Unsets a session variable
36
+ def unset(key)
37
+ @@req.session.delete(key)
38
+ end
20
39
  end
21
40
  end
@@ -0,0 +1,18 @@
1
+ module Picombo
2
+ module View
3
+ # == XML View
4
+ #
5
+ # The core view renders XML to the browser
6
+ #
7
+ # See the View documentation for usage specifics
8
+ class Stache < Mustache
9
+ # Standard constructor
10
+ def initialize(filename)
11
+ super(filename)
12
+
13
+ # Changes the content type to xml for the application
14
+ Picombo::Core.raw_response()['Content-Type'] = 'text/xml'
15
+ end
16
+ end
17
+ end
18
+ end
@@ -6,6 +6,7 @@ module Picombo
6
6
  #
7
7
  # See the View documentation for usage specifics
8
8
  class XML < Picombo::View::Core
9
+ # Standard constructor
9
10
  def initialize(filename)
10
11
  super(filename)
11
12
 
data/lib/classes/view.rb CHANGED
@@ -28,6 +28,8 @@ module Picombo
28
28
  #
29
29
  # See the View documentation for usage specifics
30
30
  class Core
31
+ require 'erb'
32
+
31
33
  @view_file = ''
32
34
  @view_data = []
33
35
 
@@ -54,17 +56,18 @@ module Picombo
54
56
  end
55
57
 
56
58
  # Renders the view to the output buffer, or optionally simply returns it if echo is true
57
- def render(echo = false)
59
+ def render(return_output = false)
58
60
  view = ERB::new(File.read(@view_file))
59
61
 
60
- if echo
61
- view.result(get_binding())
62
+ if return_output
63
+ return view.result(get_binding())
62
64
  else
63
65
  Picombo::Core.response view.result(get_binding())
64
66
  end
65
67
  end
66
68
  end
67
69
 
70
+ # Autoloader for missing view constants. Used to load non-standard view classes like XML.
68
71
  def View.const_missing(name)
69
72
  filename = name.to_s
70
73
 
@@ -0,0 +1 @@
1
+ Picombo::Router.add('_default', 'test/index')
@@ -0,0 +1,15 @@
1
+ module Picombo
2
+ module Controllers
3
+ # == Controller class for handling 404 events
4
+ #
5
+ # To override, re-define this in your application's controller directory
6
+ class Error_404
7
+ # Displays a 404 message for the current uri
8
+ def run_error(uri)
9
+ body = Picombo::Stache::Error_404.new
10
+ body.uri = uri
11
+ return [404, {'Content-Type' => 'text/html'}, body.output]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -11,23 +11,29 @@ module Picombo
11
11
  # super
12
12
  # end
13
13
  #
14
- # The default template view is called 'template' which is located in views/template.rhtml. You can change this on a per controller basis by changing the @@template vartiable in the controller:
14
+ # The default template view is called 'layout' which is located in views/layout.rb. You can change this on a per controller basis by changing the @template vartiable in the controller's constructor:
15
15
  #
16
- # @@template = 'foobar_template'
16
+ # @template = 'foobar_template'
17
17
  #
18
- # Now, you can use @@template in your controller and it will always use the same template. The template will automatically render at the end of the controller execution, so there is no need to call @@template.render manually
18
+ # Now, you can use @template in your controller and it will always use the same template. The template will automatically render at the end of the controller execution, so there is no need to call @template.output manually
19
19
  class Template
20
- @@template = 'template'
21
- @@auto_render = true
22
-
23
20
  def initialize
24
- @@template = Picombo::View::Core.new(@@template) if @@template.is_a?(String)
21
+ @template = 'layout' if @template.nil?
22
+ @auto_render = true
23
+
24
+ @template = Picombo::Stache::const_get(@template.capitalize).new if @template.is_a?(String)
25
25
 
26
- Picombo::Event.add('system.post_controller', 'Picombo::Controllers::Template.render') if @@auto_render
26
+ Picombo::Event.add('system.post_controller', [self, 'render']) if @auto_render
27
27
  end
28
28
 
29
- def self.render
30
- @@template.render if @@auto_render
29
+ def render
30
+ if @auto_render
31
+ if Picombo::Core.cli
32
+ return @template.render
33
+ end
34
+
35
+ @template.output
36
+ end
31
37
  end
32
38
  end
33
39
  end
data/lib/core/core.rb CHANGED
@@ -9,12 +9,23 @@
9
9
  # It's designed to be fast, lightweight and easy to use.
10
10
 
11
11
  module Picombo
12
+ # == Core
13
+ #
14
+ # The core class for Picombo. Handles system initialization and other core functionality.
12
15
  class Core
13
16
  @@extension = 'html'
17
+ @@cli = false
18
+
19
+ # Determines if the request was made on the CLI or not
20
+ def self.cli
21
+ @@cli
22
+ end
14
23
 
15
- def self.extension()
24
+ # Gets the extension of the request
25
+ def self.extension
16
26
  @@extension
17
27
  end
28
+ # Assigns the extension of the request
18
29
  def self.extension=(extension)
19
30
  @@extension = extension
20
31
  end
@@ -25,6 +36,8 @@ module Picombo
25
36
  Picombo::Bench.instance.start('application')
26
37
  Picombo::Bench.instance.start('loading')
27
38
 
39
+ Picombo::Event.clear!
40
+
28
41
  @@env = env
29
42
  @@req = Rack::Request.new(env)
30
43
 
@@ -110,7 +123,7 @@ module Picombo
110
123
  files = []
111
124
  $LOAD_PATH.each do |path|
112
125
  if File.exist?(path+'/'+directory+'/'+file+ext)
113
- files.unshift(path+'/'+directory+'/'+file+ext)
126
+ files.unshift(path.chomp('/')+'/'+directory+'/'+file+ext)
114
127
  end
115
128
  end
116
129
 
@@ -143,7 +156,7 @@ module Picombo
143
156
  def Picombo.const_missing(name)
144
157
  filename = name.to_s
145
158
 
146
- require 'classes/'+filename
159
+ require 'classes/'+filename.gsub(/_/, '/')
147
160
 
148
161
  raise filename+' not found!' if ! const_defined?(name)
149
162
 
@@ -173,7 +186,7 @@ module Picombo
173
186
  def Models.const_missing(name)
174
187
  filename = name.to_s
175
188
 
176
- require 'models/'+filename.downcase
189
+ require 'models/'+filename.downcase.gsub(/_/, '/')
177
190
 
178
191
  raise filename+' not found!' if ! const_defined?(name)
179
192
 
@@ -222,7 +235,7 @@ module Picombo
222
235
  def Controllers.const_missing(name)
223
236
  filename = name.to_s
224
237
 
225
- require 'controllers/'+filename
238
+ require 'controllers/'+filename.gsub(/_/, '/')
226
239
 
227
240
  raise LoadError if ! const_defined?(name)
228
241
 
@@ -0,0 +1,88 @@
1
+ require 'core/core'
2
+
3
+ module Picombo
4
+ # == Core
5
+ #
6
+ # The core class for Picombo. Handles system initialization and other core functionality.
7
+ class Core
8
+
9
+ # Standard call function that gets invoked by Rack
10
+ def call
11
+ @@cli = true
12
+
13
+ # start system benchmark
14
+ Picombo::Bench.instance.start('application')
15
+ Picombo::Bench.instance.start('loading')
16
+
17
+ @@req = Picombo::CLI_Request.new(ARGV[0])
18
+
19
+ @@response = Picombo::CLI_Response.new
20
+ @@redirect = []
21
+
22
+ # Add directory extensions to the filesystem
23
+ Picombo::Config.get('config.extensions').each do |extension|
24
+ require extension
25
+ end
26
+ $LOAD_PATH.delete(APPPATH)
27
+ $LOAD_PATH.unshift(APPPATH)
28
+
29
+ # Load hooks
30
+ Picombo::Config.get('config.hooks').each do |hook|
31
+ Picombo::Core.find_file('hooks', hook).each do |file|
32
+ require file
33
+ end
34
+ end
35
+
36
+ Picombo::Bench.instance.stop('loading')
37
+
38
+ Picombo::Log.write(:debug, 'Picombo Setup Complete')
39
+ output = Picombo::Router.new(@@req).process()
40
+
41
+ Picombo::Event.run('system.shutdown')
42
+
43
+ output
44
+ end
45
+
46
+ # Adds content to the output buffer
47
+ def self.response(str)
48
+ @@response.write(str)
49
+ end
50
+
51
+ # Renders output. Returns empty string, because all output should be "puts"'d
52
+ def self.render
53
+ ''
54
+ end
55
+ end
56
+
57
+ # Overloaded CLI Request object for compatibility
58
+ class CLI_Request
59
+ # Assigns the request path
60
+ def initialize(path)
61
+ @path = path
62
+ end
63
+
64
+ # Returns the request path
65
+ def path
66
+ @path
67
+ end
68
+ end
69
+
70
+ # Overloaded CLI Response object for compatibility
71
+ class CLI_Response
72
+ @writer = lambda { |x| @body << x }
73
+ @body = []
74
+
75
+ # Writes content to the buffer
76
+ def write(str)
77
+ s = str.to_s
78
+ @writer.call s
79
+
80
+ str
81
+ end
82
+
83
+ # returns the buffer
84
+ def finish
85
+ @body
86
+ end
87
+ end
88
+ end
@@ -1,3 +1,5 @@
1
+ require 'dm-core'
2
+
1
3
  # Set up database
2
4
  DataMapper.setup(:default,
3
5
  {:host => Picombo::Config.get('datamapper.default.host'),
@@ -0,0 +1,24 @@
1
+ require 'mustache'
2
+
3
+ module Picombo
4
+ module Stache
5
+ # Autoloader for missing mustache classes.
6
+ def Stache.const_missing(name)
7
+ filename = name.to_s
8
+
9
+ require 'views/'+filename.downcase.gsub(/_/, '/')
10
+
11
+ raise name.to_s+' not found!' if ! const_defined?(name)
12
+
13
+ klass = const_get(name)
14
+ return klass if klass
15
+ raise klass+" not found!"
16
+ end
17
+ end
18
+ end
19
+
20
+ class Mustache
21
+ def output
22
+ Picombo::Core.response(render)
23
+ end
24
+ end
@@ -1,16 +1,12 @@
1
- require 'thin'
2
- require 'erb'
3
- require 'yaml'
4
- require 'dm-core'
1
+ # to customize this, place a copy of picombo.rb in your application folder
2
+
5
3
  require 'singleton'
6
4
  require 'core/core'
7
5
  require 'classes/config'
8
6
 
7
+ # This is where the magic happens!
9
8
  def run_system()
10
9
  app = Rack::Builder.new do
11
- use Rack::ShowExceptions
12
- #use Rack::Reloader
13
- use Rack::Static, :urls => ['/css', '/images']
14
10
  use Rack::Session::Cookie
15
11
  run Picombo::Core.new
16
12
  end
@@ -0,0 +1,2 @@
1
+ <h1>Page Not Found</h1>
2
+ <p>The page you requested, <em>{{uri}}</em>, was not found.</p>
@@ -0,0 +1,17 @@
1
+ module Picombo
2
+ module Stache
3
+ class Error_404 < Mustache
4
+ self.template = File.open(Picombo::Core.find_file('views', 'error/404', true, 'mustache').shift).read
5
+
6
+ @uri = nil
7
+
8
+ def uri=(uri)
9
+ @uri = uri
10
+ end
11
+
12
+ def uri
13
+ @uri
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ Test <%= @test %>
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picombo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Jeremy Bush
@@ -9,11 +14,11 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-04-23 00:00:00 -05:00
17
+ date: 2010-06-08 00:00:00 -05:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
16
- description: Picombo is a lightweight MVC framework inspired by the Kohana PHP MVC framework.
21
+ description: Picombo is a lightweight MVC web framework that enables you to create websites quickly.
17
22
  email: contractfrombelow@gmail.com
18
23
  executables: []
19
24
 
@@ -22,38 +27,43 @@ extensions: []
22
27
  extra_rdoc_files: []
23
28
 
24
29
  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
30
+ - ./lib/classes/bench.rb
31
+ - ./lib/classes/cache/file.rb
32
+ - ./lib/classes/cache.rb
33
+ - ./lib/classes/config.rb
34
+ - ./lib/classes/cookie.rb
35
+ - ./lib/classes/e404.rb
36
+ - ./lib/classes/event.rb
37
+ - ./lib/classes/html.rb
38
+ - ./lib/classes/input.rb
39
+ - ./lib/classes/log.rb
40
+ - ./lib/classes/router.rb
41
+ - ./lib/classes/security.rb
42
+ - ./lib/classes/session.rb
43
+ - ./lib/classes/url.rb
44
+ - ./lib/classes/view/stache.rb
45
+ - ./lib/classes/view/xml.rb
46
+ - ./lib/classes/view.rb
47
+ - ./lib/config/cache.yaml
48
+ - ./lib/config/log.yaml
49
+ - ./lib/config/mimes.yaml
50
+ - ./lib/config/routes.rb
51
+ - ./lib/controllers/error/404.rb
52
+ - ./lib/controllers/template.rb
53
+ - ./lib/core/core.rb
54
+ - ./lib/core/core_cli.rb
55
+ - ./lib/hooks/datamapper.rb
56
+ - ./lib/hooks/mustache.rb
57
+ - ./lib/hooks/profiler.rb
58
+ - ./lib/picombo.rb
59
+ - ./lib/views/bench/footer.rhtml
60
+ - ./lib/views/error/404.mustache
61
+ - ./lib/views/error/404.rb
62
+ - ./lib/views/tests/test.rhtml
63
+ has_rdoc: true
56
64
  homepage: http://www.picombo.net/
65
+ licenses: []
66
+
57
67
  post_install_message:
58
68
  rdoc_options: []
59
69
 
@@ -63,20 +73,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
73
  requirements:
64
74
  - - ">="
65
75
  - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
66
78
  version: "0"
67
- version:
68
79
  required_rubygems_version: !ruby/object:Gem::Requirement
69
80
  requirements:
70
81
  - - ">="
71
82
  - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
72
85
  version: "0"
73
- version:
74
86
  requirements: []
75
87
 
76
88
  rubyforge_project:
77
- rubygems_version: 1.3.1
89
+ rubygems_version: 1.3.6
78
90
  signing_key:
79
- specification_version: 2
91
+ specification_version: 3
80
92
  summary: A lightweight MVC web framework
81
93
  test_files: []
82
94
 
@@ -1 +0,0 @@
1
- _default: test/index
@@ -1,11 +0,0 @@
1
- module Picombo
2
- module Controllers
3
- class Error_404
4
- def run_error(uri)
5
- body = Picombo::View::Core.new('404')
6
- body.set('uri', uri)
7
- return [404, {'Content-Type' => 'text/html'}, body.render(true)]
8
- end
9
- end
10
- end
11
- end
data/lib/views/404.rhtml DELETED
@@ -1,2 +0,0 @@
1
- <h1>Page Not Found</h1>
2
- <p>The page you requested, <%= @uri %>, was not found.</p>