glib-web 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/application/json/libs.rb +26 -0
  3. data/app/controllers/concerns/application/json/transformation.rb +11 -0
  4. data/app/controllers/concerns/application/json/ui.rb +73 -0
  5. data/app/controllers/concerns/application/json/validation.rb +13 -0
  6. data/app/controllers/home_controller.rb +21 -0
  7. data/app/helpers/glib/web/json_ui_helper.rb +58 -0
  8. data/app/views/app/views/json_ui/vue/renderer.html.erb +29 -0
  9. data/app/views/json_ui/garage/_nav_menu.json.jbuilder +84 -0
  10. data/app/views/json_ui/garage/actions/index.json.jbuilder +25 -0
  11. data/app/views/json_ui/garage/forms/basic.json.jbuilder +53 -0
  12. data/app/views/json_ui/garage/forms/basic_post.json.jbuilder +10 -0
  13. data/app/views/json_ui/garage/forms/file_upload.json.jbuilder +38 -0
  14. data/app/views/json_ui/garage/forms/floating_submit.json.jbuilder +48 -0
  15. data/app/views/json_ui/garage/forms/generic_post.json.jbuilder +6 -0
  16. data/app/views/json_ui/garage/forms/index.json.jbuilder +43 -0
  17. data/app/views/json_ui/garage/forms/submit_indicator.json.jbuilder +32 -0
  18. data/app/views/json_ui/garage/forms/submit_indicator_post.json.jbuilder +12 -0
  19. data/app/views/json_ui/garage/home/index.json.jbuilder +61 -0
  20. data/app/views/json_ui/garage/lists/_infinite_scroll_section.json.jbuilder +10 -0
  21. data/app/views/json_ui/garage/lists/index.json.jbuilder +25 -0
  22. data/app/views/json_ui/garage/lists/infinite_scroll.json.jbuilder +27 -0
  23. data/app/views/json_ui/garage/lists/templating.json.jbuilder +45 -0
  24. data/app/views/json_ui/garage/pages/full_width_height.json.jbuilder +39 -0
  25. data/app/views/json_ui/garage/pages/index.json.jbuilder +35 -0
  26. data/app/views/json_ui/garage/pages/layout.json.jbuilder +35 -0
  27. data/app/views/json_ui/garage/pages/nav_buttons.json.jbuilder +32 -0
  28. data/app/views/json_ui/garage/panels/horizontal.json.jbuilder +213 -0
  29. data/app/views/json_ui/garage/panels/index.json.jbuilder +34 -0
  30. data/app/views/json_ui/garage/panels/split.json.jbuilder +360 -0
  31. data/app/views/json_ui/garage/panels/vertical.json.jbuilder +94 -0
  32. data/app/views/json_ui/garage/views/basic.json.jbuilder +21 -0
  33. data/app/views/json_ui/garage/views/carousels.json.jbuilder +100 -0
  34. data/app/views/json_ui/garage/views/images.json.jbuilder +56 -0
  35. data/app/views/json_ui/garage/views/index.json.jbuilder +34 -0
  36. data/config/routes.rb +4 -0
  37. data/lib/glib/engine.rb +7 -0
  38. data/lib/glib/version.rb +5 -0
  39. data/lib/glib-web.rb +2 -0
  40. metadata +40 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 664a40041c3bd90043d897af1209c272d3bec911
4
- data.tar.gz: e6c4ea202254454e6f4ba2dd84cb84b92e5ef4d7
3
+ metadata.gz: d8c6729fef9f47c547f09daaefc76fbe6732f1a6
4
+ data.tar.gz: 56535d062ad8e4c956d6d79bb43cf794b5b56b24
5
5
  SHA512:
