Bläddra i källkod

Simplify version path separator

Ref #25.
Thibaut Courouble 10 år sedan
förälder
incheckning
16ddcb100c

+ 1 - 1
assets/javascripts/models/doc.coffee

@@ -4,7 +4,7 @@ class app.models.Doc extends app.Model
   constructor: ->
   constructor: ->
     super
     super
     @reset @
     @reset @
-    @slug_without_version = @slug.split('~v')[0]
+    @slug_without_version = @slug.split('~')[0]
     @fullName = "#{@name}" + if @version then " #{@version}" else ''
     @fullName = "#{@name}" + if @version then " #{@version}" else ''
     @icon = @slug_without_version
     @icon = @slug_without_version
     @text = @toEntry().text
     @text = @toEntry().text

+ 2 - 2
lib/app.rb

@@ -123,7 +123,7 @@ class App < Sinatra::Application
 
 
     def find_doc(slug)
     def find_doc(slug)
       settings.docs[slug] || begin
       settings.docs[slug] || begin
-        slug = "#{slug}~v"
+        slug = "#{slug}~"
         settings.docs.each do |_slug, _doc|
         settings.docs.each do |_slug, _doc|
           return _doc if _slug.start_with?(slug)
           return _doc if _slug.start_with?(slug)
         end
         end
@@ -133,7 +133,7 @@ class App < Sinatra::Application
 
 
     def user_has_docs?(slug)
     def user_has_docs?(slug)
       docs.include?(slug) || begin
       docs.include?(slug) || begin
-        slug = "#{slug}~v"
+        slug = "#{slug}~"
         docs.any? { |_slug| _slug.start_with?(slug) }
         docs.any? { |_slug| _slug.start_with?(slug) }
       end
       end
     end
     end

+ 1 - 1
lib/docs/core/doc.rb

@@ -48,7 +48,7 @@ module Docs
 
 
       def slug
       def slug
         slug = @slug || name.try(:downcase)
         slug = @slug || name.try(:downcase)
-        version? ? "#{slug}~v#{version}" : slug
+        version? ? "#{slug}~#{version}" : slug
       end
       end
 
 
       def path
       def path

+ 13 - 13
test/app_test.rb

@@ -80,11 +80,11 @@ class AppTest < MiniTest::Spec
     end
     end
 
 
     it "works with cookie" do
     it "works with cookie" do
-      set_cookie('docs=css/html~v5')
+      set_cookie('docs=css/html~5')
       get '/manifest.appcache'
       get '/manifest.appcache'
       assert last_response.ok?
       assert last_response.ok?
       assert_includes last_response.body, '/css/index.json?1420139788'
       assert_includes last_response.body, '/css/index.json?1420139788'
-      assert_includes last_response.body, '/html~v5/index.json?1420139791'
+      assert_includes last_response.body, '/html~5/index.json?1420139791'
     end
     end
 
 
     it "ignores invalid docs in the cookie" do
     it "ignores invalid docs in the cookie" do
@@ -127,17 +127,17 @@ class AppTest < MiniTest::Spec
 
 
   describe "/[doc]" do
   describe "/[doc]" do
     it "renders when the doc exists and isn't enabled" do
     it "renders when the doc exists and isn't enabled" do
