glib-web 0.4.15 → 0.4.16
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/app/controllers/concerns/glib/json/dynamic_text.rb +87 -86
- data/app/controllers/concerns/glib/json/new_dynamic_text.rb +14 -14
- data/app/helpers/glib/dynamic_texts_helper.rb +30 -1
- data/app/helpers/glib/json_ui/action_builder.rb +9 -6
- data/app/models/glib/text.rb +6 -2
- data/app/views/json_ui/garage/actions/index.json.jbuilder +15 -5
- data/lib/glib/dynamic_text/config.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a63a2f6c1b4ea589344292ac196fa72d98c006e1e582dbb06dff681ff650dc0c
|
4
|
+
data.tar.gz: 74a40e9a319791847c2f4431ffa98e19cbf28786ae0118fdba14c46aafc3c765
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5efb0e23eae6e10dacae4da8b755e0a0bd008091f1565b0129d2fbe0b14ee420cfe218ccafd7a44c0d3d7830acb152255f284bd5e8e6d9f49e48722f0f1d72b
|
7
|
+
data.tar.gz: 7f5b7da282fb4fe63899e0f63b073fca258b418d7b5aeda085caab7a3b99cd8852e8c589e677ba9fff0d07c4156e165e6e4e5b95864376100906ae49403c03c5
|
@@ -1,60 +1,90 @@
|
|
1
1
|
module Glib::Json::DynamicText
|
2
|
-
def
|
3
|
-
|
4
|
-
|
2
|
+
def __json_traversal_register_dynamic_text
|
3
|
+
@__specs = {}
|
4
|
+
@__specs_db = {}
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
__json_traversal_on_traverse do |view|
|
7
|
+
extract_spec(view, 'text')
|
8
|
+
end
|
9
9
|
|
10
|
+
__json_traversal_on_complete do |view|
|
10
11
|
if @__specs.keys.size > 0
|
11
|
-
translated_texts =
|
12
|
-
|
13
|
-
# translated_texts = retrieve_example_texts(@__specs.keys)
|
12
|
+
translated_texts = retrieve_texts(@__specs.keys)
|
13
|
+
# translated_texts = retrieve_local_texts(@__specs.keys).merge(retrieve_remote_texts(@__specs.keys))
|
14
14
|
translated_texts.each do |key, value|
|
15
15
|
@__specs[key].each do |spec|
|
16
16
|
spec.substitute_with(value)
|
17
17
|
end
|
18
|
+
|
19
|
+
if @__specs_db[key] && @__specs_db[key].images.attached?
|
20
|
+
@__specs[key].each do |spec|
|
21
|
+
spec.substitute_image_with(@__specs_db[key].images)
|
22
|
+
end
|
23
|
+
end
|
18
24
|
end
|
19
25
|
end
|
20
26
|
end
|
21
27
|
end
|
22
28
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
'home.json_ui_garage.greeting' => 'Good day!',
|
27
|
-
}
|
28
|
-
|
29
|
-
translated_texts = {}
|
30
|
-
keys.each do |key|
|
31
|
-
translated_texts[key] = examples_translations[key]
|
32
|
-
end
|
33
|
-
translated_texts
|
29
|
+
def retrieve_texts
|
30
|
+
# TODO: Check local memory
|
31
|
+
# TODO: Then check DTR
|
34
32
|
end
|
35
33
|
|
36
|
-
def retrieve_remote_texts(keys)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
34
|
+
# def retrieve_remote_texts(keys)
|
35
|
+
# retries = 0
|
36
|
+
|
37
|
+
# begin
|
38
|
+
# response = RestClient.get(ENV['DTR_URL'], { params: { keys: keys } })
|
39
|
+
# rescue Errno::ECONNREFUSED, RestClient::InternalServerError, RestClient::Exceptions::OpenTimeout, RestClient::Exceptions::ReadTimeout
|
40
|
+
# if (retries += 1) <= 3
|
41
|
+
# puts "Timeout, retrying..."
|
42
|
+
# retry
|
43
|
+
# else
|
44
|
+
# raise
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
|
48
|
+
# JSON.parse(response)
|
49
|
+
# end
|
50
|
+
|
51
|
+
# def retrieve_local_texts(keys)
|
52
|
+
# translated_texts = {}
|
53
|
+
# db_keys = []
|
54
|
+
|
55
|
+
# redis = Glib::DynamicText::Config.redis
|
56
|
+
# contents = redis.pipelined do
|
57
|
+
# keys.each do |key|
|
58
|
+
# args = @__specs[key].first.args
|
59
|
+
# options = {
|
60
|
+
# scope: args.fetch(:scope, 'itinerarybuilder'),
|
61
|
+
# lang: args.fetch(:lang, 'en')
|
62
|
+
# }
|
63
|
+
|
64
|
+
# scope_key = "#{options[:scope]}.#{options[:lang]}.#{key}"
|
65
|
+
# redis.get(scope_key)
|
66
|
+
# end
|
67
|
+
# end
|
68
|
+
|
69
|
+
# keys.each_with_index do |key, index|
|
70
|
+
# if content = contents[index]
|
71
|
+
# translated_texts[key] = content
|
72
|
+
# db_keys << key if content.match(/\{\{image(\d)\}\}/)
|
73
|
+
# else
|
74
|
+
# db_keys << key
|
75
|
+
# end
|
76
|
+
# end
|
77
|
+
|
78
|
+
# if db_keys.size > 0
|
79
|
+
# texts = Glib::Text.where(key: db_keys)
|
80
|
+
# texts.each do |text|
|
81
|
+
# translated_texts[text.key] = text.content
|
82
|
+
# @__specs_db[text.key] = text
|
83
|
+
# end
|
84
|
+
# end
|
85
|
+
|
86
|
+
# translated_texts
|
87
|
+
# end
|
58
88
|
|
59
89
|
def extract_spec(view, prop)
|
60
90
|
if (spec = view[prop])
|
@@ -69,57 +99,28 @@ module Glib::Json::DynamicText
|
|
69
99
|
def substitute_with(text)
|
70
100
|
view[prop] = text.gsub(/\{\{(\w+)\}\}/) { args.fetch($1, "{{#{$1}}}") }
|
71
101
|
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
class Glib::Json::Crawler
|
76
|
-
attr_reader :forms
|
77
102
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
def crawl_multiple(views, block)
|
83
|
-
if views.is_a? Array
|
84
|
-
views.each do |view|
|
85
|
-
case view['view']
|
86
|
-
when 'panels/form-v1'
|
87
|
-
@forms << view
|
88
|
-
crawl_single view, block
|
89
|
-
@forms.pop
|
103
|
+
def substitute_image_with(images)
|
104
|
+
view[prop] = view[prop].gsub(/\{\{image(\d)\}\}/) {
|
105
|
+
if image = images[$1.to_i - 1]
|
106
|
+
image_server_url(image.blob.key)
|
90
107
|
else
|
91
|
-
|
108
|
+
"{{image#{$1}}}"
|
92
109
|
end
|
93
|
-
|
110
|
+
}
|
94
111
|
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def crawl_vertical_content(view, block)
|
98
|
-
crawl_multiple view['childViews'], block if view
|
99
|
-
end
|
100
112
|
|
101
|
-
|
102
|
-
|
113
|
+
# TODO: Reuse method from DynamicTextsHelper
|
114
|
+
def image_server_url(blob_key, w: 100, h: 100)
|
115
|
+
return unless blob_key.present?
|
103
116
|
|
104
|
-
|
105
|
-
|
117
|
+
uri = URI::HTTPS.build(
|
118
|
+
host: 'imageserver-demo.herokuapp.com',
|
119
|
+
path: "/image/#{ENV['AWS_S3_BUCKET']}/#{blob_key}",
|
120
|
+
query: { w: w, h: h }.to_param
|
121
|
+
)
|
106
122
|
|
107
|
-
|
108
|
-
# crawl_multiple view['leftViews'], block
|
109
|
-
# crawl_multiple view['rightViews'], block
|
110
|
-
|
111
|
-
# Split panel
|
112
|
-
crawl_vertical_content view['left'], block
|
113
|
-
crawl_vertical_content view['center'], block
|
114
|
-
crawl_vertical_content view['right'], block
|
115
|
-
|
116
|
-
# TODO: crawl header and footer
|
117
|
-
# Table/List
|
118
|
-
if (sections = view['sections']).is_a? Array
|
119
|
-
sections.each do |section|
|
120
|
-
# Table
|
121
|
-
crawl_multiple section['rows'], block
|
122
|
-
end
|
123
|
+
uri.to_s
|
123
124
|
end
|
124
125
|
end
|
125
126
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# TODO: Remove old DynamicText
|
2
1
|
module Glib::Json::NewDynamicText
|
3
2
|
def __json_traversal_register_dynamic_text
|
4
3
|
@__specs = {}
|
@@ -62,7 +61,8 @@ module Glib::Json::NewDynamicText
|
|
62
61
|
translated_texts = {}
|
63
62
|
db_keys = []
|
64
63
|
|
65
|
-
|
64
|
+
redis = Glib::DynamicText::Config.redis
|
65
|
+
contents = redis.pipelined do
|
66
66
|
keys.each do |key|
|
67
67
|
args = @__specs[key].first.args
|
68
68
|
options = {
|
@@ -71,7 +71,7 @@ module Glib::Json::NewDynamicText
|
|
71
71
|
}
|
72
72
|
|
73
73
|
scope_key = "#{options[:scope]}.#{options[:lang]}.#{key}"
|
74
|
-
|
74
|
+
redis.get(scope_key)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
@@ -112,24 +112,24 @@ module Glib::Json::NewDynamicText
|
|
112
112
|
def substitute_image_with(images)
|
113
113
|
view[prop] = view[prop].gsub(/\{\{image(\d)\}\}/) {
|
114
114
|
if image = images[$1.to_i - 1]
|
115
|
-
|
115
|
+
ApplicationController.helpers.dt_image_server_url(image.blob.key)
|
116
116
|
else
|
117
117
|
"{{image#{$1}}}"
|
118
118
|
end
|
119
119
|
}
|
120
120
|
end
|
121
121
|
|
122
|
-
# TODO: Reuse method from DynamicTextsHelper
|
123
|
-
def image_server_url(blob_key, w: 100, h: 100)
|
124
|
-
|
122
|
+
# # TODO: Reuse method from DynamicTextsHelper
|
123
|
+
# def image_server_url(blob_key, w: 100, h: 100)
|
124
|
+
# return unless blob_key.present?
|
125
125
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
126
|
+
# uri = URI::HTTPS.build(
|
127
|
+
# host: 'imageserver-demo.herokuapp.com',
|
128
|
+
# path: "/image/#{ENV['AWS_S3_BUCKET']}/#{blob_key}",
|
129
|
+
# query: { w: w, h: h }.to_param
|
130
|
+
# )
|
131
131
|
|
132
|
-
|
133
|
-
end
|
132
|
+
# uri.to_s
|
133
|
+
# end
|
134
134
|
end
|
135
135
|
end
|
@@ -42,14 +42,43 @@ module Glib
|
|
42
42
|
def dt_image_server_url(blob_key, w: 100, h: 100)
|
43
43
|
return unless blob_key.present?
|
44
44
|
|
45
|
+
encryption_service = EncryptionService.new(ENV['AWS_S3_BUCKET'], ENV['PRIVATE_API_KEY'])
|
46
|
+
params_hash = {
|
47
|
+
bucket_name: ENV['AWS_S3_BUCKET'],
|
48
|
+
blob_key: blob_key,
|
49
|
+
w: w,
|
50
|
+
h: h,
|
51
|
+
expires: 1.hours.from_now.to_i
|
52
|
+
}
|
53
|
+
signature = encryption_service.encrypt(params_hash)
|
54
|
+
|
45
55
|
# TODO: This should probably be set as a parameter for json_libs
|
46
56
|
uri = URI::HTTPS.build(
|
47
57
|
host: 'imageserver-demo.herokuapp.com',
|
48
58
|
path: "/image/#{ENV['AWS_S3_BUCKET']}/#{blob_key}",
|
49
|
-
query:
|
59
|
+
query: params_hash.except(:bucket_name, :blob_key).merge(signature: signature).to_param
|
50
60
|
)
|
51
61
|
|
52
62
|
uri.to_s
|
53
63
|
end
|
64
|
+
|
65
|
+
EncryptionService = Struct.new(:salt, :private_key) do
|
66
|
+
def encrypt(value)
|
67
|
+
encryptor.encrypt_and_sign(value)
|
68
|
+
end
|
69
|
+
|
70
|
+
def decrypt(value)
|
71
|
+
encryptor.decrypt_and_verify(value)
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
def encryptor
|
76
|
+
encryptor ||= begin
|
77
|
+
key_len = ActiveSupport::MessageEncryptor.key_len
|
78
|
+
key = ActiveSupport::KeyGenerator.new(private_key).generate_key(salt, key_len)
|
79
|
+
ActiveSupport::MessageEncryptor.new(key)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
54
83
|
end
|
55
84
|
end
|
@@ -68,13 +68,16 @@ module Glib
|
|
68
68
|
action :onClose
|
69
69
|
end
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
class Oauth < Action
|
72
|
+
hash :provider
|
73
|
+
action :onSuccess
|
74
|
+
string :providerParamName
|
75
|
+
string :callbackUrlParamName
|
76
|
+
end
|
77
|
+
|
78
|
+
class Alert < Action
|
74
79
|
string :message
|
75
|
-
|
76
|
-
string :horizontalPosition
|
77
|
-
singleton_array :styleClass, :styleClasses
|
80
|
+
action :onClose
|
78
81
|
end
|
79
82
|
|
80
83
|
class Notification < Action
|
data/app/models/glib/text.rb
CHANGED
@@ -60,10 +60,14 @@ module Glib
|
|
60
60
|
|
61
61
|
after_save :update_to_redis
|
62
62
|
|
63
|
+
def self.redis
|
64
|
+
Glib::DynamicText::Config.redis
|
65
|
+
end
|
66
|
+
|
63
67
|
def self.get_content(key, default_value, options:)
|
64
68
|
scope_key = "#{options[:scope]}.#{options[:lang]}.#{key}"
|
65
69
|
|
66
|
-
content =
|
70
|
+
content = redis.get(scope_key)
|
67
71
|
text = find_by(scope: options[:scope], lang: options[:lang], key: key)
|
68
72
|
|
69
73
|
if !(content && text)
|
@@ -82,7 +86,7 @@ module Glib
|
|
82
86
|
|
83
87
|
private
|
84
88
|
def self.update_content(scope_key, content)
|
85
|
-
|
89
|
+
redis.set(scope_key, content)
|
86
90
|
end
|
87
91
|
|
88
92
|
def update_to_redis
|
@@ -12,15 +12,15 @@ json_ui_page json do |page|
|
|
12
12
|
section.rows builder: ->(template) do
|
13
13
|
template.thumbnail title: 'dialogs/alert', onClick: ->(action) do
|
14
14
|
action.dialogs_alert message: 'This is an alert dialog', onClose: ->(action) do
|
15
|
-
action.
|
15
|
+
action.snackbars_alert message: 'Closed'
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
# template.thumbnail title: 'dialogs/confirm (Experimental)', onClick: ->(action) do
|
20
20
|
# action.dialogs_confirm message: 'This is a confirm dialog', onCancel: ->(action) do
|
21
|
-
# action.
|
21
|
+
# action.snackbars_alert message: 'Canceled'
|
22
22
|
# end, onConfirm: ->(action) do
|
23
|
-
# action.
|
23
|
+
# action.snackbars_alert message: 'Confirmed'
|
24
24
|
# end
|
25
25
|
# end
|
26
26
|
|
@@ -40,8 +40,18 @@ json_ui_page json do |page|
|
|
40
40
|
action.dialogs_open url: json_ui_garage_url(path: 'forms/basic', mode: 'dialog')
|
41
41
|
end
|
42
42
|
|
43
|
-
template.thumbnail title: 'dialogs/
|
44
|
-
|
43
|
+
template.thumbnail title: 'dialogs/oauth', onClick: ->(action) do
|
44
|
+
provider = {
|
45
|
+
name: "facebook",
|
46
|
+
webRequestUrl: "https://www.facebook.com/v3.1/dialog/oauth?auth_type=rerequest&client_id=CLIENT_ID&redirect_uri=http%3A%2F%2Fwww.lvh.me%3A3000%2Foauth_callback%2Ffacebook&response_type=code&scope=email",
|
47
|
+
requestUrl: "https://www.facebook.com/v3.1/dialog/oauth",
|
48
|
+
clientId: "CLIENT_ID",
|
49
|
+
redirectUrl: "http://www.lvh.me:3000/oauth_callback/facebook.json"
|
50
|
+
}
|
51
|
+
|
52
|
+
action.dialogs_oauth provider: provider, providerParamName: "session[oauth_provider]", callbackUrlParamName: "session[[oauth_callback_url]", onSuccess: ->(action) do
|
53
|
+
action.http_post url: 'TODO: post params to server'
|
54
|
+
end
|
45
55
|
end
|
46
56
|
|
47
57
|
end
|
@@ -7,7 +7,8 @@ module Glib
|
|
7
7
|
def self.redis
|
8
8
|
if @@redis.nil?
|
9
9
|
redis_url = ENV.fetch('DT_REDIS_URL', 'redis://localhost:6379')
|
10
|
-
|
10
|
+
# Allow application to specify their own $dt_redis
|
11
|
+
@@redis = $dt_redis || Redis.new(url: redis_url)
|
11
12
|
end
|
12
13
|
@@redis
|
13
14
|
end
|