regex - Execute Ruby method on whole page in Middleman -


on middleman-built website, need execute specific ruby code on contents of pages (templates).

for example, if had following helper in config.rb:

def myexample(text)     text.gsub("dog","cat") end 

and in test.html.haml:

= myexample("some text dog.") 

my previewed , generated /test.html read:

some text cat. 

however, using several different ways output text needs modified, notably through haml's :markdown filter, prefer not wrap in = myexample("text") helper.

i able run ruby code take contents of pages (preferably) or generated html output (if first option not possible) argument passed such helper.

ideally, code run in both development , build environments, if that's not possible, build enough.

is possible so?

ps. in specific case, use shorthand notation reference other pages , use regular expression , eval() in order replace them relative links data files.

actioncontroller::base has render_to_string method give normal html output rendering partial or page, in string format. allow grab rendered html , modify before rendering real inline template.

in controller:

rendered_html = render_to_string 'your_template_or_partial' # stuff rendered_html render inline: rendered_html.html_safe, layout: 'layouts/application' 

the html_safe method makes sure rails knows it's safe render html. not want if user input being rendered , have not sanitized it!!!!

if don't want use layout when rendering, remove :layout argument.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -