From d827f57815fa251648ef136c63581d296b0b8385 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sat, 23 Feb 2008 01:56:16 -0800 Subject: [PATCH] Add a Javascript filter. Based lightly on Les Hill's patch at http://pastie.org/156177. --- lib/haml.rb | 55 +++++++++++++++++--------------- lib/haml/engine.rb | 1 + lib/haml/filters.rb | 14 ++++++++ test/haml/results/filters.xhtml | 9 ++++++ test/haml/templates/filters.haml | 6 ++++ 5 files changed, 59 insertions(+), 26 deletions(-) diff --git a/lib/haml.rb b/lib/haml.rb index 64b9b208..ee919728 100644 --- a/lib/haml.rb +++ b/lib/haml.rb @@ -546,39 +546,42 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir) # # Haml has the following filters defined: # -# [plain] Does not parse the filtered text. -# This is useful for large blocks of text without HTML tags, -# when you don't want lines starting with . or - -# to be parsed. +# [plain] Does not parse the filtered text. +# This is useful for large blocks of text without HTML tags, +# when you don't want lines starting with . or - +# to be parsed. # -# [ruby] Parses the filtered text with the normal Ruby interpreter. -# All output sent to $stdout, like with +puts+, -# is output into the Haml document. -# Not available if the suppress_eval option is set to true. -# The Ruby code is evaluated in the same context as the Haml template. +# [javascript] Surrounds the filtered text with +END + end + end + module Ruby include Base lazy_require 'stringio' diff --git a/test/haml/results/filters.xhtml b/test/haml/results/filters.xhtml index f022b68e..01009684 100644 --- a/test/haml/results/filters.xhtml +++ b/test/haml/results/filters.xhtml @@ -21,6 +21,15 @@ Wowie-zowie!

pretty much the same as above

+

+ +

This Is Plain diff --git a/test/haml/templates/filters.haml b/test/haml/templates/filters.haml index fa96b875..44afdc74 100644 --- a/test/haml/templates/filters.haml +++ b/test/haml/templates/filters.haml @@ -30,6 +30,12 @@ _pretty much the same as above_ +%p + :javascript + function newline(str) { + return "\n" + str; + } + :plain This Is