picombo 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,17 +10,17 @@ module Picombo
10
10
  # Constructor.
11
11
  def initialize(config)
12
12
  @@config = config
13
- raise "Cache directory does not exist: "+APPPATH+'cache' unless File.directory?(APPPATH+'cache/')
14
- raise "Cache directory not writable: "+APPPATH+'cache' unless File.writable?(APPPATH+'cache/')
13
+ raise "Cache directory does not exist: "+::APPPATH+'cache' unless File.directory?(::APPPATH+'cache/')
14
+ raise "Cache directory not writable: "+::APPPATH+'cache' unless File.writable?(::APPPATH+'cache/')
15
15
  end
16
16
 
17
17
  # Finds an array of files that exist for a specified key
18
18
  def exists(keys)
19
- return Dir.glob(APPPATH+'cache/*~*') if keys == true
19
+ return Dir.glob(::APPPATH+'cache/*~*') if keys == true
20
20
 
21
21
  paths = []
22
22
  [*keys].each do |key|
23
- Dir.glob(APPPATH+'cache/'+key.to_s+'~*').each do |path|
23
+ Dir.glob(::APPPATH+'cache/'+key.to_s+'~*').each do |path|
24
24
  paths.push(path)
25
25
  end
26
26
  end
@@ -37,7 +37,7 @@ module Picombo
37
37
  items.each do |key, value|
38
38
  delete(key)
39
39
 
40
- File.open(APPPATH+'cache/'+key.to_s+'~'+lifetime.to_s, 'w') {|f| f.write(Marshal.dump(value)) }
40
+ File.open(::APPPATH+'cache/'+key.to_s+'~'+lifetime.to_s, 'w') {|f| f.write(Marshal.dump(value)) }
41
41
  end
42
42
 
43
43
  return true
@@ -10,7 +10,6 @@ module Picombo
10
10
  # === Overview
11
11
  # There are several built in config file types:
12
12
  # * config.yaml
13
- # * datamapper.yaml
14
13
  # * cache.yaml
15
14
  # * log.yaml
16
15
  # * mimes.yaml
@@ -23,18 +22,18 @@ module Picombo
23
22
  # 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
23
  #
25
24
  # ==== Example
26
- # For the following file (datamapper.yaml):
25
+ # For the following file (config.yaml):
27
26
  #
28
- # default:
29
- # driver: mysql
30
- # host: localhost
31
- # database: picom_db
32
- # username: picom_u
33
- # password: picom_p
27
+ # site_domain: localhost:3000
28
+ # protocol: http
29
+ # extensions:
30
+ # []
31
+ # hooks:
32
+ # [profiler]
34
33
  #
35
- # You can get the database config value like:
34
+ # You can get the core config values like:
36
35
  #
37
- # Picombo::Config.get('datamapper.default.database')
36
+ # Picombo::Config.get('core.protocol')
38
37
  class Config
39
38
  include Enumerable
40
39
 
data/lib/classes/e404.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  module Picombo
2
- # == Main 404 exception class. Used to detect 404 errors in the app
2
+ # == 404 Exception
3
+ #
4
+ # Main 404 exception class. Used to detect 404 errors in the app.
5
+ #
6
+ # When you raise a E404 exception, Picombo will instantiate the Picombo::Controllers::Error_404 controller and execute it's run_error() method with the uri passed in. You can override how your 404 pages look by overloading this class.
3
7
  class E404 < Exception
4
8
 
5
9
  end
data/lib/classes/log.rb CHANGED
@@ -22,7 +22,7 @@ module Picombo
22
22
 
23
23
  if types[type] <= Picombo::Config.get('log.log_threshold')
24
24
  t = Time.now
25
- f = File.new(APPPATH+Picombo::Config.get('log.directory')+t.year.to_s+'-'+t.month.to_s+'-'+t.day.to_s+'.log', 'a')
25
+ f = File.new(::APPPATH+Picombo::Config.get('log.directory')+t.year.to_s+'-'+t.month.to_s+'-'+t.day.to_s+'.log', 'a')
26
26
  f.write(t.to_s+' --- '+type.to_s+': '+message.to_s+"\n");
27
27
  f.close
28
28
  end
@@ -22,6 +22,14 @@ module Picombo
22
22
  # {:controller => 'city', :method => 'index', :params => Regexp.last_match[2,3]}
23
23
  # end
24
24
  # })
25
+ #
26
+ # === Route Hashes
27
+ # The router uses route hashes as shown above to determine which controller/method should be run. It has the following properties:
28
+ # :controller - The controller name to execute
29
+ # :method - The method of the controller to run
30
+ # :param - The parameters to pass to the controller method
31
+ #
32
+ # If you use lambda routes, you *must* return a properly formatted routing hash.
25
33
 
26
34
  class Router
27
35
  @@req = nil
@@ -0,0 +1,44 @@
1
+ require 'mustache'
2
+
3
+ module Picombo
4
+ # == Mustache Module
5
+ #
6
+ # Picombo comes with builtin support for Mustache view templates
7
+ #
8
+ # === How to use
9
+ #
10
+ # All view files go into the views folder. You need a .rb class along with a .mustache template file. Your view class files should extend the Mustache class:
11
+ #
12
+ # module Picombo
13
+ # module Stache
14
+ # class Home_Index < Mustache
15
+ # self.template = File.open(Picombo::Core.find_file('views', 'home/index', true, 'mustache').shift).read
16
+ # end
17
+ # end
18
+ # end
19
+ #
20
+ # You should always set the template in your class. In most scenarios, it's easiest to read it in from a file as displayed above. You can also specify a raw string template there and not do the file read.
21
+ #
22
+ # To render the template to your browser, use the output method:
23
+ # Picombo::Stache::Home_Index.new.output
24
+ module Stache
25
+ # Autoloader for missing mustache classes.
26
+ def Stache.const_missing(name)
27
+ filename = name.to_s
28
+
29
+ require 'views/'+filename.downcase.gsub(/_/, '/')
30
+
31
+ raise name.to_s+' not found!' if ! const_defined?(name)
32
+
33
+ klass = const_get(name)
34
+ return klass if klass
35
+ raise klass+" not found!"
36
+ end
37
+ end
38
+ end
39
+
40
+ class Mustache
41
+ def output
42
+ Picombo::Core.response(render)
43
+ end
44
+ end
data/lib/core/core.rb CHANGED
@@ -7,6 +7,65 @@
7
7
  # Picombo is a Rack-based Ruby MVC web framework with design principles taken from the Kohana PHP Framework.
