glib-web 0.3.10 → 0.3.11
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/application/json/libs.rb +12 -11
- data/app/controllers/concerns/application/json/transformation.rb +1 -1
- data/app/controllers/concerns/application/json/ui.rb +1 -1
- data/app/controllers/concerns/application/json/validation.rb +1 -1
- data/app/controllers/concerns/glib/json/libs.rb +93 -0
- data/app/controllers/concerns/glib/json/transformation.rb +11 -0
- data/app/controllers/concerns/glib/json/ui.rb +66 -0
- data/app/controllers/concerns/glib/json/validation.rb +13 -0
- metadata +15 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69432dcf32db57ac795c618f216d7e2bd36b564b13872700135271b88e80c02c
|
4
|
+
data.tar.gz: c9adde3694e7663e5dc422bd8271649a9ca07095ba4397f1ccbb80b6b3a4c972
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d7b997aa956b6905ee1224f47af35314ed936894acb4f49373c8e0af987c12757e0f9b24983ea6288531bbe64877e9a8dff025c3f38a0e883c592710a4d5097
|
7
|
+
data.tar.gz: 8f749848943c2d2236a174851947238379c874dc4257359f7e0e6348711809972afaebfd29059e14ced9d2a709317bb9988204a192ce39b9c2ca83c19735f52a
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# TODO: Deprecate
|
2
|
+
module Application::Json::Libs
|
2
3
|
extend ActiveSupport::Concern
|
3
4
|
|
4
5
|
included do
|
@@ -27,7 +28,7 @@ module Concerns::Application::Json::Libs
|
|
27
28
|
def json_ui_app_is_android?
|
28
29
|
json_ui_app_device_os == 'android'
|
29
30
|
end
|
30
|
-
|
31
|
+
|
31
32
|
def json_ui_app_is_ios?
|
32
33
|
json_ui_app_device_os == 'ios'
|
33
34
|
end
|
@@ -41,9 +42,9 @@ module Concerns::Application::Json::Libs
|
|
41
42
|
module ClassMethods
|
42
43
|
|
43
44
|
def json_libs_init(options)
|
44
|
-
include
|
45
|
-
include
|
46
|
-
include
|
45
|
+
include Application::Json::Transformation
|
46
|
+
include Application::Json::Validation
|
47
|
+
include Application::Json::Ui
|
47
48
|
|
48
49
|
before_action :__json_ui_start
|
49
50
|
|
@@ -54,7 +55,7 @@ module Concerns::Application::Json::Libs
|
|
54
55
|
after_action :__json_transformation_commit
|
55
56
|
after_action :__json_validate_perform
|
56
57
|
end
|
57
|
-
|
58
|
+
|
58
59
|
def json_libs_set_locale
|
59
60
|
before_action do
|
60
61
|
# Need to explicitly fallback to EN
|
@@ -63,7 +64,7 @@ module Concerns::Application::Json::Libs
|
|
63
64
|
I18n.locale = :en
|
64
65
|
end
|
65
66
|
end
|
66
|
-
|
67
|
+
|
67
68
|
def json_libs_force_json_ui
|
68
69
|
before_action do
|
69
70
|
if params[:_render] != 'v1'
|
@@ -72,17 +73,17 @@ module Concerns::Application::Json::Libs
|
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
75
|
-
def json_libs_rescue_csrf
|
76
|
+
def json_libs_rescue_csrf
|
76
77
|
rescue_from ActionController::InvalidAuthenticityToken do |exception|
|
77
78
|
sign_out(:user)
|
78
79
|
|
79
80
|
respond_to do |format|
|
80
81
|
format.json do
|
81
|
-
render json: {
|
82
|
-
onResponse: {
|
82
|
+
render json: {
|
83
|
+
onResponse: {
|
83
84
|
action: 'windows/open-v1',
|
84
85
|
url: root_url
|
85
|
-
}
|
86
|
+
}
|
86
87
|
}
|
87
88
|
end
|
88
89
|
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Glib::Json::Libs
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
extend ClassMethods
|
6
|
+
|
7
|
+
helper_method :json_ui_app_bundle_id, :json_ui_app_build_version, :json_ui_app_device_os
|
8
|
+
helper_method :json_ui_app_is_android?, :json_ui_app_is_ios?, :json_ui_app_is_web?
|
9
|
+
end
|
10
|
+
|
11
|
+
def json_ui_app_bundle_id
|
12
|
+
@json_ui_app_bundle_id ||= request.headers['JsonUiApp-Bundle-Id']
|
13
|
+
end
|
14
|
+
|
15
|
+
def json_ui_app_build_version
|
16
|
+
@json_ui_app_build_version ||= request.headers['JsonUiApp-Build-Version']
|
17
|
+
@json_ui_app_build_version = params[:build_version] if @json_ui_app_build_version.nil? && Rails.env.development? # For easy testing
|
18
|
+
@json_ui_app_build_version
|
19
|
+
end
|
20
|
+
|
21
|
+
def json_ui_app_device_os
|
22
|
+
@json_ui_app_device_os ||= request.headers['JsonUiApp-Device-Os']
|
23
|
+
@json_ui_app_device_os = params[:device_os] if @json_ui_app_device_os.nil? && Rails.env.development? # For easy testing
|
24
|
+
@json_ui_app_device_os || 'web'
|
25
|
+
end
|
26
|
+
|
27
|
+
def json_ui_app_is_android?
|
28
|
+
json_ui_app_device_os == 'android'
|
29
|
+
end
|
30
|
+
|
31
|
+
def json_ui_app_is_ios?
|
32
|
+
json_ui_app_device_os == 'ios'
|
33
|
+
end
|
34
|
+
|
35
|
+
def json_ui_app_is_web?
|
36
|
+
json_ui_app_device_os == 'web'
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
module ClassMethods
|
42
|
+
|
43
|
+
def json_libs_init(options)
|
44
|
+
include Glib::Json::Transformation
|
45
|
+
include Glib::Json::Validation
|
46
|
+
include Glib::Json::Ui
|
47
|
+
|
48
|
+
before_action :__json_ui_start
|
49
|
+
|
50
|
+
# Note that after_action gets executed in reverse
|
51
|
+
after_action do
|
52
|
+
__json_ui_commit(options)
|
53
|
+
end
|
54
|
+
after_action :__json_transformation_commit
|
55
|
+
after_action :__json_validate_perform
|
56
|
+
end
|
57
|
+
|
58
|
+
def json_libs_set_locale
|
59
|
+
before_action do
|
60
|
+
# Need to explicitly fallback to EN
|
61
|
+
I18n.locale = params[:_locale] || :en
|
62
|
+
rescue
|
63
|
+
I18n.locale = :en
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def json_libs_force_json_ui
|
68
|
+
before_action do
|
69
|
+
if params[:_render] != 'v1'
|
70
|
+
redirect_to url_for(params.to_unsafe_h.merge(_render: 'v1'))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def json_libs_rescue_csrf
|
76
|
+
rescue_from ActionController::InvalidAuthenticityToken do |exception|
|
77
|
+
sign_out(:user)
|
78
|
+
|
79
|
+
respond_to do |format|
|
80
|
+
format.json do
|
81
|
+
render json: {
|
82
|
+
onResponse: {
|
83
|
+
action: 'windows/open-v1',
|
84
|
+
url: root_url
|
85
|
+
}
|
86
|
+
}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Glib::Json::Transformation
|
2
|
+
def json_transformation_start
|
3
|
+
if request.format == 'json'
|
4
|
+
@__transformed_json ||= JSON.parse(response.body) rescue nil
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def __json_transformation_commit
|
9
|
+
response.body = @__transformed_json.to_json if @__transformed_json
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Glib::Json::Ui
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
rescue_from ActionController::UnknownFormat do |exception|
|
6
|
+
if json_ui_activated?
|
7
|
+
# Tell `__json_ui_start()` to avoid rendering this page while still retaining the `_render` param
|
8
|
+
# so that the page remains linking to other json_ui pages.
|
9
|
+
redirect_to url_for(format: nil, _skip_render: true)
|
10
|
+
else
|
11
|
+
raise exception
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Override
|
17
|
+
def form_authenticity_token
|
18
|
+
Rails.env.test? ? 'test_token' : super
|
19
|
+
end
|
20
|
+
|
21
|
+
# NOTE: Override default_url_options and call this method
|
22
|
+
def json_ui_url_options
|
23
|
+
options = {}
|
24
|
+
options[:_render] = params[:_render]
|
25
|
+
options[:_locale] = params[:_locale]
|
26
|
+
options[:format] = :json if request.format == :json
|
27
|
+
options
|
28
|
+
end
|
29
|
+
|
30
|
+
def json_ui_activated?
|
31
|
+
@__json_ui_activated
|
32
|
+
end
|
33
|
+
|
34
|
+
def __json_ui_start
|
35
|
+
@__json_ui_activated = false
|
36
|
+
@__json_ui_rendering = false
|
37
|
+
if params[:_render].present?
|
38
|
+
@__json_ui_activated = true
|
39
|
+
request.variant = :ui
|
40
|
+
|
41
|
+
if request.format.html? && params[:_skip_render] != 'true'
|
42
|
+
@__json_ui_rendering = true
|
43
|
+
request.format = 'json'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def __json_ui_commit(options)
|
49
|
+
if @__json_ui_rendering
|
50
|
+
if (hash = json_transformation_start).is_a?(Hash)
|
51
|
+
case params[:_render]
|
52
|
+
when 'v1'
|
53
|
+
__json_ui_vue(hash, options)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def __json_ui_vue(hash, options)
|
62
|
+
renderer_path = options[:renderer_path]
|
63
|
+
@__json_ui_orig_page = response.body
|
64
|
+
response.body = render_to_string(template: renderer_path, layout: false, content_type: 'text/html', locals: { page: hash, options: options })
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Glib::Json::Validation
|
2
|
+
def __json_validate_perform
|
3
|
+
if Rails.env.development? && params[:_validate] == 'true'
|
4
|
+
if (hash = json_transformation_start).is_a?(Hash)
|
5
|
+
json_validate = JSONValidate.new(hash)
|
6
|
+
response_message = json_validate.valid?
|
7
|
+
hash[:_json] = {
|
8
|
+
validationErrors: response_message
|
9
|
+
}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glib-web
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ''
|
@@ -14,16 +14,22 @@ dependencies:
|
|
14
14
|
name: activestorage
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.2.3
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 6.1.0
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 5.2.3
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: 6.
|
32
|
+
version: 6.1.0
|
27
33
|
description:
|
28
34
|
email: ''
|
29
35
|
executables: []
|
@@ -34,6 +40,10 @@ files:
|
|
34
40
|
- app/controllers/concerns/application/json/transformation.rb
|
35
41
|
- app/controllers/concerns/application/json/ui.rb
|
36
42
|
- app/controllers/concerns/application/json/validation.rb
|
43
|
+
- app/controllers/concerns/glib/json/libs.rb
|
44
|
+
- app/controllers/concerns/glib/json/transformation.rb
|
45
|
+
- app/controllers/concerns/glib/json/ui.rb
|
46
|
+
- app/controllers/concerns/glib/json/validation.rb
|
37
47
|
- app/controllers/glib/home_controller.rb
|
38
48
|
- app/helpers/glib/dynamic_texts_helper.rb
|
39
49
|
- app/helpers/glib/json_ui/abstract_builder.rb
|