Ref #25.
Unified · Split
| @@ -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.version | 61 | if doc.version? |
| 62 | versions = '' | 62 | versions = '' |
| 63 | loop | 63 | loop |
| 64 | versions += @tmpl('sidebarDoc', doc, disabled: true) | 64 | versions += @tmpl('sidebarDoc', doc, disabled: true) |
| @@ -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.version | 37 | 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 | else | 40 | else |
| @@ -13,7 +13,7 @@ module Docs · 12 unmodified lines | |||
| 13 | end | 13 | 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 slug | 49 | def slug |
| 50 | slug = @slug || name.try(:downcase) | 50 | slug = @slug || name.try(:downcase) |
| 51 | version? ? "#{slug}~#{version}" : slug | 51 | version? ? "#{slug}~#{version.downcase.gsub(/[^a-z0-9\_\.]/, '_')}" : slug |
| 52 | end | 52 | end |
| 53 | 53 | ||
| 54 | def path | 54 | def path |
| @@ -66,7 +66,7 @@ module Docs · 11 unmodified lines | |||
| 66 | def as_json | 66 | 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 | json | 71 | json |
| 72 | end | 72 | end |
| @@ -45,9 +45,9 @@ class DocsDocTest < MiniTest::Spec · 44 unmodified lines | |||
| 45 | assert_equal 'doc', Docs::Doc.slug | 45 | assert_equal 'doc', Docs::Doc.slug |
| 46 | end | 46 | end |
| 47 | 47 | ||
| 48 | it "returns 'doc~42' when the class is Docs::Doc and its #version is '42'" do | 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 { '42' } | 49 | stub(Docs::Doc).version { '4.2 LTS' } |
| 50 | assert_equal 'doc~42', Docs::Doc.slug | 50 | assert_equal 'doc~4.2_lts', Docs::Doc.slug |
| 51 | end | 51 | end |
| 52 | 52 | ||
| 53 | it "returns 'foo~42' when #slug has been set to 'foo' and #version to '42'" do | 53 | 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 | end | 142 | end |
| 143 | end | 143 | 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 | end | 150 | end |
| 145 | 151 | ||
| 146 | describe ".store_page" do | 152 | describe ".store_page" do |