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
58 docs = [].concat(app.disabledDocs.all()...)58 docs = [].concat(app.disabledDocs.all()...)
59 59
60 while doc = docs.shift()60 while doc = docs.shift()
61 if doc.version61 if doc.version?
62 versions = ''62 versions = ''
63 loop63 loop
64 versions += @tmpl('sidebarDoc', doc, disabled: true)64 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
34 docs = app.docs.all().concat(app.disabledDocs.all()...)34 docs = app.docs.all().concat(app.disabledDocs.all()...)
35 35
36 while doc = docs.shift()36 while doc = docs.shift()
37 if doc.version37 if doc.version?
38 [docs, versions] = @extractVersions(docs, doc)38 [docs, versions] = @extractVersions(docs, doc)
39 html += @tmpl('sidebarVersionedDoc', doc, @renderVersions(versions), open: app.docs.contains(doc))39 html += @tmpl('sidebarVersionedDoc', doc, @renderVersions(versions), open: app.docs.contains(doc))
40 else40 else
lib/docs/core/doc.rb+3−3
@@ -13,7 +13,7 @@ module Docs · 12 unmodified lines
13 end13 end
14 14
15 def version(version = nil, &block)15 def version(version = nil, &block)
16 return @version if version.nil?16 return @version unless block_given?
17 17
18 klass = Class.new(self)18 klass = Class.new(self)
19 klass.class_exec(&block)19 klass.class_exec(&block)
@@ -48,7 +48,7 @@ module Docs · 28 unmodified lines
48 48
49 def slug49 def slug
50 slug = @slug || name.try(:downcase)50 slug = @slug || name.try(:downcase)
51 version? ? "#{slug}~#{version}" : slug51 version? ? "#{slug}~#{version.downcase.gsub(/[^a-z0-9\_\.]/, '_')}" : slug
52 end52 end
53 53
54 def path54 def path
@@ -66,7 +66,7 @@ module Docs · 11 unmodified lines
66 def as_json66 def as_json
67 json = { name: name, slug: slug, type: type }67 json = { name: name, slug: slug, type: type }
68 json[:links] = links if links.present?68 json[:links] = links if links.present?
69 json[:version] = version if version.present?69 json[:version] = version if version.present? || defined?(@version)
70 json[:release] = release if release.present?70 json[:release] = release if release.present?
71 json71 json
72 end72 end
test/lib/docs/core/doc_test.rb+9−3
@@ -45,9 +45,9 @@ class DocsDocTest < MiniTest::Spec · 44 unmodified lines
45 assert_equal 'doc', Docs::Doc.slug45 assert_equal 'doc', Docs::Doc.slug
46 end46 end
47 47
48 it "returns 'doc~42' when the class is Docs::Doc and its #version is '42'" do48 it "returns 'doc~4.2_lts' when the class is Docs::Doc and its #version is '42 LTS'" do
49 stub(Docs::Doc).version { '42' }49 stub(Docs::Doc).version { '4.2 LTS' }
50 assert_equal 'doc~42', Docs::Doc.slug50 assert_equal 'doc~4.2_lts', Docs::Doc.slug
51 end51 end
52 52
53 it "returns 'foo~42' when #slug has been set to 'foo' and #version to '42'" do53 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
141 assert_equal attribute, doc.as_json[attribute.to_sym]141 assert_equal attribute, doc.as_json[attribute.to_sym]
142 end142 end
143 end143 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
144 end150 end
145 151
146 describe ".store_page" do152 describe ".store_page" do