radiant 0.6.7 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of radiant might be problematic. Click here for more details.

Files changed (96) hide show
  1. data/CHANGELOG +35 -3
  2. data/CONTRIBUTORS +11 -1
  3. data/README +5 -3
  4. data/app/controllers/admin/welcome_controller.rb +7 -0
  5. data/app/migrate/020_add_session_info_to_users.rb +11 -0
  6. data/app/models/page.rb +22 -9
  7. data/app/models/standard_tags.rb +133 -10
  8. data/app/models/user.rb +9 -1
  9. data/app/views/admin/page/edit.html.haml +5 -4
  10. data/app/views/admin/welcome/login.html.haml +42 -24
  11. data/app/views/layouts/application.html.haml +1 -1
  12. data/config/environment.rb +4 -2
  13. data/db/migrate/020_add_session_info_to_users.rb +11 -0
  14. data/db/migrate/021_remove_session_expire_from_users.rb +9 -0
  15. data/db/schema.rb +3 -2
  16. data/lib/generators/instance/instance_generator.rb +2 -1
  17. data/lib/generators/instance/templates/instance_environment.rb +5 -3
  18. data/lib/login_system.rb +13 -0
  19. data/lib/radiant.rb +1 -1
  20. data/lib/radiant/admin_ui.rb +21 -21
  21. data/lib/radiant/extension/script.rb +251 -0
  22. data/lib/radiant/extension_loader.rb +22 -20
  23. data/lib/radiant/initializer.rb +1 -1
  24. data/lib/radiant/setup.rb +2 -0
  25. data/lib/tasks/framework.rake +39 -29
  26. data/public/500.html +1 -1
  27. data/public/javascripts/admin/admin.js +11 -9
  28. data/script/extension +5 -0
  29. data/spec/controllers/admin/user_controller_spec.rb +1 -1
  30. data/spec/controllers/admin/welcome_controller_spec.rb +31 -5
  31. data/spec/controllers/site_controller_spec.rb +15 -2
  32. data/spec/lib/login_system_spec.rb +106 -60
  33. data/spec/lib/radiant/extension/script_spec.rb +349 -0
  34. data/spec/lib/radiant/extension_loader_spec.rb +3 -0
  35. data/spec/models/page_spec.rb +62 -2
  36. data/spec/models/standard_tags_spec.rb +150 -3
  37. data/spec/models/user_spec.rb +28 -0
  38. data/spec/scenarios/file_not_found_scenario.rb +5 -0
  39. data/spec/scenarios/pages_scenario.rb +6 -0
  40. data/spec/scenarios/snippets_scenario.rb +4 -0
  41. data/test/fixtures/users.yml +11 -6
  42. data/vendor/plugins/haml/FAQ +138 -0
  43. data/vendor/plugins/haml/REVISION +1 -0
  44. data/vendor/plugins/haml/Rakefile +54 -62
  45. data/vendor/plugins/haml/VERSION +1 -1
  46. data/vendor/plugins/haml/init.rb +6 -1
  47. data/vendor/plugins/haml/lib/haml.rb +72 -12
  48. data/vendor/plugins/haml/lib/haml/buffer.rb +47 -40
  49. data/vendor/plugins/haml/lib/haml/engine.rb +20 -30
  50. data/vendor/plugins/haml/lib/haml/error.rb +4 -5
  51. data/vendor/plugins/haml/lib/haml/exec.rb +4 -2
  52. data/vendor/plugins/haml/lib/haml/filters.rb +30 -15
  53. data/vendor/plugins/haml/lib/haml/helpers.rb +47 -28
  54. data/vendor/plugins/haml/lib/haml/helpers/action_view_mods.rb +74 -25
  55. data/vendor/plugins/haml/lib/haml/precompiler.rb +92 -51
  56. data/vendor/plugins/haml/lib/haml/template.rb +11 -3
  57. data/vendor/plugins/haml/lib/haml/template/patch.rb +1 -1
  58. data/vendor/plugins/haml/lib/sass.rb +26 -3
  59. data/vendor/plugins/haml/lib/sass/constant.rb +26 -57
  60. data/vendor/plugins/haml/lib/sass/constant/literal.rb +1 -0
  61. data/vendor/plugins/haml/lib/sass/constant/nil.rb +9 -0
  62. data/vendor/plugins/haml/lib/sass/css.rb +17 -2
  63. data/vendor/plugins/haml/lib/sass/engine.rb +11 -5
  64. data/vendor/plugins/haml/test/haml/engine_test.rb +57 -39
  65. data/vendor/plugins/haml/test/haml/helper_test.rb +20 -4
  66. data/vendor/plugins/haml/test/haml/html2haml_test.rb +1 -3
  67. data/vendor/plugins/haml/test/haml/results/content_for_layout.xhtml +1 -2
  68. data/vendor/plugins/haml/test/haml/results/eval_suppressed.xhtml +2 -4
  69. data/vendor/plugins/haml/test/haml/results/filters.xhtml +12 -8
  70. data/vendor/plugins/haml/test/haml/results/helpers.xhtml +2 -5
  71. data/vendor/plugins/haml/test/haml/results/just_stuff.xhtml +1 -3
  72. data/vendor/plugins/haml/test/haml/results/nuke_inner_whitespace.xhtml +40 -0
  73. data/vendor/plugins/haml/test/haml/results/nuke_outer_whitespace.xhtml +148 -0
  74. data/vendor/plugins/haml/test/haml/results/original_engine.xhtml +2 -4
  75. data/vendor/plugins/haml/test/haml/results/tag_parsing.xhtml +1 -6
  76. data/vendor/plugins/haml/test/haml/results/very_basic.xhtml +2 -4
  77. data/vendor/plugins/haml/test/haml/results/whitespace_handling.xhtml +13 -21
  78. data/vendor/plugins/haml/test/haml/template_test.rb +31 -48
  79. data/vendor/plugins/haml/test/haml/templates/filters.haml +13 -0
  80. data/vendor/plugins/haml/test/haml/templates/helpers.haml +1 -1
  81. data/vendor/plugins/haml/test/haml/templates/just_stuff.haml +0 -1
  82. data/vendor/plugins/haml/test/haml/templates/nuke_inner_whitespace.haml +32 -0
  83. data/vendor/plugins/haml/test/haml/templates/nuke_outer_whitespace.haml +144 -0
  84. data/vendor/plugins/haml/test/haml/templates/partials.haml +1 -1
  85. data/vendor/plugins/haml/test/haml/templates/tag_parsing.haml +0 -3
  86. data/vendor/plugins/haml/test/haml/templates/whitespace_handling.haml +10 -10
  87. data/vendor/plugins/haml/test/sass/engine_test.rb +11 -5
  88. data/vendor/plugins/haml/test/sass/plugin_test.rb +2 -6
  89. data/vendor/plugins/haml/test/sass/results/constants.css +2 -0
  90. data/vendor/plugins/haml/test/sass/templates/constants.sass +3 -0
  91. data/vendor/plugins/haml/test/{haml/test_helper.rb → test_helper.rb} +4 -3
  92. metadata +21 -11
  93. data/vendor/plugins/haml/TODO +0 -9
  94. data/vendor/plugins/haml/extra/haml-mode.el +0 -328
  95. data/vendor/plugins/haml/extra/sass-mode.el +0 -88
  96. data/vendor/plugins/haml/test/profile.rb +0 -65
@@ -0,0 +1 @@
1
+ (release)
@@ -1,38 +1,27 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
 
4
- volatile_requires = ['rcov/rcovtask']
5
- not_loaded = []
6
- volatile_requires.each do |file|
7
- begin
8
- require file
9
- rescue LoadError
10
- not_loaded.push file
11
- end
12
- end
13
-
14
4
  # ----- Benchmarking -----
15
5
 
16
- temp_desc = <<END
6
+ desc <<END
17
7
  Benchmark haml against ERb.
18
- TIMES=n sets the number of runs. Defaults to 100.
8
+ TIMES=n sets the number of runs. Defaults to 1000.
19
9
  END
20
-
21
- desc temp_desc.chomp
22
10
  task :benchmark do
23
11
  sh "ruby test/benchmark.rb #{ENV['TIMES']}"
24
12
  end
25
13
 
26
14
  # ----- Default: Testing ------
27
15
 
28
- desc 'Default: run unit tests.'
29
16
  task :default => :test
30
17
 
31
18
  require 'rake/testtask'
32
19
 
33
20
  Rake::TestTask.new do |t|
34
21
  t.libs << 'lib'
35
- t.pattern = 'test/**/*_test.rb'
22
+ test_files = FileList['test/**/*_test.rb']
23
+ test_files.exclude('test/rails/*')
24
+ t.test_files = test_files
36
25
  t.verbose = true
