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
Jérome Perrin
gitlab-ce
Commits
c463eeb0
Commit
c463eeb0
authored
Oct 20, 2011
by
gitlabhq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring
parent
48924dfe
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
66 additions
and
37 deletions
+66
-37
app/helpers/application_helper.rb
app/helpers/application_helper.rb
+0
-21
app/models/snippet.rb
app/models/snippet.rb
+7
-0
app/views/commits/_diff.html.haml
app/views/commits/_diff.html.haml
+3
-4
app/views/projects/_tree_file.html.haml
app/views/projects/_tree_file.html.haml
+4
-6
app/views/snippets/show.html.haml
app/views/snippets/show.html.haml
+1
-2
config/initializers/grit_ext.rb
config/initializers/grit_ext.rb
+8
-0
lib/utils.rb
lib/utils.rb
+43
-4
No files found.
app/helpers/application_helper.rb
View file @
c463eeb0
...
@@ -53,25 +53,4 @@ module ApplicationHelper
...
@@ -53,25 +53,4 @@ module ApplicationHelper
[
projects
,
default_nav
,
project_nav
].
flatten
.
to_json
[
projects
,
default_nav
,
project_nav
].
flatten
.
to_json
end
end
def
handle_file_type
(
file_name
,
mime_type
=
nil
)
if
file_name
=~
/(\.rb|\.ru|\.rake|Rakefile|\.gemspec|\.rbx|Gemfile)$/
:ruby
elsif
file_name
=~
/\.py$/
:python
elsif
file_name
=~
/(\.pl|\.scala|\.c|\.cpp|\.java|\.haml|\.html|\.sass|\.scss|\.xml|\.php|\.erb)$/
$1
[
1
..-
1
].
to_sym
elsif
file_name
=~
/\.js$/
:javascript
elsif
file_name
=~
/\.sh$/
:bash
elsif
file_name
=~
/\.coffee$/
:coffeescript
elsif
file_name
=~
/\.yml$/
:yaml
elsif
file_name
=~
/\.md$/
:minid
else
:text
end
end
end
end
app/models/snippet.rb
View file @
c463eeb0
class
Snippet
<
ActiveRecord
::
Base
class
Snippet
<
ActiveRecord
::
Base
include
Utils
::
Colorize
belongs_to
:project
belongs_to
:project
belongs_to
:author
,
:class_name
=>
"User"
belongs_to
:author
,
:class_name
=>
"User"
has_many
:notes
,
:as
=>
:noteable
has_many
:notes
,
:as
=>
:noteable
...
@@ -28,6 +30,11 @@ class Snippet < ActiveRecord::Base
...
@@ -28,6 +30,11 @@ class Snippet < ActiveRecord::Base
".js"
,
".sh"
,
".coffee"
,
".yml"
,
".md"
".js"
,
".sh"
,
".coffee"
,
".yml"
,
".md"
]
]
end
end
def
colorize
ft
=
handle_file_type
(
file_name
)
Albino
.
colorize
(
content
,
ft
,
:html
,
'utf-8'
,
"linenos=True"
)
end
end
end
# == Schema Information
# == Schema Information
#
#
...
...
app/views/commits/_diff.html.haml
View file @
c463eeb0
-
require
"utils"
.file_stats
.file_stats
-
@commit
.
diffs
.
each
do
|
diff
|
-
@commit
.
diffs
.
each
do
|
diff
|
-
if
diff
.
deleted_file
-
if
diff
.
deleted_file
...
@@ -35,7 +34,7 @@
...
@@ -35,7 +34,7 @@
%strong
{
:id
=>
"#{diff.b_path}"
}=
diff
.
b_path
%strong
{
:id
=>
"#{diff.b_path}"
}=
diff
.
b_path
%br
/
%br
/
.diff_file_content
.diff_file_content
-
if
file
.
mime_type
=~
/application|text/
&&
!
Utils
.
binary?
(
file
.
data
)
-
if
file
.
text?
-
lines_arr
=
diff
.
diff
.
lines
.
to_a
-
lines_arr
=
diff
.
diff
.
lines
.
to_a
-
line_old
=
lines_arr
[
2
].
match
(
/-(\d)/
)[
0
].
to_i
.
abs
rescue
0
-
line_old
=
lines_arr
[
2
].
match
(
/-(\d)/
)[
0
].
to_i
.
abs
rescue
0
-
line_new
=
lines_arr
[
2
].
match
(
/\+(\d)/
)[
0
].
to_i
.
abs
rescue
0
-
line_new
=
lines_arr
[
2
].
match
(
/\+(\d)/
)[
0
].
to_i
.
abs
rescue
0
...
@@ -50,9 +49,9 @@
...
@@ -50,9 +49,9 @@
-
else
-
else
-
line_new
+=
1
-
line_new
+=
1
-
line_old
+=
1
-
line_old
+=
1
-
elsif
file
.
mime_type
=~
/image/
-
elsif
file
.
image?
.diff_file_content_image
.diff_file_content_image
%img
{
:src
=>
"data:
image/jpeg
;base64,#{Base64.encode64(file.data)}"
}
%img
{
:src
=>
"data:
#{file.mime_type}
;base64,#{Base64.encode64(file.data)}"
}
-
else
-
else
%p
%p
%center
No preview for this file type
%center
No preview for this file type
app/views/projects/_tree_file.html.haml
View file @
c463eeb0
-
require
"utils"
.view_file
.view_file
.view_file_header
.view_file_header
%strong
%strong
...
@@ -6,14 +5,13 @@
...
@@ -6,14 +5,13 @@
=
link_to
"raw"
,
blob_project_path
(
@project
,
:commit_id
=>
@commit
.
id
,
:path
=>
params
[
:path
]
),
:class
=>
"right"
,
:target
=>
"_blank"
=
link_to
"raw"
,
blob_project_path
(
@project
,
:commit_id
=>
@commit
.
id
,
:path
=>
params
[
:path
]
),
:class
=>
"right"
,
:target
=>
"_blank"
=
link_to
"history"
,
project_commits_path
(
@project
,
:path
=>
params
[
:path
]),
:class
=>
"right"
,
:style
=>
"margin-right:10px;"
=
link_to
"history"
,
project_commits_path
(
@project
,
:path
=>
params
[
:path
]),
:class
=>
"right"
,
:style
=>
"margin-right:10px;"
%br
/
%br
/
-
if
file
.
mime_type
=~
/application|text/
&&
!
Utils
.
binary?
(
file
.
data
)
-
if
file
.
text?
.view_file_content
.view_file_content
-
ft
=
handle_file_type
(
file
.
name
,
file
.
mime_type
)
:erb
:erb
<%=
raw
Albino
.
colorize
(
content
,
ft
,
:html
,
'utf-8'
,
"linenos=True"
)
%>
<%=
raw
file
.
colorize
%>
-
elsif
file
.
mime_type
=~
/image/
-
elsif
file
.
image?
.view_file_content_image
.view_file_content_image
%img
{
:src
=>
"data:
image/jpeg
;base64,#{Base64.encode64(file.data)}"
}
%img
{
:src
=>
"data:
#{file.mime_type}
;base64,#{Base64.encode64(file.data)}"
}
-
else
-
else
%p
%p
%center
No preview for this file type
%center
No preview for this file type
...
...
app/views/snippets/show.html.haml
View file @
c463eeb0
...
@@ -7,9 +7,8 @@
...
@@ -7,9 +7,8 @@
=
@snippet
.
file_name
=
@snippet
.
file_name
%br
/
%br
/
.view_file_content
.view_file_content
-
ft
=
handle_file_type
(
@snippet
.
file_name
)
:erb
:erb
<%=
raw
Albino
.
colorize
(
@snippet
.
content
,
ft
,
:html
,
'utf-8'
,
"linenos=True"
)
%>
<%=
raw
@snippet
.
colorize
%>
-
if
can?
(
current_user
,
:admin_snippet
,
@project
)
||
@snippet
.
author
==
current_user
-
if
can?
(
current_user
,
:admin_snippet
,
@project
)
||
@snippet
.
author
==
current_user
=
link_to
'Edit'
,
edit_project_snippet_path
(
@project
,
@snippet
),
:class
=>
"lbutton positive"
=
link_to
'Edit'
,
edit_project_snippet_path
(
@project
,
@snippet
),
:class
=>
"lbutton positive"
...
...
config/initializers/grit_ext.rb
0 → 100644
View file @
c463eeb0
require
'grit'
require
'albino'
require
"utils"
Grit
::
Blob
.
class_eval
do
include
Utils
::
FileHelper
include
Utils
::
Colorize
end
lib/utils.rb
View file @
c463eeb0
module
Utils
module
Utils
def
self
.
binary?
(
string
)
module
FileHelper
string
.
each_byte
do
|
x
|
def
binary?
(
string
)
x
.
nonzero?
or
return
true
string
.
each_byte
do
|
x
|
x
.
nonzero?
or
return
true
end
false
end
def
image?
mime_type
=~
/image/
end
def
text?
mime_type
=~
/application|text/
&&
!
binary?
(
data
)
end
end
module
Colorize
def
colorize
ft
=
handle_file_type
(
name
,
mime_type
)
Albino
.
colorize
(
data
,
ft
,
:html
,
'utf-8'
,
"linenos=True"
)
end
def
handle_file_type
(
file_name
,
mime_type
=
nil
)
if
file_name
=~
/(\.rb|\.ru|\.rake|Rakefile|\.gemspec|\.rbx|Gemfile)$/
:ruby
elsif
file_name
=~
/\.py$/
:python
elsif
file_name
=~
/(\.pl|\.scala|\.c|\.cpp|\.java|\.haml|\.html|\.sass|\.scss|\.xml|\.php|\.erb)$/
$1
[
1
..-
1
].
to_sym
elsif
file_name
=~
/\.js$/
:javascript
elsif
file_name
=~
/\.sh$/
:bash
elsif
file_name
=~
/\.coffee$/
:coffeescript
elsif
file_name
=~
/\.yml$/
:yaml
elsif
file_name
=~
/\.md$/
:minid
else
:text
end
end
end
false
end
end
end
end
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