Skip to content

Commit

Permalink
Add support for EPP templates (rouge-ruby#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
ananace committed Apr 25, 2018
1 parent a58789a commit db73696
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rouge/demos/epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%- |
Optional[String] $title,
| -%>
<title><%= $title %></title>
51 changes: 51 additions & 0 deletions lib/rouge/lexers/epp.rb
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
13 changes: 13 additions & 0 deletions spec/lexers/epp_spec.rb
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
24 changes: 24 additions & 0 deletions spec/visual/samples/epp
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 %>
<% } -%>

<% } -%>

0 comments on commit db73696

Please sign in to comment.