Skip to content

Commit

Permalink
Merge pull request #1645 from mdyd-dev/api-for-lsp-filters
Browse files Browse the repository at this point in the history
Api for lsp filters
  • Loading branch information
Slashek authored Aug 25, 2023
2 parents ee4a685 + b034b1c commit c8ff066
Show file tree
Hide file tree
Showing 8 changed files with 407 additions and 69 deletions.
92 changes: 92 additions & 0 deletions app/views/partials/api/liquid/context.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"context": {
"authenticity_token": "dKMZZIkp7Utk7Y9E0CQ6WnC05JbvUDiHRHznS_Mif-iE9qhq4pcjwy00JWKzs-5KBxw-Q-H4igMmc-H0TnEb8A",
"session": {
"language": "en",
"_csrf_token": "O_HUDNkhlld7xL0sP2EyB7PX_mptXgRrkiZq63RO6m0",
"session_id": "52e9ae9637a28bc1d187e1fa9394acc1"
},
"csrf_request_valid": true,
"current_user": {
"first_name": "Jane",
"last_name": "Doe",
"email": "jane@doe.com",
"id": "12345",
"slug": "jane-doe"
},
"headers": {
"QUERY_STRING": ""
},
"params": {
"slug": "debug2",
"format": "html"
},
"language": "en",
"environment": "staging",
"is_xhr": false,
"instance": {
"id": 5682,
"uuid": "479c4bde-8c36-45fc-b730-95adc2649dd6",
"name": "piotrze-tests3"
},
"location": {
"url": "https://piotrze-tests3.staging.oregon.platform-os.com/debug2",
"href": "/debug2",
"host": "piotrze-tests3.staging.oregon.platform-os.com",
"pathname": "/debug2",
"search": {}
},
"page": {
"id": 8893286,
"slug": "debug2",
"enable_profiler": false,
"layout": "application",
"layout_name": "application",
"metadata": null
},
"layout": {
"metadata": null
},
"visitor": {
"ip": "185.238.205.195"
},
"useragent": "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0",
"device": {
"bot": false,
"bot_name": null,
"device_brand": null,
"device_name": null,
"device_type": "desktop",
"full_version": "116.0",
"known": true,
"name": "Firefox",
"os_full_version": null,
"os_name": "GNU/Linux"
},
"cookies": {
"_pos_session": "52e9ae9637a28bc1d187e1fa9394acc1"
},
"version": "60e9bc12f29f8b31a26e364965976a52fc72d39d",
"post_params": "",
"hcaptcha_site_key": "ce2a4f04-a5cf-4da6-bd8a-da2e74c8913a",
"globals": {
"time_zones": {
"all": "Returns array of all time zones",
"us_zones": "Returns array of all us time zones"
}
},
"modules": {
"module": {
"name": "core",
"scope_name": "core",
"version": "0.0.1",
"version_info": {
"version_name": "0.0.1"
},
"subscription_info": {}
}
},
"constants": {},
"flash": {}
}
}
30 changes: 30 additions & 0 deletions app/views/partials/api/liquid/extract.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env ruby

require 'json'

def extract(objects, node, parent_name = nil)
node.each do |k, v|
next if !v.is_a?(Hash)

type_name = v.class.name.downcase
properties = []
if v.is_a?(Hash)
properties = v.map { |kk, vv|
property_type = vv.class.name.downcase
property_type = 'number' if vv.is_a?(Numeric)
property_type = kk if vv.is_a?(Hash)
{ name: kk, type: property_type }
}
end
objects << { name: k, type: type_name, parent: parent_name, properties: properties, global: parent_name.nil? }
objects = extract(objects, v, k) if v.is_a?(Hash)
end

objects
end

context = JSON.parse(File.read('context.json'))
data = extract([], context)

File.write('objects_json.liquid', JSON.dump(data))
puts data
5 changes: 0 additions & 5 deletions app/views/partials/api/liquid/filters.liquid
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{% liquid
function filters = 'api/liquid/platformos_filters', data: data
function standard_filters = 'api/liquid/standard_filters'
log filters[0], type: 'filters[0]'
log standard_filters[0], type: 'standard_filters[0]'
%}

