tzispa 0.5.17 → 0.6.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/tzispa/api/handler.rb +1 -1
- data/lib/tzispa/app.rb +19 -13
- data/lib/tzispa/context.rb +2 -1
- data/lib/tzispa/controller/auth_layout.rb +37 -0
- data/lib/tzispa/controller/layout.rb +3 -4
- data/lib/tzispa/domain.rb +20 -10
- data/lib/tzispa/http/context.rb +10 -4
- data/lib/tzispa/version.rb +1 -1
- data/tzispa.gemspec +5 -5
- metadata +14 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d1e2f805b398259308d37b08aaf4b1afe9d2537
|
4
|
+
data.tar.gz: 751ff37e20bdb8f0c0fc27a12aa7250523b80c99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c98965cffb98d15718affc2fa467a9cd6fce46c9033bfcdbdaf1fc55849679708e75fa6db836e735be380d3af9cb8e2f71a753c1dbc92d47ffef0cfb8af43069
|
7
|
+
data.tar.gz: a38443bda7a70802a8baf6d946a5c5293576dcdf8742f5afaf04f658154017454a06c34c71add5324796ab3f5fc9b6b6850ba9a6aff22c39035d2ff29fa4932a
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@ Tzispa
|
|
2
2
|
|
3
3
|
General purpose web framework
|
4
4
|
|
5
|
+
## v0.6.0
|
6
|
+
- code refactoring & templates namespace simplification
|
7
|
+
- added auth_layout controller
|
8
|
+
- added context cache
|
9
|
+
- added default format from config in layout url builders
|
10
|
+
- removed per app rig engines
|
11
|
+
|
5
12
|
## v0.5.17
|
6
13
|
- remove debug puts
|
7
14
|
|
data/lib/tzispa/api/handler.rb
CHANGED
@@ -26,7 +26,7 @@ module Tzispa
|
|
26
26
|
using Tzispa::Utils
|
27
27
|
|
28
28
|
attr_reader :context, :response_verb, :data, :status
|
29
|
-
def_delegators :@context, :request, :response, :app, :repository, :config
|
29
|
+
def_delegators :@context, :request, :response, :app, :repository, :config, :logger
|
30
30
|
|
31
31
|
HANDLER_STATUS_UNDEFINED = nil
|
32
32
|
HANDLER_STATUS_OK = :ok
|
data/lib/tzispa/app.rb
CHANGED
@@ -8,7 +8,6 @@ require 'tzispa/routes'
|
|
8
8
|
require 'tzispa/config/appconfig'
|
9
9
|
require 'tzispa/middleware'
|
10
10
|
require 'tzispa_data'
|
11
|
-
require "tzispa_rig"
|
12
11
|
|
13
12
|
|
14
13
|
module Tzispa
|
@@ -30,6 +29,14 @@ module Tzispa
|
|
30
29
|
|
31
30
|
class << self
|
32
31
|
|
32
|
+
alias :__new__ :new
|
33
|
+
|
34
|
+
def new(*args, &block)
|
35
|
+
__new__(*args, &block).tap { |app|
|
36
|
+
add app
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
33
40
|
def applications
|
34
41
|
synchronize do
|
35
42
|
@@applications ||= Hash.new{ |hash, key| raise UnknownApplication.new("#{key}") }
|
@@ -53,19 +60,18 @@ module Tzispa
|
|
53
60
|
end
|
54
61
|
end
|
55
62
|
|
56
|
-
def run(
|
57
|
-
theapp = self.new
|
63
|
+
def run(appid, builder: nil, on: nil, &block)
|
64
|
+
theapp = self.new appid, on: on, &block
|
58
65
|
theapp.run builder
|
59
66
|
end
|
60
67
|
|
61
68
|
end
|
62
69
|
|
63
|
-
def initialize(
|
64
|
-
@domain = Domain.new(
|
70
|
+
def initialize(appid, on: nil, &block)
|
71
|
+
@domain = Domain.new(appid)
|
65
72
|
@config = Config::AppConfig.new(@domain).load!
|
66
73
|
@middleware = Middleware.new self
|
67
74
|
@routes ||= Routes.new(self, on)
|
68
|
-
self.class.add(self)
|
69
75
|
instance_eval(&block) if block
|
70
76
|
end
|
71
77
|
|
@@ -84,12 +90,11 @@ module Tzispa
|
|
84
90
|
def load!
|
85
91
|
self.class.synchronize {
|
86
92
|
load_locales
|
87
|
-
@repository = Data::Repository.new(config.repository.to_h).load! if config.respond_to? :repository
|
88
|
-
@engine = Rig::Engine.new(self, config.template_cache.enabled, config.template_cache.size)
|
89
93
|
@logger = Logger.new("logs/#{domain.name}.log", config.logging.shift_age).tap { |log|
|
90
94
|
log.level = config.developing ? Logger::DEBUG : Logger::INFO
|
91
95
|
} if config.logging&.enabled
|
92
|
-
|
96
|
+
domain_setup
|
97
|
+
@repository = Data::Repository.new(config.repository.to_h).load!(domain) if config.respond_to? :repository
|
93
98
|
@loaded = true
|
94
99
|
}
|
95
100
|
self
|
@@ -101,7 +106,8 @@ module Tzispa
|
|
101
106
|
|
102
107
|
private
|
103
108
|
|
104
|
-
def
|
109
|
+
def domain_setup
|
110
|
+
domain.require_dir
|
105
111
|
domain.require_dir 'helpers'
|
106
112
|
domain.require_dir 'services'
|
107
113
|
domain.require_dir 'api'
|
@@ -109,9 +115,9 @@ module Tzispa
|
|
109
115
|
end
|
110
116
|
|
111
117
|
def load_locales
|
112
|
-
if
|
113
|
-
I18n.
|
114
|
-
I18n.load_path += Dir["#{
|
118
|
+
if config.respond_to?(:locales)
|
119
|
+
I18n.enforce_available_locales = false
|
120
|
+
I18n.load_path += Dir["config/locales/*.yml", "#{domain.path}/locales/*.yml"]
|
115
121
|
end
|
116
122
|
end
|
117
123
|
|
data/lib/tzispa/context.rb
CHANGED
@@ -7,12 +7,13 @@ module Tzispa
|
|
7
7
|
class Context
|
8
8
|
extend Forwardable
|
9
9
|
|
10
|
-
attr_reader :app, :env
|
10
|
+
attr_reader :app, :env, :cache
|
11
11
|
def_delegators :app, :config, :logger, :domain, :repository
|
12
12
|
|
13
13
|
def initialize(app, environment)
|
14
14
|
@env = environment
|
15
15
|
@app = app
|
16
|
+
@cache = Hash.new
|
16
17
|
I18n.locale = app.config.locales.default.to_sym if app.config&.respond_to?(:locales)
|
17
18
|
end
|
18
19
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tzispa_rig'
|
4
|
+
require 'tzispa/controller/base'
|
5
|
+
require 'tzispa/controller/exceptions'
|
6
|
+
require 'tzispa/helpers/response'
|
7
|
+
require 'tzispa_rig'
|
8
|
+
|
9
|
+
module Tzispa
|
10
|
+
module Controller
|
11
|
+
class AuthLayout < Base
|
12
|
+
include Tzispa::Helpers::Response
|
13
|
+
|
14
|
+
def render!
|
15
|
+
if (layout_name == login_layout) || context.login
|
16
|
+
rig = Tzispa::Rig::Engine.layout name: layout_name, domain: application.domain, content_type: context.router_params[:format] || config.default_format
|
17
|
+
response.body << rig.render(context)
|
18
|
+
content_type rig.content_type
|
19
|
+
else
|
20
|
+
context.redirect login_layout, true, response
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def layout_name
|
27
|
+
context.layout || config.default_layout
|
28
|
+
end
|
29
|
+
|
30
|
+
def login_layout
|
31
|
+
config.login_layout
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -4,18 +4,17 @@ require 'tzispa_rig'
|
|
4
4
|
require 'tzispa/controller/base'
|
5
5
|
require 'tzispa/controller/exceptions'
|
6
6
|
require 'tzispa/helpers/response'
|
7
|
+
require 'tzispa_rig'
|
7
8
|
|
8
9
|
module Tzispa
|
9
10
|
module Controller
|
10
11
|
class Layout < Base
|
11
|
-
|
12
12
|
include Tzispa::Helpers::Response
|
13
13
|
|
14
14
|
def render!
|
15
|
-
|
16
|
-
rig = context.app.engine.layout(name: layout_name, format: layout_format.to_sym)
|
15
|
+
rig = Tzispa::Rig::Engine.layout name: layout_name, domain: application.domain, content_type: context.router_params[:format] || config.default_format
|
17
16
|
response.body << rig.render(context)
|
18
|
-
content_type
|
17
|
+
content_type rig.content_type
|
19
18
|
end
|
20
19
|
|
21
20
|
private
|
data/lib/tzispa/domain.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'tzispa/utils/string'
|
4
|
+
|
3
5
|
module Tzispa
|
4
6
|
class Domain
|
5
7
|
|
8
|
+
using Tzispa::Utils
|
9
|
+
|
6
10
|
attr_reader :name, :root
|
7
11
|
|
8
12
|
DEFAULT_DOMAIN_NAME = :default
|
@@ -22,24 +26,30 @@ module Tzispa
|
|
22
26
|
Kernel.require "./#{path}/#{file}"
|
23
27
|
end
|
24
28
|
|
25
|
-
def require_dir(dir)
|
26
|
-
Dir["./#{path}/#{dir}/*.rb"].each { |file|
|
27
|
-
name = file.split('/').last.split('.').first
|
28
|
-
Kernel.require "./#{path}/#{dir}/#{name}"
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
29
|
def load(file)
|
33
30
|
Kernel.load "./#{path}/#{file}.rb"
|
34
31
|
end
|
35
32
|
|
36
|
-
def
|
37
|
-
|
33
|
+
def require_dir(dir = nil)
|
34
|
+
rqpath = dir ? "/#{path}/#{dir}" : "/#{path}"
|
35
|
+
Dir[".#{rqpath}/*.rb"].each { |file|
|
36
|
+
name = file.split('/').last.split('.').first
|
37
|
+
Kernel.require ".#{rqpath}/#{name}"
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def load_dir(dir = nil)
|
42
|
+
rqpath = dir ? "/#{path}/#{dir}" : "/#{path}"
|
43
|
+
Dir[".#{rqpath}/*.rb"].each { |file|
|
38
44
|
name = file.split('/').last
|
39
|
-
Kernel.load "
|
45
|
+
Kernel.load ".#{rqpath}/#{name}"
|
40
46
|
}
|
41
47
|
end
|
42
48
|
|
49
|
+
def include(cmod)
|
50
|
+
name.to_s.capitalize.constantize.include cmod
|
51
|
+
end
|
52
|
+
|
43
53
|
def self.require(domain, file)
|
44
54
|
self.new(name: domain).require(file)
|
45
55
|
end
|
data/lib/tzispa/http/context.rb
CHANGED
@@ -91,12 +91,12 @@ module Tzispa
|
|
91
91
|
|
92
92
|
def layout_path(layout, params={})
|
93
93
|
params = params.merge(layout: layout) unless app.config.default_layout&.to_sym == layout
|
94
|
-
app.routes.path layout, params
|
94
|
+
app.routes.path layout, normalize_format(params)
|
95
95
|
end
|
96
96
|
|
97
97
|
def app_layout_path(app_name, layout, params={})
|
98
98
|
params = params.merge(layout: layout) unless app[app_name].config.default_layout&.to_sym == layout
|
99
|
-
app[app_name].routes.path layout, params
|
99
|
+
app[app_name].routes.path layout, normalize_format(params)
|
100
100
|
end
|
101
101
|
|
102
102
|
def layout_canonical_url(layout, params={})
|
@@ -107,7 +107,7 @@ module Tzispa
|
|
107
107
|
app[app_name].config.canonical_url + app_layout_path(app_name, layout, params)
|
108
108
|
end
|
109
109
|
|
110
|
-
def api(handler, verb, predicate, sufix, app_name)
|
110
|
+
def api(handler, verb, predicate, sufix, app_name = nil)
|
111
111
|
unless app_name
|
112
112
|
canonical_url :api, handler: handler, verb: verb, predicate: predicate, sufix: sufix
|
113
113
|
else
|
@@ -129,8 +129,14 @@ module Tzispa
|
|
129
129
|
sign == sign_array(args, config.salt)
|
130
130
|
end
|
131
131
|
|
132
|
+
private
|
132
133
|
|
133
|
-
|
134
|
+
def normalize_format(params)
|
135
|
+
params.tap { |pmm|
|
136
|
+
pmm[:format] = config.default_format unless pmm[:format]
|
137
|
+
}
|
138
|
+
end
|
134
139
|
|
140
|
+
end
|
135
141
|
end
|
136
142
|
end
|
data/lib/tzispa/version.rb
CHANGED
data/tzispa.gemspec
CHANGED
@@ -16,13 +16,13 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.required_ruby_version = '~> 2.3'
|
17
17
|
|
18
18
|
s.add_dependency 'rack', '~> 2.0', '>= 2.0.1'
|
19
|
-
s.add_dependency 'i18n', '~> 0.
|
19
|
+
s.add_dependency 'i18n', '~> 0.8.0'
|
20
20
|
s.add_dependency 'thor', '~> 0.19.0'
|
21
21
|
s.add_dependency 'http_router', '~> 0.11.2'
|
22
|
-
s.add_dependency 'tzispa_helpers', '~> 0.2'
|
23
|
-
s.add_dependency 'tzispa_utils', '~> 0.
|
24
|
-
s.add_dependency 'tzispa_rig', '~> 0.
|
25
|
-
s.add_dependency 'tzispa_data', '~> 0.
|
22
|
+
s.add_dependency 'tzispa_helpers', '~> 0.2.2'
|
23
|
+
s.add_dependency 'tzispa_utils', '~> 0.3'
|
24
|
+
s.add_dependency 'tzispa_rig', '~> 0.5'
|
25
|
+
s.add_dependency 'tzispa_data', '~> 0.3'
|
26
26
|
|
27
27
|
s.files = Dir.glob("{lib,bin}/**/*") + %w(README.md CHANGELOG.md LICENSE tzispa.gemspec)
|
28
28
|
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
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
|
+
version: 0.6.0
|
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:
|
11
|
+
date: 2017-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -36,14 +36,14 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 0.
|
39
|
+
version: 0.8.0
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 0.
|
46
|
+
version: 0.8.0
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: thor
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,56 +78,56 @@ dependencies:
|
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
81
|
+
version: 0.2.2
|
82
82
|
type: :runtime
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
88
|
+
version: 0.2.2
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: tzispa_utils
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: '0.
|
95
|
+
version: '0.3'
|
96
96
|
type: :runtime
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '0.
|
102
|
+
version: '0.3'
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: tzispa_rig
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
107
|
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 0.
|
109
|
+
version: '0.5'
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: 0.
|
116
|
+
version: '0.5'
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
118
|
name: tzispa_data
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
121
|
- - "~>"
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version: 0.
|
123
|
+
version: '0.3'
|
124
124
|
type: :runtime
|
125
125
|
prerelease: false
|
126
126
|
version_requirements: !ruby/object:Gem::Requirement
|
127
127
|
requirements:
|
128
128
|
- - "~>"
|
129
129
|
- !ruby/object:Gem::Version
|
130
|
-
version: 0.
|
130
|
+
version: '0.3'
|
131
131
|
description: A sparkling web framework based on Rack and inspired by Sinatra and Lotus
|
132
132
|
email:
|
133
133
|
- japinero@area-integral.com
|
@@ -155,6 +155,7 @@ files:
|
|
155
155
|
- lib/tzispa/config/yaml.rb
|
156
156
|
- lib/tzispa/context.rb
|
157
157
|
- lib/tzispa/controller/api.rb
|
158
|
+
- lib/tzispa/controller/auth_layout.rb
|
158
159
|
- lib/tzispa/controller/base.rb
|
159
160
|
- lib/tzispa/controller/exceptions.rb
|
160
161
|
- lib/tzispa/controller/http_error.rb
|
@@ -189,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
189
190
|
version: '0'
|
190
191
|
requirements: []
|
191
192
|
rubyforge_project:
|
192
|
-
rubygems_version: 2.
|
193
|
+
rubygems_version: 2.6.10
|
193
194
|
signing_key:
|
194
195
|
specification_version: 4
|
195
196
|
summary: A sparkling web framework
|