Module: Glib::Json::Ui

Extended by:
ActiveSupport::Concern
Defined in:
app/controllers/concerns/glib/json/ui.rb

Instance Method Summary collapse

Instance Method Details

#__json_ui_commit(options) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/controllers/concerns/glib/json/ui.rb', line 73

def __json_ui_commit(options)
  return if response.status >= 300

  case @__json_ui_rendering
  when :vue
    if (hash = json_transformation_start).is_a?(Hash)
      __json_ui_vue(hash, options)
    else
      raise "Invalid JSON UI payload: #{hash}"
    end
  end
end

#__json_ui_rendering?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/controllers/concerns/glib/json/ui.rb', line 35

def __json_ui_rendering?
  @__json_ui_rendering != nil
end

#__json_ui_start(options) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/concerns/glib/json/ui.rb', line 57

def __json_ui_start(options)
  @__json_ui_activated = false
  @__json_ui_rendering = nil
  if options[:when] == :always || params[:_render] == 'v1'
    @__json_ui_activated = true
    request.variant = :ui

    # Some bots (e.g. Line and DuckDuckGo) passes `*/*` in the `Accept` header
    is_html = request.format.html? || request.format == '*/*'
    if is_html && params[:_skip_render] != 'true'
      @__json_ui_rendering = :vue
      request.format = 'json'
    end
  end
end

#form_authenticity_token(*args) ⇒ Object

Override



17
18
19
# File 'app/controllers/concerns/glib/json/ui.rb', line 17

def form_authenticity_token(*args)
  Rails.env.test? ? 'test_token' : super
end

#json_ui_activated?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/controllers/concerns/glib/json/ui.rb', line 31

def json_ui_activated?
  @__json_ui_activated
end

#json_ui_page_lifecycle_prop(name) ⇒ Object



39
40
41
42
43
44
# File 'app/controllers/concerns/glib/json/ui.rb', line 39

def json_ui_page_lifecycle_prop(name)
  if (hash = json_transformation_start).is_a?(Hash) && hash['body']  # A valid page
    hash[name] ||= { 'action' => 'runMultiple', 'childActions' => [] }
    hash[name]['childActions']
  end
end

#json_ui_response_lifecycle_propObject



46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/concerns/glib/json/ui.rb', line 46

def json_ui_response_lifecycle_prop
  prop_name = 'onResponse'
  if (hash = json_transformation_start).is_a?(Hash) && hash[prop_name]  # A valid response
    if hash[prop_name]['action'] != 'runMultiple'
      childActions = [hash[prop_name]]
      hash[prop_name] = { 'action' => 'runMultiple', 'childActions' => childActions }
      childActions
    end
  end
end

#json_ui_url_optionsObject

NOTE: Override default_url_options and call this method



22
23
24
25
26
27
28
29
# File 'app/controllers/concerns/glib/json/ui.rb', line 22

def json_ui_url_options
  options = {}
  options[:_render] = params[:_render]
  options[:_locale] = params[:_locale]
  options[:_preview] = params[:_preview]
  options[:format] = :json if request.format == :json
  options
end