Add support for blank and non-number version names

Ref #25.
This commit is contained in:
Thibaut Courouble 2016-01-24 12:55:46 -05:00
parent 16ddcb100c
commit 3df9cfff98
4 changed files with 14 additions and 8 deletions

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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