tzispa_helpers 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/tzispa/helpers/login.rb +21 -0
- data/lib/tzispa/helpers/macro_field.rb +58 -0
- data/lib/tzispa/helpers/request.rb +16 -48
- data/lib/tzispa/helpers/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff5ee9fd3dbe5599f7ba42bace28922feb0c8ce4
|
4
|
+
data.tar.gz: ddfc4699dd6ee7e4b84a5cb0dbf122d4f6531862
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30ad6c7d0682f26e51958570daeae58ab0e3a8da45a2ecd4749b0ec0193a6761e40959aa9600dc38513aa6d2a6490ce95954b05d0ce228d363860cd02a5aa7b1
|
7
|
+
data.tar.gz: df205ac43b8b2be62d400379e298bf42c9539c30edb733faa037977e7fff742e9cb89bb9f238898863d5a050b18bed42c20a4e0d67142f28df5e0a26d8027b3b
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tzispa
|
4
|
+
module Helpers
|
5
|
+
module Login
|
6
|
+
|
7
|
+
def login_redirect
|
8
|
+
context.redirect(context.layout_path(context.config.login_layout.to_sym), true, context.response) if login_redirect?
|
9
|
+
end
|
10
|
+
|
11
|
+
def login_redirect?
|
12
|
+
!context.logged? && (context.layout != context.config.login_layout)
|
13
|
+
end
|
14
|
+
|
15
|
+
def unauthorized_but_logged
|
16
|
+
context.not_authorized unless context.logged?
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tzispa/utils/string'
|
4
|
+
require 'json'
|
5
|
+
require_relative 'text'
|
6
|
+
|
7
|
+
module Tzispa
|
8
|
+
module Helpers
|
9
|
+
module MacroField
|
10
|
+
|
11
|
+
include Tzispa::Helpers::Text
|
12
|
+
using Tzispa::Utils::TzString
|
13
|
+
|
14
|
+
def process_macros(source, fields, data_object: nil, json: nil)
|
15
|
+
(data_object || {}).tap do |data|
|
16
|
+
fields.each do |name|
|
17
|
+
macro_field = name.split('@:')
|
18
|
+
macro = macro_field.first.to_sym if macro_field.length == 2
|
19
|
+
field = macro_field.length == 2 ? macro_field.last : macro_field.first
|
20
|
+
build_field source, field, macro, data
|
21
|
+
end
|
22
|
+
json&.each do |key, value|
|
23
|
+
data.send "#{key}=", build_json_field(source, value)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def build_field(source, field, macro, data)
|
29
|
+
field.split(':').tap do |orig, dest|
|
30
|
+
dest ||= orig
|
31
|
+
value = if String == source[orig]
|
32
|
+
String.unescape_html(source[orig])
|
33
|
+
else
|
34
|
+
source[orig]
|
35
|
+
end
|
36
|
+
value = macro ? send(macro, value) : value
|
37
|
+
if data.is_a? ::Hash
|
38
|
+
data[dest.to_sym] = value
|
39
|
+
else
|
40
|
+
data.send "#{dest}=".to_sym, value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def build_json_field(source, values)
|
46
|
+
{}.tap do |data|
|
47
|
+
values.each do |name|
|
48
|
+
macro_field = name.split('@:')
|
49
|
+
macro = macro_field.first.to_sym if macro_field.length == 2
|
50
|
+
field = macro_field.length == 2 ? macro_field.last : macro_field.first
|
51
|
+
build_field source, field, macro, data
|
52
|
+
end
|
53
|
+
end.to_json
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -2,36 +2,32 @@
|
|
2
2
|
|
3
3
|
require 'tzispa/utils/string'
|
4
4
|
require 'json'
|
5
|
+
require_relative 'macro_field'
|
5
6
|
|
6
7
|
module Tzispa
|
7
8
|
module Helpers
|
8
9
|
module Request
|
9
10
|
|
10
|
-
|
11
|
+
include Tzispa::Helpers::MacroField
|
12
|
+
|
13
|
+
def request_json(key = nil)
|
14
|
+
return unless request.content_type&.include?('application/json')
|
15
|
+
body = request.body.gets
|
16
|
+
key ? JSON.parse(body)[key] : JSON.parse(body)
|
17
|
+
end
|
18
|
+
|
19
|
+
def request_json_object(key = nil, data_object:, fields:, json: nil)
|
20
|
+
process_macros request_json(key), fields, data_object: data_object,
|
21
|
+
json: json
|
22
|
+
end
|
11
23
|
|
12
24
|
def request_data(fields)
|
13
|
-
|
14
|
-
fields.each do |name|
|
15
|
-
macro_field = name.split('@:')
|
16
|
-
macro = macro_field.first.to_sym if macro_field.length == 2
|
17
|
-
field = macro_field.length == 2 ? macro_field.last : macro_field.first
|
18
|
-
build_field field, macro, data
|
19
|
-
end
|
20
|
-
end
|
25
|
+
process_macros request, fields
|
21
26
|
end
|
22
27
|
|
23
28
|
def request_data_object(data_object:, fields:, json: nil)
|
24
|
-
data_object
|
25
|
-
|
26
|
-
macro_field = name.split('@:')
|
27
|
-
macro = macro_field.first.to_sym if macro_field.length == 2
|
28
|
-
field = macro_field.length == 2 ? macro_field.last : macro_field.first
|
29
|
-
build_field field, macro, data
|
30
|
-
end
|
31
|
-
json&.each do |key, value|
|
32
|
-
data.send "#{key}=", build_json_field(value)
|
33
|
-
end
|
34
|
-
end
|
29
|
+
process_macros request, fields, data_object: data_object,
|
30
|
+
json: json
|
35
31
|
end
|
36
32
|
|
37
33
|
def request_file_upload(request_file:, destination_path:, save_as: nil, keep_ext: true)
|
@@ -53,34 +49,6 @@ module Tzispa
|
|
53
49
|
size: ::File.size(dest_file), type: filetype }
|
54
50
|
end
|
55
51
|
|
56
|
-
def build_field(field, macro, data)
|
57
|
-
field.split(':').tap do |src, dest|
|
58
|
-
dest ||= src
|
59
|
-
value = if String == request[src]
|
60
|
-
String.unescape_html(request[src])
|
61
|
-
else
|
62
|
-
request[src]
|
63
|
-
end
|
64
|
-
value = macro ? send(macro, value) : value
|
65
|
-
if data.is_a? ::Hash
|
66
|
-
data[dest.to_sym] = value
|
67
|
-
else
|
68
|
-
data.send "#{dest}=".to_sym, value
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def build_json_field(values)
|
74
|
-
{}.tap do |data|
|
75
|
-
values.each do |name|
|
76
|
-
macro_field = name.split('@:')
|
77
|
-
macro = macro_field.first.to_sym if macro_field.length == 2
|
78
|
-
field = macro_field.length == 2 ? macro_field.last : macro_field.first
|
79
|
-
build_field field, macro, data
|
80
|
-
end
|
81
|
-
end.to_json
|
82
|
-
end
|
83
|
-
|
84
52
|
end
|
85
53
|
end
|
86
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tzispa_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
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: 2017-
|
11
|
+
date: 2017-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -67,6 +67,8 @@ files:
|
|
67
67
|
- lib/tzispa/helpers/hooks/after.rb
|
68
68
|
- lib/tzispa/helpers/hooks/before.rb
|
69
69
|
- lib/tzispa/helpers/html.rb
|
70
|
+
- lib/tzispa/helpers/login.rb
|
71
|
+
- lib/tzispa/helpers/macro_field.rb
|
70
72
|
- lib/tzispa/helpers/mime.rb
|
71
73
|
- lib/tzispa/helpers/pattern.rb
|
72
74
|
- lib/tzispa/helpers/provider.rb
|