File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ class app.views.DocList extends app.View
5858 docs = [].concat (app .disabledDocs .all ()... )
5959
6060 while doc = docs .shift ()
61- if doc .version
61+ if doc .version ?
6262 versions = ' '
6363 loop
6464 versions += @ tmpl (' sidebarDoc' , doc, disabled : true )
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ class app.views.DocPicker extends app.View
3434 docs = app .docs .all ().concat (app .disabledDocs .all ()... )
3535
3636 while doc = docs .shift ()
37- if doc .version
37+ if doc .version ?
3838 [docs , versions ] = @ extractVersions (docs, doc)
3939 html += @ tmpl (' sidebarVersionedDoc' , doc, @ renderVersions (versions), open : app .docs .contains (doc))
4040 else
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ def inherited(subclass)
1313 end
1414
1515 def version ( version = nil , &block )
16- return @version if version . nil ?
16+ return @version unless block_given ?
1717
1818 klass = Class . new ( self )
1919 klass . class_exec ( &block )
@@ -48,7 +48,7 @@ def name
4848
4949 def slug
5050 slug = @slug || name . try ( :downcase )
51- version? ? "#{ slug } ~#{ version } " : slug
51+ version? ? "#{ slug } ~#{ version . downcase . gsub ( /[^a-z0-9 \_ \. ]/ , '_' ) } " : slug
5252 end
5353
5454 def path
@@ -66,7 +66,7 @@ def db_path
6666 def as_json
6767 json = { name : name , slug : slug , type : type }
6868 json [ :links ] = links if links . present?
69- json [ :version ] = version if version . present?
69+ json [ :version ] = version if version . present? || defined? ( @version )
7070 json [ :release ] = release if release . present?
7171 json
7272 end
Original file line number Diff line number Diff line change @@ -45,9 +45,9 @@ class DocsDocTest < MiniTest::Spec
4545 assert_equal 'doc' , Docs ::Doc . slug
4646 end
4747
48- it "returns 'doc~42 ' when the class is Docs::Doc and its #version is '42'" do
49- stub ( Docs ::Doc ) . version { '42 ' }
50- assert_equal 'doc~42 ' , Docs ::Doc . slug
48+ it "returns 'doc~4.2_lts ' when the class is Docs::Doc and its #version is '42 LTS '" do
49+ stub ( Docs ::Doc ) . version { '4.2 LTS ' }
50+ assert_equal 'doc~4.2_lts ' , Docs ::Doc . slug
5151 end
5252
5353 it "returns 'foo~42' when #slug has been set to 'foo' and #version to '42'" do
@@ -141,6 +141,12 @@ class DocsDocTest < MiniTest::Spec
141141 assert_equal attribute , doc . as_json [ attribute . to_sym ]
142142 end
143143 end
144+
145+ it "includes the doc's version when it's defined and nil" do
146+ refute doc . as_json . key? ( :version )
147+ doc . version = nil
148+ assert doc . as_json . key? ( :version )
149+ end
144150 end
145151
146152 describe ".store_page" do
You can’t perform that action at this time.
0 commit comments