Skip to content

Commit

Permalink
Fix Javascript to work with new Haml 5.0 escape behavior
Browse files Browse the repository at this point in the history
The interpolated Ruby in a Haml :javascript filter now gets HTML escaped, breaking the way it was being used in the shared _head template to pass the set of valid languages and projects.

The fix is to pass it as an HTML dataset instead, and pull that into the Javascript afterwards. I followed the example of railsadminteam/rails_admin#2870
  • Loading branch information
ragesoss committed May 26, 2017
1 parent 896ce96 commit 0f9dd16
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/views/shared/_head.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

= javascript_include_tag '/assets/javascripts/i18n'
= javascript_include_tag '/assets/javascripts/i18n/' + I18n.locale.to_s
#wikis{:'data-projects' => Wiki::PROJECTS.to_json, :'data-languages' => Wiki::LANGUAGES.to_json}
:javascript
I18n.defaultLocale = "#{I18n.default_locale}";
I18n.locale = "#{I18n.locale}";
Expand All @@ -27,8 +28,8 @@
disableTraining: #{Features.disable_training?}
}

WikiProjects = #{Wiki::PROJECTS}
WikiLanguages = #{Wiki::LANGUAGES}
WikiProjects = document.getElementById("wikis").dataset.projects
WikiLanguages = document.getElementById("wikis").dataset.languages

SentryDsn = "#{ENV['sentry_public_dsn']}"
SalesforceServer = "#{ENV['SF_SERVER']}"
Expand Down

0 comments on commit 0f9dd16

Please sign in to comment.