tzispa 0.4.6 → 0.4.7
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/tzispa/app.rb +16 -2
- data/lib/tzispa/config/appconfig.rb +1 -2
- data/lib/tzispa/controller/base.rb +3 -49
- data/lib/tzispa/http/context.rb +7 -0
- data/lib/tzispa/http/request.rb +0 -70
- data/lib/tzispa/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be0264dbd88974cd802bdc9e3e4d71413d90b47e
|
4
|
+
data.tar.gz: 9d27f6794453d3d9f351c608463fc492000ac474
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be70785ed4efbe53d86c975e99832a62eb91ca50ac46877e0de19727b1bbb2714c3217c96e937892146309c8b3e0f1f8b19c6897d2b6e778bb7d47dd758d82b2
|
7
|
+
data.tar.gz: d72f41fcd6edabadc31276bdf935f260adf6f44ec4194089c25f60afd8329202ab0a384d7c8831a833a641b50349ac91bb5938d672dbb5b6ae990eec0ecce2b1
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@ Tzispa
|
|
2
2
|
|
3
3
|
General purpose web framework
|
4
4
|
|
5
|
+
## v0.4.7
|
6
|
+
- remove browser detection obsolete code
|
7
|
+
- remake app error handling and reporting
|
8
|
+
|
5
9
|
## v0.4.6
|
6
10
|
- add browser detection support
|
7
11
|
- allow specify a url fragment to redirect to the referer page section
|
data/lib/tzispa/app.rb
CHANGED
@@ -8,6 +8,7 @@ require 'tzispa/routes'
|
|
8
8
|
require 'tzispa/config/appconfig'
|
9
9
|
require 'tzispa/middleware'
|
10
10
|
require 'tzispa/http/context'
|
11
|
+
require 'tzispa/helpers/error_view'
|
11
12
|
require 'tzispa_data'
|
12
13
|
require "tzispa_rig"
|
13
14
|
|
@@ -21,6 +22,8 @@ module Tzispa
|
|
21
22
|
class Application
|
22
23
|
extend Forwardable
|
23
24
|
|
25
|
+
include Tzispa::Helpers::ErrorView
|
26
|
+
|
24
27
|
attr_reader :domain, :config, :middleware, :repository, :engine, :logger
|
25
28
|
def_delegator :@middleware, :use
|
26
29
|
def_delegator :@domain, :name
|
@@ -73,8 +76,19 @@ module Tzispa
|
|
73
76
|
|
74
77
|
def call(env)
|
75
78
|
env[Tzispa::ENV_TZISPA_APP] = self
|
76
|
-
|
77
|
-
|
79
|
+
context = Tzispa::Http::Context.new(env)
|
80
|
+
env[Tzispa::ENV_TZISPA_CONTEXT] = context
|
81
|
+
begin
|
82
|
+
middleware.call(env)
|
83
|
+
rescue StandardError, ScriptError => ex
|
84
|
+
logger.error "#{ex.message}\n#{ex.backtrace.map { |trace| "\t #{trace}" }.join('\n') if ex.respond_to?(:backtrace) && ex.backtrace}"
|
85
|
+
if config.developing
|
86
|
+
context.error error_report(ex)
|
87
|
+
else
|
88
|
+
context.error error_page(domain)
|
89
|
+
end
|
90
|
+
context.response.finish
|
91
|
+
end
|
78
92
|
end
|
79
93
|
|
80
94
|
def load!
|
@@ -35,14 +35,13 @@ module Tzispa
|
|
35
35
|
@config ||= Tzispa::Config::Yaml.load(filename)
|
36
36
|
end
|
37
37
|
|
38
|
-
def create_default(host:, layout: 'index',
|
38
|
+
def create_default(host:, layout: 'index', locale: 'en')
|
39
39
|
hcfg = Hash.new.tap { |cfg|
|
40
40
|
cfg['id'] = domain.name
|
41
41
|
cfg['default_layout'] = layout
|
42
42
|
cfg['default_format'] = 'htm'
|
43
43
|
cfg['host_name'] = host
|
44
44
|
cfg['canonical_url'] = "http://#{host}"
|
45
|
-
cfg['dev_mode'] = dev_mode
|
46
45
|
cfg['default_encoding'] = 'utf-8'
|
47
46
|
cfg['auth_required'] = false
|
48
47
|
cfg['salt'] = secret(24)
|
@@ -12,7 +12,7 @@ module Tzispa
|
|
12
12
|
extend Forwardable
|
13
13
|
|
14
14
|
attr_reader :context
|
15
|
-
def_delegators :@context, :request, :response, :config
|
15
|
+
def_delegators :@context, :request, :response, :config, :error
|
16
16
|
|
17
17
|
def initialize(callmethod=nil)
|
18
18
|
@callmethod = callmethod
|
@@ -28,58 +28,12 @@ module Tzispa
|
|
28
28
|
|
29
29
|
def invoke(callmethod)
|
30
30
|
status = catch(:halt) {
|
31
|
-
|
32
|
-
send "#{@callmethod}"
|
33
|
-
rescue StandardError, ScriptError => ex
|
34
|
-
context.app.logger.error "#{ex.message}\n#{ex.backtrace.map { |trace| "\t #{trace}" }.join('\n') if ex.respond_to?(:backtrace) && ex.backtrace}"
|
35
|
-
error error_report(ex)
|
36
|
-
end
|
31
|
+
send "#{@callmethod}"
|
37
32
|
}
|
38
33
|
response.status = status if status.is_a?(Integer)
|
39
|
-
error_page(response.status) if (response.client_error? || response.server_error?)
|
34
|
+
error context.app.error_page(response.status) if (response.client_error? || response.server_error?)
|
40
35
|
end
|
41
36
|
|
42
|
-
def error(body)
|
43
|
-
500.tap { |code|
|
44
|
-
response.status = code
|
45
|
-
response.body = body
|
46
|
-
}
|
47
|
-
end
|
48
|
-
|
49
|
-
def error_report(error=nil)
|
50
|
-
text = String.new('<!DOCTYPE html>')
|
51
|
-
text << '<html lang="es"><head>'
|
52
|
-
text << '<meta charset="utf-8" />'
|
53
|
-
text << '<style> html {background:#cccccc; font-family:Arial; font-size:15px; color:#555;} body {width:75%; max-width:1200px; margin:18px auto; background:#fff; border-radius:6px; padding:32px 24px;} ul{list-style:none; margin:0; padding:0;} li{font-style:italic; color:#666;} h1 {color:#2ECC71;} </style>'
|
54
|
-
text << '</head><body>'
|
55
|
-
text << "<h5>#{Tzispa::FRAMEWORK_NAME} #{Tzispa::VERSION}</h5>\n"
|
56
|
-
if error && config.developing
|
57
|
-
text << "<h1>#{error.class.name}</h1><h3>#{error.message}</h1>\n"
|
58
|
-
text << '<ol>' + error.backtrace.map { |trace| "<li>#{trace}</li>\n" }.join + '</ol>' if error.respond_to?(:backtrace) && error.backtrace
|
59
|
-
else
|
60
|
-
text << "<h1>Error 500</h1>\n"
|
61
|
-
text << "Se ha producido un error inesperado al tramitar la petición"
|
62
|
-
end
|
63
|
-
text << '</body></html>'
|
64
|
-
end
|
65
|
-
|
66
|
-
def error_page(status)
|
67
|
-
begin
|
68
|
-
error_file = "#{context.app.domain.path}/error/#{status}.htm"
|
69
|
-
response.body = Tzispa::Rig::File.new(error_file).load!.content
|
70
|
-
rescue
|
71
|
-
response.body = String.new('<!DOCTYPE html>')
|
72
|
-
response.body << '<html lang="es"><head>'
|
73
|
-
response.body << '<meta charset="utf-8" />'
|
74
|
-
response.body << '<style> html {background:#cccccc; font-family:Arial; font-size:15px; color:#555;} body {width:75%; max-width:1200px; margin:18px auto; background:#fff; border-radius:6px; padding:32px 24px;} #main {margin:auto; } h1 {color:#2ECC71; font-size:4em; text-align:center;} </style>'
|
75
|
-
response.body << '</head><body>'
|
76
|
-
response.body << '<div id="main">'
|
77
|
-
response.body << "<h5>#{Tzispa::FRAMEWORK_NAME} #{Tzispa::VERSION}</h5>\n"
|
78
|
-
response.body << "<h1>Error #{status}</h1>\n"
|
79
|
-
response.body << '</div>'
|
80
|
-
response.body << '</body></html>'
|
81
|
-
end
|
82
|
-
end
|
83
37
|
|
84
38
|
end
|
85
39
|
|
data/lib/tzispa/http/context.rb
CHANGED
@@ -38,6 +38,13 @@ module Tzispa
|
|
38
38
|
router_params&.fetch(:layout, nil)
|
39
39
|
end
|
40
40
|
|
41
|
+
def error(body)
|
42
|
+
500.tap { |code|
|
43
|
+
response.status = code
|
44
|
+
response.body = body
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
41
48
|
def set_last_access
|
42
49
|
session[SESSION_LAST_ACCESS] = Time.now.utc.iso8601
|
43
50
|
end
|
data/lib/tzispa/http/request.rb
CHANGED
@@ -36,76 +36,6 @@ module Tzispa
|
|
36
36
|
request_method == "UNLINK"
|
37
37
|
end
|
38
38
|
|
39
|
-
def browser_is? name
|
40
|
-
name = name.to_s.strip
|
41
|
-
return true if browser_name == name
|
42
|
-
return true if name == 'mozilla' && browser_name == 'gecko'
|
43
|
-
return true if name == 'ie' && browser_name.index('ie')
|
44
|
-
return true if name == 'webkit' && %w{safari chrome iphone ipad ipod}.include?(browser_name)
|
45
|
-
return true if name == 'ios' && %w{iphone ipad ipod}.include?(browser_name)
|
46
|
-
return true if name == 'robots' && %w{googlebot msnbot yahoobot}.include?(browser_name)
|
47
|
-
end
|
48
|
-
|
49
|
-
# Returns the user agent string as determined by the plugin
|
50
|
-
def browser_name
|
51
|
-
@browser_name ||= begin
|
52
|
-
if user_agentindex('msie') && !user_agent.index('opera') && !user_agent.index('webtv')
|
53
|
-
'ie'+user_agent[user_agent.index('msie')+5].chr
|
54
|
-
elsif user_agent.index('gecko/')
|
55
|
-
'gecko'
|
56
|
-
elsif user_agent.index('opera')
|
57
|
-
'opera'
|
58
|
-
elsif user_agent.index('konqueror')
|
59
|
-
'konqueror'
|
60
|
-
elsif user_agent.index('ipod')
|
61
|
-
'ipod'
|
62
|
-
elsif user_agent.index('ipad')
|
63
|
-
'ipad'
|
64
|
-
elsif user_agent.index('iphone')
|
65
|
-
'iphone'
|
66
|
-
elsif user_agent.index('chrome/')
|
67
|
-
'chrome'
|
68
|
-
elsif user_agent.index('applewebkit/')
|
69
|
-
'safari'
|
70
|
-
elsif user_agent.index('googlebot/')
|
71
|
-
'googlebot'
|
72
|
-
elsif user_agent.index('msnbot')
|
73
|
-
'msnbot'
|
74
|
-
elsif user_agent.index('yahoo! slurp')
|
75
|
-
'yahoobot'
|
76
|
-
#Everything thinks it's mozilla, so this goes last
|
77
|
-
elsif user_agent.index('mozilla/')
|
78
|
-
'gecko'
|
79
|
-
else
|
80
|
-
'unknown'
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# Determine the version of webkit.
|
86
|
-
# Useful for determing rendering capabilties
|
87
|
-
def browser_webkit_version
|
88
|
-
if browser_is? 'webkit'
|
89
|
-
match = user_agent.match(%r{\bapplewebkit/([\d\.]+)\b})
|
90
|
-
if (match)
|
91
|
-
match[1].to_f
|
92
|
-
else
|
93
|
-
nil
|
94
|
-
end
|
95
|
-
else
|
96
|
-
nil
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
#Gather the user agent and store it for use.
|
101
|
-
def user_agent
|
102
|
-
@ua ||= begin
|
103
|
-
@env['HTTP_USER_AGENT'].downcase
|
104
|
-
rescue
|
105
|
-
''
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
39
|
end
|
110
40
|
end
|
111
41
|
end
|
data/lib/tzispa/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tzispa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Antonio Piñero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|