utopia 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.travis.yml +9 -0
- data/Gemfile +8 -0
- data/README.md +72 -0
- data/Rakefile +9 -0
- data/bin/utopia +42 -13
- data/lib/utopia/extensions/array.rb +19 -3
- data/lib/utopia/extensions/date.rb +19 -3
- data/lib/utopia/extensions/hash.rb +19 -3
- data/lib/utopia/extensions/maybe.rb +19 -0
- data/lib/utopia/extensions/rack.rb +21 -3
- data/lib/utopia/extensions/regexp.rb +19 -3
- data/lib/utopia/extensions/string.rb +19 -3
- data/lib/utopia/http.rb +56 -0
- data/lib/utopia/link.rb +19 -3
- data/lib/utopia/middleware/all.rb +19 -3
- data/lib/utopia/middleware/content/node.rb +21 -5
- data/lib/utopia/middleware/content/processor.rb +118 -0
- data/lib/utopia/middleware/content.rb +22 -7
- data/lib/utopia/middleware/controller.rb +19 -7
- data/lib/utopia/middleware/directory_index.rb +19 -3
- data/lib/utopia/middleware/localization/name.rb +19 -3
- data/lib/utopia/middleware/localization.rb +19 -3
- data/lib/utopia/middleware/logger.rb +19 -3
- data/lib/utopia/middleware/redirector.rb +19 -5
- data/lib/utopia/middleware/requester.rb +19 -3
- data/lib/utopia/middleware/static.rb +20 -6
- data/lib/utopia/middleware.rb +22 -5
- data/lib/utopia/path.rb +26 -6
- data/lib/utopia/session/encrypted_cookie.rb +19 -3
- data/lib/utopia/setup/Gemfile +8 -0
- data/lib/utopia/setup/config.ru +4 -13
- data/lib/utopia/setup.rb +25 -4
- data/lib/utopia/tag.rb +45 -24
- data/lib/utopia/tags/all.rb +19 -3
- data/lib/utopia/tags/deferred.rb +19 -3
- data/lib/utopia/tags/environment.rb +29 -0
- data/lib/utopia/tags/node.rb +19 -3
- data/lib/utopia/tags/override.rb +19 -3
- data/lib/utopia/tags.rb +19 -3
- data/lib/utopia/time_store.rb +19 -3
- data/lib/utopia/version.rb +20 -10
- data/lib/utopia.rb +20 -17
- data/test/content_root/_heading.xnode +1 -0
- data/test/content_root/index.xnode +1 -0
- data/test/test_content_middleware.rb +86 -0
- data/test/test_path.rb +32 -0
- data/utopia.gemspec +31 -0
- metadata +56 -42
- data/ext/utopia/xnode/fast_scanner/extconf.rb +0 -6
- data/ext/utopia/xnode/fast_scanner/parser.c +0 -289
- data/lib/utopia/http_status_codes.rb +0 -39
- data/lib/utopia/middleware/benchmark.rb +0 -29
- data/lib/utopia/middleware/filter.rb +0 -35
- data/lib/utopia/tags/env.rb +0 -13
- data/lib/utopia/tags/fortune.rb +0 -9
- data/lib/utopia/tags/gallery.rb +0 -275
- data/lib/utopia/tags/google_analytics.rb +0 -21
- data/lib/utopia/trenni.rb +0 -149
- data/lib/utopia/xnode/processor.rb +0 -86
- data/lib/utopia/xnode/scanner.rb +0 -159
- data/lib/utopia/xnode.rb +0 -6
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Utopia
|
2
|
+
|
3
|
+
Utopia is a website generation framework which provides a robust set of tools
|
4
|
+
to build highly complex dynamic websites. It uses the filesystem heavily for
|
5
|
+
content and provides frameworks for interacting with files and directories as
|
6
|
+
structure representing the website.
|
7
|
+
|
8
|
+
Utopia builds on top of Rack with the following middleware:
|
9
|
+
|
10
|
+
* `Utopia::Middleware::Static`: Serve static files with recursive lookup
|
11
|
+
* `Utopia::Middleware::Requester`: Allow nesting of virtual requests
|
12
|
+
* `Utopia::Middleware::Redirector`: Redirect URL patterns and status codes
|
13
|
+
* `Utopia::Middleware::Logger`: Advanced rotating access log
|
14
|
+
* `Utopia::Middleware::Localization`: Non-intrusive localization of resources
|
15
|
+
* `Utopia::Middleware::DirectoryIndex`: Redirect directory requests to specific files
|
16
|
+
* `Utopia::Middleware::Controller`: Dynamic behaviour with recursive execution
|
17
|
+
* `Utopia::Middleware::Content`: XML-style template engine with powerful tag behaviours
|
18
|
+
* `Utopia::Session::EncryptedCookie`: Session storage using an encrypted cookie
|
19
|
+
|
20
|
+
For more details please see the main [project page][1].
|
21
|
+
|
22
|
+
[1]: http://www.oriontransfer.co.nz/gems/utopia
|
23
|
+
|
24
|
+
[![Build Status](https://secure.travis-ci.org/ioquatix/utopia.png)](http://travis-ci.org/ioquatix/utopia)
|
25
|
+
|
26
|
+
## Installation
|
27
|
+
|
28
|
+
Install utopia:
|
29
|
+
|
30
|
+
$ gem install utopia
|
31
|
+
|
32
|
+
Create a new site:
|
33
|
+
|
34
|
+
$ utopia setup www.example.com
|
35
|
+
$ cd www.example.com
|
36
|
+
$ thin start -p 9000
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
The default site includes documentation and examples.
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
Released under the MIT license.
|
53
|
+
|
54
|
+
Copyright, 2012, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
55
|
+
|
56
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
57
|
+
of this software and associated documentation files (the "Software"), to deal
|
58
|
+
in the Software without restriction, including without limitation the rights
|
59
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
60
|
+
copies of the Software, and to permit persons to whom the Software is
|
61
|
+
furnished to do so, subject to the following conditions:
|
62
|
+
|
63
|
+
The above copyright notice and this permission notice shall be included in
|
64
|
+
all copies or substantial portions of the Software.
|
65
|
+
|
66
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
67
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
68
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
69
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
70
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
71
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
72
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
data/bin/utopia
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
3
23
|
require 'rubygems'
|
4
24
|
require 'utopia/setup'
|
5
25
|
require 'rake'
|
@@ -8,26 +28,35 @@ $app = Rake.application = Rake::Application.new
|
|
8
28
|
$app.init('Utopia')
|
9
29
|
|
10
30
|
task :setup do
|
11
|
-
|
31
|
+
path = File.expand_path(ARGV.last, Dir.getwd)
|
32
|
+
FileUtils.mkdir_p path
|
33
|
+
|
34
|
+
Dir.chdir(path) do
|
35
|
+
Utopia::Setup.copy(path)
|
12
36
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
else
|
17
|
-
$stderr.puts "Type `thin start' to start the web server."
|
18
|
-
end
|
37
|
+
if `which thin`.strip == ""
|
38
|
+
$stderr.puts "Next, please install thin: `sudo gem install thin'."
|
39
|
+
end
|
19
40
|
|
20
|
-
|
21
|
-
|
22
|
-
|
41
|
+
if `which git`.strip == ""
|
42
|
+
$stderr.puts "Now is a good time to learn about git : http://git-scm.com/"
|
43
|
+
end
|
23
44
|
|
24
|
-
|
25
|
-
|
45
|
+
unless File.exist? '.git'
|
46
|
+
sh("git", "init")
|
47
|
+
sh("git", "add", ".")
|
48
|
+
sh("git", "commit", "-m", "Initial utopia site.")
|
49
|
+
end
|
26
50
|
end
|
27
51
|
|
28
52
|
$stderr.puts "*** Thanks for trying out Utopia! ***"
|
29
53
|
end
|
30
54
|
|
31
|
-
task :
|
55
|
+
task :help do
|
56
|
+
$stderr.puts "To create a new site, use the setup task:"
|
57
|
+
$stderr.puts "$ #{File.basename($0)} setup www.example.com"
|
58
|
+
end
|
59
|
+
|
60
|
+
task :default => :help
|
32
61
|
|
33
62
|
$app.top_level
|
@@ -1,6 +1,22 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
4
20
|
|
5
21
|
class Array
|
6
22
|
def find_index(&block)
|
@@ -1,6 +1,22 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
4
20
|
|
5
21
|
# These amendments allow for Date <=> DateTime <=> Time, and so on.
|
6
22
|
# Use only if required. This implementation works for Ruby 1.9.2.
|
@@ -1,6 +1,22 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
4
20
|
|
5
21
|
class Hash
|
6
22
|
def symbolize_keys
|
@@ -1,3 +1,22 @@
|
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
1
20
|
|
2
21
|
class NilClass
|
3
22
|
def maybe?
|
@@ -1,6 +1,24 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'rack'
|
4
22
|
|
5
23
|
class Rack::Request
|
6
24
|
def url_with_path(path = "")
|
@@ -1,6 +1,22 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
4
20
|
|
5
21
|
class Regexp
|
6
22
|
def self.starts_with(string)
|
@@ -1,6 +1,22 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
4
20
|
|
5
21
|
class String
|
6
22
|
HTML_ESCAPE = {"&" => "&", "<" => "<", ">" => ">", "\"" => """}
|
data/lib/utopia/http.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
module Utopia
|
22
|
+
module HTTP
|
23
|
+
STATUS_CODES = {
|
24
|
+
:success => 200,
|
25
|
+
:created => 201,
|
26
|
+
:accepted => 202,
|
27
|
+
:moved => 301,
|
28
|
+
:found => 302,
|
29
|
+
:see_other => 303,
|
30
|
+
:not_modified => 304,
|
31
|
+
:redirect => 307,
|
32
|
+
:bad_request => 400,
|
33
|
+
:unauthorized => 401,
|
34
|
+
:forbidden => 403,
|
35
|
+
:not_found => 404,
|
36
|
+
:unsupported_method => 405,
|
37
|
+
:gone => 410,
|
38
|
+
:teapot => 418,
|
39
|
+
:error => 500,
|
40
|
+
:unimplemented => 501,
|
41
|
+
:unavailable => 503
|
42
|
+
}
|
43
|
+
|
44
|
+
STATUS_DESCRIPTIONS = {
|
45
|
+
400 => "Bad Request",
|
46
|
+
401 => "Permission Denied",
|
47
|
+
403 => "Access Forbidden",
|
48
|
+
404 => "Resource Not Found",
|
49
|
+
405 => "Unsupported Method",
|
50
|
+
416 => "Byte range unsatisfiable",
|
51
|
+
500 => "Internal Server Error",
|
52
|
+
501 => "Not Implemented",
|
53
|
+
503 => "Service Unavailable"
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
data/lib/utopia/link.rb
CHANGED
@@ -1,6 +1,22 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
4
20
|
|
5
21
|
require 'yaml'
|
6
22
|
|
@@ -1,6 +1,22 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
4
20
|
|
5
21
|
require 'pathname'
|
6
22
|
|
@@ -1,10 +1,26 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
4
20
|
|
5
21
|
require 'set'
|
6
22
|
|
7
|
-
require 'utopia/
|
23
|
+
require 'utopia/middleware/content/processor'
|
8
24
|
require 'utopia/link'
|
9
25
|
|
10
26
|
module Utopia
|
@@ -118,7 +134,7 @@ module Utopia
|
|
118
134
|
end
|
119
135
|
|
120
136
|
def parse_xml(xml_data)
|
121
|
-
|
137
|
+
Processor.parse_xml(xml_data, self)
|
122
138
|
end
|
123
139
|
|
124
140
|
attr :request
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'utopia/tag'
|
22
|
+
require 'trenni/parser'
|
23
|
+
require 'trenni/strings'
|
24
|
+
|
25
|
+
module Utopia
|
26
|
+
module Middleware
|
27
|
+
class Content
|
28
|
+
class Processor
|
29
|
+
def self.parse_xml(xml_data, delegate)
|
30
|
+
processor = self.new(delegate)
|
31
|
+
|
32
|
+
processor.parse(xml_data)
|
33
|
+
end
|
34
|
+
|
35
|
+
class UnbalancedTagError < StandardError
|
36
|
+
def initialize(scanner, start_position, current_tag, closing_tag)
|
37
|
+
@scanner = scanner
|
38
|
+
@start_position = start_position
|
39
|
+
@current_tag = current_tag
|
40
|
+
@closing_tag = closing_tag
|
41
|
+
|
42
|
+
@starting_line = @scanner.calculate_line_number(@start_pos)
|
43
|
+
@ending_line = @scanner.calculate_line_number
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_s
|
47
|
+
"Unbalanced Tag #{@current_tag}. " \
|
48
|
+
"Line #{@starting_line[0]}: #{@starting_line[4]} has been closed by #{@closing_tag} on line #{@ending_line[0]}: #{@ending_line[4]}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def initialize(delegate)
|
53
|
+
@delegate = delegate
|
54
|
+
@stack = []
|
55
|
+
|
56
|
+
@parser = Trenni::Parser.new(self)
|
57
|
+
end
|
58
|
+
|
59
|
+
def parse(input)
|
60
|
+
@parser.parse(input)
|
61
|
+
end
|
62
|
+
|
63
|
+
def begin_parse(scanner)
|
64
|
+
@scanner = scanner
|
65
|
+
end
|
66
|
+
|
67
|
+
def text(text)
|
68
|
+
@delegate.cdata(text)
|
69
|
+
end
|
70
|
+
|
71
|
+
def cdata(text)
|
72
|
+
@delegate.cdata(Trenni::Strings::to_html(text))
|
73
|
+
end
|
74
|
+
|
75
|
+
def comment(text)
|
76
|
+
@delegate.cdata("<!#{text}>")
|
77
|
+
end
|
78
|
+
|
79
|
+
def begin_tag(tag_name, begin_tag_type)
|
80
|
+
if begin_tag_type == :opened
|
81
|
+
@stack << [Tag.new(tag_name, {}), @scanner.pos]
|
82
|
+
else
|
83
|
+
current_tag, current_position = @stack.pop
|
84
|
+
|
85
|
+
if (tag_name != current_tag.name)
|
86
|
+
raise UnbalancedTagError.new(@scanner, current_position, current_tag.name, tag_name)
|
87
|
+
end
|
88
|
+
|
89
|
+
@delegate.tag_end(current_tag)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def finish_tag(begin_tag_type, end_tag_type)
|
94
|
+
if begin_tag_type == :opened # <...
|
95
|
+
if end_tag_type == :closed # <.../>
|
96
|
+
cur, pos = @stack.pop
|
97
|
+
cur.closed = true
|
98
|
+
|
99
|
+
@delegate.tag_complete(cur)
|
100
|
+
elsif end_tag_type == :opened # <...>
|
101
|
+
cur, pos = @stack.last
|
102
|
+
|
103
|
+
@delegate.tag_begin(cur)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def attribute(name, value)
|
109
|
+
@stack.last[0].attributes[name] = value
|
110
|
+
end
|
111
|
+
|
112
|
+
def instruction(content)
|
113
|
+
cdata("<?#{content}?>")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|