Ref #25.
Unified · Split
| @@ -58,7 +58,7 @@ class app.views.DocList extends app.View · 57 unmodified lines | ||
| 58 | 58 | docs = [].concat(app.disabledDocs.all()...) |
| 59 | 59 | |
| 60 | 60 | while doc = docs.shift() |
| 61 | − if doc.version | |
| 61 | + if doc.version? | |
| 62 | 62 | versions = '' |
| 63 | 63 | loop |
| 64 | 64 | versions += @tmpl('sidebarDoc', doc, disabled: true) |
| @@ -34,7 +34,7 @@ class app.views.DocPicker extends app.View · 33 unmodified lines | ||
| 34 | 34 | docs = app.docs.all().concat(app.disabledDocs.all()...) |
| 35 | 35 | |
| 36 | 36 | while doc = docs.shift() |
| 37 | − if doc.version | |
| 37 | + if doc.version? | |
| 38 | 38 | [docs, versions] = @extractVersions(docs, doc) |
| 39 | 39 | html += @tmpl('sidebarVersionedDoc', doc, @renderVersions(versions), open: app.docs.contains(doc)) |
| 40 | 40 | else |
| @@ -13,7 +13,7 @@ module Docs · 12 unmodified lines | ||
| 13 | 13 | end |
| 14 | 14 | |
| 15 | 15 | def version(version = nil, &block) |
| 16 | − return @version if version.nil? | |
| 16 | + return @version unless block_given? | |
| 17 | 17 | |
| 18 | 18 | klass = Class.new(self) |
| 19 | 19 | klass.class_exec(&block) |
| @@ -48,7 +48,7 @@ module Docs · 28 unmodified lines | ||
| 48 | 48 | |
| 49 | 49 | def slug |
| 50 | 50 | slug = @slug || name.try(:downcase) |
| 51 | − version? ? "#{slug}~#{version}" : slug | |
| 51 | + version? ? "#{slug}~#{version.downcase.gsub(/[^a-z0-9\_\.]/, '_')}" : slug | |
| 52 | 52 | end |
| 53 | 53 | |
| 54 | 54 | def path |
| @@ -66,7 +66,7 @@ module Docs · 11 unmodified lines | ||
| 66 | 66 | def as_json |
| 67 | 67 | json = { name: name, slug: slug, type: type } |
| 68 | 68 | json[:links] = links if links.present? |
| 69 | − json[:version] = version if version.present? | |
| 69 | + json[:version] = version if version.present? || defined?(@version) | |
| 70 | 70 | json[:release] = release if release.present? |
| 71 | 71 | json |
| 72 | 72 | end |
| @@ -45,9 +45,9 @@ class DocsDocTest < MiniTest::Spec · 44 unmodified lines | ||
| 45 | 45 | assert_equal 'doc', Docs::Doc.slug |
| 46 | 46 | end |
| 47 | 47 | |
| 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 | |
| 51 | 51 | end |
| 52 | 52 | |
| 53 | 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 | 141 | assert_equal attribute, doc.as_json[attribute.to_sym] |
| 142 | 142 | end |
| 143 | 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 | 150 | end |
| 145 | 151 | |
| 146 | 152 | describe ".store_page" do |