spire 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  gem "rack", ">= 1.3.0"
2
-
2
+ gem "rack-rewrite", ">= 1.2.1"
3
3
  gem "haml", ">= 3.1.0"
4
4
  gem "erubis", ">= 2.7.0"
5
5
 
data/Gemfile.lock CHANGED
@@ -8,6 +8,7 @@ GEM
8
8
  git (>= 1.2.5)
9
9
  rake
10
10
  rack (1.3.3)
11
+ rack-rewrite (1.2.1)
11
12
  rake (0.9.2)
12
13
  rcov (0.9.10)
13
14
 
@@ -20,4 +21,5 @@ DEPENDENCIES
20
21
  haml (>= 3.1.0)
21
22
  jeweler (~> 1.6.4)
22
23
  rack (>= 1.3.0)
24
+ rack-rewrite (>= 1.2.1)
23
25
  rcov
data/README.rdoc CHANGED
@@ -6,7 +6,7 @@ Light controller-only rack framework with a dash of views.
6
6
 
7
7
  gem install spire
8
8
  spire -c project_name
9
- cd project_name && rackup
9
+ cd !$ && rackup
10
10
 
11
11
  This will install spire, create a project called 'project_name' in the same directory it's run in, and then start the site.
12
12
 
@@ -29,46 +29,47 @@ That would when '/foo/bar' is requested return the response found in the FooCont
29
29
 
30
30
  Controllers are named to tie with the routes (read above). They are stored in:
31
31
  project_name/app/controllers/
32
- And must be defined like so:
33
- class Test < Spire::MainController
32
+ With the naming scheme like so:
33
+ FooController.rb
34
+ Where Foo is the name of the controller. The name must be camel-cased. All classes must be defined like so:
35
+ class Foo < Spire::MainController
34
36
 
35
37
  end
36
38
  as a skeleton controller for the framework to use. An example response would look like this:
37
39
  class Index < Spire::MainController
38
40
  def index
39
- Spire::Response.new("This is just a response")
41
+ "This is just a response"
40
42
  end
41
43
  end
42
44
  This would display a html page with that text. The Response.new initiator could be used like so:
