diff --git a/assets/javascripts/views/sidebar/doc_list.coffee b/assets/javascripts/views/sidebar/doc_list.coffee index 21135972..0a8b2a5a 100644 --- a/assets/javascripts/views/sidebar/doc_list.coffee +++ b/assets/javascripts/views/sidebar/doc_list.coffee @@ -58,7 +58,7 @@ class app.views.DocList extends app.View docs = [].concat(app.disabledDocs.all()...) while doc = docs.shift() - if doc.version + if doc.version? versions = '' loop versions += @tmpl('sidebarDoc', doc, disabled: true) diff --git a/assets/javascripts/views/sidebar/doc_picker.coffee b/assets/javascripts/views/sidebar/doc_picker.coffee index 9cc73183..3dae5c51 100644 --- a/assets/javascripts/views/sidebar/doc_picker.coffee +++ b/assets/javascripts/views/sidebar/doc_picker.coffee @@ -34,7 +34,7 @@ class app.views.DocPicker extends app.View docs = app.docs.all().concat(app.disabledDocs.all()...) while doc = docs.shift() - if doc.version + if doc.version? [docs, versions] = @extractVersions(docs, doc) html += @tmpl('sidebarVersionedDoc', doc, @renderVersions(versions), open: app.docs.contains(doc)) else diff --git a/lib/docs/core/doc.rb b/lib/docs/core/doc.rb index cf62ba56..52bb3a33 100644 --- a/lib/docs/core/doc.rb +++ b/lib/docs/core/doc.rb @@ -13,7 +13,7 @@ module Docs end def version(version = nil, &block) - return @version if version.nil? + return @version unless block_given? klass = Class.new(self) klass.class_exec(&block) @@ -48,7 +48,7 @@ module Docs def slug slug = @slug || name.try(:downcase) - version? ? "#{slug}~#{version}" : slug + version? ? "#{slug}~#{version.downcase.gsub(/[^a-z0-9\_\.]/, '_')}" : slug end def path @@ -66,7 +66,7 @@ module Docs def as_json json = { name: name, slug: slug, type: type } json[:links] = links if links.present? - json[:version] = version if version.present? + json[:version] = version if version.present? || defined?(@version) json[:release] = release if release.present? json end diff --git a/test/lib/docs/core/doc_test.rb b/test/lib/docs/core/doc_test.rb index d8ba011c..e836d42c 100644 --- a/test/lib/docs/core/doc_test.rb +++ b/test/lib/docs/core/doc_test.rb @@ -45,9 +45,9 @@ class DocsDocTest < MiniTest::Spec assert_equal 'doc', Docs::Doc.slug end - it "returns 'doc~42' when the class is Docs::Doc and its #version is '42'" do - stub(Docs::Doc).version { '42' } - assert_equal 'doc~42', Docs::Doc.slug + it "returns 'doc~4.2_lts' when the class is Docs::Doc and its #version is '42 LTS'" do + stub(Docs::Doc).version { '4.2 LTS' } + assert_equal 'doc~4.2_lts', Docs::Doc.slug end it "returns 'foo~42' when #slug has been set to 'foo' and #version to '42'" do @@ -141,6 +141,12 @@ class DocsDocTest < MiniTest::Spec assert_equal attribute, doc.as_json[attribute.to_sym] end end + + it "includes the doc's version when it's defined and nil" do + refute doc.as_json.key?(:version) + doc.version = nil + assert doc.as_json.key?(:version) + end end describe ".store_page" do