{{ filters | concat: standard_filters | array_sort_by: 'name' }}
{% comment %}
{{ filters | hash_merge: standard_filters | html_safe }}
{% endcomment %}
56 changes: 56 additions & 0 deletions app/views/partials/api/liquid/object.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{% liquid
if item.parent
assign parent_handle = item.parent | append: '.'
endif
%}
{% parse_json data %}
{
"access": {
"global": {{ item.global | json }},
"parents": [
{% if data.parent %}
{
"object": {{data.parent | json}},
"property": {{item.name | json}}
}
{% endif %}
],
"template": []
},
"deprecated": false,
"deprecation_reason": "",
"description": "todo description",
"properties": [
{% for property in item.properties %}
{
"deprecated": false,
"deprecation_reason": "",
"description": "",
"examples": [

],
"return_type": [
{
"type": "{{property.type}}",
"name": "",
"description": "",
"array_value": ""
}
],
"summary": "todo property summary",
"name": "{{property.name}}"
}{% unless forloop.last %},{% endunless %}
{% endfor %}
],
"summary": "todo summary",
"name": "{{item.name}}",
"examples": [],
"json_data": {
"path": "",
"handle": "{{parent_handle}}{{item.name}}",
"data_from_file": ""
},
"return_type": []
}
{% endparse_json %}
{% return data %}
69 changes: 5 additions & 64 deletions app/views/partials/api/liquid/objects.liquid
Original file line number Diff line number Diff line change
@@ -1,65 +1,6 @@
[
{
"access": {
"global": true,
"parents": [
],
"template": [
]
},
"deprecated": false,
"deprecation_reason": "",
"description": "The `user_agent` object consists of a `User-agent` directive, and a value of the name of the user-agent. For example:\n\n```\nUser-agent: *\n```\n\n&gt; Tip:\n&gt; You can [customize the `robots.txt` file](/themes/seo/robots-txt) with the [`robots.txt.liquid` template](/themes/architecture/templates/robots-txt-liquid).",
"properties": [
{
"deprecated": false,
"deprecation_reason": "",
"description": "",
"examples": [
{% liquid
function objects = 'api/liquid/platformos_objects', data: data
function standard_objects = 'api/liquid/standard_objects'
%}

],
"return_type": [
{
"type": "string",
"name": "",
"description": "",
"array_value": ""
}
],
"summary": "Returns `User-agent`.",
"name": "directive"
},
{
"deprecated": false,
"deprecation_reason": "",
"description": "",
"examples": [

],
"return_type": [
{
"type": "string",
"name": "",
"description": "",
"array_value": ""
}
],
"summary": "The name of the user-agent.",
"name": "value"
}
],
"summary": "context with all global variables",
"name": "context",
"examples": [

],
"json_data": {
"path": "/robots.txt",
"handle": "robots.default_groups[0].user_agent",
"data_from_file": ""
},
"return_type": [

]
}
]
{{ objects | concat: standard_objects | array_sort_by: 'name' }}
1 change: 1 addition & 0 deletions app/views/partials/api/liquid/objects_json.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"name":"context","type":"hash","parent":null,"properties":[{"name":"authenticity_token","type":"string"},{"name":"session","type":"session"},{"name":"csrf_request_valid","type":"trueclass"},{"name":"current_user","type":"current_user"},{"name":"headers","type":"headers"},{"name":"params","type":"params"},{"name":"language","type":"string"},{"name":"environment","type":"string"},{"name":"is_xhr","type":"falseclass"},{"name":"instance","type":"instance"},{"name":"location","type":"location"},{"name":"page","type":"page"},{"name":"layout","type":"layout"},{"name":"visitor","type":"visitor"},{"name":"useragent","type":"string"},{"name":"device","type":"device"},{"name":"cookies","type":"cookies"},{"name":"version","type":"string"},{"name":"post_params","type":"string"},{"name":"hcaptcha_site_key","type":"string"},{"name":"globals","type":"globals"},{"name":"modules","type":"modules"},{"name":"constants","type":"constants"},{"name":"flash","type":"flash"}],"global":true},{"name":"session","type":"hash","parent":"context","properties":[{"name":"language","type":"string"},{"name":"_csrf_token","type":"string"},{"name":"session_id","type":"string"}],"global":false},{"name":"current_user","type":"hash","parent":"context","properties":[{"name":"first_name","type":"string"},{"name":"last_name","type":"string"},{"name":"email","type":"string"},{"name":"id","type":"string"},{"name":"slug","type":"string"}],"global":false},{"name":"headers","type":"hash","parent":"context","properties":[{"name":"QUERY_STRING","type":"string"}],"global":false},{"name":"params","type":"hash","parent":"context","properties":[{"name":"slug","type":"string"},{"name":"format","type":"string"}],"global":false},{"name":"instance","type":"hash","parent":"context","properties":[{"name":"id","type":"number"},{"name":"uuid","type":"string"},{"name":"name","type":"string"}],"global":false},{"name":"location","type":"hash","parent":"context","properties":[{"name":"url","type":"string"},{"name":"href","type":"string"},{"name":"host","type":"string"},{"name":"pathname","type":"string"},{"name":"search","type":"search"}],"global":false},{"name":"search","type":"hash","parent":"location","properties":[],"global":false},{"name":"page","type":"hash","parent":"context","properties":[{"name":"id","type":"number"},{"name":"slug","type":"string"},{"name":"enable_profiler","type":"falseclass"},{"name":"layout","type":"string"},{"name":"layout_name","type":"string"},{"name":"metadata","type":"nilclass"}],"global":false},{"name":"layout","type":"hash","parent":"context","properties":[{"name":"metadata","type":"nilclass"}],"global":false},{"name":"visitor","type":"hash","parent":"context","properties":[{"name":"ip","type":"string"}],"global":false},{"name":"device","type":"hash","parent":"context","properties":[{"name":"bot","type":"falseclass"},{"name":"bot_name","type":"nilclass"},{"name":"device_brand","type":"nilclass"},{"name":"device_name","type":"nilclass"},{"name":"device_type","type":"string"},{"name":"full_version","type":"string"},{"name":"known","type":"trueclass"},{"name":"name","type":"string"},{"name":"os_full_version","type":"nilclass"},{"name":"os_name","type":"string"}],"global":false},{"name":"cookies","type":"hash","parent":"context","properties":[{"name":"_pos_session","type":"string"}],"global":false},{"name":"globals","type":"hash","parent":"context","properties":[{"name":"time_zones","type":"time_zones"}],"global":false},{"name":"time_zones","type":"hash","parent":"globals","properties":[{"name":"all","type":"string"},{"name":"us_zones","type":"string"}],"global":false},{"name":"modules","type":"hash","parent":"context","properties":[{"name":"module","type":"module"}],"global":false},{"name":"module","type":"hash","parent":"modules","properties":[{"name":"name","type":"string"},{"name":"scope_name","type":"string"},{"name":"version","type":"string"},{"name":"version_info","type":"version_info"},{"name":"subscription_info","type":"subscription_info"}],"global":false},{"name":"version_info","type":"hash","parent":"module","properties":[{"name":"version_name","type":"string"}],"global":false},{"name":"subscription_info","type":"hash","parent":"module","properties":[],"global":false},{"name":"constants","type":"hash","parent":"context","properties":[],"global":false},{"name":"flash","type":"hash","parent":"context","properties":[],"global":false}]
13 changes: 13 additions & 0 deletions app/views/partials/api/liquid/platformos_objects.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% parse_json data %}
{% render 'api/liquid/objects_json' %}
{% endparse_json %}
{% liquid
assign objects = '[]' | parse_json
for item in data
function object = 'api/liquid/object', item: item

assign objects = objects | array_add: object
endfor

return objects
%}
Loading

0 comments on commit c8ff066

Please sign in to comment.