43
- Spire::Response.new("<h1>This is a test page</h1>, "text/html", 200)
44
- Where the first argument is the output, second argument is the content-type and the last the status/response code.
45
+ def index
46
+ @status = 200
47
+ @content_type = "text/html;"
48
+ return "Hi, I'm a test page!"
49
+ end
50
+ Where the first instance variable @status is the HTTP status to show, the second being the content type, and the last being the returned value as a string.
45
51
 
46
52
  == Views
47
53
 
54
+ === RHTML
55
+ RHTML templates are executed using erubis due to its speed. To create a erb view, you must create a view in:
56
+ /app/views/
57
+ With the naming scheme of:
58
+ template.rhtml
59
+ The .rhtml is important so Spire knows what file it is. To pass data to a view, you simply define an instance variable before you render the template and it will automatically be accessible in your view template.
60
+ To render a template, you simply use:
61
+ render("index.rhtml")
62
+
48
63
  === HAML
49
64
  HAML templates can be rendered like so:
50
- Spire::Response.new(render("index", "haml", ["Welcome to Spire!",
51
- "This is a base app to extend your own on. Have fun!"]))
65
+ render("index.haml")
52
66
  This would load the index.haml view in:
53
- project_name/app/views/index.haml
54
- The first argument in the render method above is the file name, the second being the file type, and the last is the content to pass to the view. In the above example, it's an array of two strings.
55
- To access the data in the view, you have to use the 'data' variable like so:
56
- %title= data[0]
57
- %h1= data[1]
58
- This above example would use the first array entry from our render method as a title, and the second array entry for a nice big header.
67
+ /app/views/index.haml
68
+ To pass data to the view, define and fill an instance variable with content or an object, and you can use it inside your HAML view.
59
69
 
60
70
  === HTML
61
71
  HTML are static templates to be used in your project/app, they can't use variables, nor can they execute ruby code. They can be rendered using:
62
- Spire::Response.new(render("index", "html"))
72
+ render("index.html")
63
73
  Which would load the 'index.html' file from:
64
74
  project_name/app/views/index.html
65
- The first argument is the file name, the second being the extension.
66
-
67
- = Coming soon...
68
- More documentation will be coming soon as more features are being added
69
- === Error Handler
70
- === SASS Support
71
- === Improved Response handler
72
- === Lots of bugfixes
73
- === Some secret goodes!
74
-
75
+ The first argument is the file name, the second being the extension.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
data/lib/spire/error.rb CHANGED
@@ -1,11 +1,42 @@
1
1
  module Spire
2
2
  class Error
3
3
  def initialize(message, status='200')
4
- @return = Response.new(message, 'text/html; charset=uft8;', status)
4
+ case status
5
+ when 200
6
+ self.return_error(message, status)
7
+ when 404
8
+ self.return_404
9
+ when 401
10
+ self.return_401
11
+ when 204
12
+ self.return_204
13
+ when 301
14
+ self.return_301
15
+ end
16
+ end
17
+
18
+ def return_404
19
+ @return = Response.new("404 // Page not found", 'text/html;', 404)
20
+ end
21
+
22
+ def return_401
23
+ @return = Response.new("401 // Not authorized", 'text/html;', 401)
24
+ end
25
+
26
+ def return_204
27
+ @return = Response.new("204 // No content", 'text/html;', 204)
28
+ end
29
+
30
+ def return_301
31
+ @return = Response.new("301 // Moved permanently", 'text/html;', 301)
32
+ end
33
+
34
+ def return_error(message, status)
35
+ @return = Response.new(message, 'text/html;', status)
5
36
  end
6
37
 
7
38
  def to_rack
8
39
  @return.to_rack
9
40
  end
10
41
  end
11
- end
42
+ end
data/lib/spire/router.rb CHANGED
@@ -3,59 +3,64 @@ module Spire
3
3
  def initialize(base_path, routes)
4
4
  @base_path = base_path
5
5
  @routes = routes
6
+ @app = {}
6
7
  end
7
8
 
8
9
  def disect(env)
9
10
  req = env['REQUEST_PATH'].split("/")
10
- @request = {"controller" => req[1], "action" => req[2]}
11
+ @request = {"controller" => req[1], "action" => req[2]}
11
12
  end
12
13
 
13
14
  def route
14
- @controller_value = nil
15
- @action_value = nil
16
- if @request["controller"] == "favicon.ico"
17
- return Response.new(File.open("public/favicon.ico", 'r').read, "image/ico;")
15
+ if @request["controller"] == "public"
16
+ self.return_file
18
17
  end
18
+
19
19
  if @request["controller"] == nil
20
20
  route = @routes['default'].split("#")
21
- @controller_value = route[0].capitalize
22
- @action_value = route[1]
21
+ @app["controller"] = route[0].capitalize
22
+ @app["action"] = route[1]
23
23
  else
24
24
  @routes.each do |key, value|
25
25
  keys = key.split("/")
26
26
  values = value.split("#")
27
27
  if @request["controller"] == keys[1] && @request["action"] == keys[3]
28
- puts values[0]
29
- @controller_value = values[0].capitalize
30
- puts @controller_value
31
- @action_value = values[1]
28
+ @app["controller"] = values[0].capitalize
29
+ @app["action"] = values[1]
32
30
  elsif @request["controller"] == keys[1]
33
- puts values[0]
34
- @controller_value = values[0].capitalize
35
- puts @controller_value
36
- @action_value = values[1]
31
+ @app["controller"] = values[0].capitalize
32
+ @app["action"] = values[1]
37
33
  end
38
34
  end
39
35
  end
40
- unless @controller_value
41
- return Error.new("<title>404</title><body><h2>404 // Page not found</h2></body>")
36
+
37
+ unless @app["controller"]
38
+ return Error.new(nil ,404)
42
39
  end
40
+
43
41
  return self.run
44
42
  end
45
43
 
44
+ def return_file
45
+ # still need to add checks for mime types. this will be done in a seperate class once i get round to it
46
+ return Response.new(File.open("/public/#{@request["action"]}", "r").read)
47
+ end
48
+
46
49
  def run
47
- require "#{@base_path}/controllers/#{@controller_value}Controller"
48
- @app = Kernel.const_get(@controller_value).new(@base_path)
50
+ require "#{@base_path}/controllers/#{@app["controller"]}Controller"
51
+ @class = Kernel.const_get(@app["controller"]).new(@base_path)
49
52
 
50
- result = @app.method(@action_value).call
53
+ result = @class.method(@app["action"]).call
54
+
51
55
  content_type = "text/html;"
52
56
  status = 200
53
57
 
54
- if @app.instance_variable_get(:@status)
55
- status = @app.instance_variable_get(:@status)
58
+ if @class.instance_variable_get(:@status)
59
+ status = @class.instance_variable_get(:@status)
56
60
  end
57
- if @app.instance_variable_get(:@content_type)
58
- content_type = @app.instance_variable_get(:content_type)
61
+
62
+ if @class.instance_variable_get(:@content_type)
63
+ content_type = @class.instance_variable_get(:content_type)
59
64
  end
60
65
 
61
66
  return Response.new(result, content_type, status)
data/spire.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "spire"
8
- s.version = "0.2.2"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Scott Nicol"]
12
- s.date = "2011-10-06"
12
+ s.date = "2011-10-07"
13
13
  s.description = "Light rack-based framework with controllers, static views and a router \n with templating engine support coming soon"
14
14
  s.email = "scott@scottnicol.co.uk"
15
15
  s.executables = ["spire"]
@@ -41,6 +41,7 @@ Gem::Specification.new do |s|
41
41
 
42
42
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
43
  s.add_runtime_dependency(%q<rack>, [">= 1.3.0"])
44
+ s.add_runtime_dependency(%q<rack-rewrite>, [">= 1.2.1"])
44
45
  s.add_runtime_dependency(%q<haml>, [">= 3.1.0"])
45
46
  s.add_runtime_dependency(%q<erubis>, [">= 2.7.0"])
46
47
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -48,6 +49,7 @@ Gem::Specification.new do |s|
48
49
  s.add_development_dependency(%q<rcov>, [">= 0"])
49
50
  else
50
51
  s.add_dependency(%q<rack>, [">= 1.3.0"])
52
+ s.add_dependency(%q<rack-rewrite>, [">= 1.2.1"])
51
53
  s.add_dependency(%q<haml>, [">= 3.1.0"])
52
54
  s.add_dependency(%q<erubis>, [">= 2.7.0"])
53
55
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -56,6 +58,7 @@ Gem::Specification.new do |s|
56
58
  end
57
59
  else
58
60
  s.add_dependency(%q<rack>, [">= 1.3.0"])
61
+ s.add_dependency(%q<rack-rewrite>, [">= 1.2.1"])
59
62
  s.add_dependency(%q<haml>, [">= 3.1.0"])
60
63
  s.add_dependency(%q<erubis>, [">= 2.7.0"])
61
64
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-06 00:00:00.000000000Z
12
+ date: 2011-10-07 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &70150248916120 !ruby/object:Gem::Requirement
16
+ requirement: &70227958728580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,21 @@ dependencies:
21
21
  version: 1.3.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70150248916120
24
+ version_requirements: *70227958728580
25
+ - !ruby/object:Gem::Dependency
26
+ name: rack-rewrite
27
+ requirement: &70227958723620 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.2.1
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70227958723620
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: haml
27
- requirement: &70150248915580 !ruby/object:Gem::Requirement
38
+ requirement: &70227958712040 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,10 +43,10 @@ dependencies:
32
43
  version: 3.1.0
33
44
  type: :runtime
34
45
  prerelease: false
35
- version_requirements: *70150248915580
46
+ version_requirements: *70227958712040
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: erubis
38
- requirement: &70150248915020 !ruby/object:Gem::Requirement
49
+ requirement: &70227958709100 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: 2.7.0
44
55
  type: :runtime
45
56
  prerelease: false
46
- version_requirements: *70150248915020
57
+ version_requirements: *70227958709100
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: bundler
49
- requirement: &70150248914520 !ruby/object:Gem::Requirement
60
+ requirement: &70227958707440 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ~>
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: 1.0.0
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *70150248914520
68
+ version_requirements: *70227958707440
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: jeweler
60
- requirement: &70150248914020 !ruby/object:Gem::Requirement
71
+ requirement: &70227958705300 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ~>
@@ -65,10 +76,10 @@ dependencies:
65
76
  version: 1.6.4
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *70150248914020
79
+ version_requirements: *70227958705300
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: rcov
71
- requirement: &70150248913480 !ruby/object:Gem::Requirement
82
+ requirement: &70227958703260 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ! '>='
@@ -76,7 +87,7 @@ dependencies:
76
87
  version: '0'
77
88
  type: :development
78
89
  prerelease: false
79
- version_requirements: *70150248913480
90
+ version_requirements: *70227958703260
80
91
  description: ! "Light rack-based framework with controllers, static views and a router
81
92
  \n with templating engine support coming soon"
82
93
  email: scott@scottnicol.co.uk
@@ -113,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
124
  version: '0'
114
125
  segments:
115
126
  - 0
116
- hash: 98693962747438593
127
+ hash: -337069759895717094
117
128
  required_rubygems_version: !ruby/object:Gem::Requirement
118
129
  none: false
119
130
  requirements: