History

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

Thibaut Courouble committed 10 years ago

Commit a59786b1 parent ebd6a223 files · +5 −5Browse files

Unified · Split

3 files
  1. assets/javascripts/app/app.coffee +2 −1
  2. test/app_test.rb +2 −2
  3. views/other.erb +1 −2
assets/javascripts/app/app.coffee+2−1
@@ -27,7 +27,8 @@ · 26 unmodified lines
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+2−2
@@ -185,13 +185,13 @@ class AppTest < MiniTest::Spec · 184 unmodified lines
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="{&quot;name&quot;:&quot;HTML&quot;,&quot;slug&quot;:&quot;html~4&quot;'
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="{&quot;name&quot;:&quot;HTML&quot;,&quot;slug&quot;:&quot;html~5&quot;'
195195 end
196196
197197 it "returns 404 when the type is blank" do
views/other.erb+1−2
@@ -13,9 +13,8 @@ · 12 unmodified lines
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>

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t