Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for EPP templates (#901) #903

Merged
merged 4 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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={})
super(opts)
@parent = lexer_option(:parent) { PlainText.new(opts) }
@puppet_lexer = Puppet.new(opts)
end

start do
parent.reset!
@puppet_lexer.reset!
end

open = /<%%|<%=|<%#|(<%-|<%)(\s*\|)?/
close = /%%>|(\|\s*)?(-%>|%>)/

state :root do
rule %r/<%#/, Comment, :comment

rule open, Comment::Preproc, :puppet

rule %r/.+?(?=#{open})|.+/m do
delegate parent
end
end

state :comment do
rule close, Comment, :pop!
rule %r/.+?(?=#{close})|.+/m, Comment
end

state :puppet do
rule close, Comment::Preproc, :pop!

rule %r/.+?(?=#{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 %>
<% } -%>

<% } -%>
pyrmont marked this conversation as resolved.
Show resolved Hide resolved