utopia 0.11.3 → 0.11.4

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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDlhNmM0MzcwM2VlMWUxNTJlM2YzYzMzMTk4ODczYjZiMTkwYjBjNg==
5
+ data.tar.gz: !binary |-
6
+ Y2YxYzAxNzc3NjY3ZWI5MjU5NDI4YzgxMzFjODg5MmM4M2YyZGRlYQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NjJlODdhODQ3MjM0MzAwMDNmZDczNGQ2Mzg5ZjIzYjQwODE3NzJmMWI0MDFh
10
+ MGQ0NDU5MzJiNDQ1NDU0OTcxNjdhMTM4YmQ3ODBjNzgzNDY0MWRmYmZkNmRi
11
+ MDJkMzdkMGVkOWY5OTQyZDE3NGZjNzFlYzZlYzI0OTA1Mzg2NzA=
12
+ data.tar.gz: !binary |-
13
+ MzJjZjcwNWNhY2JlZjljMzVhNzk5NDM0MTIzZTQyYzViZGM4ODY4NGY1Yzdk
14
+ ZTUzYzBiMDNmOTVjMDk2YmVmYTIzNTE1N2NlOTNjMmM5Y2FjZDA5MmJiODYw
15
+ Y2JmNTg0MWFkNDc0MWNhYjA5ZjdiMDBlOWRkZjliODA5OGNiZDA=
@@ -0,0 +1,132 @@
1
+ # Copyright, 2013, 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 'net/smtp'
22
+ require 'mail'
23
+
24
+ module Utopia
25
+ module Middleware
26
+ # Catches all exceptions raised from the app it wraps and sends a useful email with the exception, stacktrace, and contents of the environment.
27
+ class MailExceptions
28
+ # A basic local non-authenticated SMTP server.
29
+ LOCAL_SMTP = [:smtp, {
30
+ :address => "localhost",
31
+ :port => 25,
32
+ :enable_starttls_auto => false
33
+ }]
34
+
35
+ def initialize(app, config = {})
36
+ @app = app
37
+
38
+ @to = config[:to] || "postmaster"
39
+ @from = config.fetch(:from) {(ENV['USER'] || 'rack') + "@localhost"}
40
+ @subject = config[:subject] || '%{exception} [PID %{pid} : %{cwd}]'
41
+ @delivery_method = config.fetch(:delivery_method, LOCAL_SMTP)
42
+ end
43
+
44
+ def call(env)
45
+ begin
46
+ return @app.call(env)
47
+ rescue => exception
48
+ send_notification exception, env
49
+
50
+ raise
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ REQUEST_KEYS = [:ip, :referrer, :path, :user_agent]
57
+
58
+ def generate_body(exception, env)
59
+ io = StringIO.new
60
+
61
+ # Dump out useful rack environment variables:
62
+ request = Rack::Request.new(env)
63
+
64
+ io.puts "#{request.request_method} #{request.url}"
65
+
66
+ io.puts
67
+
68
+ REQUEST_KEYS.each do |key|
69
+ value = request.send(key)
70
+ io.puts "request.#{key}: #{value.inspect}"
71
+ end
72
+
73
+ request.params.each do |key, value|
74
+ io.puts "request.params.#{key}: #{value.inspect}"
75
+ end
76
+
77
+ io.puts
78
+
79
+ if exception.respond_to?(:backtrace)
80
+ io.puts exception.backtrace
81
+ else
82
+ io.puts exception.to_s
83
+ end
84
+
85
+ return io.string
86
+ end
87
+
88
+ def generate_mail(exception, env)
89
+ attributes = {
90
+ exception: exception.to_s,
91
+ pid: $$,
92
+ cwd: Dir.getwd,
93
+ }
94
+
95
+ mail = Mail.new(
96
+ :from => @from,
97
+ :to => @to,
98
+ :subject => @subject % attributes
99
+ )
100
+
101
+ mail.text_part = Mail::Part.new
102
+ mail.text_part.body = generate_body(exception, env)
103
+
104
+ if body = extract_body(env) and body.size > 0
105
+ mail.attachments['body.bin'] = body
106
+ end
107
+
108
+ mail.attachments['environment.yaml'] = YAML::dump(env)
109
+
110
+ return mail
111
+ end
112
+
113
+ def send_notification(exception, env)
114
+ mail = generate_mail(exception, env)
115
+
116
+ mail.delivery_method(*@delivery_method) if @delivery_method
117
+
118
+ mail.deliver
119
+ rescue => mail_exception
120
+ $stderr.puts mail_exception.to_s
121
+ $stderr.puts mail_exception.backtrace
122
+ end
123
+
124
+ def extract_body(env)
125
+ if io = env['rack.input']
126
+ io.rewind if io.respond_to?(:rewind)
127
+ io.read
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
@@ -7,8 +7,7 @@ $LOAD_PATH << File.join(File.dirname(__FILE__), "lib")
7
7
  gem 'utopia', "= $UTOPIA_VERSION"
8
8
  require 'utopia/middleware/all'
9
9
 
10
- # Utopia relies on effectively caching resources:
11
- gem 'rack-cache'
10
+ # Utopia relies heavily on a local cache:
12
11
  require 'rack/cache'
13
12
 
14
13
  if UTOPIA_ENV == :development
@@ -16,7 +15,7 @@ if UTOPIA_ENV == :development
16
15
  else
17
16
  use Utopia::Middleware::ExceptionHandler, "/errors/exception"
18
17
 
19
- # You might want to use the Rack::MailExceptions middleware to get notifications about problems.
18
+ use Utopia::Middleware::MailExceptions
20
19
  end
21
20
 
22
21
  use Rack::ContentLength
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Utopia
22
- VERSION = "0.11.3"
22
+ VERSION = "0.11.4"
23
23
  end
data/utopia.gemspec CHANGED
@@ -4,28 +4,28 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'utopia/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "utopia"
8
- gem.version = Utopia::VERSION
9
- gem.authors = ["Samuel Williams"]
10
- gem.email = ["samuel.williams@oriontransfer.co.nz"]
11
- gem.description = <<-EOF
12
- Utopia is a website generation framework which provides a robust set of tools
13
- to build highly complex dynamic websites. It uses the filesystem heavily for
14
- content and provides frameworks for interacting with files and directories as
15
- structure representing the website.
16
- EOF
17
- gem.summary = %q{Utopia is a framework for building dynamic content-driven websites.}
18
- gem.homepage = ""
7
+ gem.name = "utopia"
8
+ gem.version = Utopia::VERSION
9
+ gem.authors = ["Samuel Williams"]
10
+ gem.email = ["samuel.williams@oriontransfer.co.nz"]
11
+ gem.description = <<-EOF
12
+ Utopia is a website generation framework which provides a robust set of tools
13
+ to build highly complex dynamic websites. It uses the filesystem heavily for
14
+ content and provides frameworks for interacting with files and directories as
15
+ structure representing the website.
16
+ EOF
17
+ gem.summary = %q{Utopia is a framework for building dynamic content-driven websites.}
18
+ gem.homepage = ""
19
19
 
20
- gem.files = `git ls-files`.split($/)
21
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
22
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
23
- gem.require_paths = ["lib"]
20
+ gem.files = `git ls-files`.split($/)
21
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
22
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
23
+ gem.require_paths = ["lib"]
24
24
 
25
- gem.add_dependency "trenni", "~> 1.2.0"
26
- gem.add_dependency "mime-types"
27
- gem.add_dependency "rack", "~> 1.4.1"
25
+ gem.add_dependency "trenni", "~> 1.2.0"
26
+ gem.add_dependency "mime-types"
27
+ gem.add_dependency "rack", "~> 1.4.1"
28
28
 
29
- gem.add_dependency "rack-cache"
30
- gem.add_dependency "rack-contrib"
29
+ gem.add_dependency "rack-cache"
30
+ gem.add_dependency "mail"
31
31
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utopia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.3
5
- prerelease:
4
+ version: 0.11.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Samuel Williams
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-04 00:00:00.000000000 Z
11
+ date: 2013-03-07 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: trenni
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: mime-types
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rack
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rack-cache
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,15 +62,13 @@ dependencies:
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ! '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
- name: rack-contrib
70
+ name: mail
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,15 +76,14 @@ dependencies:
86
76
  type: :runtime
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ! '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
- description: ! " Utopia is a website generation framework which provides a robust
95
- set of tools\n to build highly complex dynamic websites. It uses the filesystem
96
- heavily for\n content and provides frameworks for interacting with files and directories
97
- as\n structure representing the website.\n"
83
+ description: ! "\t\tUtopia is a website generation framework which provides a robust
84
+ set of tools\n\t\tto build highly complex dynamic websites. It uses the filesystem
85
+ heavily for\n\t\tcontent and provides frameworks for interacting with files and
86
+ directories as\n\t\tstructure representing the website.\n"
98
87
  email:
99
88
  - samuel.williams@oriontransfer.co.nz
100
89
  executables:
@@ -128,6 +117,7 @@ files:
128
117
  - lib/utopia/middleware/localization.rb
129
118
  - lib/utopia/middleware/localization/name.rb
130
119
  - lib/utopia/middleware/logger.rb
120
+ - lib/utopia/middleware/mail_exceptions.rb
131
121
  - lib/utopia/middleware/redirector.rb
132
122
  - lib/utopia/middleware/requester.rb
133
123
  - lib/utopia/middleware/static.rb
@@ -166,27 +156,26 @@ files:
166
156
  - utopia.gemspec
167
157
  homepage: ''
168
158
  licenses: []
159
+ metadata: {}
169
160
  post_install_message:
170
161
  rdoc_options: []
171
162
  require_paths:
172
163
  - lib
173
164
  required_ruby_version: !ruby/object:Gem::Requirement
174
- none: false
175
165
  requirements:
176
166
  - - ! '>='
177
167
  - !ruby/object:Gem::Version
178
168
  version: '0'
179
169
  required_rubygems_version: !ruby/object:Gem::Requirement
180
- none: false
181
170
  requirements:
182
171
  - - ! '>='
183
172
  - !ruby/object:Gem::Version
184
173
  version: '0'
185
174
  requirements: []
186
175
  rubyforge_project:
187
- rubygems_version: 1.8.24
176
+ rubygems_version: 2.0.2
188
177
  signing_key:
189
- specification_version: 3
178
+ specification_version: 4
190
179
  summary: Utopia is a framework for building dynamic content-driven websites.
191
180
  test_files:
192
181
  - test/content_root/_heading.xnode