Browse Source

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

Thibaut Courouble 9 năm trước cách đây
mục cha
commit
a59786be2e
3 tập tin đã thay đổi với 5 bổ sung5 xóa
  1. 2 1
      assets/javascripts/app/app.coffee
  2. 2 2
      test/app_test.rb
  3. 1 2
      views/other.erb

+ 2 - 1
assets/javascripts/app/app.coffee

@@ -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()

+ 2 - 2
test/app_test.rb

@@ -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

+ 1 - 2
views/other.erb

@@ -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>