8
8
  #
9
9
  # It's designed to be fast, lightweight and easy to use.
10
+ #
11
+ # == Filesystem Structure
12
+ #
13
+ # Picombo supports automatic class autoloading. This depends on the directory structure of Picombo. It has a few standard structures:
14
+ #
15
+ # classes/
16
+ # config/
17
+ # controllers/
18
+ # hooks/
19
+ # models/
20
+ # views/
21
+ #
22
+ # === Classes
23
+ # This is the location that general classes go in the filesystem.
24
+ #
25
+ # These class names must be in the Picombo module to be properly autoloaded.
26
+ #
27
+ # === Config
28
+ # This is where config items go. All config files except the Route file should be YAML to be read properly.
29
+ #
30
+ # === Controllers
31
+ # This is where controllers go (See the controllers doc for more information).
32
+ #
33
+ # These class names should be in the Picombo::Controllers module to be properly autoloaded.
34
+ #
35
+ # === Hooks
36
+ # Hooks go here. You can use hooks to extend/replace/expand system functionality. Hooks run before anything else in the system setup process.
37
+ #
38
+ # === Models
39
+ # This is where your models go (See the models doc for more information).
40
+ #
41
+ # These class names should be in the Picombo::Models module to be properly autoloaded.
42
+ #
43
+ # === Views
44
+ # This is where views go (See the Stache docs for specific usage).
45
+ #
46
+ # If you write a Picombo extension, it's important to know that all extensions should follow this same directory layout. In Picombo, all standard filesystem locations are searched from application first, through the extension list, and finally down to the core system folder. This lets you easily extend and replace functionality with extensions.
47
+ #
48
+ # == Autoloading
49
+ # As long as your files/classes are setup as above, autoloading will "just work". There's one special case, however: underscores in class names. When you have an underscore in your class name, it will be translated to a directory seperator.
50
+ #
51
+ # class Picombo::Controllers::Foo_Bar
52
+ #
53
+ # lives in:
54
+ # controllers/foo/bar.rb
55
+ #
56
+ # and
57
+ # class Picombo::Cache_Memcache
58
+ #
59
+ # lives in:
60
+ # classes/cache/memcache.rb
61
+ #
62
+ # == Typical Request Flow
63
+ # In a typical Picombo request here's how a request get's processed:
64
+ #
65
+ # 1. URI comes in from the browser to the server, and is passes to the Router
66
+ # 2. The router processes the URI using the routes.rb config file to do any special routing
67
+ # 3. The routed URI is the then processed by the appropriate controller
68
+ # 4. The controller processes any input, works with Views and Models to generate the request output
10
69
 
11
70
  module Picombo
12
71
  # == Core
@@ -40,8 +99,8 @@ module Picombo
40
99
  Picombo::Config.get('config.extensions').each do |extension|
41
100
  require extension
42
101
  end
43
- $LOAD_PATH.delete(APPPATH)
44
- $LOAD_PATH.unshift(APPPATH)
102
+ $LOAD_PATH.delete(::APPPATH)
103
+ $LOAD_PATH.unshift(::APPPATH)
45
104
 
46
105
  # Load hooks
47
106
  Picombo::Config.get('config.hooks').each do |hook|
data/lib/core/core_cli.rb CHANGED
@@ -1,9 +1,6 @@
1
1
  require 'core/core'
2
2
 
3
3
  module Picombo
4
- # == Core
5
- #
6
- # The core class for Picombo. Handles system initialization and other core functionality.
7
4
  class Core
8
5
 
9
6
  # Standard call function that gets invoked by Rack
@@ -23,8 +20,8 @@ module Picombo
23
20
  Picombo::Config.get('config.extensions').each do |extension|
24
21
  require extension
25
22
  end
26
- $LOAD_PATH.delete(APPPATH)
27
- $LOAD_PATH.unshift(APPPATH)
23
+ $LOAD_PATH.delete(::APPPATH)
24
+ $LOAD_PATH.unshift(::APPPATH)
28
25
 
29
26
  # Load hooks
30
27
  Picombo::Config.get('config.hooks').each do |hook|
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 1
9
- version: 0.3.1
8
+ - 2
9
+ version: 0.3.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jeremy Bush
@@ -66,6 +66,7 @@ files:
66
66
  - ./lib/classes/log.rb
67
67
  - ./lib/classes/router.rb
68
68
  - ./lib/classes/session.rb
69
+ - ./lib/classes/stache.rb
69
70
  - ./lib/classes/url.rb
70
71
  - ./lib/config/cache.yaml
71
72
  - ./lib/config/log.yaml
@@ -75,7 +76,6 @@ files:
75
76
  - ./lib/controllers/template.rb
76
77
  - ./lib/core/core.rb
77
78
  - ./lib/core/core_cli.rb
78
- - ./lib/hooks/mustache.rb
79
79
  - ./lib/hooks/profiler.rb
80
80
  - ./lib/picombo.rb
81
81
  - ./lib/views/error/404.mustache
@@ -1,24 +0,0 @@
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