tzispa 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/tzispa/app.rb +3 -2
- data/lib/tzispa/controller/api.rb +13 -5
- data/lib/tzispa/http/context.rb +1 -1
- data/lib/tzispa/http/request.rb +8 -0
- data/lib/tzispa/middleware.rb +1 -1
- data/lib/tzispa/version.rb +1 -1
- data/tzispa.gemspec +4 -3
- metadata +22 -9
- data/lib/tzispa/autoreload.rb +0 -110
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c89e8ec7f20be6d2513d85e5951f8040efdfb1e
|
4
|
+
data.tar.gz: aadaaee55360b82fd09d644c0e48eb3ef76d03bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee05ed3e7c10f7eda755d9564838cf8024c830a44e29381307674ff11e595c437cac4a1fbb1b527efce8ad30ae0cb8de780260a4a27c520c3c8e193928094e0e
|
7
|
+
data.tar.gz: 89dbc1f7e155605d2194b9302711040663186fdf738cd1463b8f1226a1c92c51198353ce734aa29872b27e6db85eb7dae6b9ebfd8e165a1f7b0ecc0d24030aa1
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@ Tzispa
|
|
2
2
|
|
3
3
|
General purpose web framework
|
4
4
|
|
5
|
+
## v0.4.6
|
6
|
+
- add browser detection support
|
7
|
+
- allow specify a url fragment to redirect to the referer page section
|
8
|
+
- middleware management fixes
|
9
|
+
|
5
10
|
## v0.4.5
|
6
11
|
- remove _load_assets_middleware
|
7
12
|
- add browser detection capability
|
data/lib/tzispa/app.rb
CHANGED
@@ -16,7 +16,7 @@ module Tzispa
|
|
16
16
|
|
17
17
|
ENV_TZISPA_APP = :tzispa__app
|
18
18
|
ENV_TZISPA_CONTEXT = :tzispa__context
|
19
|
-
|
19
|
+
|
20
20
|
|
21
21
|
class Application
|
22
22
|
extend Forwardable
|
@@ -81,13 +81,14 @@ module Tzispa
|
|
81
81
|
unless @loaded
|
82
82
|
Mutex.new.synchronize {
|
83
83
|
load_locales
|
84
|
-
@middleware.load!
|
85
84
|
@repository = Data::Repository.new(@config.repository.to_h).load! if @config.respond_to? :repository
|
86
85
|
@engine = Rig::Engine.new(self, @config.template_cache.enabled, @config.template_cache.size)
|
87
86
|
@logger = Logger.new("logs/#{@domain.name}.log", 'weekly')
|
88
87
|
@logger.level = @config.respond_to?(:developing) && @config.developing ? Logger::DEBUG : Logger::INFO
|
89
88
|
@domain.require_dir 'helpers'
|
90
89
|
@domain.require_dir 'api'
|
90
|
+
@domain.require_dir 'middleware'
|
91
|
+
@middleware.load!
|
91
92
|
@loaded = true
|
92
93
|
}
|
93
94
|
end
|
@@ -30,7 +30,11 @@ module Tzispa
|
|
30
30
|
|
31
31
|
def redirect
|
32
32
|
context.flash << hnd.message
|
33
|
-
url = hnd.data
|
33
|
+
url = if hnd.data
|
34
|
+
hnd.data.start_with?('#') ? "#{request.referer}#{hnd.data}" : hnd.data
|
35
|
+
else
|
36
|
+
request.referer
|
37
|
+
end
|
34
38
|
context.redirect url, response
|
35
39
|
end
|
36
40
|
|
@@ -42,10 +46,14 @@ module Tzispa
|
|
42
46
|
end
|
43
47
|
|
44
48
|
def json
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
+
if hnd.data.is_a?(::Hash)
|
50
|
+
data = hnd.data
|
51
|
+
data[:__result_status] = hnd.status
|
52
|
+
data[:__result_message] = hnd.message
|
53
|
+
else
|
54
|
+
data = JSON.parse(hnd.data)
|
55
|
+
end
|
56
|
+
response.body << data.to_json
|
49
57
|
content_type :json
|
50
58
|
set_action_headers
|
51
59
|
end
|
data/lib/tzispa/http/context.rb
CHANGED
data/lib/tzispa/http/request.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rack'
|
4
|
+
require 'browser'
|
4
5
|
|
5
6
|
module Tzispa
|
6
7
|
module Http
|
@@ -8,6 +9,13 @@ module Tzispa
|
|
8
9
|
|
9
10
|
alias secure? ssl?
|
10
11
|
|
12
|
+
attr_reader :browser
|
13
|
+
|
14
|
+
def initialize(env)
|
15
|
+
super(env)
|
16
|
+
@browser = Browser.new user_agent, accept_language: env["HTTP_ACCEPT_LANGUAGE"]
|
17
|
+
end
|
18
|
+
|
11
19
|
def forwarded?
|
12
20
|
@env.include? "HTTP_X_FORWARDED_HOST"
|
13
21
|
end
|
data/lib/tzispa/middleware.rb
CHANGED
data/lib/tzispa/version.rb
CHANGED
data/tzispa.gemspec
CHANGED
@@ -20,9 +20,10 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_dependency 'i18n', '~> 0.7.0'
|
21
21
|
s.add_dependency 'http_router', '~> 0.11.2'
|
22
22
|
s.add_dependency 'moneta', '~> 0.8.0'
|
23
|
-
s.add_dependency '
|
24
|
-
s.add_dependency '
|
25
|
-
s.add_dependency '
|
23
|
+
s.add_dependency 'browser', '~> 2.1'
|
24
|
+
s.add_dependency 'tzispa_helpers', '~> 0.1'
|
25
|
+
s.add_dependency 'tzispa_utils', '~> 0.2'
|
26
|
+
s.add_dependency 'tzispa_rig', '~> 0.3'
|
26
27
|
s.add_dependency 'tzispa_data', '~> 0.1.1'
|
27
28
|
|
28
29
|
s.files = Dir.glob("{lib,bin}/**/*") + %w(README.md CHANGELOG.md LICENSE tzispa.gemspec)
|
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.6
|
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-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -80,48 +80,62 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.8.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: browser
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.1'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.1'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: tzispa_helpers
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.1
|
103
|
+
version: '0.1'
|
90
104
|
type: :runtime
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.1
|
110
|
+
version: '0.1'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: tzispa_utils
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - "~>"
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.2
|
117
|
+
version: '0.2'
|
104
118
|
type: :runtime
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.2
|
124
|
+
version: '0.2'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: tzispa_rig
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
129
|
- - "~>"
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0.
|
131
|
+
version: '0.3'
|
118
132
|
type: :runtime
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
136
|
- - "~>"
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0.
|
138
|
+
version: '0.3'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: tzispa_data
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -151,7 +165,6 @@ files:
|
|
151
165
|
- lib/tzispa.rb
|
152
166
|
- lib/tzispa/api/handler.rb
|
153
167
|
- lib/tzispa/app.rb
|
154
|
-
- lib/tzispa/autoreload.rb
|
155
168
|
- lib/tzispa/bin/tzispa
|
156
169
|
- lib/tzispa/cli.rb
|
157
170
|
- lib/tzispa/command/api.rb
|
data/lib/tzispa/autoreload.rb
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
# This file extends the Kernel's require function and adds the
|
2
|
-
# AutoReload module which allows to reload files once they have changed
|
3
|
-
# on the disk.
|
4
|
-
#
|
5
|
-
# Basically, you just require your files as usual, and if you want to update
|
6
|
-
# the files, either call AutoReload.reload(file) or AutoReload.reload_all.
|
7
|
-
#
|
8
|
-
# Usage:
|
9
|
-
# irb -rautoload
|
10
|
-
#
|
11
|
-
# Then type 'reload' on the prompt to reload require'd files which have
|
12
|
-
# changed in the meantime.
|
13
|
-
#
|
14
|
-
# Written by Mikio L. Braun, March 16, 2008, edited Jan 15, 2010
|
15
|
-
|
16
|
-
require 'pp'
|
17
|
-
require 'set'
|
18
|
-
|
19
|
-
# This module tracks loaded files and their timestamps and allows to reload
|
20
|
-
# files which have changed automatically by calling reload.
|
21
|
-
module AutoReload
|
22
|
-
# stores the normalized filenames and their File.mtime timestamps
|
23
|
-
@timestamps = Hash.new
|
24
|
-
@notfound = Set.new
|
25
|
-
@verbose = false
|
26
|
-
|
27
|
-
def self.verbose=(flag)
|
28
|
-
@verbose = flag
|
29
|
-
end
|
30
|
-
|
31
|
-
# find the full path to a file
|
32
|
-
def self.locate(file)
|
33
|
-
return nil if @notfound.include? file
|
34
|
-
$:.each do |dir|
|
35
|
-
fullpath = File.join(dir, file)
|
36
|
-
if File.exists? fullpath
|
37
|
-
return fullpath
|
38
|
-
elsif File.exists?(fullpath + '.rb')
|
39
|
-
return fullpath + '.rb'
|
40
|
-
elsif File.exists?(fullpath + '.so')
|
41
|
-
return fullpath + '.so'
|
42
|
-
end
|
43
|
-
end
|
44
|
-
# puts "[AutoReload] File #{file} not found!"
|
45
|
-
@notfound.add file
|
46
|
-
return nil
|
47
|
-
end
|
48
|
-
|
49
|
-
# store the time stamp of a file
|
50
|
-
def self.timestamp(file)
|
51
|
-
path = locate(file)
|
52
|
-
if path
|
53
|
-
file = normalize(path, file)
|
54
|
-
@timestamps[file] = File.mtime(path)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# put the extension on a filename
|
59
|
-
def self.normalize(path, file)
|
60
|
-
if File.extname(file) == ""
|
61
|
-
return file + File.extname(path)
|
62
|
-
else
|
63
|
-
return file
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# show all stored files and their timestamp
|
68
|
-
def self.dump
|
69
|
-
pp @timestamps
|
70
|
-
end
|
71
|
-
|
72
|
-
# reload a file
|
73
|
-
def self.reload(file, force=false)
|
74
|
-
path = locate(file)
|
75
|
-
file = normalize(path, file)
|
76
|
-
|
77
|
-
if force or (path and File.mtime(path) > @timestamps[file])
|
78
|
-
puts "[AutoReload] reloading #{file}" if @verbose
|
79
|
-
|
80
|
-
# delete file from list of loaded modules, and reload
|
81
|
-
$".delete file
|
82
|
-
require file
|
83
|
-
return true
|
84
|
-
else
|
85
|
-
return false
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# reload all files which were required
|
90
|
-
def self.reload_all(force=false)
|
91
|
-
@timestamps.each_key do |file|
|
92
|
-
self.reload(file, force)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
# Overwrite 'require' to register the time stamps instead.
|
98
|
-
module Kernel # :nodoc:
|
99
|
-
alias old_require require
|
100
|
-
|
101
|
-
def require(file)
|
102
|
-
AutoReload.timestamp(file)
|
103
|
-
old_require(file)
|
104
|
-
end
|
105
|
-
|
106
|
-
def reload
|
107
|
-
AutoReload.reload_all
|
108
|
-
return
|
109
|
-
end
|
110
|
-
end
|