Change single-doc setup to use data-attribute instead of inline script

pull/417/head
Thibaut Courouble 9 years ago
parent ebd6a2204d
commit a59786be2e

@ -27,7 +27,8 @@
@document = new app.views.Document
@mobile = new app.views.Mobile if @isMobile()
if @DOC
if document.body.hasAttribute('data-doc')
@DOC = JSON.parse(document.body.getAttribute('data-doc'))
@bootOne()
else if @DOCS
@bootAll()

@ -185,13 +185,13 @@ class AppTest < MiniTest::Spec
it "works when the doc exists" do
get '/html~4-foo-bar_42/'
assert last_response.ok?
assert_includes last_response.body, 'app.DOC = {"name":"HTML","slug":"html~4"'
assert_includes last_response.body, 'data-doc="{&quot;name&quot;:&quot;HTML&quot;,&quot;slug&quot;:&quot;html~4&quot;'
end
it "works when the doc has no version in the path and a version exists" do
get '/html-foo-bar_42/'
assert last_response.ok?
assert_includes last_response.body, 'app.DOC = {"name":"HTML","slug":"html~5"'
assert_includes last_response.body, 'data-doc="{&quot;name&quot;:&quot;HTML&quot;,&quot;slug&quot;:&quot;html~5&quot;'
end
it "returns 404 when the type is blank" do

@ -13,9 +13,8 @@
<link rel="stylesheet" href="<%= main_stylesheet_path %>" data-alt="<%= alternate_stylesheet_path %>">
<%= javascript_tag 'application', asset_host: false %><% unless App.production? %>
<%= javascript_tag 'debug' %><% end %>
<script>app.DOC = <%= @doc.to_json %>;</script>
</head>
<body class="_booting _noscript">
<body class="_booting _noscript" data-doc="<%= CGI::escape_html @doc.to_json %>">
<noscript class="_fail">DevDocs requires JavaScript to run.</noscript>
<%= erb :app %></body>
</html>

Loading…
Cancel
Save