Add support for blank and non-number version names

Ref #25.
pull/308/merge
Thibaut Courouble 9 years ago
parent 16ddcb100c
commit 3df9cfff98

@ -58,7 +58,7 @@ class app.views.DocList extends app.View
docs = [].concat(app.disabledDocs.all()...) docs = [].concat(app.disabledDocs.all()...)
while doc = docs.shift() while doc = docs.shift()
if doc.version if doc.version?
versions = '' versions = ''
loop loop
versions += @tmpl('sidebarDoc', doc, disabled: true) versions += @tmpl('sidebarDoc', doc, disabled: true)

@ -34,7 +34,7 @@ class app.views.DocPicker extends app.View
docs = app.docs.all().concat(app.disabledDocs.all()...) docs = app.docs.all().concat(app.disabledDocs.all()...)
while doc = docs.shift() while doc = docs.shift()
if doc.version if doc.version?
[docs, versions] = @extractVersions(docs, doc) [docs, versions] = @extractVersions(docs, doc)
html += @tmpl('sidebarVersionedDoc', doc, @renderVersions(versions), open: app.docs.contains(doc)) html += @tmpl('sidebarVersionedDoc', doc, @renderVersions(versions), open: app.docs.contains(doc))
else else

@ -13,7 +13,7 @@ module Docs
end end
def version(version = nil, &block) def version(version = nil, &block)
return @version if version.nil? return @version unless block_given?
klass = Class.new(self) klass = Class.new(self)
klass.class_exec(&block) klass.class_exec(&block)
@ -48,7 +48,7 @@ module Docs
def slug def slug
slug = @slug || name.try(:downcase) slug = @slug || name.try(:downcase)
version? ? "#{slug}~#{version}" : slug version? ? "#{slug}~#{version.downcase.gsub(/[^a-z0-9\_\.]/, '_')}" : slug
end end
def path def path
@ -66,7 +66,7 @@ module Docs
def as_json def as_json
json = { name: name, slug: slug, type: type } json = { name: name, slug: slug, type: type }
json[:links] = links if links.present? 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[:release] = release if release.present?
json json
end end

@ -45,9 +45,9 @@ class DocsDocTest < MiniTest::Spec
assert_equal 'doc', Docs::Doc.slug assert_equal 'doc', Docs::Doc.slug
end end
it "returns 'doc~42' when the class is Docs::Doc and its #version is '42'" do it "returns 'doc~4.2_lts' when the class is Docs::Doc and its #version is '42 LTS'" do
stub(Docs::Doc).version { '42' } stub(Docs::Doc).version { '4.2 LTS' }
assert_equal 'doc~42', Docs::Doc.slug assert_equal 'doc~4.2_lts', Docs::Doc.slug
end end
it "returns 'foo~42' 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
@ -141,6 +141,12 @@ class DocsDocTest < MiniTest::Spec
assert_equal attribute, doc.as_json[attribute.to_sym] assert_equal attribute, doc.as_json[attribute.to_sym]
end end
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 end
describe ".store_page" do describe ".store_page" do

Loading…
Cancel
Save