forked from rouge-ruby/rouge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for EPP templates (rouge-ruby#901)
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<%- | | ||
Optional[String] $title, | ||
| -%> | ||
<title><%= $title %></title> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# -*- coding: utf-8 -*- # | ||
|
||
module Rouge | ||
module Lexers | ||
class EPP < TemplateLexer | ||
title "EPP" | ||
desc "Embedded Puppet template files" | ||
|
||
tag 'epp' | ||
|
||
filenames '*.epp' | ||
|
||
def initialize(opts={}) | ||
@puppet_lexer = Puppet.new(opts) | ||
|
||
super(opts) | ||
end | ||
|
||
start do | ||
parent.reset! | ||
@puppet_lexer.reset! | ||
end | ||
|
||
open = /<%%|<%=|<%#|(<%-|<%)(\s*?\|)?/ | ||
close = /%%>|(\|\s*?)?(-%>|%>)/ | ||
|
||
state :root do | ||
rule /<%#/, Comment, :comment | ||
|
||
rule open, Comment::Preproc, :puppet | ||
|
||
rule /.+?(?=#{open})|.+/m do | ||
delegate parent | ||
end | ||
end | ||
|
||
state :comment do | ||
rule close, Comment, :pop! | ||
rule /.+?(?=#{close})|.+/m, Comment | ||
end | ||
|
||
state :puppet do | ||
rule close, Comment::Preproc, :pop! | ||
|
||
rule /.+?(?=#{close})|.+/m do | ||
delegate @puppet_lexer | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# -*- coding: utf-8 -*- # | ||
|
||
describe Rouge::Lexers::EPP do | ||
let(:subject) { Rouge::Lexers::EPP.new } | ||
|
||
describe 'guessing' do | ||
include Support::Guessing | ||
|
||
it 'guesses by filename' do | ||
assert_guess :filename => 'foo.html.epp' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<%- | Boolean $keys_enable, | ||
String $keys_file, | ||
Array $keys_trusted, | ||
String $keys_requestkey, | ||
String $keys_controlkey | ||
| -%> | ||
<%# Parameter tag ↑ -%> | ||
|
||
<%# Non-printing tag ↓ -%> | ||
<% if $keys_enable { -%> | ||
|
||
<%# Expression-printing tag ↓ -%> | ||
keys <%= $keys_file %> | ||
<% unless $keys_trusted =~ Array[Data,0,0] { -%> | ||
trustedkey <%= $keys_trusted.join(' ') %> | ||
<% } -%> | ||
<% if $keys_requestkey =~ String[1] { -%> | ||
requestkey <%= $keys_requestkey %> | ||
<% } -%> | ||
<% if $keys_controlkey =~ String[1] { -%> | ||
controlkey <%= $keys_controlkey %> | ||
<% } -%> | ||
|
||
<% } -%> |