Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
gitlab-ce
Commits
90bdcac6
Commit
90bdcac6
authored
Feb 20, 2014
by
Ciro Santillli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Blob and tree gfm links to anchors work.
Fixes #6046
parent
499a1185
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
118 additions
and
15 deletions
+118
-15
CHANGELOG
CHANGELOG
+1
-0
app/helpers/gitlab_markdown_helper.rb
app/helpers/gitlab_markdown_helper.rb
+5
-2
features/project/source/markdown_render.feature
features/project/source/markdown_render.feature
+27
-11
features/steps/project/project_markdown_render.rb
features/steps/project/project_markdown_render.rb
+74
-1
spec/factories.rb
spec/factories.rb
+10
-0
spec/helpers/gitlab_markdown_helper_spec.rb
spec/helpers/gitlab_markdown_helper_spec.rb
+1
-1
spec/seed_project.tar.gz
spec/seed_project.tar.gz
+0
-0
No files found.
CHANGELOG
View file @
90bdcac6
...
@@ -21,6 +21,7 @@ v 6.6.0
...
@@ -21,6 +21,7 @@ v 6.6.0
- Restyle Issue#show page and MR#show page
- Restyle Issue#show page and MR#show page
- Ability to filter by multiple labels for Issues page
- Ability to filter by multiple labels for Issues page
- Rails version to 4.0.3
- Rails version to 4.0.3
- Blob and tree gfm links to anchors work
v 6.5.1
v 6.5.1
- Fix branch selectbox when create merge request from fork
- Fix branch selectbox when create merge request from fork
...
...
app/helpers/gitlab_markdown_helper.rb
View file @
90bdcac6
...
@@ -124,12 +124,14 @@ module GitlabMarkdownHelper
...
@@ -124,12 +124,14 @@ module GitlabMarkdownHelper
end
end
def
rebuild_path
(
path_with_namespace
,
path
,
requested_path
,
ref
)
def
rebuild_path
(
path_with_namespace
,
path
,
requested_path
,
ref
)
path
.
gsub!
(
/(#.*)/
,
""
)
id
=
$1
||
""
file_path
=
relative_file_path
(
path
,
requested_path
)
file_path
=
relative_file_path
(
path
,
requested_path
)
[
[
path_with_namespace
,
path_with_namespace
,
path_with_ref
(
file_path
,
ref
),
path_with_ref
(
file_path
,
ref
),
file_path
file_path
].
compact
.
join
(
"/"
)
].
compact
.
join
(
"/"
)
.
gsub
(
/\/*$/
,
''
)
+
id
end
end
# Checks if the path exists in the repo
# Checks if the path exists in the repo
...
@@ -154,6 +156,7 @@ module GitlabMarkdownHelper
...
@@ -154,6 +156,7 @@ module GitlabMarkdownHelper
# If we are at doc/api and the README.md shown in below the tree view
# If we are at doc/api and the README.md shown in below the tree view
# this takes the rquest path(doc/api) and adds users.md so the path looks like doc/api/users.md
# this takes the rquest path(doc/api) and adds users.md so the path looks like doc/api/users.md
def
build_nested_path
(
path
,
request_path
)
def
build_nested_path
(
path
,
request_path
)
return
request_path
if
path
==
""
return
path
unless
request_path
return
path
unless
request_path
if
local_path
(
request_path
)
==
"tree"
if
local_path
(
request_path
)
==
"tree"
base
=
request_path
.
split
(
"/"
).
push
(
path
)
base
=
request_path
.
split
(
"/"
).
push
(
path
)
...
@@ -166,7 +169,7 @@ module GitlabMarkdownHelper
...
@@ -166,7 +169,7 @@ module GitlabMarkdownHelper
end
end
def
file_exists?
(
path
)
def
file_exists?
(
path
)
return
false
if
path
.
nil?
||
path
.
empty?
return
false
if
path
.
nil?
return
@repository
.
blob_at
(
current_sha
,
path
).
present?
||
@repository
.
tree
(
current_sha
,
path
).
entries
.
any?
return
@repository
.
blob_at
(
current_sha
,
path
).
present?
||
@repository
.
tree
(
current_sha
,
path
).
entries
.
any?
end
end
...
...
features/project/source/markdown_render.feature
View file @
90bdcac6
...
@@ -4,9 +4,7 @@ Feature: Project markdown render
...
@@ -4,9 +4,7 @@ Feature: Project markdown render
And
I own project
"Delta"
And
I own project
"Delta"
Given
I visit project source page
Given
I visit project source page
# -------------------------------------------
# Tree README
# README
# -------------------------------------------
Scenario
:
Tree view should have correct links in README
Scenario
:
Tree view should have correct links in README
Given
I go directory which contains README file
Given
I go directory which contains README file
...
@@ -41,9 +39,7 @@ Feature: Project markdown render
...
@@ -41,9 +39,7 @@ Feature: Project markdown render
Then
I should see rendered README which contains correct links
Then
I should see rendered README which contains correct links
And
Header
"Application details"
should have correct id and link
And
Header
"Application details"
should have correct id and link
# -------------------------------------------
# Blob
# File content
# -------------------------------------------
Scenario
:
I
navigate to doc directory to view documentation in master
Scenario
:
I
navigate to doc directory to view documentation in master
And
I navigate to the doc/api/README
And
I navigate to the doc/api/README
...
@@ -61,9 +57,7 @@ Feature: Project markdown render
...
@@ -61,9 +57,7 @@ Feature: Project markdown render
And
I navigate to the doc/api/README
And
I navigate to the doc/api/README
And
Header
"GitLab API"
should have correct id and link
And
Header
"GitLab API"
should have correct id and link
# -------------------------------------------
# Markdown branch
# Markdown branch README
# -------------------------------------------
Scenario
:
I
browse files from markdown branch
Scenario
:
I
browse files from markdown branch
When
I visit markdown branch
When
I visit markdown branch
...
@@ -93,9 +87,31 @@ Feature: Project markdown render
...
@@ -93,9 +87,31 @@ Feature: Project markdown render
And
I click on raketasks in doc/api/README
And
I click on raketasks in doc/api/README
Then
I should see correct directory rendered for markdown branch
Then
I should see correct directory rendered for markdown branch
# -------------------------------------------
Scenario
:
Tree markdown links view empty urls should have correct urls
When
I visit markdown branch
Then
The link with text
"empty"
should have url
"tree/markdown"
When
I visit markdown branch
"README.md"
blob
Then
The link with text
"empty"
should have url
"blob/markdown/README.md"
When
I visit markdown branch
"d"
tree
Then
The link with text
"empty"
should have url
"tree/markdown/d"
When
I visit markdown branch
"d/README.md"
blob
Then
The link with text
"empty"
should have url
"blob/markdown/d/README.md"
# "ID" means "#id" on the tests below, because we are unable to escape the hash sign.
# which Spinach interprets as the start of a comment.
Scenario
:
All markdown links with ids should have correct urls
When
I visit markdown branch
Then
The link with text
"ID"
should have url
"tree/markdownID"
Then
The link with text
"/ID"
should have url
"tree/markdownID"
Then
The link with text
"README.mdID"
should have url
"blob/markdown/README.mdID"
Then
The link with text
"d/README.mdID"
should have url
"blob/markdown/d/README.mdID"
When
I visit markdown branch
"README.md"
blob
Then
The link with text
"ID"
should have url
"blob/markdown/README.mdID"
Then
The link with text
"/ID"
should have url
"blob/markdown/README.mdID"
Then
The link with text
"README.mdID"
should have url
"blob/markdown/README.mdID"
Then
The link with text
"d/README.mdID"
should have url
"blob/markdown/d/README.mdID"
# Wiki
# Wiki
# -------------------------------------------
Scenario
:
I
create a wiki page with different links
Scenario
:
I
create a wiki page with different links
Given
I go to wiki page
Given
I go to wiki page
...
...
features/steps/project/project_markdown_render.rb
View file @
90bdcac6
# If you need to modify the existing seed repository for your tests,
# it is recommended that you make the changes on the `markdown` branch of the seed project repository,
# which should only be used by tests in this file. See `/spec/factories.rb#project` for more info.
class
Spinach::Features::ProjectMarkdownRender
<
Spinach
::
FeatureSteps
class
Spinach::Features::ProjectMarkdownRender
<
Spinach
::
FeatureSteps
include
SharedAuthentication
include
SharedAuthentication
include
SharedPaths
include
SharedPaths
...
@@ -50,7 +53,7 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
...
@@ -50,7 +53,7 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
end
end
Then
'I should see correct doc/api directory rendered'
do
Then
'I should see correct doc/api directory rendered'
do
current_path
.
should
==
project_tree_path
(
@project
,
"master/doc/api
/
"
)
current_path
.
should
==
project_tree_path
(
@project
,
"master/doc/api"
)
page
.
should
have_content
"README.md"
page
.
should
have_content
"README.md"
page
.
should
have_content
"users.md"
page
.
should
have_content
"users.md"
end
end
...
@@ -64,6 +67,18 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
...
@@ -64,6 +67,18 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
page
.
should
have_content
"bundle exec rake gitlab:env:info RAILS_ENV=production"
page
.
should
have_content
"bundle exec rake gitlab:env:info RAILS_ENV=production"
end
end
And
'I click on link "empty" in the README'
do
within
(
'.readme-holder'
)
do
click_link
"empty"
end
end
And
'I click on link "id" in the README'
do
within
(
'.readme-holder'
)
do
click_link
"#id"
end
end
And
'I navigate to the doc/api/README'
do
And
'I navigate to the doc/api/README'
do
click_link
"doc"
click_link
"doc"
click_link
"api"
click_link
"api"
...
@@ -90,10 +105,24 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
...
@@ -90,10 +105,24 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
click_link
"Rake tasks"
click_link
"Rake tasks"
end
end
# Markdown branch
When
'I visit markdown branch'
do
When
'I visit markdown branch'
do
visit
project_tree_path
(
@project
,
"markdown"
)
visit
project_tree_path
(
@project
,
"markdown"
)
end
end
When
'I visit markdown branch "README.md" blob'
do
visit
project_blob_path
(
@project
,
"markdown/README.md"
)
end
When
'I visit markdown branch "d" tree'
do
visit
project_tree_path
(
@project
,
"markdown/d"
)
end
When
'I visit markdown branch "d/README.md" blob'
do
visit
project_blob_path
(
@project
,
"markdown/d/README.md"
)
end
Then
'I should see files from repository in markdown branch'
do
Then
'I should see files from repository in markdown branch'
do
current_path
.
should
==
project_tree_path
(
@project
,
"markdown"
)
current_path
.
should
==
project_tree_path
(
@project
,
"markdown"
)
page
.
should
have_content
"Gemfile"
page
.
should
have_content
"Gemfile"
...
@@ -124,6 +153,50 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
...
@@ -124,6 +153,50 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
page
.
should
have_content
"Get a list of users."
page
.
should
have_content
"Get a list of users."
end
end
# Expected link contents
Then
'The link with text "empty" should have url "tree/markdown"'
do
find
(
'a'
,
text:
/^empty$/
)[
'href'
]
==
current_host
+
project_tree_path
(
@project
,
"markdown"
)
end
Then
'The link with text "empty" should have url "blob/markdown/README.md"'
do
find
(
'a'
,
text:
/^empty$/
)[
'href'
]
==
current_host
+
project_blob_path
(
@project
,
"markdown/README.md"
)
end
Then
'The link with text "empty" should have url "tree/markdown/d"'
do
find
(
'a'
,
text:
/^empty$/
)[
'href'
]
==
current_host
+
project_tree_path
(
@project
,
"markdown/d"
)
end
Then
'The link with text "empty" should have url "blob/markdown/d/README.md"'
do
find
(
'a'
,
text:
/^empty$/
)[
'href'
]
==
current_host
+
project_blob_path
(
@project
,
"markdown/d/README.md"
)
end
Then
'The link with text "ID" should have url "tree/markdownID"'
do
find
(
'a'
,
text:
/^#id$/
)[
'href'
]
==
current_host
+
project_tree_path
(
@project
,
"markdown"
)
+
'#id'
end
Then
'The link with text "/ID" should have url "tree/markdownID"'
do
find
(
'a'
,
text:
/^\/#id$/
)[
'href'
]
==
current_host
+
project_tree_path
(
@project
,
"markdown"
)
+
'#id'
end
Then
'The link with text "README.mdID" should have url "blob/markdown/README.mdID"'
do
find
(
'a'
,
text:
/^README.md#id$/
)[
'href'
]
==
current_host
+
project_blob_path
(
@project
,
"markdown/README.md"
)
+
'#id'
end
Then
'The link with text "d/README.mdID" should have url "blob/markdown/d/README.mdID"'
do
find
(
'a'
,
text:
/^d\/README.md#id$/
)[
'href'
]
==
current_host
+
project_blob_path
(
@project
,
"d/markdown/README.md"
)
+
'#id'
end
Then
'The link with text "ID" should have url "blob/markdown/README.mdID"'
do
find
(
'a'
,
text:
/^#id$/
)[
'href'
]
==
current_host
+
project_blob_path
(
@project
,
"markdown/README.md"
)
+
'#id'
end
Then
'The link with text "/ID" should have url "blob/markdown/README.mdID"'
do
find
(
'a'
,
text:
/^\/#id$/
)[
'href'
]
==
current_host
+
project_blob_path
(
@project
,
"markdown/README.md"
)
+
'#id'
end
# Wiki
Given
'I go to wiki page'
do
Given
'I go to wiki page'
do
click_link
"Wiki"
click_link
"Wiki"
current_path
.
should
==
project_wiki_path
(
@project
,
"home"
)
current_path
.
should
==
project_wiki_path
(
@project
,
"home"
)
...
...
spec/factories.rb
View file @
90bdcac6
...
@@ -34,6 +34,16 @@ FactoryGirl.define do
...
@@ -34,6 +34,16 @@ FactoryGirl.define do
creator
creator
end
end
# Generates a test repository from the repository stored under `spec/seed_project.tar.gz`.
# Once you run `rake gitlab:setup`, you can see what the repository looks like under `tmp/repositories/gitlabhq`.
# In order to modify files in the repository, you must untar the seed, modify and remake the tar.
# Before recompressing, do not forget to `git checkout master`.
# After recompressing, you need to run `RAILS_ENV=test bundle exec rake gitlab:setup` to regenerate the seeds under tmp.
#
# If you want to modify the repository only for an specific type of tests, e.g., markdown tests,
# consider using a feature branch to reduce the chances of collision with other tests.
# Create a new commit, and use the same commit message that you will use for the change in the main repo.
# Changing the commig message and SHA of branch `master` may break tests.
factory
:project
,
parent: :empty_project
do
factory
:project
,
parent: :empty_project
do
path
{
'gitlabhq'
}
path
{
'gitlabhq'
}
...
...
spec/helpers/gitlab_markdown_helper_spec.rb
View file @
90bdcac6
...
@@ -454,7 +454,7 @@ describe GitlabMarkdownHelper do
...
@@ -454,7 +454,7 @@ describe GitlabMarkdownHelper do
it
"should handle relative urls in reference links for a directory in master"
do
it
"should handle relative urls in reference links for a directory in master"
do
actual
=
"[GitLab API doc directory][GitLab readmes]
\n
[GitLab readmes]: doc/api/
\n
"
actual
=
"[GitLab API doc directory][GitLab readmes]
\n
[GitLab readmes]: doc/api/
\n
"
expected
=
"<p><a href=
\"
/
#{
project
.
path_with_namespace
}
/tree/master/doc/api
/
\"
>GitLab API doc directory</a></p>
\n
"
expected
=
"<p><a href=
\"
/
#{
project
.
path_with_namespace
}
/tree/master/doc/api
\"
>GitLab API doc directory</a></p>
\n
"
markdown
(
actual
).
should
match
(
expected
)
markdown
(
actual
).
should
match
(
expected
)
end
end
...
...
spec/seed_project.tar.gz
View file @
90bdcac6
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment