utopia 0.10.0 → 0.11.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.
Files changed (62) hide show
  1. data/.gitignore +17 -0
  2. data/.travis.yml +9 -0
  3. data/Gemfile +8 -0
  4. data/README.md +72 -0
  5. data/Rakefile +9 -0
  6. data/bin/utopia +42 -13
  7. data/lib/utopia/extensions/array.rb +19 -3
  8. data/lib/utopia/extensions/date.rb +19 -3
  9. data/lib/utopia/extensions/hash.rb +19 -3
  10. data/lib/utopia/extensions/maybe.rb +19 -0
  11. data/lib/utopia/extensions/rack.rb +21 -3
  12. data/lib/utopia/extensions/regexp.rb +19 -3
  13. data/lib/utopia/extensions/string.rb +19 -3
  14. data/lib/utopia/http.rb +56 -0
  15. data/lib/utopia/link.rb +19 -3
  16. data/lib/utopia/middleware/all.rb +19 -3
  17. data/lib/utopia/middleware/content/node.rb +21 -5
  18. data/lib/utopia/middleware/content/processor.rb +118 -0
  19. data/lib/utopia/middleware/content.rb +22 -7
  20. data/lib/utopia/middleware/controller.rb +19 -7
  21. data/lib/utopia/middleware/directory_index.rb +19 -3
  22. data/lib/utopia/middleware/localization/name.rb +19 -3
  23. data/lib/utopia/middleware/localization.rb +19 -3
  24. data/lib/utopia/middleware/logger.rb +19 -3
  25. data/lib/utopia/middleware/redirector.rb +19 -5
  26. data/lib/utopia/middleware/requester.rb +19 -3
  27. data/lib/utopia/middleware/static.rb +20 -6
  28. data/lib/utopia/middleware.rb +22 -5
  29. data/lib/utopia/path.rb +26 -6
  30. data/lib/utopia/session/encrypted_cookie.rb +19 -3
  31. data/lib/utopia/setup/Gemfile +8 -0
  32. data/lib/utopia/setup/config.ru +4 -13
  33. data/lib/utopia/setup.rb +25 -4
  34. data/lib/utopia/tag.rb +45 -24
  35. data/lib/utopia/tags/all.rb +19 -3
  36. data/lib/utopia/tags/deferred.rb +19 -3
  37. data/lib/utopia/tags/environment.rb +29 -0
  38. data/lib/utopia/tags/node.rb +19 -3
  39. data/lib/utopia/tags/override.rb +19 -3
  40. data/lib/utopia/tags.rb +19 -3
  41. data/lib/utopia/time_store.rb +19 -3
  42. data/lib/utopia/version.rb +20 -10
  43. data/lib/utopia.rb +20 -17
  44. data/test/content_root/_heading.xnode +1 -0
  45. data/test/content_root/index.xnode +1 -0
  46. data/test/test_content_middleware.rb +86 -0
  47. data/test/test_path.rb +32 -0
  48. data/utopia.gemspec +31 -0
  49. metadata +56 -42
  50. data/ext/utopia/xnode/fast_scanner/extconf.rb +0 -6
  51. data/ext/utopia/xnode/fast_scanner/parser.c +0 -289
  52. data/lib/utopia/http_status_codes.rb +0 -39
  53. data/lib/utopia/middleware/benchmark.rb +0 -29
  54. data/lib/utopia/middleware/filter.rb +0 -35
  55. data/lib/utopia/tags/env.rb +0 -13
  56. data/lib/utopia/tags/fortune.rb +0 -9
  57. data/lib/utopia/tags/gallery.rb +0 -275
  58. data/lib/utopia/tags/google_analytics.rb +0 -21
  59. data/lib/utopia/trenni.rb +0 -149
  60. data/lib/utopia/xnode/processor.rb +0 -86
  61. data/lib/utopia/xnode/scanner.rb +0 -159
  62. data/lib/utopia/xnode.rb +0 -6
@@ -1,6 +1,22 @@
1
- # This file is part of the "Utopia Framework" project, and is released under the MIT license.
2
- # Copyright 2010 Samuel Williams. All rights reserved.
3
- # See <utopia.rb> for licensing details.
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 'utopia/middleware'
6
22
  require 'utopia/link'
@@ -8,7 +24,8 @@ require 'utopia/path'
8
24
  require 'utopia/tags'
9
25
 
10
26
  require 'utopia/middleware/content/node'
11
- require 'utopia/trenni'
27
+ require 'utopia/middleware/content/processor'
28
+ require 'trenni/template'
12
29
 
13
30
  module Utopia
14
31
  module Middleware
@@ -18,8 +35,6 @@ module Utopia
18
35
  @app = app
19
36
 
20
37
  @root = File.expand_path(options[:root] || Utopia::Middleware::default_root)
21
-
22
- LOG.info "** #{self.class.name}: Running in #{@root}"
23
38
 
24
39
  # Set to hash to enable caching
25
40
  @nodes = {}
@@ -32,7 +47,7 @@ module Utopia
32
47
  attr :passthrough
33
48
 
34
49
  def fetch_xml(path)
35
- read_file = lambda { Trenni.new(File.read(path), path) }
50
+ read_file = lambda { Trenni::Template.load(path) }
36
51
 
37
52
  if @files
38
53
  @files.fetch(path) do |key|
@@ -1,10 +1,25 @@
1
- # This file is part of the "Utopia Framework" project, and is released under the MIT license.
2
- # Copyright 2010 Samuel Williams. All rights reserved.
3
- # See <utopia.rb> for licensing details.
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 'utopia/middleware'
6
22
  require 'utopia/path'
7
- require 'utopia/http_status_codes'
8
23
 
9
24
  class Rack::Request
10
25
  def controller(&block)
@@ -18,7 +33,6 @@ end
18
33
 
19
34
  module Utopia
20
35
  module Middleware
21
-
22
36
  class Controller
23
37
  module Direct
24
38
  def process!(path, request)
@@ -227,8 +241,6 @@ module Utopia
227
241
  @app = app
228
242
  @root = options[:root] || Utopia::Middleware::default_root
229
243
 
230
- LOG.info "** #{self.class.name}: Running in #{@root}"
231
-
232
244
  @controllers = {}
233
245
  @cache_controllers = (UTOPIA_ENV == :production)
234
246
 
@@ -1,6 +1,22 @@
1
- # This file is part of the "Utopia Framework" project, and is released under the MIT license.
2
- # Copyright 2010 Samuel Williams. All rights reserved.
3
- # See <utopia.rb> for licensing details.
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 'utopia/middleware'
6
22
  require 'utopia/path'
@@ -1,6 +1,22 @@
1
- # This file is part of the "Utopia Framework" project, and is released under the MIT license.
2
- # Copyright 2010 Samuel Williams. All rights reserved.
3
- # See <utopia.rb> for licensing details.
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
  module Utopia
6
22
  module Middleware
@@ -1,6 +1,22 @@
1
- # This file is part of the "Utopia Framework" project, and is released under the MIT license.
2
- # Copyright 2010 Samuel Williams. All rights reserved.
3
- # See <utopia.rb> for licensing details.
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 'utopia/middleware'
6
22
  require 'utopia/middleware/localization/name'
@@ -1,6 +1,22 @@
1
- # This file is part of the "Utopia Framework" project, and is released under the MIT license.
2
- # Copyright 2010 Samuel Williams. All rights reserved.
3
- # See <utopia.rb> for licensing details.
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 'utopia/middleware'
6
22
  require 'utopia/time_store'
@@ -1,6 +1,22 @@
1
- # This file is part of the "Utopia Framework" project, and is released under the MIT license.
2
- # Copyright 2010 Samuel Williams. All rights reserved.
3
- # See <utopia.rb> for licensing details.
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 'utopia/middleware'
6
22
  require 'utopia/extensions/regexp'
@@ -139,8 +155,6 @@ module Utopia
139
155
  @patterns = normalize_patterns(@patterns)
140
156
 
141
157
  @errors = options[:errors]
142
-
143
- LOG.info "** #{self.class.name}: Running with #{@strings.size + @patterns.size} rules"
144
158
  end
145
159
 
146
160
  def redirect(uri, match_data)
@@ -1,6 +1,22 @@
1
- # This file is part of the "Utopia Framework" project, and is released under the MIT license.
2
- # Copyright 2010 Samuel Williams. All rights reserved.
3
- # See <utopia.rb> for licensing details.
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 'utopia/middleware'
6
22
 
@@ -1,6 +1,22 @@
1
- # This file is part of the "Utopia Framework" project, and is released under the MIT license.
2
- # Copyright 2010 Samuel Williams. All rights reserved.
3
- # See <utopia.rb> for licensing details.
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 'utopia/middleware'
6
22
  require 'utopia/path'
@@ -184,6 +200,7 @@ module Utopia
184
200
  end
185
201
 
186
202
  public
203
+
187
204
  def initialize(app, options = {})
188
205
  @app = app
189
206
  @root = options[:root] || Utopia::Middleware::default_root
@@ -195,9 +212,6 @@ module Utopia
195
212
  end
196
213
 
197
214
  @cache_control = options[:cache_control] || "public, max-age=3600"
198
-
199
- LOG.info "** #{self.class.name}: Running in #{@root} with #{extensions.size} filetypes"
200
- # LOG.info @extensions.inspect
201
215
  end
202
216
 
203
217
  def fetch_file(path)
@@ -1,11 +1,28 @@
1
- # This file is part of the "Utopia Framework" project, and is released under the MIT license.
2
- # Copyright 2010 Samuel Williams. All rights reserved.
3
- # See <utopia.rb> for licensing details.
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
  require 'logger'
7
23
 
8
- require 'utopia/http_status_codes'
24
+ require 'utopia/http'
25
+
9
26
  require 'utopia/extensions/rack'
10
27
 
11
28
  module Utopia
@@ -18,7 +35,7 @@ module Utopia
18
35
  end
19
36
 
20
37
  def self.failure(status = 500, message = "Non-specific error")
21
- body = "#{HTTP_STATUS_DESCRIPTIONS[status] || status.to_s}: #{message}"
38
+ body = "#{HTTP::STATUS_DESCRIPTIONS[status] || status.to_s}: #{message}"
22
39
 