-      set_cookie('docs=html~v5')
-      get '/html~v4/', {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
+      set_cookie('docs=html~5')
+      get '/html~4/', {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
       assert last_response.ok?
       assert last_response.ok?
     end
     end
 
 
     it "redirects via JS cookie when the doc exists and is enabled" do
     it "redirects via JS cookie when the doc exists and is enabled" do
-      set_cookie('docs=html~v5')
-      get '/html~v5/', {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
+      set_cookie('docs=html~5')
+      get '/html~5/', {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
       assert last_response.redirect?
       assert last_response.redirect?
       assert_equal 'http://example.org/', last_response['Location']
       assert_equal 'http://example.org/', last_response['Location']
-      assert last_response['Set-Cookie'].start_with?("initial_path=%2Fhtml%7Ev5%2F; path=/; expires=")
+      assert last_response['Set-Cookie'].start_with?("initial_path=%2Fhtml%7E5%2F; path=/; expires=")
     end
     end
 
 
     it "renders when the doc exists, has no version in the path, and isn't enabled" do
     it "renders when the doc exists, has no version in the path, and isn't enabled" do
@@ -146,7 +146,7 @@ class AppTest < MiniTest::Spec
     end
     end
 
 
     it "redirects via JS cookie when the doc exists, has no version in the path, and a version is enabled" do
     it "redirects via JS cookie when the doc exists, has no version in the path, and a version is enabled" do
-      set_cookie('docs=html~v5')
+      set_cookie('docs=html~5')
       get '/html/', {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
       get '/html/', {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
       assert last_response.redirect?
       assert last_response.redirect?
       assert_equal 'http://example.org/', last_response['Location']
       assert_equal 'http://example.org/', last_response['Location']
@@ -160,7 +160,7 @@ class AppTest < MiniTest::Spec
     end
     end
 
 
     it "returns 404 when the doc doesn't exist" do
     it "returns 404 when the doc doesn't exist" do
-      get '/html~v6/'
+      get '/html~6/'
       assert last_response.not_found?
       assert last_response.not_found?
     end
     end
 
 
@@ -177,15 +177,15 @@ class AppTest < MiniTest::Spec
 
 
   describe "/[doc]-[type]" do
   describe "/[doc]-[type]" do
     it "works when the doc exists" do
     it "works when the doc exists" do
-      get '/html~v4-foo-bar_42/'
+      get '/html~4-foo-bar_42/'
       assert last_response.ok?
       assert last_response.ok?
-      assert_includes last_response.body, 'app.DOC = {"name":"HTML","slug":"html~v4"'
+      assert_includes last_response.body, 'app.DOC = {"name":"HTML","slug":"html~4"'
     end
     end
 
 
     it "works when the doc has no version in the path and a version exists" do
     it "works when the doc has no version in the path and a version exists" do
       get '/html-foo-bar_42/'
       get '/html-foo-bar_42/'
       assert last_response.ok?
       assert last_response.ok?
-      assert_includes last_response.body, 'app.DOC = {"name":"HTML","slug":"html~v5"'
+      assert_includes last_response.body, 'app.DOC = {"name":"HTML","slug":"html~5"'
     end
     end
 
 
     it "returns 404 when the type is blank" do
     it "returns 404 when the type is blank" do
@@ -199,7 +199,7 @@ class AppTest < MiniTest::Spec
     end
     end
 
 
     it "returns 404 when the doc doesn't exist" do
     it "returns 404 when the doc doesn't exist" do
-      get '/html~v6-bar/'
+      get '/html~6-bar/'
       assert last_response.not_found?
       assert last_response.not_found?
     end
     end
 
 

+ 1 - 1
test/files/docs.json

@@ -1 +1 @@
-[{"name":"CSS","slug":"css","type":"mdn","release":null,"mtime":1420139788,"db_size":3460507},{"name":"DOM","slug":"dom","type":"mdn","release":null,"mtime":1420139789,"db_size":11399128},{"name":"DOM Events","slug":"dom_events","type":"mdn","release":null,"mtime":1420139790,"db_size":889020},{"name":"HTML","slug":"html~v5","type":"mdn","version":"5","mtime":1420139791,"db_size":1835647},{"name":"HTML","slug":"html~v4","type":"mdn","version":"4","mtime":1420139790,"db_size":1835646},{"name":"HTTP","slug":"http","type":"rfc","release":null,"mtime":1420139790,"db_size":183083},{"name":"JavaScript","slug":"javascript","type":"mdn","release":null,"mtime":1420139791,"db_size":4125477}]
+[{"name":"CSS","slug":"css","type":"mdn","release":null,"mtime":1420139788,"db_size":3460507},{"name":"DOM","slug":"dom","type":"mdn","release":null,"mtime":1420139789,"db_size":11399128},{"name":"DOM Events","slug":"dom_events","type":"mdn","release":null,"mtime":1420139790,"db_size":889020},{"name":"HTML","slug":"html~5","type":"mdn","version":"5","mtime":1420139791,"db_size":1835647},{"name":"HTML","slug":"html~4","type":"mdn","version":"4","mtime":1420139790,"db_size":1835646},{"name":"HTTP","slug":"http","type":"rfc","release":null,"mtime":1420139790,"db_size":183083},{"name":"JavaScript","slug":"javascript","type":"mdn","release":null,"mtime":1420139791,"db_size":4125477}]

+ 4 - 4
test/lib/docs/core/doc_test.rb

@@ -45,15 +45,15 @@ class DocsDocTest < MiniTest::Spec
       assert_equal 'doc', Docs::Doc.slug
       assert_equal 'doc', Docs::Doc.slug
     end
     end
 
 
-    it "returns 'doc~v42' when the class is Docs::Doc and its #version is '42'" do
+    it "returns 'doc~42' when the class is Docs::Doc and its #version is '42'" do
       stub(Docs::Doc).version { '42' }
       stub(Docs::Doc).version { '42' }
-      assert_equal 'doc~v42', Docs::Doc.slug
+      assert_equal 'doc~42', Docs::Doc.slug
     end
     end
 
 
-    it "returns 'foo~v42' when #slug has been set to 'foo' and #version to '42'" do
+    it "returns 'foo~42' when #slug has been set to 'foo' and #version to '42'" do
       doc.slug = 'foo'
       doc.slug = 'foo'
       doc.version = '42'
       doc.version = '42'
-      assert_equal 'foo~v42', doc.slug
+      assert_equal 'foo~42', doc.slug
     end
     end
   end
   end