Skip to content

Commit 3599da6

Browse files
committed
chore: Remove erb templete requirments from editor
Configurations can be suppied to JavaScript with data attributes. This simplifies the JavaScript migration to Webpack.
1 parent e9d4d79 commit 3599da6

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

app/assets/javascripts/editor/editor.js.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var CodeOceanEditor = {
3333

3434
lastCopyText: null,
3535

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

app/assets/javascripts/editor/participantsupport.js.erb renamed to app/assets/javascripts/editor/participantsupport.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CodeOceanEditorFlowr = {
2-
isFlowrEnabled: <%= CodeOcean::Config.new(:code_ocean).read[:flowr][:enabled] %>,
2+
isFlowrEnabled: document.documentElement.dataset.flowrEnabled === 'true',
33
flowrResultHtml:
44
'<div class="card mb-2">' +
55
'<div id="{{headingId}}" role="tab" class="card-header">' +
@@ -29,7 +29,7 @@ CodeOceanEditorFlowr = {
2929
var stackoverflowRequests = _.map(insights, function (insight) {
3030
var queryParams = {
3131
accepted: true,
32-
pagesize: <%= CodeOcean::Config.new(:code_ocean).read[:flowr][:answers_per_query] or 3 %>,
32+
pagesize: Number(document.documentElement.dataset.flowrAnswersPerQuery),
3333
order: 'desc',
3434
sort: 'relevance',
3535
site: 'stackoverflow',

app/helpers/application_helper.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,13 @@ def value_column(value)
9191
def yes
9292
tag.i(nil, class: 'fa-solid fa-check')
9393
end
94+
95+
def html_data_attributes
96+
{
97+
'data-default-locale' => I18n.default_locale,
98+
'data-events-enabled' => CodeOcean::Config.new(:code_ocean).read.dig('codeocean_events', 'enabled'),
99+
'data-flowr-enabled' => CodeOcean::Config.new(:code_ocean).read.dig(:flowr, :enabled),
100+
'data-flowr-answers-per-query' => CodeOcean::Config.new(:code_ocean).read[:flowranswers_per_query] || 3,
101+
}
102+
end
94103
end

app/views/layouts/application.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
doctype html
2-
html lang=I18n.locale data-default-locale=I18n.default_locale
2+
html lang=I18n.locale *html_data_attributes
33
head
44
meta charset='utf-8'
55
meta name='viewport' content='width=device-width, initial-scale=1'

0 commit comments

Comments
 (0)