glib-web 4.39.1 → 4.39.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acbdde8fcc5033a60d976bf56fc3222d3ab1e7e9a138c65c326e3e16912ed729
4
- data.tar.gz: 0b4ab5237c244659ddd40351b3b480fcb76a04e103aa1660e8c63f246d72333b
3
+ metadata.gz: 93226f57a31d7506df878201485705c4bddf72c12e76701cf256dbcbea1b9f50
4
+ data.tar.gz: 535de1bcc5ffcee41c5296425d69e10bbaf86a9cd76920396e876ac7be3a2416
5
5
  SHA512:
6
- metadata.gz: 5b68ef7f7342522130b45f15b5216d07ae9df74d2267b5590ae3a7ed049d97419b4e599ba6db66bc5ba2f21d41a58afe653a547216194b331a28b2996d376287
7
- data.tar.gz: 6d6d29eb399863ca102ad6658f39f78f5b69bd7c6353b14be961270de7f5ecf07b6906899e3e8bc2630f1d744e09929efe4ac2a3910a78c4a2b7ec6feb7ec110
6
+ metadata.gz: 1939b128493528c5281b6d93af4b792d3301905b8ccdc771886e42d5be153f193f39f6dee34c14c6d59562b813aedf50e8dde913baff7ac81c5322c1e7f6ab9f
7
+ data.tar.gz: 6c8b6491839e5185076831ba5d21bf27901322de5ef8ee7f3e3df71c6751ce95371d91a72af070fe7339d23b246369c13181ba08d8c995c55cc71866ea494806
@@ -0,0 +1,145 @@
1
+ module Glib
2
+ class ApiDocsController < ApplicationController
3
+ prepend_before_action do
4
+ params[:_skip_custom_render] = 'true' if params[:custom_render] != 'true'
5
+ end
6
+
7
+ if try(:glib_auth_inited?)
8
+ skip_before_action :glib_load_resource
9
+ skip_before_action :glib_authorize_resource
10
+ end
11
+
12
+ # Skip JSON injections from the host app
13
+ skip_after_action :json_inject_left_menu, raise: false
14
+ skip_after_action :json_inject_feature_usage_analytics, raise: false
15
+ skip_after_action :json_inject_flash_actions, raise: false
16
+
17
+ before_action :set_path_prefix
18
+ layout false
19
+
20
+ # Override injection methods to do nothing
21
+ def json_inject_left_menu; end
22
+ def json_inject_feature_usage_analytics; end
23
+ def json_inject_flash_actions; end
24
+
25
+ def set_path_prefix
26
+ @path_prefix = 'glib/api_docs'
27
+ end
28
+
29
+ # GET /glib/json_ui_api
30
+ def index
31
+ @categories = load_all_categories
32
+ end
33
+
34
+ # GET /glib/json_ui_api/:category
35
+ def show
36
+ @category = params[:category]
37
+ @doc = load_documentation(@category)
38
+
39
+ unless @doc
40
+ render plain: "Category '#{@category}' not found", status: :not_found
41
+ return
42
+ end
43
+
44
+ @components = @doc['components'] || {}
45
+ end
46
+
47
+ # GET /glib/json_ui_api/:category/:component
48
+ def component
49
+ @category = params[:category]
50
+ @component_key = params[:component]
51
+ @doc = load_documentation(@category)
52
+
53
+ unless @doc
54
+ render plain: "Category '#{@category}' not found", status: :not_found
55
+ return
56
+ end
57
+
58
+ @component = @doc['components'][@component_key]
59
+
60
+ unless @component
61
+ render plain: "Component '#{@component_key}' not found in category '#{@category}'", status: :not_found
62
+ return
63
+ end
64
+ end
65
+
66
+ private
67
+
68
+ def load_all_categories
69
+ # Try to find the doc/components directory
70
+ # First try the gem's path
71
+ doc_path = Glib::Web::Engine.root.join('doc', 'components')
72
+
73
+ # If not found, try relative to Rails root (for development in host app)
74
+ unless Dir.exist?(doc_path)
75
+ doc_path = Rails.root.join('..', 'glib-web', 'doc', 'components')
76
+ end
77
+
78
+ return [] unless Dir.exist?(doc_path)
79
+
80
+ categories = []
81
+ Dir.glob(doc_path.join('*.yml')).each do |file|
82
+ next if File.basename(file) == 'README.md'
83
+
84
+ basename = File.basename(file, '.yml')
85
+ doc = YAML.load_file(file)
86
+
87
+ categories << {
88
+ 'key' => basename,
89
+ 'name' => basename.titleize,
90
+ 'file' => file,
91
+ 'component_count' => doc['components']&.size || 0,
92
+ 'source_file' => doc.dig('meta', 'source_file')
93
+ }
94
+ end
95
+
96
+ categories.sort_by { |c| c['name'] }
97
+ end
98
+
99
+ def load_documentation(category)
100
+ # Try to find the YAML file
101
+ # First try the gem's path
102
+ doc_path = Glib::Web::Engine.root.join('doc', 'components', "#{category}.yml")
103
+
104
+ # If not found, try relative to Rails root (for development in host app)
105
+ unless File.exist?(doc_path)
106
+ doc_path = Rails.root.join('..', 'glib-web', 'doc', 'components', "#{category}.yml")
107
+ end
108
+
109
+ return nil unless File.exist?(doc_path)
110
+
111
+ YAML.load_file(doc_path)
112
+ end
113
+
114
+ helper_method :json_ui_api_url
115
+ def json_ui_api_url(category: nil, component: nil)
116
+ if component && category
117
+ "/glib/json_ui_api/#{category}/#{component}"
118
+ elsif category
119
+ "/glib/json_ui_api/#{category}"
120
+ else
121
+ "/glib/json_ui_api"
122
+ end
123
+ end
124
+
125
+ helper_method :property_type_badge_class
126
+ def property_type_badge_class(type)
127
+ case type
128
+ when 'string', 'text'
129
+ 'badge-primary'
130
+ when 'int', 'float'
131
+ 'badge-success'
132
+ when 'bool'
133
+ 'badge-info'
134
+ when 'action'
135
+ 'badge-warning'
136
+ when 'views', 'panels_builder'
137
+ 'badge-secondary'
138
+ when 'hash', 'array'
139
+ 'badge-dark'
140
+ else
141
+ 'badge-light'
142
+ end
143
+ end
144
+ end
145
+ end
@@ -162,6 +162,22 @@ module Glib
162
162
  end
