I'm trying to setup Rouge for my Rails app and I'm having issues with passing in inline ERB strings or blocks. When it reads ERB from a file it works fine however. Here is an example of what I have -
Works
rouge_helper.rb
def rouge(file, language)
formatter = Rouge::Formatters::HTML.new(css_class: 'highlight', wrap: true)
lexer = Rouge::Lexer.find(language)
output = formatter.format(lexer.lex(file))
output
end
app/views/example/_partial.html.erb
<p>hello <%= p "world" %></p>
app/views/example/index.html.erb
<pre class="highlight">
<code>
<%= raw rouge(File.read(Rails.root + "app/views/example/_partial.html.erb"), "erb") %>
</code>
</pre>
Does not work
When I repleace the index.html.erb file with this -
<pre class="highlight">
<code>
<%= raw rouge("<p>hello <%= p 'world' %></p>", "erb") %>
</code>
</pre>
I get this error -
app/views/styleguide/index.html.erb:3: syntax error, unexpected '>' app/views/styleguide/index.html.erb:5: unknown regexp options - pr app/views/styleguide/index.html.erb:6: unterminated string meets end of file app/views/styleguide/index.html.erb:6: syntax error, unexpected end-of-input, expecting ')'
Desired Result
<p>hello <%= p "world" %></p>