37
26
  end
38
27
  Rake::Task[:test].send(:add_comment, <<END)
@@ -42,7 +31,6 @@ END
42
31
  # ----- Packaging -----
43
32
 
44
33
  require 'rake/gempackagetask'
45
- require 'lib/haml'
46
34
  load 'haml.gemspec'
47
35
 
48
36
  Rake::GemPackageTask.new(HAML_GEMSPEC) do |pkg|
@@ -53,8 +41,9 @@ Rake::GemPackageTask.new(HAML_GEMSPEC) do |pkg|
53
41
  end
54
42
  end
55
43
 
56
- desc "This is an internal task."
57
44
  task :revision_file do
45
+ require 'lib/haml'
46
+
58
47
  if Haml.version[:rev] && !Rake.application.top_level_tasks.include?('release')
59
48
  File.open('REVISION', 'w') { |f| f.puts Haml.version[:rev] }
60
49
  elsif Rake.application.top_level_tasks.include?('release')
@@ -66,13 +55,15 @@ end
66
55
  Rake::Task[:package].prerequisites.insert(0, :revision_file)
67
56
 
68
57
  # We also need to get rid of this file after packaging.
69
- Rake::Task[:package].enhance { File.delete('REVISION') if File.exists?('REVISION') }
58
+ at_exit { File.delete('REVISION') rescue nil }
70
59
 
60
+ desc "Install Haml as a gem."
71
61
  task :install => [:package] do
72
62
  sudo = RUBY_PLATFORM =~ /win32/ ? '' : 'sudo'
