Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
// Note: Directives are only processed if they come before any application code.
// Once you have a line that does not include a comment or whitespace then Sprockets will stop looking for directives.
// If you use a directive outside of the "header" of the document it will not do anything, and won't raise any errors.
// <% config_file = CodeOcean::Config.new(:code_ocean, erb: false) %>
//= depend_on <%= config_file.path.basename %>

var CodeOceanEditor = {
THEME: window.getCurrentTheme() === 'dark' ? 'ace/theme/tomorrow_night' : 'ace/theme/tomorrow',

Expand Down Expand Up @@ -33,7 +27,7 @@ var CodeOceanEditor = {

lastCopyText: null,

sendEvents: <%= config_file.read['codeocean_events'] ? config_file.read['codeocean_events']['enabled'] : false %>,
sendEvents: document.documentElement.dataset.eventsEnabled === 'true',
eventURL: Routes.events_path(),
fileTypeURL: Routes.file_types_path(),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CodeOceanEditorFlowr = {
isFlowrEnabled: <%= CodeOcean::Config.new(:code_ocean).read[:flowr][:enabled] %>,
isFlowrEnabled: document.documentElement.dataset.flowrEnabled === 'true',
Comment thread
MrSerth marked this conversation as resolved.
flowrResultHtml:
'<div class="card mb-2">' +
'<div id="{{headingId}}" role="tab" class="card-header">' +
Expand Down Expand Up @@ -29,7 +29,7 @@ CodeOceanEditorFlowr = {
var stackoverflowRequests = _.map(insights, function (insight) {
var queryParams = {
accepted: true,
pagesize: <%= CodeOcean::Config.new(:code_ocean).read[:flowr][:answers_per_query] or 3 %>,
pagesize: Number(document.documentElement.dataset.flowrAnswersPerQuery),
order: 'desc',
sort: 'relevance',
site: 'stackoverflow',
Expand Down
11 changes: 11 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,15 @@ def value_column(value)
def yes
tag.i(nil, class: 'fa-solid fa-check')
end

def html_data_attributes
config = CodeOcean::Config.new(:code_ocean).read

{
'data-default-locale' => I18n.default_locale,
'data-events-enabled' => config.dig(:codeocean_events, :enabled),
'data-flowr-enabled' => config.dig(:flowr, :enabled),
'data-flowr-answers-per-query' => config.dig(:flowr, :answers_per_query) || 3,
}
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.slim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
doctype html
html lang=I18n.locale data-default-locale=I18n.default_locale
html lang=I18n.locale *html_data_attributes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After we got the other parts right here, I am returning to my previous question regarding the gloabl scope.

Previously, you wrote:

The JavaScript needs this when the page loads. I don't want to make too large changes to JavaScript at the moment.

Some of the data attributes are not needed when the page loads, but can also be parsed later, I'd say. Rather than touching this part multiple times, I would suggest to get it right now.

head
meta charset='utf-8'
meta name='viewport' content='width=device-width, initial-scale=1'
Expand Down