Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic JSON and YAML rendering in pre tag #389

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion app/helpers/blazer/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ def blazer_format_value(key, value)
link_to value, value, target: "_blank"
end
else
value
if key.include?("json")
content_tag(:pre, format_json_value(value), class: "hljs")
elsif key.include?("yaml")
content_tag(:pre, format_yaml_value(value), class: "hljs")
else
value
end
end
end

Expand All @@ -39,5 +45,19 @@ def blazer_js_var(name, value)
def blazer_series_name(k)
k.nil? ? "null" : k.to_s
end

private

def format_json_value(value)
JSON.pretty_generate(JSON.parse(value))
rescue JSON::ParserError
value
end

def format_yaml_value(value)
YAML.dump(YAML.load(value))
rescue StandardError
value
end
end
end
5 changes: 5 additions & 0 deletions app/views/blazer/queries/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@

Vue.nextTick(function () {
$("#results-html").html(data)
document.querySelectorAll("#results-html .hljs").forEach((item)=>{
if(item.textContent.length < 5000) {
hljs.highlightBlock(item)
}
});
})
}
},
Expand Down
5 changes: 5 additions & 0 deletions app/views/blazer/queries/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
function showRun(data) {
$("#results").html(data)
$("#results table").stupidtable(stupidtableCustomSettings).stickyTableHeaders({fixedOffset: 60})
document.querySelectorAll("#results .hljs").forEach((item)=>{
if(item.textContent.length < 5000) {
hljs.highlightBlock(item)
}
});
}

function showError(message) {
Expand Down