spire 0.3.3 → 0.4.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/README.rdoc +28 -4
- data/Rakefile +1 -2
- data/VERSION +1 -1
- data/lib/spire/class/MainController.rb +1 -0
- data/lib/spire/error.rb +23 -21
- data/lib/spire/public.rb +5 -10
- data/lib/spire/resource/mime.rb +2 -1
- data/lib/spire/router.rb +9 -10
- data/spire.gemspec +3 -4
- metadata +19 -20
- data/routes.rb +0 -4
data/README.rdoc
CHANGED
@@ -12,6 +12,12 @@ This will install spire, create a project called 'project_name' in the same dire
|
|
12
12
|
|
13
13
|
= Usage
|
14
14
|
|
15
|
+
== Creating a project
|
16
|
+
|
17
|
+
To create a new project you simply use the spire executable like so:
|
18
|
+
spire -c my_project
|
19
|
+
and it will make a template app in ./my_project in the folder it was executed.
|
20
|
+
|
15
21
|
== Routes
|
16
22
|
|
17
23
|
Routes are used in the config.ru, they work like the old-style Rails routes:
|
@@ -49,6 +55,12 @@ This would display a html page with that text. The Response.new initiator could
|
|
49
55
|
end
|
50
56
|
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.
|
51
57
|
|
58
|
+
=== Controller generator
|
59
|
+
|
60
|
+
You can generate controllers using the spire executable. To do this you can simply run:
|
61
|
+
spire -g foo
|
62
|
+
Which will generate the FooController in the app/controllers directory with all the necessary code for you.
|
63
|
+
|
52
64
|
== Views
|
53
65
|
|
54
66
|
=== RHTML
|
@@ -58,18 +70,30 @@ With the naming scheme of:
|
|
58
70
|
template.rhtml
|
59
71
|
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
72
|
To render a template, you simply use:
|
61
|
-
render
|
73
|
+
render :view => "index.rhtml"
|
62
74
|
|
63
75
|
=== HAML
|
64
76
|
HAML templates can be rendered like so:
|
65
|
-
render
|
77
|
+
render :view => "index.haml"
|
66
78
|
This would load the index.haml view in:
|
67
79
|
/app/views/index.haml
|
68
80
|
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.
|
69
81
|
|
70
82
|
=== HTML
|
71
83
|
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:
|
72
|
-
render
|
84
|
+
render :view => "index.html"
|
73
85
|
Which would load the 'index.html' file from:
|
74
86
|
project_name/app/views/index.html
|
75
|
-
The first argument is the file name, the second being the extension.
|
87
|
+
The first argument is the file name, the second being the extension.
|
88
|
+
You could also use:
|
89
|
+
render :file => "index.html"
|
90
|
+
if the html file is in:
|
91
|
+
/public/index.html
|
92
|
+
|
93
|
+
== Files
|
94
|
+
To return a file from a method, you can use the render method for this task:
|
95
|
+
render :file => "test.pdf"
|
96
|
+
This will give the browser the file 'test.pdf' from the /public directory. This method will also match the content-type of this automatically using magic and will give the browser the correct content type and response automatically. This will also give a HTML 404 error page if the file does not exist.
|
97
|
+
|
98
|
+
== Dependencies
|
99
|
+
You will need 'git', 'wget' and 'ruby' and 'rubygems' to get started.
|
data/Rakefile
CHANGED
@@ -18,8 +18,7 @@ Jeweler::Tasks.new do |gem|
|
|
18
18
|
gem.homepage = "http://github.com/snicol/spire"
|
19
19
|
gem.license = "MIT"
|
20
20
|
gem.summary = %Q{A light controller-only rack framework with a dash of views}
|
21
|
-
gem.description = %Q{Light rack-based framework with controllers,
|
22
|
-
with templating engine support coming soon}
|
21
|
+
gem.description = %Q{Light rack-based framework with controllers, HAML/ERB views, router & error handler}
|
23
22
|
gem.email = "scott@scottnicol.co.uk"
|
24
23
|
gem.authors = ["Scott Nicol"]
|
25
24
|
# dependencies defined in Gemfile
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/spire/error.rb
CHANGED
@@ -1,33 +1,27 @@
|
|
1
1
|
module Spire
|
2
2
|
class Error
|
3
|
-
def initialize(opts={})
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
case status
|
3
|
+
def initialize(opts={:status => 200, :message=> "Unknown Error"})
|
4
|
+
|
5
|
+
case opts[:status]
|
8
6
|
when 200
|
9
|
-
self.return_error(message, status)
|
7
|
+
self.return_error(opts[:message], opts[:status])
|
10
8
|
when 404
|
9
|
+
if opts[:message]
|
10
|
+
self.return_error(opts[:message], opts[:status])
|
11
|
+
else
|
11
12
|
self.return_404
|
13
|
+
end
|
14
|
+
when 444
|
15
|
+
self.return_444
|
12
16
|
when 401
|
13
17
|
self.return_401
|
14
18
|
when 204
|
15
19
|
self.return_204
|
16
20
|
when 301
|
17
21
|
self.return_301
|
18
|
-
when 444
|
19
|
-
self.return_444
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
|
-
def return_404
|
24
|
-
@return = Response.new("404 // Page not found", 'text/html;', 404)
|
25
|
-
end
|
26
|
-
|
27
|
-
def return_401
|
28
|
-
@return = Response.new("401 // Not authorized", 'text/html;', 401)
|
29
|
-
end
|
30
|
-
|
31
25
|
def return_204
|
32
26
|
@return = Response.new("204 // No content", 'text/html;', 204)
|
33
27
|
end
|
@@ -35,15 +29,23 @@ module Spire
|
|
35
29
|
def return_301
|
36
30
|
@return = Response.new("301 // Moved permanently", 'text/html;', 301)
|
37
31
|
end
|
38
|
-
|
39
|
-
def
|
40
|
-
@return = Response.new(
|
32
|
+
|
33
|
+
def return_401
|
34
|
+
@return = Response.new("401 // Not authorized", 'text/html;', 401)
|
35
|
+
end
|
36
|
+
|
37
|
+
def return_404
|
38
|
+
@return = Response.new("404 // Page not found", 'text/html;', 404)
|
41
39
|
end
|
42
|
-
|
40
|
+
|
43
41
|
def return_444
|
44
42
|
@return = Response.new("No response made by the server, check for a valid response", 'text/html;', 404)
|
45
43
|
end
|
46
|
-
|
44
|
+
|
45
|
+
def return_error(message, status)
|
46
|
+
@return = Response.new(message, 'text/html;', status)
|
47
|
+
end
|
48
|
+
|
47
49
|
def to_rack
|
48
50
|
@return.to_rack
|
49
51
|
end
|
data/lib/spire/public.rb
CHANGED
@@ -3,21 +3,20 @@ require 'spire/resource/mime'
|
|
3
3
|
module Spire
|
4
4
|
class Public
|
5
5
|
def initialize(opts={:render=>true})
|
6
|
-
@
|
7
|
-
@render = opts[:render]
|
6
|
+
@opts = opts
|
8
7
|
mime = Mime.new
|
9
8
|
@mime_types = mime.return_mimes
|
10
9
|
end
|
11
10
|
|
12
11
|
def extension_check
|
13
|
-
file_extension = File.extname(@file)
|
12
|
+
file_extension = File.extname(@opts[:file])
|
14
13
|
@mime_types.each do |ext, type|
|
15
14
|
if file_extension == ext
|
16
15
|
@content_type = type
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
|
-
if @render
|
19
|
+
if @opts[:render]
|
21
20
|
self.create_response
|
22
21
|
else
|
23
22
|
return [false, @content_type]
|
@@ -26,18 +25,14 @@ module Spire
|
|
26
25
|
|
27
26
|
def create_response
|
28
27
|
path = File.expand_path(__FILE__)
|
29
|
-
path["lib/spire/public.rb"] = "public/#{@file}"
|
30
|
-
return Error.new(:status => 404) unless File.exists?(path)
|
28
|
+
path["lib/spire/public.rb"] = "public/#{@opts[:file]}"
|
29
|
+
return Error.new(:status => 404, :message => "404 // File not found") unless File.exists?(path)
|
31
30
|
file = IO.read(path)
|
32
31
|
@return = {}
|
33
32
|
@return[:file] = file
|
34
33
|
@return[:content_type] = @content_type
|
35
34
|
return @return
|
36
35
|
end
|
37
|
-
|
38
|
-
def to_rack
|
39
|
-
@return.to_rack
|
40
|
-
end
|
41
36
|
|
42
37
|
end
|
43
38
|
end
|
data/lib/spire/resource/mime.rb
CHANGED
@@ -8,12 +8,13 @@ module Spire
|
|
8
8
|
".css" => "text/css",
|
9
9
|
".ics" => "text/calendar",
|
10
10
|
".csv" => "text/csv",
|
11
|
-
|
11
|
+
|
12
12
|
".png" => "image/png",
|
13
13
|
".jpeg" => "image/jpeg",
|
14
14
|
".gif" => "image/gif",
|
15
15
|
".bmp" => "image/bmp",
|
16
16
|
".tiff" => "image/tiff",
|
17
|
+
".ico" => "image/image/x-icon",
|
17
18
|
|
18
19
|
".mpeg" => "video/mpeg",
|
19
20
|
|
data/lib/spire/router.rb
CHANGED
@@ -13,9 +13,8 @@ module Spire
|
|
13
13
|
|
14
14
|
def route
|
15
15
|
@app["controller"] = nil
|
16
|
-
|
17
|
-
|
18
|
-
self.return_file
|
16
|
+
if @request["controller"] == "favicon.ico"
|
17
|
+
return self.return_file("favicon.ico")
|
19
18
|
end
|
20
19
|
|
21
20
|
if @request["controller"] == nil
|
@@ -36,15 +35,15 @@ module Spire
|
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
|
-
unless @app["controller"]
|
40
|
-
return Error.new :status => 404
|
38
|
+
unless @app["controller"]
|
39
|
+
return Error.new :message => "404 // Route not found in system/routes.rb", :status => 404
|
41
40
|
end
|
42
41
|
|
43
42
|
return self.run
|
44
43
|
end
|
45
44
|
|
46
|
-
def return_file
|
47
|
-
result = Public.new :file =>
|
45
|
+
def return_file(file)
|
46
|
+
result = Public.new :file => file, :render => true
|
48
47
|
file = result.extension_check
|
49
48
|
return Response.new(file[:file], file[:content_type], 200)
|
50
49
|
end
|
@@ -63,9 +62,9 @@ module Spire
|
|
63
62
|
|
64
63
|
content_type = "text/html;"
|
65
64
|
status = 200
|
66
|
-
|
67
|
-
if result == 404
|
68
|
-
return Error.new :status => 404
|
65
|
+
|
66
|
+
if result == 404 or result == nil
|
67
|
+
return Error.new :message => "404 // No method/Response from method. See #{@app["controller"]}##{@app["action"]} and check for a response", :status => 404
|
69
68
|
end
|
70
69
|
|
71
70
|
if @class.instance_variable_get(:@status)
|
data/spire.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "spire"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
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-
|
13
|
-
s.description = "Light rack-based framework with controllers,
|
12
|
+
s.date = "2011-10-21"
|
13
|
+
s.description = "Light rack-based framework with controllers, HAML/ERB views, router & error handler"
|
14
14
|
s.email = "scott@scottnicol.co.uk"
|
15
15
|
s.executables = ["spire"]
|
16
16
|
s.extra_rdoc_files = [
|
@@ -30,7 +30,6 @@ Gem::Specification.new do |s|
|
|
30
30
|
"lib/spire/public.rb",
|
31
31
|
"lib/spire/resource/mime.rb",
|
32
32
|
"lib/spire/router.rb",
|
33
|
-
"routes.rb",
|
34
33
|
"spire.gemspec"
|
35
34
|
]
|
36
35
|
s.homepage = "http://github.com/snicol/spire"
|
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.
|
4
|
+
version: 0.4.0
|
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-
|
12
|
+
date: 2011-10-21 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70167713606260 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.3.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70167713606260
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rack-rewrite
|
27
|
-
requirement: &
|
27
|
+
requirement: &70167713605780 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.2.1
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70167713605780
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: haml
|
38
|
-
requirement: &
|
38
|
+
requirement: &70167713605300 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 3.1.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70167713605300
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: erubis
|
49
|
-
requirement: &
|
49
|
+
requirement: &70167713604820 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 2.7.0
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70167713604820
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bundler
|
60
|
-
requirement: &
|
60
|
+
requirement: &70167713604340 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.0.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70167713604340
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: jeweler
|
71
|
-
requirement: &
|
71
|
+
requirement: &70167713603860 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 1.6.4
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70167713603860
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rcov
|
82
|
-
requirement: &
|
82
|
+
requirement: &70167713603380 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,9 +87,9 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
91
|
-
description:
|
92
|
-
|
90
|
+
version_requirements: *70167713603380
|
91
|
+
description: Light rack-based framework with controllers, HAML/ERB views, router &
|
92
|
+
error handler
|
93
93
|
email: scott@scottnicol.co.uk
|
94
94
|
executables:
|
95
95
|
- spire
|
@@ -110,7 +110,6 @@ files:
|
|
110
110
|
- lib/spire/public.rb
|
111
111
|
- lib/spire/resource/mime.rb
|
112
112
|
- lib/spire/router.rb
|
113
|
-
- routes.rb
|
114
113
|
- spire.gemspec
|
115
114
|
homepage: http://github.com/snicol/spire
|
116
115
|
licenses:
|
@@ -127,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
126
|
version: '0'
|
128
127
|
segments:
|
129
128
|
- 0
|
130
|
-
hash:
|
129
|
+
hash: 2784368830073330069
|
131
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
131
|
none: false
|
133
132
|
requirements:
|
data/routes.rb
DELETED