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
27 @document = new app.views.Document27 @document = new app.views.Document
28 @mobile = new app.views.Mobile if @isMobile()28 @mobile = new app.views.Mobile if @isMobile()
29 29
30 if @DOC30 if document.body.hasAttribute('data-doc')
31 @DOC = JSON.parse(document.body.getAttribute('data-doc'))
31 @bootOne()32 @bootOne()
32 else if @DOCS33 else if @DOCS
33 @bootAll()34 @bootAll()
test/app_test.rb+2−2
@@ -185,13 +185,13 @@ class AppTest < MiniTest::Spec · 184 unmodified lines
185 it "works when the doc exists" do185 it "works when the doc exists" do
186 get '/html~4-foo-bar_42/'186 get '/html~4-foo-bar_42/'
187 assert last_response.ok?187 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;'
189 end189 end
190 190
191 it "works when the doc has no version in the path and a version exists" do191 it "works when the doc has no version in the path and a version exists" do
192 get '/html-foo-bar_42/'192 get '/html-foo-bar_42/'
193 assert last_response.ok?193 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;'
195 end195 end
196 196
197 it "returns 404 when the type is blank" do197 it "returns 404 when the type is blank" do
views/other.erb+1−2
@@ -13,9 +13,8 @@ · 12 unmodified lines
13 <link rel="stylesheet" href="<%= main_stylesheet_path %>" data-alt="<%= alternate_stylesheet_path %>">13 <link rel="stylesheet" href="<%= main_stylesheet_path %>" data-alt="<%= alternate_stylesheet_path %>">
14 <%= javascript_tag 'application', asset_host: false %><% unless App.production? %>14 <%= javascript_tag 'application', asset_host: false %><% unless App.production? %>
15 <%= javascript_tag 'debug' %><% end %>15 <%= javascript_tag 'debug' %><% end %>
16 <script>app.DOC = <%= @doc.to_json %>;</script>
17</head>16</head>
18<body class="_booting _noscript">17<body class="_booting _noscript" data-doc="<%= CGI::escape_html @doc.to_json %>">
19<noscript class="_fail">DevDocs requires JavaScript to run.</noscript>18<noscript class="_fail">DevDocs requires JavaScript to run.</noscript>
20<%= erb :app %></body>19<%= erb :app %></body>
21</html>20</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