Skip to content

Commit

Permalink
Adding support to detect the difference between a Grails gsp and a Go…
Browse files Browse the repository at this point in the history
…su gsp.
  • Loading branch information
beckje01 committed Aug 29, 2011
1 parent 5b9b461 commit 3dd06de
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/linguist/blob_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,19 @@ def guess_r_language
Language['R']
end
end


# Internal: Guess language of .gsp files.
#
# Returns a Language.
def guess_gsp_language
if lines.grep(/<%|<%@|${|<%|<g:|<meta name="layout"|<r:/).any?

This comment has been minimized.

Copy link
@josh

josh Aug 29, 2011

Contributor
Language['Groovy Server Pages']
else
Language['Gosu']
end
end


# Internal: Guess language from the first line.
#
Expand Down
10 changes: 10 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,16 @@ Groovy:
- .gradle
- .groovy

Groovy Server Pages:
group: Groovy
lexer: Java Server Page
overrides:
- .gsp
aliases:
- gsp
extensions:
- .gsp

HTML:
type: markup
primary_extension: .html
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/bar.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Testing with SiteMesh and Resources</title>
<meta name="layout" content="blankMain"/>
<r:require module="style"/>
</head>
<body>
</body>
</html>
16 changes: 16 additions & 0 deletions test/fixtures/hello-pagedirective.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%@ page contentType="text/html;charset=UTF-8" %>

<html>
<head>
<title>Using page directive tag</title>
</head>
<body>
<div class="center">
<a href="#" alt="Download" id="downloadButton">Download</a>
</div>
<div class="center">
<a href="#" alt="Print" id="printButton">Print</a>
</div>
</body>
</html>

9 changes: 9 additions & 0 deletions test/fixtures/hello-resources.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Testing with Resources</title>
<r:require module="style"/>
</head>
<body>
</body>
</html>
6 changes: 6 additions & 0 deletions test/test_blob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,12 @@ def test_language
assert_equal Language['Gosu'], blob("hello.gsp").language
assert_equal Language['Gosu'], blob("Hello.gst").language
assert_equal Language['Gosu'], blob("hello.vark").language

#Groovy Server Pages
assert_equal Language['Groovy Server Pages'], blob("bar.gsp").language
assert_equal Language['Groovy Server Pages'], blob("hello-resources.gsp").language
assert_equal Language['Groovy Server Pages'], blob("hello-pagedirective.gsp").language

end

def test_lexer
Expand Down

0 comments on commit 3dd06de

Please sign in to comment.