History

Add support for blank and non-number version names

Ref #25.

Thibaut Courouble committed 10 years ago

Commit 3df9cff1 parent 16ddcb14 files · +14 −8Browse files

Unified · Split

4 files
  1. assets/javascripts/views/sidebar/doc_list.coffee +1 −1
  2. assets/javascripts/views/sidebar/doc_picker.coffee +1 −1
  3. lib/docs/core/doc.rb +3 −3
  4. test/lib/docs/core/doc_test.rb +9 −3
assets/javascripts/views/sidebar/doc_list.coffee+1−1
@@ -58,7 +58,7 @@ class app.views.DocList extends app.View · 57 unmodified lines
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)
assets/javascripts/views/sidebar/doc_picker.coffee+1−1
@@ -34,7 +34,7 @@ class app.views.DocPicker extends app.View · 33 unmodified lines
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
lib/docs/core/doc.rb+3−3
@@ -13,7 +13,7 @@ module Docs · 12 unmodified lines
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 @@ module Docs · 28 unmodified lines
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 @@ module Docs · 11 unmodified lines
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
test/lib/docs/core/doc_test.rb+9−3
@@ -45,9 +45,9 @@ class DocsDocTest < MiniTest::Spec · 44 unmodified lines
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 · 87 unmodified lines
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