This is just a preview of what seems to be the minimal changes to suppress
indentation with an :ugly option to Haml::Engine. This is completely untested,
unchecked, and is basically just intended to give an idea of what might kind
of change I'm contemplating.

Not sure whether Google will mangle the patch as it's the first time I'm
sending a patch Google Groups using "git send-email".

---
 lib/haml/buffer.rb      |   20 +++++++++++++-------
 lib/haml/engine.rb      |    8 ++++++--
 lib/haml/precompiler.rb |   14 ++++++++++----
 3 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/lib/haml/buffer.rb b/lib/haml/buffer.rb
index 4bdac1d..c2763e7 100644
--- a/lib/haml/buffer.rb
+++ b/lib/haml/buffer.rb
@@ -32,7 +32,8 @@ module Haml
     # Creates a new buffer.
     def initialize(options = {})
       @options = {
-        :attr_wrapper => "'"
+        :attr_wrapper => "'",
+        :ugly => false
       }.merge options
       @buffer = ""
       @tabulation = 0
@@ -45,7 +46,7 @@ module Haml
     # Renders +text+ with the proper tabulation. This also deals with
     # making a possible one-line tag one line or not.
     def push_text(text, tab_change = 0)
-      if(@tabulation > 0)
+      if(@tabulation > 0 && [EMAIL PROTECTED]:ugly])
         # Have to push every line in by the extra user set tabulation
         text.gsub!(/^/m, '  ' * @tabulation)
       end
@@ -78,11 +79,11 @@ module Haml
           @buffer << "\n"
         end
         
-        result = result.gsub(/^/m, tabs(tabulation))
+        result = result.gsub(/^/m, tabs(tabulation)) unless @options[:ugly]
         @buffer << "#{result}\n"
         
         if close_tag
-          @buffer << "#{tabs(tabulation-1)}</#{close_tag}>\n"
+          @buffer << @options[:ugly] ? "</#{close_tag}>\n" : 
"#{tabs(tabulation-1)}</#{close_tag}>\n"
           @real_tabs -= 1
         end
       end
@@ -108,10 +109,16 @@ module Haml
       else
         str = ">\n"
       end
-      @buffer << 
"#{tabs(tabulation)}<#{name}#{Precompiler.build_attributes(@options[:attr_wrapper],
 attributes)}#{str}"
+      if @options[:ugly]
+        @buffer << 
"#{tabs(tabulation)}<#{name}#{Precompiler.build_attributes(@options[:attr_wrapper],
 attributes)}#{str}"
+      else
+        @buffer << 
"<#{name}#{Precompiler.build_attributes(@options[:attr_wrapper], 
attributes)}#{str}"
+      end
       if content
         if Buffer.one_liner?(content)
           @buffer << "#{content}</#{name}>\n"
+        elsif @options[:ugly]
+          @buffer << "\n#{content}\n</#{name}>\n"
         else
           @buffer << 
"\n#{tabs(@real_tabs+1)}#{content}\n#{tabs(@real_tabs)}</#{name}>\n"
         end
@@ -152,8 +159,7 @@ module Haml
     # Gets <tt>count</tt> tabs. Mostly for internal use.
     def tabs(count)
       tabs = count + @tabulation
-      '  ' * tabs
-      @@tab_cache[tabs] ||= '  ' * tabs
+      @@tab_cache[tabs] ||= (@options[:ugly] ? '' : '  ' * tabs)
     end
 
     # Takes an array of objects and uses the class and id of the first
diff --git a/lib/haml/engine.rb b/lib/haml/engine.rb
index b54fc38..97d0740 100644
--- a/lib/haml/engine.rb
+++ b/lib/haml/engine.rb
@@ -45,7 +45,8 @@ module Haml
           'redcloth' => Haml::Filters::RedCloth,
           'textile' => Haml::Filters::Textile,
           'markdown' => Haml::Filters::Markdown },
-        :filename => '(haml)'
+        :filename => '(haml)',
+        :ugly => false
       }
       @options.rec_merge! options
 
@@ -232,7 +233,10 @@ END
     # Returns a hash of options that Haml::Buffer cares about.
     # This should remain loadable form #inspect.
     def options_for_buffer
-      {:attr_wrapper => @options[:attr_wrapper]}
+      {
+        :attr_wrapper => @options[:attr_wrapper],
+        :ugly => @options[:ugly]
+      }
     end
   end
 end
diff --git a/lib/haml/precompiler.rb b/lib/haml/precompiler.rb
index 3625356..667adb2 100644
--- a/lib/haml/precompiler.rb
+++ b/lib/haml/precompiler.rb
@@ -270,7 +270,7 @@ END
     # Adds <tt>text</tt> to <tt>@buffer</tt> with appropriate tabulation
     # without parsing it.
     def push_merged_text(text, tab_change = 0, try_one_liner = false)
-      @merged_text  << "#{'  ' * @output_tabs}#{text}"
+      @merged_text  << @options[:ugly] ? text : "#{'  ' * @output_tabs}#{text}"
       @tab_change   += tab_change
       @try_one_liner = try_one_liner
     end
@@ -299,9 +299,13 @@ END
 
     # Adds +text+ to <tt>@buffer</tt> while flattening text.
     def push_flat(line)
-      tabulation = line.spaces - @flat_spaces
-      tabulation = tabulation > -1 ? tabulation : 0
-      @filter_buffer << "#{' ' * tabulation}#{line.unstripped}\n"
+      unless @options[:ugly]
+        tabulation = line.spaces - @flat_spaces
+        tabulation = tabulation > -1 ? tabulation : 0
+        @filter_buffer << "#{' ' * tabulation}#{line.unstripped}\n"
+      else
+        @filter_buffer << "#{line.unstripped}\n"
+      end
     end
 
     # Causes <tt>text</tt> to be evaluated in the context of
@@ -388,6 +392,8 @@ END
 
       if filter == Haml::Filters::Preserve
         push_silent("_hamlout.buffer << #{filtered.dump} << \"\\n\";")
+      elsif @options[:ugly]
+        push_text(filtered.rstrip)
       else
         push_text(filtered.rstrip.gsub("\n", "\n#{'  ' * @output_tabs}"))
       end
-- 
1.5.4.1-dirty


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to