Implement Page#title.

This commit is contained in:
Tom Preston-Werner
2010-07-22 14:48:46 -07:00
parent 792c682f1d
commit 1af9898b4d
57 changed files with 60 additions and 44 deletions
+1
View File
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
s.add_dependency('sinatra', "~> 1.0.0")
s.add_dependency('mustache', [">= 0.11.2", "< 1.0.0"])
s.add_dependency('sanitize', "~> 1.0.0")
s.add_dependency('nokogiri', "~> 1.0.0")
s.add_development_dependency('shoulda')
s.add_development_dependency('mocha')
+1 -3
View File
@@ -223,9 +223,7 @@ html {overflow-y: scroll;}
}
.wikistyle h1:first-child {
margin-top: 0 !important;
padding-top: .25em !important;
border-top: none !important;
display: none;
}
.wikistyle h2 {
+1 -1
View File
@@ -4,7 +4,7 @@ module Precious
attr_reader :content, :page
def human_name
@name.gsub(/-/, ' ')
@page.title
end
def title
+23 -1
View File
@@ -52,6 +52,28 @@ module Gollum
@blob && @blob.name
end
# Public: If the first element of a formatted page is an <h1> tag it can
# be considered the title of the page and used in the display. If the
# first element is NOT an <h1> tag, the title will be constructed from the
# filename by stripping the extension and replacing any dashes with
# spaces.
#
# Returns the fully sanitized String title.
def title
doc = Nokogiri::HTML(self.formatted_data)
if doc.first_element_child &&
doc.first_element_child.children &&
doc.first_element_child.children.first &&
doc.first_element_child.children.first.children &&
doc.first_element_child.children.first.children.first &&
doc.first_element_child.children.first.children.first.name &&
doc.first_element_child.children.first.children.first.name == 'h1'
Sanitize.clean(doc.first_element_child.children.first.children.first.to_html)
else
Sanitize.clean(self.name.split('.')[0..-2].join('.').gsub('-', ' '))
end
end
# Public: The path of the page within the repo.
#
# Returns the String path.
@@ -134,7 +156,7 @@ module Gollum
#
# Returns the String canonical name.
def self.cname(name)
name.gsub(%r{[ /]}, '-')
name.gsub(%r{[ /<>]}, '-')
end
# Convert a format Symbol into an extension String.
+1
View File
@@ -0,0 +1 @@
d61c3de65957b5997c236393b3ad4d70b5cd8931 refs/heads/master
@@ -1,3 +0,0 @@
xŽK
1}‘ɯ{"Á…à:ŸŽi‰ñþÎʸy‹¢
^–ÖÖÆúÃè̬vI‡ì‘Ù‰”CÉ–BXB´¦úìÐR¯Øy ™4F«i‰„•m`¦´,uÎÕ”ì¢sä+ªøép“×Îï!Ûtç¾q‡Óviò”–䘥AZ9‹¦™æYít9vù¿^Õµ3üF}ɆJü
@@ -1,2 +0,0 @@
xA
Â0E]çsÊ4i3-ˆx‚ë$`…é@:Þß‚7pûyïý¢"«A?'kÌÀ¥r‰†ŒiX|
@@ -1 +0,0 @@
x’AΣ@ …9Ο―°΄‡‚ΤMO Δ± 8P8TrObe2<“ϊορd[΅έR.φΌ<Ο3uή½}κφj=vΗδά³8Aξ &•DNΔΓΡZ¥®9Ζ0$J€ΰiq8M„±±ΗUώM΄·Η.m!/rλbΖ …p?DYbiN_+8”Ο% Lρ|ή$π ,ΚΉΨT«{ΚΆ—d0ΟjkBR@R–Π‚W
@@ -0,0 +1,2 @@
xŽKNC1 EgÞ@«|»–êˆ1$ÆIì'JIŒÒtÀîyk`zuÎÑmÖûuALô´¦*HËŒ‚5Šœ¹TŸâv*UH²VòX[ -°û)SÇÁÐ’(fÎT33µ˜0qª©ÈIÈ×ÜöP
®<Ö§Mx·oSïËÆáCçÐ ÏËú¥Û—õjÇfýB$>'dŽpðä½Û×ýåÚáÿùîõ1n¿°]¿FéztéML
@@ -1,2 +0,0 @@
xM
Β0F]ηsJ:™ζD< Αυ¤ B:%Ζ…··gpω=ήƒoΦZΠΡ΅7Η)η’Dk‰Ω³υ(qN#ν[Z27Y;d%eοCIΘ'XM.Δ9ΰbψΣΪমMή]Χα.m•§®υRυ¥5λqΦz†C¤0Z?Α`ƒµf§ϋΛΎΛυ†—δ+°=΄«ωo#J
@@ -1,2 +0,0 @@
x]’AÓ@ …9ϯ°Ä¡ uSqÙÇ" 8PŠ8Tr'±2Gw£þ{<ÙVˆ•r±çåù{ž©£ÔðøîñÕkØs¬öØ÷œrÿ•Àl ˜U {Iœ
¤ƒ£·>K]³¦0f GÊ€ÐÑN«ü›h[~-nN}Þ‚-rïLâÆ Åø0&YRiŸN_+8”/%ŽLé|Þdè0æ+,ÊVlªÕ=›èõYGhuÍ-¡G) AÉ$¶Ð©LŽÛrבR2˜IóLñèúaÀÙH×?.ôþ£R-ê’ð+uì+¨…#FÊU_<í3­³&TÅÕ¯ßÛ¶/7ƒ£ÄuÄ=GÿÎméÁWg.P
@@ -1,2 +0,0 @@
ÍM
Â0P×=Å\ ’¯M Eܹu!¸NÒé4‰“û Á<^””6%ô8if¦¶k{c]˜mg
@@ -1,2 +0,0 @@
xKjΓ0@»Φ)ζ)#{$ ”΅‹@ΧϊhΪΘdωώρΆθφρΌΆ½ί&,k|™C¨„€iuK³ΒƒΝ±q‰#ΚΝEDnΙ<mBΖj‘Χ…ΙE!j­Q
ΎT³ΕZΛJ©΅l1ΏuΐU;|Ω§n—/ x›Ϊ?ΊώhΟϊZ΄Ώƒ]“χΑYΈ`@4'=/η)§ηθώzsΏmΏp<`Χ.°Ο£5σΓ,L
@@ -1 +0,0 @@
xKjУ0@Лж)ц)#i,KPJаE k}fhкШdљўёЂшіёМЊНп&8^ц`ь)9&AOњт#)5-таGМM(и,Fя"-ЇE"By
@@ -1,3 +0,0 @@
@@ -1,3 +0,0 @@
xŽAjB1@»Î)æJ&Ñ™"nÜ \'™‰m!$ÆEo߆nïÁ«Öû÷„°ã9TA0S+I˜¨*i.A«Ï©qh"Ã>bLâžyè2AZ %TöŒH-¡–Jå÷ZI˜
ëêÎå÷ü²7ëpúš¶lî:pœÖÏÝ~¬ÛVë'ÀÀè}ÂaãÉ{·Òõr®òÿz—Eà™
m}¸ü*XƒÏü¶¸?øçOi
@@ -0,0 +1,2 @@
P pack-dcbeaf3f6ff6c5eb08ea2b0a2d83626e8763546b.pack
+1 -1
View File
@@ -1,2 +1,2 @@
# pack-refs with: peeled
5bc1aaec6149e854078f1d0f8b71933bbc6c2e43 refs/heads/master
d61c3de65957b5997c236393b3ad4d70b5cd8931 refs/heads/master
+1 -1
View File
@@ -1 +1 @@
4fde706c7c8d3b30b6caec8c82ff4c01261350f2
94523d7ae48aeba575099dd12926420d8fd0425d
+20
View File
@@ -52,4 +52,24 @@ context "Page" do
assert_equal "José", Gollum::Page.cname("José")
assert_equal "モルドール", Gollum::Page.cname("モルドール")
end
test "title from filename with normal contents" do
page = @wiki.page('Bilbo Baggins')
assert_equal 'Bilbo Baggins', page.title
end
test "title from filename with html contents" do
page = @wiki.page('My <b>Precious')
assert_equal 'My Precious', page.title
end
test "title from h1 with normal contents" do
page = @wiki.page('Home')
assert_equal "The LOTR Wiki", page.title
end
test "title from h1 with html contents" do
page = @wiki.page('Eye Of Sauron')
assert_equal "Eye Of Sauron", page.title
end
end
+7 -16
View File
@@ -16,35 +16,26 @@ context "Wiki" do
test "shows paginated log with no page" do
Gollum::Wiki.per_page = 3
assert_equal %w(
4fde706c7c8d3b30b6caec8c82ff4c01261350f2
1e716a3178a76fe39ee7b88f0cf2dc4a447566f6
afe2034d400ba21e13361f38f74900c51dbc7fde),
@wiki.log.map { |c| c.id }
commits = @wiki.repo.commits[0..2].map { |x| x.id }
assert_equal commits, @wiki.log.map { |c| c.id }
end
test "shows paginated log with 1st page" do
Gollum::Wiki.per_page = 3
assert_equal %w(
4fde706c7c8d3b30b6caec8c82ff4c01261350f2
1e716a3178a76fe39ee7b88f0cf2dc4a447566f6
afe2034d400ba21e13361f38f74900c51dbc7fde),
@wiki.log(:page => 1).map { |c| c.id }
commits = @wiki.repo.commits[0..2].map { |x| x.id }
assert_equal commits, @wiki.log(:page => 1).map { |c| c.id }
end
test "shows paginated log with next page" do
Gollum::Wiki.per_page = 3
assert_equal %w(
f25eccd98e9b667f9e22946f3e2f945378b8a72d
b0d108328459e44fff4a76cd19b10ddc34adce4b
f01428b3138994aab19d5f880b6f37336ddf1f24),
@wiki.log(:page => 2).map { |c| c.id }
commits = @wiki.repo.commits[3..5].map { |x| x.id }
assert_equal commits, @wiki.log(:page => 2).map { |c| c.id }
end
test "list pages" do
pages = @wiki.pages
assert_equal \
%w(Bilbo-Baggins.md Eye-Of-Sauron.md Home.textile),
%w(Bilbo-Baggins.md Eye-Of-Sauron.md Home.textile My-<b>Precious.md),
pages.map { |p| p.name }.sort
end
end