glib-web 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9187e21e6dc23404a709478c99906553f56d04cd956096d42ff6663ab805856b
4
+ data.tar.gz: f7c91119a66ea42fe3073b77cf89f3705448dee70ebbe5f74ce91f604b2100d1
5
+ SHA512:
6
+ metadata.gz: b40412fdcf224f041a7937ca88e869e77738e4f533225b0119fab448f741c16a1029bec51e073816363efddb2bf408e9ff1e9f58b599c282281603cede1b005f
7
+ data.tar.gz: db3db6a11e5ad2f898a181277f4df99dda527ecf949dda0b61f45a5448069950ae78c317e9dfe2183486f253e5693b9d865f61919f4f7c3c976f805ca44c599e
File without changes
@@ -0,0 +1,26 @@
1
+ module Concerns::Application::Json::Libs
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ def json_libs_init(options)
11
+ include Concerns::Application::Json::Transformation
12
+ include Concerns::Application::Json::Validation
13
+ include Concerns::Application::Json::Ui
14
+
15
+ before_action :__json_ui_start
16
+
17
+ # Note that after_action gets executed in reverse
18
+ after_action do
19
+ __json_ui_commit(options[:renderer_path])
20
+ end
21
+ after_action :__json_transformation_commit
22
+ after_action :__json_validate_perform
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ module Concerns::Application::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,61 @@
1
+ module Concerns::Application::Json::Ui
2
+ extend ActiveSupport::Concern
3
+
4
+ # NOTE: Override default_url_options and call this method
5
+ def json_ui_url_options
6
+ options = {}
7
+ options[:_render] = params[:_render]
8
+ options[:format] = :json if request.format == :json
9
+ options
10
+ end
11
+
12
+ def json_ui_activated
13
+ @__json_ui_activated
14
+ end
15
+
16
+ def __json_ui_start
17
+ @__json_ui_activated = false
18
+ @__json_ui_rendering = false
19
+ if params[:_render].present?
20
+ @__json_ui_activated = true
21
+ request.variant = :ui
22
+
23
+ if request.format.html?
24
+ @__json_ui_rendering = true
25
+ request.format = 'json'
26
+ end
27
+ end
28
+ end
29
+
30
+ def __json_ui_commit(renderer_path)
31
+ if @__json_ui_rendering
32
+ if (hash = json_transformation_start).is_a?(Hash)
33
+ case params[:_render]
34
+ when 'v1'
35
+ __json_ui_vue(hash, renderer_path)
36
+ when 'mdc'
37
+ __json_ui_mdc(hash)
38
+ when 'vue'
39
+ __json_ui_vue(hash)
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ # TODO: Remove. Deprecated
48
+ def __json_ui_mdc(hash)
49
+ prepend_view_path 'app/views/json_ui/mdc'
50
+ if (next_action = hash['onResponse']).is_a?(Hash)
51
+ response.body = render_to_string(file: 'renderer.js', layout: false, content_type: 'text/javascript', locals: { response: next_action })
52
+ else
53
+ response.body = render_to_string(file: 'renderer.html', layout: false, content_type: 'text/html', locals: { page: hash })
54
+ end
55
+ end
56
+
57
+ def __json_ui_vue(hash, renderer_path)
58
+ @__json_ui_orig_page = response.body
59
+ response.body = render_to_string(file: renderer_path, layout: false, content_type: 'text/html', locals: { page: hash })
60
+ end
61
+ end
@@ -0,0 +1,13 @@
1
+ module Concerns::Application::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
@@ -0,0 +1,58 @@
1
+ module Glib
2
+ module Web
3
+ module JsonUiHelper
4
+ def json_body_with_list(json, header = nil, footer = nil, options = {})
5
+ json.header header
6
+ json.content do
7
+ json.subviews [1] do
8
+ json.view 'panels/list-v1'
9
+ json.width 'matchParent'
10
+ json.nextPage options[:nextPage]
11
+ json.sections [1] do
12
+ yield
13
+ end
14
+ end
15
+ end
16
+ json.footer footer
17
+ end
18
+
19
+ def json_body_with_scroll(json, header = nil, footer = nil, options = {})
20
+ json.header header
21
+ json.content do
22
+ json.subviews [1] do
23
+ json.view 'panels/scroll-v1'
24
+ json.width 'matchParent'
25
+ json.padding options[:padding]
26
+ json.subviews do
27
+ yield
28
+ end
29
+ end
30
+ end
31
+ json.footer footer
32
+ end
33
+
34
+ def json_body_with_form(json, header = nil, footer = nil, options = {})
35
+ json.header header
36
+ json_body_with_scroll json do
37
+ json.child! do
38
+ json.view 'panels/form-v1'
39
+ json.width 'matchParent'
40
+ json.(options, :url, :method)
41
+ json.padding options[:padding]
42
+ json.local options[:local]
43
+ json.subviews do
44
+ json.child! do
45
+ json.view 'fields/hidden-v1'
46
+ json.name 'authenticity_token'
47
+ json.value form_authenticity_token
48
+ end
49
+
50
+ yield
51
+ end
52
+ end
53
+ end
54
+ json.footer footer
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,6 @@
1
+ module Glib
2
+ module Web
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Glib
2
+ module Web
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/glib-web.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "glib/version"
2
+ require "glib/engine" if defined?(::Rails)
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: glib-web
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ''
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: ''
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - app/controllers/concerns/.keep
20
+ - app/controllers/concerns/application/json/libs.rb
21
+ - app/controllers/concerns/application/json/transformation.rb
22
+ - app/controllers/concerns/application/json/ui.rb
23
+ - app/controllers/concerns/application/json/validation.rb
24
+ - app/helpers/glib/web/json_ui_helper.rb
25
+ - lib/glib-web.rb
26
+ - lib/glib/engine.rb
27
+ - lib/glib/version.rb
28
+ homepage:
29
+ licenses: []
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 2.7.6
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: ''
51
+ test_files: []