From c1ebb7a0b963cc547521743a35a97b595d9321bd Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sat, 4 Mar 2017 10:58:05 -0500 Subject: [PATCH] Improve Doc#name and Doc#slug --- lib/docs/core/doc.rb | 12 +++++++----- test/lib/docs/core/manifest_test.rb | 4 +++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/docs/core/doc.rb b/lib/docs/core/doc.rb index 5baa9973..73323fec 100644 --- a/lib/docs/core/doc.rb +++ b/lib/docs/core/doc.rb @@ -44,14 +44,11 @@ module Docs end def name - @name || super.try(:demodulize) + @name || super.demodulize end def slug - slug = @slug || ( - raise "Slug must be set explicitly when name (#{name}) consists of anything else than [\\w\\.%]" if /[^\w\.%]/ =~ name - name.try(:downcase) - ) + slug = @slug || default_slug || raise('slug is required') version? ? "#{slug}~#{version_slug}" : slug end @@ -119,6 +116,11 @@ module Docs private + def default_slug + return if name =~ /[^A-Za-z0-9_]/ + name.downcase + end + def store_page?(page) page[:entries].present? end diff --git a/test/lib/docs/core/manifest_test.rb b/test/lib/docs/core/manifest_test.rb index 1138b9c6..ccf8d247 100644 --- a/test/lib/docs/core/manifest_test.rb +++ b/test/lib/docs/core/manifest_test.rb @@ -3,7 +3,9 @@ require 'docs' class ManifestTest < MiniTest::Spec let :doc do - Class.new Docs::Doc + doc = Class.new Docs::Doc + doc.name = 'TestDoc' + doc end let :store do