23
40
  return [status, {
24
41
  "Content-Type" => "text/plain",
data/lib/utopia/path.rb CHANGED
@@ -1,8 +1,22 @@
1
- # This file is part of the "Utopia Framework" project, and is released under the MIT license.
2
- # Copyright 2010 Samuel Williams. All rights reserved.
3
- # See <utopia.rb> for licensing details.
4
-
5
- require 'rack/utils'
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.
6
20
 
7
21
  module Utopia
8
22
 
@@ -21,6 +35,12 @@ module Utopia
21
35
  create(path)
22
36
  end
23
37
 
38
+ def self.unescape(string)
39
+ string.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n) {
40
+ [$1.delete('%')].pack('H*')
41
+ }
42
+ end
43
+
24
44
  def self.create(path)
25
45
  case path
26
46
  when Path
@@ -28,7 +48,7 @@ module Utopia
28
48
  when Array
29
49
  return Path.new(path)
30
50
  when String
31
- path = Rack::Utils.unescape(path)
51
+ path = unescape(path)
32
52
  # Ends with SEPARATOR
33
53
  if path[-1,1] == SEPARATOR
34
54
  return Path.new(path.split(SEPARATOR) << "")
@@ -1,6 +1,22 @@
1
- # This file is part of the "Utopia Framework" project, and is released under the MIT license.
2
- # Copyright 2010 Samuel Williams. All rights reserved.
3
- # See <utopia.rb> for licensing details.
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 'openssl'
6
22
  require 'digest/sha2'
@@ -0,0 +1,8 @@
1
+
2
+ source "http://rubygems.org"
3
+
4
+ gem "utopia", "= $UTOPIA_VERSION"
5
+
6
+ group :development do
7
+ gem "thin"
8
+ end
@@ -4,14 +4,11 @@ UTOPIA_ENV = (ENV['UTOPIA_ENV'] || ENV['RACK_ENV'] || :development).to_sym
4
4
  $LOAD_PATH << File.join(File.dirname(__FILE__), "lib")
5
5
 
6
6
  # It is recommended that you always explicity specify the version of the gem you are using.
7
- gem 'utopia', $UTOPIA_VERSION
7
+ gem 'utopia', "= $UTOPIA_VERSION"
8
8
  require 'utopia/middleware/all'
9
9
  require 'utopia/tags/env'
10
10
 
11
- gem 'rack-contrib'
12
- require 'rack/contrib'
13
-
14
- # Utopia relies heavily on accurately caching resources
11
+ # Utopia relies on effectively caching resources:
15
12
  gem 'rack-cache'
16
13
  require 'rack/cache'
17
14
 
@@ -19,13 +16,8 @@ if UTOPIA_ENV == :development
19
16
  use Rack::ShowExceptions
20
17
  else
21
18
  use Utopia::Middleware::ExceptionHandler, "/errors/exception"
22
-
23
- # Fill out these details to receive email reports of exceptions when running in a production environment.
24
- # use Rack::MailExceptions do |mail|
25
- # mail.from $MAIL_EXCEPTIONS_FROM
26
- # mail.to $MAIL_EXCEPTIONS_TO
27
- # mail.subject "Website Error: %s"
28
- # end
19
+
20
+ # You might want to use the Rack::MailExceptions middleware to get notifications about problems.
29
21
  end
30
22
 
31
23
  use Rack::ContentLength
@@ -34,7 +26,6 @@ use Utopia::Middleware::Logger
34
26
  use Utopia::Middleware::Redirector, {
35
27
  :strings => {
36
28
  '/' => '/welcome/index',
37
- '/utopia' => 'http://www.oriontransfer.co.nz/software/utopia/demo'
38
29
  },
39
30
  :errors => {
40
31
  404 => "/errors/file-not-found"
data/lib/utopia/setup.rb CHANGED
@@ -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
  require 'utopia/version'
3
22
  require 'fileutils'
@@ -30,10 +49,12 @@ module Utopia
30
49
  FileUtils.mkdir_p(File.join(to, path))
31
50
  end
32
51
 
33
- $stderr.puts "Updating config.ru..."
34
- config_ru = File.join(to, "config.ru")
35
- buf = File.read(config_ru).gsub('$UTOPIA_VERSION', Utopia::VERSION::STRING.dump)
36
- File.open(config_ru, "w") { |fp| fp.write(buf) }
52
+ ['config.ru', 'Gemfile'].each do |configuration_file|
53
+ $stderr.puts "Updating #{configuration_file}..."
54
+ path = File.join(to, configuration_file)
55
+ buffer = File.read(path).gsub('$UTOPIA_VERSION', Utopia::VERSION)
56
+ File.open(path, "w") { |file| file.write(buffer) }
57
+ end
37
58
  end
38
59
  end
39
60
  end
data/lib/utopia/tag.rb CHANGED
@@ -1,10 +1,31 @@
1
- # This file is part of the "Utopia Framework" project, and is released under the MIT license.
2
- # Copyright 2010 Samuel Williams. All rights reserved.
3
- # See <utopia.rb> for licensing details.
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
  module Utopia
6
-
7
22
  class Tag
23
+ def == other
24
+ if Tag === other
25
+ [@name, @attributes, @closed] == [other.name, other.attributes, other.closed]
26
+ end
27
+ end
28
+
8
29
  def self.closed(name, attributes = {})
9
30
  tag = Tag.new(name, attributes)
10
31
  tag.closed = true
@@ -31,10 +52,10 @@ module Utopia
31
52
  @content.write text
32
53
  end
33
54
 
34
- def to_html(content = nil, buf = StringIO.new)
35
- write_full_html(buf, content)
55
+ def to_html(content = nil, buffer = StringIO.new)
56
+ write_full_html(buffer, content)
36
57
 
37
- return buf.string
58
+ return buffer.string
38
59
  end
39
60
 
40
61
  def to_hash
@@ -42,41 +63,41 @@ module Utopia
42
63
  end
43
64
 
44
65
  def to_s
45
- buf = StringIO.new
46
- write_open_html(buf)
47
- return buf.string
66
+ buffer = StringIO.new
67
+ write_full_html(buffer)
68
+ return buffer.string
48
69
  end
49
70
 
50
- def write_open_html(buf, terminate = false)
51
- buf ||= StringIO.new
52
- buf.write "<#{name}"
71
+ def write_open_html(buffer, terminate = false)
72
+ buffer ||= StringIO.new
73
+ buffer.write "<#{name}"
53
74
 
54
75
  @attributes.each do |key, value|
55
76
  if value
56
- buf.write " #{key}=\"#{value}\""
77
+ buffer.write " #{key}=\"#{value}\""
57
78
  else
58
- buf.write " #{key}"
79
+ buffer.write " #{key}"
59
80
  end
60
81
  end
61
82
 
62
83
  if terminate
63
- buf.write "/>"
84
+ buffer.write "/>"
64
85
  else
65
- buf.write ">"
86
+ buffer.write ">"
66
87
  end
67
88
  end
68
89
 
69
- def write_close_html(buf)
70
- buf.write "</#{name}>"
90
+ def write_close_html(buffer)
91
+ buffer.write "</#{name}>"
71
92
  end
72
93
 
73
- def write_full_html(buf, content = nil)
94
+ def write_full_html(buffer, content = nil)
74
95
  if @closed && content == nil
75
- write_open_html(buf, true)
96
+ write_open_html(buffer, true)
76
97
  else
77
- write_open_html(buf)
78
- buf.write(content)
79
- write_close_html(buf)
98
+ write_open_html(buffer)
99
+ buffer.write(content)
100
+ write_close_html(buffer)
80
101
  end
81
102
  end
82
103
  end