Improve Doc#name and Doc#slug

pull/602/head
Thibaut Courouble 8 years ago
parent b36f3f8095
commit c1ebb7a0b9

@ -44,14 +44,11 @@ module Docs
end end
def name def name
@name || super.try(:demodulize) @name || super.demodulize
end end
def slug def slug
slug = @slug || ( slug = @slug || default_slug || raise('slug is required')
raise "Slug must be set explicitly when name (#{name}) consists of anything else than [\\w\\.%]" if /[^\w\.%]/ =~ name
name.try(:downcase)
)
version? ? "#{slug}~#{version_slug}" : slug version? ? "#{slug}~#{version_slug}" : slug
end end
@ -119,6 +116,11 @@ module Docs
private private
def default_slug
return if name =~ /[^A-Za-z0-9_]/
name.downcase
end
def store_page?(page) def store_page?(page)
page[:entries].present? page[:entries].present?
end end

@ -3,7 +3,9 @@ require 'docs'
class ManifestTest < MiniTest::Spec class ManifestTest < MiniTest::Spec
let :doc do let :doc do
Class.new Docs::Doc doc = Class.new Docs::Doc
doc.name = 'TestDoc'
doc
end end
let :store do let :store do

Loading…
Cancel
Save