Skip to content

Commit a59786b

Browse files
committed
Change single-doc setup to use data-attribute instead of inline script
1 parent ebd6a22 commit a59786b

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

assets/javascripts/app/app.coffee

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
@document = new app.views.Document
2828
@mobile = new app.views.Mobile if @isMobile()
2929

30-
if @DOC
30+
if document.body.hasAttribute('data-doc')
31+
@DOC = JSON.parse(document.body.getAttribute('data-doc'))
3132
@bootOne()
3233
else if @DOCS
3334
@bootAll()

test/app_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,13 @@ def app
185185
it "works when the doc exists" do
186186
get '/html~4-foo-bar_42/'
187187
assert last_response.ok?
188-
assert_includes last_response.body, 'app.DOC = {"name":"HTML","slug":"html~4"'
188+
assert_includes last_response.body, 'data-doc="{"name":"HTML","slug":"html~4"'
189189
end
190190

191191
it "works when the doc has no version in the path and a version exists" do
192192
get '/html-foo-bar_42/'
193193
assert last_response.ok?
194-
assert_includes last_response.body, 'app.DOC = {"name":"HTML","slug":"html~5"'
194+
assert_includes last_response.body, 'data-doc="{"name":"HTML","slug":"html~5"'
195195
end
196196

197197
it "returns 404 when the type is blank" do

views/other.erb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
<link rel="stylesheet" href="<%= main_stylesheet_path %>" data-alt="<%= alternate_stylesheet_path %>">
1414
<%= javascript_tag 'application', asset_host: false %><% unless App.production? %>
1515
<%= javascript_tag 'debug' %><% end %>
16-
<script>app.DOC = <%= @doc.to_json %>;</script>
1716
</head>
18-
<body class="_booting _noscript">
17+
<body class="_booting _noscript" data-doc="<%= CGI::escape_html @doc.to_json %>">
1918
<noscript class="_fail">DevDocs requires JavaScript to run.</noscript>
2019
<%= erb :app %></body>
2120
</html>

0 commit comments

Comments
 (0)