Skip to content

Commit 5da187f

Browse files
[bug fix] dynamic property render in snippets (#1424)
* [bug fix] dynamic property render in snippets Addresses: #1355 Demo: https://user-images.githubusercontent.com/55496123/220007755-4d4fa5f6-0534-4c7a-a499-06978793219c.mov * feat: pointing to cms tag 3.5 (#1426) --------- Co-authored-by: Er. Ajay Shrestha <[email protected]>
1 parent 5f74f68 commit 5da187f

File tree

5 files changed

+24
-27
lines changed

5 files changed

+24
-27
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ gem 'ros-apartment', require: 'apartment'
3131
gem 'ros-apartment-sidekiq', require: 'apartment-sidekiq'
3232
gem 'apartment-activejob'
3333
gem 'devise'
34-
gem "comfortable_mexican_sofa",git: 'https://github.com/restarone/comfortable-mexican-sofa', tag: '3.4'
34+
gem "comfortable_mexican_sofa",git: 'https://github.com/restarone/comfortable-mexican-sofa', tag: '3.5'
3535
gem "comfy_blog", git: 'https://github.com/restarone/comfy-blog', branch: 'master'
3636
gem 'simple_discussion', git: 'https://github.com/restarone/simple_discussion', branch: 'master'
3737
gem 'gravatar_image_tag'

Gemfile.lock

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GIT
22
remote: https://github.com/restarone/comfortable-mexican-sofa
3-
revision: 456fb8507e9668128529c0302fa2e77e029c1f88
4-
tag: 3.4
3+
revision: ccf9415ae220453a199759b8ecbb8e9436c75c85
4+
tag: 3.5
55
specs:
66
comfortable_mexican_sofa (2.0.19)
77
active_link_to (>= 1.0.0)
@@ -210,7 +210,6 @@ GEM
210210
encryptor (3.0.0)
211211
errbase (0.2.1)
212212
erubi (1.10.0)
213-
erubis (2.7.0)
214213
exception_notification (4.5.0)
215214
actionmailer (>= 5.2, < 8)
216215
activesupport (>= 5.2, < 8)
@@ -231,21 +230,16 @@ GEM
231230
gravatar_image_tag (1.2.0)
232231
groupdate (5.2.2)
233232
activesupport (>= 5)
234-
haml (5.2.2)
235-
temple (>= 0.8.0)
233+
haml (6.1.1)
234+
temple (>= 0.8.2)
235+
thor
236236
tilt
237-
haml-rails (2.0.1)
237+
haml-rails (2.1.0)
238238
actionpack (>= 5.1)
239239
activesupport (>= 5.1)
240-
haml (>= 4.0.6, < 6.0)
241-
html2haml (>= 1.0.1)
240+
haml (>= 4.0.6)
242241
railties (>= 5.1)
243242
hashdiff (1.0.1)
244-
html2haml (2.2.0)
245-
erubis (~> 2.7.0)
246-
haml (>= 4.0, < 6)
247-
nokogiri (>= 1.6.0)
248-
ruby_parser (~> 3.5)
249243
html_page (0.1.0)
250244
http-accept (1.7.0)
251245
http-cookie (1.0.3)
@@ -261,7 +255,7 @@ GEM
261255
jbuilder (2.11.2)
262256
activesupport (>= 5.0.0)
263257
jmespath (1.6.1)
264-
jquery-rails (4.4.0)
258+
jquery-rails (4.5.1)
265259
rails-dom-testing (>= 1, < 3)
266260
railties (>= 4.2.0)
267261
thor (>= 0.14, < 2.0)
@@ -355,7 +349,7 @@ GEM
355349
nokogiri (>= 1.6)
356350
rails-html-sanitizer (1.4.2)
357351
loofah (~> 2.3)
358-
rails-i18n (7.0.3)
352+
rails-i18n (7.0.6)
359353
i18n (>= 0.7, < 2)
360354
railties (>= 6.0.0, < 8)
361355
railties (6.1.5)
@@ -399,8 +393,6 @@ GEM
399393
ruby-vips (2.1.4)
400394
ffi (~> 1.12)
401395
ruby2_keywords (0.0.5)
402-
ruby_parser (3.19.1)
403-
sexp_processor (~> 4.16)
404396
rubyzip (2.3.0)
405397
safely_block (0.3.0)
406398
errbase (>= 0.1.1)
@@ -418,7 +410,6 @@ GEM
418410
childprocess (>= 0.5, < 4.0)
419411
rubyzip (>= 1.2.2)
420412
semantic_range (3.0.0)
421-
sexp_processor (4.16.1)
422413
sidekiq (6.4.1)
423414
connection_pool (>= 2.2.2)
424415
rack (~> 2.0)
@@ -452,7 +443,7 @@ GEM
452443
rails (>= 5.1)
453444
responders
454445
stripe (>= 3.15.0)
455-
temple (0.8.2)
446+
temple (0.10.0)
456447
thor (1.2.1)
457448
tilt (2.0.10)
458449
turbo-rails (1.1.1)

app/controllers/comfy/admin/api_namespaces_controller.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ def show
4343

4444
field, direction = params[:q].key?(:s) ? params[:q][:s].split(" ") : [nil, nil]
4545
fields_in_properties = @api_namespace.properties.keys
46+
@custom_properties = {}
47+
@api_namespace.properties.values.each_with_index do |obj,index|
48+
if(obj.present? && obj != "nil" && obj != "\"\"")
49+
@custom_properties[fields_in_properties[index]] = obj;
50+
end
51+
end
52+
@custom_properties = JSON.parse(@custom_properties.to_json, object_class: OpenStruct).to_s.gsub(/=/,': ').gsub(/#<OpenStruct/,'{').gsub(/>/,'}').gsub("\\", "'").gsub(/"'"/,'"').gsub(/'""/,'"')
4653
@image_options = @api_namespace.non_primitive_properties.select { |non_primitive_property| non_primitive_property.field_type == 'file' }.pluck(:label)
4754
# check if we are sorting by a field inside properties jsonb column
4855
if field && fields_in_properties.include?(field)

app/views/comfy/admin/api_namespaces/show.html.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@
115115
%pre= @api_namespace.snippet
116116
%p
117117
%b API HTML Renderer index snippet:
118-
%pre= "{{ cms:helper api_namespace_resource_index '#{@api_namespace.slug}', scope: { properties: { property: value } } }}"
118+
%pre= "{{ cms:helper render_api_namespace_resource_index '#{@api_namespace.slug}', scope: { properties: #{@custom_properties} } }}"
119119
%p
120120
%b API HTML Renderer show snippet:
121-
%pre= "{{ cms:helper api_namespace_resource '#{@api_namespace.slug}', scope: { properties: { property: value } } }}"
121+
%pre= "{{ cms:helper render_api_namespace_resource '#{@api_namespace.slug}', scope: { properties: #{@custom_properties} } }}"
122122
%p
123123
.d-flex.justify-content-between
124124
%b Preview (outer border is present in preview only):

test/controllers/admin/comfy/api_namespaces_controller_test.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -775,18 +775,17 @@ class Comfy::Admin::ApiNamespacesControllerTest < ActionDispatch::IntegrationTes
775775
test "#index: Rendering tab should include documentation on form snippet and API HTML renderer snippets" do
776776
sign_in(@user)
777777
@api_namespace.has_form = "1"
778+
properties = { test_id: 123, obj:{ a:"b", c:"d"}, title: "Hello World", published: true, arr:[ 1, 2, 3], alpha_arr: ["a", "b"] }
778779

780+
@api_namespace.update(properties: properties)
779781
get api_namespace_url(@api_namespace)
780782
assert_response :success
781-
782783
assert_select "b", {count: 1, text: "Form rendering snippet:"}
783784
assert_select "pre", {count: 1, text: @api_namespace.snippet}
784-
785785
assert_select "b", {count: 1, text: "API HTML Renderer index snippet:"}
786-
assert_select "pre", {count: 1, text: "{{ cms:helper api_namespace_resource_index '#{@api_namespace.slug}', scope: { properties: { property: value } } }}"}
787-
786+
assert_select "pre", {count: 1, text: "{{ cms:helper render_api_namespace_resource_index '#{@api_namespace.slug}', scope: { properties: { arr: [1, 2, 3], obj: { a: \"b\", c: \"d\"}, title: \"Hello World\", test_id: 123, alpha_arr: [\"a\", \"b\"], published: true} } }}"}
788787
assert_select "b", {count: 1, text: "API HTML Renderer show snippet:"}
789-
assert_select "pre", {count: 1, text: "{{ cms:helper api_namespace_resource '#{@api_namespace.slug}', scope: { properties: { property: value } } }}"}
788+
assert_select "pre", {count: 1, text: "{{ cms:helper render_api_namespace_resource '#{@api_namespace.slug}', scope: { properties: { arr: [1, 2, 3], obj: { a: \"b\", c: \"d\"}, title: \"Hello World\", test_id: 123, alpha_arr: [\"a\", \"b\"], published: true} } }}"}
790789
end
791790

792791
######## API Accessibility Tests - START #########

0 commit comments

Comments
 (0)