6
- metadata.gz: 1fade6072e77809c761b192b2d0efb61f9f4c170d0c8c45aebbb338c492fed021891e0b9a020a0a0b6fc739ed1192cc7b1665273e8586e992cbcb6aa6c4bbb6e
7
- data.tar.gz: 37ee0021f571efdb4f6c4b125b7a0b6f5cef4e7611d41e4e0fab61253ce1c93b3eaabcc2cd5937cdf3f3511c82fc8e56d3a5b837f3b9f34c5b3f3532cae504be
6
+ metadata.gz: 99098abc2072c7f901b86bfbc9b205cc1a9f7d5c5dc02bcbf7eee97a06510ba7fca76b494463f8013cbe5eaddddefbc38a7270a55cc665528427ce227107a243
7
+ data.tar.gz: 66b542dc266d511deac569350cf68a32b5bffa6e3d107d5d288e83bcc4bb296906fc619c70ca857d4a19a234d4f33f82fd75eeeec47bc314b32a7f256b642673
@@ -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,73 @@
1
+ module Concerns::Application::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
+ # NOTE: Override default_url_options and call this method
17
+ def json_ui_url_options
18
+ options = {}
19
+ options[:_render] = params[:_render]
20
+ options[:format] = :json if request.format == :json
21
+ options
22
+ end
23
+
24
+ def json_ui_activated?
25
+ @__json_ui_activated
26
+ end
27
+
28
+ def __json_ui_start
29
+ @__json_ui_activated = false
30
+ @__json_ui_rendering = false
31
+ if params[:_render].present?
32
+ @__json_ui_activated = true
33
+ request.variant = :ui
34
+
35
+ if request.format.html? && params[:_skip_render] != 'true'
36
+ @__json_ui_rendering = true
37
+ request.format = 'json'
38
+ end
39
+ end
40
+ end
41
+
42
+ def __json_ui_commit(renderer_path)
43
+ if @__json_ui_rendering
44
+ if (hash = json_transformation_start).is_a?(Hash)
45
+ case params[:_render]
46
+ when 'v1'
47
+ __json_ui_vue(hash, renderer_path)
48
+ when 'mdc'
49
+ __json_ui_mdc(hash)
50
+ when 'vue'
51
+ __json_ui_vue(hash)
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ # TODO: Remove. Deprecated
60
+ def __json_ui_mdc(hash)
61
+ prepend_view_path 'app/views/json_ui/mdc'
62
+ if (next_action = hash['onResponse']).is_a?(Hash)
63
+ response.body = render_to_string(file: 'renderer.js', layout: false, content_type: 'text/javascript', locals: { response: next_action })
64
+ else
65
+ response.body = render_to_string(file: 'renderer.html', layout: false, content_type: 'text/html', locals: { page: hash })
66
+ end
67
+ end
68
+
69
+ def __json_ui_vue(hash, renderer_path)
70
+ @__json_ui_orig_page = response.body
71
+ response.body = render_to_string(file: renderer_path, layout: false, content_type: 'text/html', locals: { page: hash })
72
+ end
73
+ 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,21 @@
1
+ class HomeController < ApplicationController
2
+
3
+ def json_ui_garage
4
+ @path_prefix = 'json_ui/garage'
5
+ @sample_image_url = 'https://cdn-images-1.medium.com/max/1200/1*Qc0XxYm-qAZL-7tjjlNfrg.png'
6
+
7
+ # prepend_view_path 'app/views/json_ui/garage'
8
+ path = "#{@path_prefix}/#{params[:path] || 'home/index'}"
9
+ render path
10
+ end
11
+
12
+ def json_ui_garage_url(options = {})
13
+ Glib::Web::Engine.routes.url_helpers.json_ui_garage_url(options.merge(
14
+ host: request.host,
15
+ port: request.port,
16
+ _render: params[:_render], format: params[:format])
17
+ )
18
+ end
19
+
20
+ helper_method :json_ui_garage_url
21
+ 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,29 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta charset="utf-8" />
6
+ <meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport" />
7
+
8
+ <title>App</title>
9
+ <%= csrf_meta_tags %>
10
+
11
+ <%= javascript_pack_tag 'vue_renderer', defer: true %>
12
+ <%#= javascript_include_tag 'vue_renderer_extras', defer: true %>
13
+
14
+ <%= stylesheet_pack_tag 'vue_renderer' %>
15
+ <%#= stylesheet_link_tag 'vue_renderer_extras', media: 'all' %>
16
+
17
+ <link href="https://fonts.googleapis.com/css?family=Material+Icons" rel="stylesheet" />
18
+ </head>
19
+
20
+ <body>
21
+ <noscript>Please enable JavaScript to view this web site.</noscript>
22
+ <div id="app"></div>
23
+
24
+ <script>
25
+ var __page = <%= raw @__json_ui_orig_page%>;
26
+ </script>
27
+ </body>
28
+
29
+ </html>
@@ -0,0 +1,84 @@
1
+ json.leftDrawer do
2
+ json.items do
3
+ json.child! do
4
+ json.icon do
5
+ json.materialName 'home'
6
+ end
7
+ json.text 'Home'
8
+ json.onClick do
9
+ json.action 'windows/open-v1'
10
+ json.url json_ui_garage_url
11
+ end
12
+ end
13
+ end
14
+
15
+ json.items do
16
+ json.child! do
17
+ json.text 'Pages'
18
+ json.onClick do
19
+ json.action 'windows/open-v1'
20
+ json.url json_ui_garage_url(path: 'pages/index')
21
+ end
22
+ end
23
+ end
24
+
25
+ json.items do
26
+ json.child! do
27
+ json.text 'Lists'
28
+ json.onClick do
29
+ json.action 'windows/open-v1'
30
+ json.url json_ui_garage_url(path: 'lists/index')
31
+ end
32
+ end
33
+ end
34
+
35
+ json.items do
36
+ json.child! do
37
+ json.text 'Forms'
38
+ json.onClick do
39
+ json.action 'windows/open-v1'
40
+ json.url json_ui_garage_url(path: 'forms/index')
41
+ end
42
+ end
43
+ end
44
+
45
+ json.items do
46
+ json.child! do
47
+ json.text 'Panels'
48
+ json.onClick do
49
+ json.action 'windows/open-v1'
50
+ json.url json_ui_garage_url(path: 'panels/index')
51
+ end
52
+ end
53
+ end
54
+
55
+ json.items do
56
+ json.child! do
57
+ json.text 'Views'
58
+ json.onClick do
59
+ json.action 'windows/open-v1'
60
+ json.url json_ui_garage_url(path: 'views/index')
61
+ end
62
+ end
63
+ end
64
+
65
+ json.items do
66
+ json.child! do
67
+ json.text 'Actions'
68
+ json.onClick do
69
+ json.action 'windows/open-v1'
70
+ json.url json_ui_garage_url(path: 'actions/index')
71
+ end
72
+ end
73
+ end
74
+
75
+ json.items do
76
+ json.child! do
77
+ json.text 'Diagnostics'
78
+ json.onClick do
79
+ json.action 'dialogs/alert-v1'
80
+ json.message 'JSON UI v1.0'
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,25 @@
1
+ json.title 'Actions'
2
+
3
+ render './nav_menu', json: json
4
+
5
+ json_body_with_list json do
6
+ json.rows do
7
+ json.child! do
8
+ json.template 'default-v1'
9
+ json.title 'Alert'
10
+ json.onClick do
11
+ json.action 'dialogs/alert-v1'
12
+ json.message 'This is an alert'
13
+ end
14
+ end
15
+
16
+ # json.child! do
17
+ # json.template 'default-v1'
18
+ # json.title 'Remote Content'
19
+ # json.onClick do
20
+ # json.action 'dialogs/open-v1'
21
+ # json.url ''
22
+ # end
23
+ # end
24
+ end
25
+ end
@@ -0,0 +1,53 @@
1
+ json.title 'Forms'
2
+
3
+ render "#{@path_prefix}/nav_menu", json: json
4
+
5
+ options = {
6
+ url: json_ui_garage_url(path: 'forms/basic_post'),
7
+ method: 'post',
8
+ padding: { top: 12, left: 20, right: 20, bottom: 12 }
9
+ }
10
+ json_body_with_form json, nil, nil, options do
11
+ json.child! do
12
+ json.view 'fields/text-v1'
13
+ json.name 'user[name]'
14
+ json.width 'matchParent'
15
+ json.label 'Name'
16
+ end
17
+
18
+ json.child! do
19
+ json.view 'fields/email-v1'
20
+ json.name 'user[email]'
21
+ json.width 'matchParent'
22
+ json.label 'Email'
23
+ end
24
+
25
+ json.child! do
26
+ json.view 'fields/password-v1'
27
+ json.name 'user[password]'
28
+ json.width 'matchParent'
29
+ json.label 'Password'
30
+ end
31
+
32
+ json.child! do
33
+ json.view 'panels/split-v1'
34
+ json.width 'matchParent'
35
+
36
+ json.content do
37
+ json.right do
38
+ json.view 'button-v1'
39
+ json.text 'Submit'
40
+ json.onClick do
41
+ json.action 'forms/submit-v1'
42
+
43
+ # json.action 'forms/encode-v1'
44
+ # json.paramName 'formData'
45
+ # json.onEncoded do
46
+ # json.action 'http/post-v1'
47
+ # json.url json_ui_garage_url(path: 'forms/basic_post')
48
+ # end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,10 @@
1
+ name, email, password = params.require(:user).values_at(:name, :email, :password)
2
+ json.onResponse do
3
+ if name.present? && email.present? && password.present?
4
+ json.action 'dialogs/alert-v1'
5
+ json.message "Submitted information: #{name}, #{email}, #{password}"
6
+ else
7
+ json.action 'dialogs/alert-v1'
8
+ json.message 'Please enter all required information'
9
+ end
10
+ end
@@ -0,0 +1,38 @@
1
+ json.title 'Forms'
2
+
3
+ render "#{@path_prefix}/nav_menu", json: json
4
+
5
+ options = {
6
+ url: json_ui_garage_url(path: 'forms/generic_post'),
7
+ method: 'post',
8
+ padding: { top: 12, left: 20, right: 20, bottom: 12 }
9
+ }
10
+ json_body_with_form json, nil, nil, options do
11
+ json.child! do
12
+ json.view 'fields/file-v1'
13
+ json.name 'user[photo]'
14
+ json.width 'matchParent'
15
+ json.label 'Photo'
16
+
17
+ json.value 'VALUE_OF_THE_PREVIOUS_IMAGE_WHICH_IS_USEFUL_WHEN_UPDATING_EXISTING_MODEL'
18
+
19
+ json.accepts "image/*"
20
+ # json.s3_bucket 'BUCKET_NAME'
21
+ # json.s3_path_prefix 'uploads/images'
22
+ json.s3_direct_upload_url rails_direct_uploads_path
23
+
24
+ # This is for security so we don't have to reveal key/secret in the json api
25
+ # json.s3_signature_url 'URL_TO_OUR_SERVER_TO_GET_GENERATED_SIGNATURE'
26
+
27
+ json.file_size_limit 5000 # 5 MB
28
+ json.file_size_limit_alert_text 'Too big!'
29
+ end
30
+
31
+ json.child! do
32
+ json.view 'button-v1'
33
+ json.text 'Submit'
34
+ json.onClick do
35
+ json.action 'forms/submit-v1'
36
+ end
37
+ end
38
+ end