163
163
  end
164
164
 
165
+ def self.enum(propName, options = {})
166
+ define_method(propName) do |value|
167
+ str = to_string(value)
168
+
169
+ if !Rails.env.production?
170
+ allowed_options = options[:options] || []
171
+ if allowed_options.present? && !allowed_options.map(&:to_s).include?(str)
172
+ raise "Invalid value for #{propName}: '#{str}'. Allowed values: #{allowed_options.map(&:inspect).join(', ')}"
173
+ end
174
+ end
175
+
176
+ instance_variable_set("@#{propName}", str) if options[:cache]
177
+ json.set! propName, str
178
+ end
179
+ end
180
+
165
181
  # Support either string or dynamic_text hash
166
182
  def self.text(propName, options = {})
167
183
  define_method(propName) do |value|
@@ -2,7 +2,11 @@ class Glib::JsonUi::ActionBuilder
2
2
  module Dialogs
3
3
  class Alert < Action
4
4
  string :title
5
+
6
+ # Alert message text to display.
7
+ # @note Does not support markdown formatting. For markdown support, use dialogs/show with a custom body instead.
5
8
  string :message
9
+
6
10
  action :onLoad
7
11
  action :onClose
8
12
  singleton_array :styleClass, :styleClasses
@@ -48,6 +48,8 @@ module Glib
48
48
  string :paramNameForNewSectionedRowIndex
49
49
 
50
50
  panels_builder :accessory, :header, :body, :footer
51
+
52
+ enum :textFormat, options: [:plain, :markdown]
51
53
  end
52
54
 
53
55
  class Featured < Standard
@@ -18,9 +18,24 @@ class Glib::JsonUi::ViewBuilder
18
18
  { only_path: true }
19
19
  end
20
20
 
21
+ # Validates field input according to specified rules.
22
+ # @param validation [Hash] Hash of validation types and their options
23
+ # @example
24
+ # validation presence: { message: 'Required' }
25
+ # validation format: { with: /\A\d+\z/, message: 'Must be a number' }
26
+ # validation length: { minimum: 3, maximum: 20, message: { too_short: 'Too short', too_long: 'Too long' } }
27
+ # @note Supported validation types: presence, required, absence, acceptance, numericality, format, inclusion, exclusion, length
28
+ # @see /home/hgani/workspace/glib-web-npm/components/validation.js Frontend validation implementation
21
29
  def validation(validation)
22
30
  return if validation.blank?
23
31
 
32
+ # Validate that all keys are supported validation types
33
+ supported_validations = %i[presence required absence acceptance numericality format inclusion exclusion length]
34
+ invalid_keys = validation.keys - supported_validations
35
+ if invalid_keys.any?
36
+ raise ArgumentError, "Unsupported validation type(s): #{invalid_keys.join(', ')}. Supported types: #{supported_validations.join(', ')}"
37
+ end
38
+
24
39
  if validation[:format].present?
25
40
  context.cast_to_js_regex(validation[:format])
26
41
  end