73
63
  sh %{#{sudo} gem install --no-ri pkg/haml-#{File.read('VERSION').strip}}
74
64
  end
75
65
 
66
+ desc "Release a new Haml package to Rubyforge. Requires the NAME and VERSION flags."
76
67
  task :release => [:package] do
77
68
  name, version = ENV['NAME'], ENV['VERSION']
78
69
  raise "Must supply NAME and VERSION for release task." unless name && version
@@ -91,35 +82,26 @@ rescue LoadError
91
82
  require 'rake/rdoctask'
92
83
  end
93
84
 
94
- rdoc_task = Proc.new do |rdoc|
85
+ Rake::RDocTask.new do |rdoc|
95
86
  rdoc.title = 'Haml/Sass'
96
87
  rdoc.options << '--line-numbers' << '--inline-source'
97
- rdoc.rdoc_files.include('README.rdoc')
88
+ rdoc.rdoc_files.include(*FileList.new('*') do |list|
89
+ list.exclude(/(^|[^.a-z])[a-z]+/)
90
+ list.exclude('TODO')
91
+ end.to_a)
98
92
  rdoc.rdoc_files.include('lib/**/*.rb')
93
+ rdoc.rdoc_files.exclude('TODO')
99
94
  rdoc.rdoc_files.exclude('lib/haml/buffer.rb')
100
95
  rdoc.rdoc_files.exclude('lib/sass/tree/*')
101
- end
102
-
103
- Rake::RDocTask.new do |rdoc|
104
- rdoc_task.call(rdoc)
105
96
  rdoc.rdoc_dir = 'rdoc'
106
- end
107
-
108
- Rake::RDocTask.new(:rdoc_devel) do |rdoc|
109
- rdoc_task.call(rdoc)
110
- rdoc.rdoc_dir = 'rdoc_devel'
111
- rdoc.options << '--all'
112
- rdoc.rdoc_files.include('test/*.rb')
113
-
114
- # Get rid of exclusion rules
115
- rdoc.rdoc_files = Rake::FileList.new(*rdoc.rdoc_files.to_a)
116
- rdoc.rdoc_files.include('lib/haml/buffer.rb')
117
- rdoc.rdoc_files.include('lib/sass/tree/*')
97
+ rdoc.main = 'README.rdoc'
118
98
  end
119
99
 
120
100
  # ----- Coverage -----
121
101
 
122
- unless not_loaded.include? 'rcov/rcovtask'
102
+ begin
103
+ require 'rcov/rcovtask'
104
+
123
105
  Rcov::RcovTask.new do |t|
124
106
  t.test_files = FileList['test/**/*_test.rb']
125
107
  t.rcov_opts << '-x' << '"^\/"'
@@ -128,31 +110,41 @@ unless not_loaded.include? 'rcov/rcovtask'
128
110
  end
129
111
  t.verbose = true
130
112
  end
131
- end
113
+ rescue LoadError; end
132
114
 
133
115
  # ----- Profiling -----
134
116
 
135
- temp_desc = <<-END
136
- Run a profile of haml.
137
- ENGINE=str sets the engine to be profiled (Haml or Sass).
138
- TIMES=n sets the number of runs. Defaults to 100.
139
- FILE=n sets the file to profile. Defaults to 'standard'.
140
- END
141
- desc temp_desc.chomp
142
- task :profile do
143
- require 'test/profile'
144
-
145
- engine = ENV['ENGINE'] && ENV['ENGINE'].downcase == 'sass' ? Sass : Haml
146
-
147
- puts '-'*51, "Profiling #{engine}", '-'*51
148
-
149
- args = []
150
- args.push ENV['TIMES'].to_i if ENV['TIMES']
151
- args.push ENV['FILE'] if ENV['FILE']
152
-
153
- profiler = engine::Profiler.new
154
- res = profiler.profile(*args)
155
- puts res
117
+ begin
118
+ require 'ruby-prof'
119
+
120
+ desc <<END
121
+ Run a profile of haml.
122
+ ENGINE=str sets the engine to be profiled. Defaults to Haml.
123
+ TIMES=n sets the number of runs. Defaults to 1000.
124
+ FILE=str sets the file to profile.
125
+ Defaults to 'standard' for Haml and 'complex' for Sass.
126
+ OUTPUT=str sets the ruby-prof output format.
127
+ Can be Flat, CallInfo, or Graph. Defaults to Flat. Defaults to Flat.
128
+ END
129
+ task :profile do
130
+ engine = (ENV['ENGINE'] || 'haml').downcase
131
+ times = (ENV['TIMES'] || '1000').to_i
132
+ file = ENV['FILE']
133
+
134
+ if engine == 'sass'
135
+ require 'lib/sass'
136
+
137
+ file = File.read("#{File.dirname(__FILE__)}/test/sass/templates/#{file || 'complex'}.sass")
138
+ result = RubyProf.profile { times.times { Sass::Engine.new(file).render } }
139
+ else
140
+ require 'lib/haml'
141
+
142
+ file = File.read("#{File.dirname(__FILE__)}/test/haml/templates/#{file || 'standard'}.haml")
143
+ obj = Object.new
144
+ Haml::Engine.new(file).def_method(obj, :render)
145
+ result = RubyProf.profile { times.times { obj.render } }
146
+ end
156
147
 
157
- puts '-'*51
158
- end
148
+ RubyProf.const_get("#{(ENV['OUTPUT'] || 'Flat').capitalize}Printer").new(result).print
149
+ end
150
+ rescue LoadError; end
@@ -1 +1 @@
1
- 1.9.0
1
+ 2.0.1
@@ -1,2 +1,7 @@
1
- require 'haml'
1
+ begin
2
+ require File.join(File.dirname(__FILE__), 'lib', 'haml') # From here
3
+ rescue LoadError
4
+ require 'haml' # From gem
5
+ end
6
+
2
7
  Haml.init_rails(binding)
@@ -342,6 +342,61 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
342
342
  # </div>
343
343
  # </div>
344
344
  #
345
+ # ==== > and <
346
+ #
347
+ # <tt>></tt> and <tt><</tt> give you more control over the whitespace near a tag.
348
+ # <tt>></tt> will remove all whitespace surrounding a tag,
349
+ # while <tt><</tt> will remove all whitespace immediately within a tag.
350
+ # You can think of them as alligators eating the whitespace:
351
+ # <tt>></tt> faces out of the tag and eats the whitespace on the outside,
352
+ # and <tt><</tt> faces into the tag and eats the whitespace on the inside.
353
+ # They're placed at the end of a tag definition,
354
+ # after class, id, and attribute declarations
355
+ # but before <tt>/</tt> or <tt>=</tt>.
356
+ # For example:
357
+ #
358
+ # %blockquote<
359
+ # %div
360
+ # Foo!
361
+ #
362
+ # is compiled to:
363
+ #
364
+ # <blockquote><div>
365
+ # Foo!
366
+ # </div></blockquote>
367
+ #
368
+ # And:
369
+ #
370
+ # %img
371
+ # %img>
372
+ # %img
373
+ #
374
+ # is compiled to:
375
+ #
376
+ # <img /><img /><img />
377
+ #
378
+ # And:
379
+ #
380
+ # %p<= "Foo\nBar"
381
+ #
382
+ # is compiled to:
383
+ #
384
+ # <p>Foo
385
+ # Bar</p>
386
+ #
387
+ # And finally:
388
+ #
389
+ # %img
390
+ # %pre><
391
+ # foo
392
+ # bar
393
+ # %img
394
+ #
395
+ # is compiled to:
396
+ #
397
+ # <img /><pre>foo
398
+ # bar</pre><img />
399
+ #
345
400
  # ==== =
346
401
  #
347
402
  # <tt>=</tt> is placed at the end of a tag definition,
@@ -600,6 +655,9 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
600
655
  # [javascript] Surrounds the filtered text with <script> and CDATA tags.
601
656
  # Useful for including inline Javascript.
602
657
  #
658
+ # [escaped] Works the same as plain, but HTML-escapes the text
659
+ # before placing it in the document.
660
+ #
603
661
  # [ruby] Parses the filtered text with the normal Ruby interpreter.
604
662
  # All output sent to <tt>$stdout</tt>, like with +puts+,
605
663
  # is output into the Haml document.
@@ -630,7 +688,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
630
688
  # is installed
631
689
  # (BlueCloth takes precedence if both are installed).
632
690
  #
633
- # You can also define your own filters (see Setting Options, below).
691
+ # You can also define your own filters (see Haml::Filters).
634
692
  #
635
693
  # === Ruby evaluators
636
694
  #
@@ -856,9 +914,16 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
856
914
  #
857
915
  # === Haml Options
858
916
  #
859
- # Options can be set by setting the hash <tt>Haml::Template.options</tt>
860
- # from <tt>environment.rb</tt> in Rails,
861
- # or by passing an options hash to Haml::Engine.
917
+ # Options can be set by setting the <tt>Haml::Template.options</tt> hash
918
+ # in <tt>environment.rb</tt> in Rails...
919
+ #
920
+ # Haml::Template.options[:output] = :html5
921
+ #
922
+ # ...or by setting the <tt>Merb::Config[:haml]</tt> hash in <tt>init.rb</tt> in Merb...
923
+ #
924
+ # Merb::Config[:haml][:output] = :html5
925
+ #
926
+ # ...or by passing an options hash to Haml::Engine.new.
862
927
  # Available options are:
863
928
  #
864
929
  # [<tt>:output</tt>] Determines the output format. The default is :xhtml.
@@ -869,7 +934,8 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
869
934
  # [<tt>:escape_html</tt>] Sets whether or not to escape HTML-sensitive characters in script.
870
935
  # If this is true, = behaves like &=;
871
936
  # otherwise, it behaves like !=.
872
- # <b>Note that this escapes tag attributes.</b>
937
+ # Note that if this is set, != should be used for yielding to subtemplates
938
+ # and rendering partials.
873
939
  # Defaults to false.
874
940
  #
875
941
  # [<tt>:suppress_eval</tt>] Whether or not attribute hashes and Ruby scripts
@@ -893,12 +959,6 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
893
959
  # This is useful for inline templates,
894
960
  # similar to the last argument to Kernel#eval.
895
961
  #
896
- # [<tt>:filters</tt>] A hash of filters that can be applied to Haml code.
897
- # The keys are the string names of the filters;
898
- # the values are references to the classes of the filters.
899
- # User-defined filters should always have lowercase keys,
900
- # and should have the interface described in Haml::Filters::Base.
901
- #
902
962
  # [<tt>:autoclose</tt>] A list of tag names that should be automatically self-closed
903
963
  # if they have no content.
904
964
  # Defaults to <tt>['meta', 'img', 'link', 'br', 'hr', 'input', 'area', 'param', 'col', 'base']</tt>.
@@ -937,7 +997,7 @@ module Haml
937
997
 
938
998
  if File.exists?(scope('REVISION'))
939
999
  rev = File.read(scope('REVISION')).strip
940
- rev = nil if rev !~ /a-f0-9+/
1000
+ rev = nil if rev !~ /[a-f0-9]+/
941
1001
  end
942
1002
 
943
1003
  if rev.nil? && File.exists?(scope('.git/HEAD'))
@@ -84,58 +84,70 @@ module Haml
84
84
 
85
85
  # Renders +text+ with the proper tabulation. This also deals with
86
86
  # making a possible one-line tag one line or not.
87
- def push_text(text, tab_change = 0)
87
+ def push_text(text, dont_tab_up = false, tab_change = 0)
88
88
  if @tabulation > 0 && !@options[:ugly]
89
- # Have to push every line in by the extra user set tabulation
90
- text.gsub!(/^/m, ' ' * @tabulation)
89
+ # Have to push every line in by the extra user set tabulation.
90
+ # Don't push lines with just whitespace, though,
91
+ # because that screws up precompiled indentation.
92
+ text.gsub!(/^(?!\s+$)/m, tabs)
93
+ text.sub!(tabs, '') if dont_tab_up
91
94
  end
92
95
 
93
96
  @buffer << text
94
97
  @real_tabs += tab_change
98
+ @dont_tab_up_next_line = false
95
99
  end
96
100
 
97
101
  # Properly formats the output of a script that was run in the
98
102
  # instance_eval.
99
- def push_script(result, preserve_script, close_tag = nil, preserve_tag = false, escape_html = false)
103
+ def push_script(result, preserve_script, in_tag = false, preserve_tag = false,
104
+ escape_html = false, nuke_inner_whitespace = false)
100
105
  tabulation = @real_tabs
101
106
 
102
107
  if preserve_tag
103
108
  result = Haml::Helpers.preserve(result)
104
109
  elsif preserve_script
105
- result = Haml::Helpers.find_and_preserve(result)
110
+ result = Haml::Helpers.find_and_preserve(result, options[:preserve])
106
111
  end
107
112
 
108
- result = result.to_s
109
- while result[-1] == ?\n
110
- # String#chomp is slow
111
- result = result[0...-1]
113
+ result = result.to_s.rstrip
114
+ result = html_escape(result) if escape_html
115
+
116
+ has_newline = result.include?("\n")
117
+ if in_tag && !nuke_inner_whitespace && (@options[:ugly] || !has_newline || preserve_tag)
118
+ @buffer << result
119
+ @real_tabs -= 1
120
+ return
112
121
  end
113
122
 
114
- result = html_escape(result) if escape_html
123
+ @buffer << "\n" if in_tag && !nuke_inner_whitespace
124
+
125
+ # Precompiled tabulation may be wrong
126
+ if @tabulation > 0 && !in_tag
127
+ result = tabs + result
128
+ end
115
129
 
116
- if close_tag && (@options[:ugly] || !result.include?("\n") || preserve_tag)
117
- @buffer << "#{result}</#{close_tag}>\n"
130
+ if has_newline && !@options[:ugly]
131
+ result = result.gsub "\n", "\n" + tabs(tabulation)
132
+
133
+ # Add tabulation if it wasn't precompiled
134
+ result = tabs(tabulation) + result if in_tag && !nuke_inner_whitespace
135
+ end
136
+ @buffer << "#{result}"
137
+ @buffer << "\n" unless nuke_inner_whitespace
138
+
139
+ if in_tag && !nuke_inner_whitespace
140
+ # We never get here if @options[:ugly] is true
141
+ @buffer << tabs(tabulation-1)
118
142
  @real_tabs -= 1
119
- else
120
- if close_tag
121
- @buffer << "\n"
122
- end
123
-
124
- result = result.gsub(/^/m, tabs(tabulation)) unless @options[:ugly]
125
- @buffer << "#{result}\n"
126
-
127
- if close_tag
128
- # We never get here if @options[:ugly] is true
129
- @buffer << "#{tabs(tabulation-1)}</#{close_tag}>\n"
130
- @real_tabs -= 1
131
- end
132
143
  end
133
144
  nil
134
145
  end
135
146
 
136
147
  # Takes the various information about the opening tag for an
137
148
  # element, formats it, and adds it to the buffer.
138
- def open_tag(name, self_closing, try_one_line, preserve_tag, escape_html, class_id, obj_ref, content, *attributes_hashes)
149
+ def open_tag(name, self_closing, try_one_line, preserve_tag, escape_html, class_id,
150
+ nuke_outer_whitespace, nuke_inner_whitespace, obj_ref, content, *attributes_hashes)
139
151
  tabulation = @real_tabs
140
152
 
141
153
  attributes = class_id
@@ -146,25 +158,20 @@ module Haml
146
158
  self.class.merge_attrs(attributes, parse_object_ref(obj_ref)) if obj_ref
147
159
 
148
160
  if self_closing
149
- str = " />\n"
150
- elsif try_one_line || preserve_tag
151
- str = ">"
161
+ str = " />" + (nuke_outer_whitespace ? "" : "\n")
152
162
  else
153
- str = ">\n"
163
+ str = ">" + (try_one_line || preserve_tag || nuke_inner_whitespace ? "" : "\n")
154
164
  end
155
165
 
156
166
  attributes = Precompiler.build_attributes(html?, @options[:attr_wrapper], attributes)
157
- @buffer << "#{@options[:ugly] ? '' : tabs(tabulation)}<#{name}#{attributes}#{str}"
167
+ @buffer << "#{nuke_outer_whitespace || @options[:ugly] ? '' : tabs(tabulation)}<#{name}#{attributes}#{str}"
158
168
 
159
169
  if content
160
- if @options[:ugly] || !content.include?("\n")
161
- @buffer << "#{content}</#{name}>\n"
162
- else
163
- @buffer << "\n#{tabs(@real_tabs+1)}#{content}\n#{tabs(@real_tabs)}</#{name}>\n"
164
- end
165
- elsif !self_closing
166
- @real_tabs += 1
170
+ @buffer << "#{content}</#{name}>" << (nuke_outer_whitespace ? "" : "\n")
171
+ return
167
172
  end
173
+
174
+ @real_tabs += 1 unless self_closing || nuke_inner_whitespace
168
175
  end
169
176
 
170
177
  def self.merge_attrs(to, from)
@@ -191,8 +198,8 @@ module Haml
191
198
 
192
199
  @@tab_cache = {}
193
200
  # Gets <tt>count</tt> tabs. Mostly for internal use.
194
- def tabs(count)
195
- tabs = count + @tabulation
201
+ def tabs(count = 0)
202
+ tabs = [count + @tabulation, 0].max
196
203
  @@tab_cache[tabs] ||= ' ' * tabs
197
204
  end
198
205