haml-edge 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. data/EDGE_GEM_VERSION +1 -0
  2. data/FAQ +138 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +332 -0
  5. data/REVISION +1 -0
  6. data/Rakefile +226 -0
  7. data/VERSION +1 -0
  8. data/bin/css2sass +7 -0
  9. data/bin/haml +9 -0
  10. data/bin/html2haml +7 -0
  11. data/bin/sass +8 -0
  12. data/extra/edge_gem_watch.rb +13 -0
  13. data/extra/haml-mode.el +596 -0
  14. data/extra/sass-mode.el +200 -0
  15. data/init.rb +8 -0
  16. data/lib/haml/buffer.rb +255 -0
  17. data/lib/haml/engine.rb +268 -0
  18. data/lib/haml/error.rb +22 -0
  19. data/lib/haml/exec.rb +395 -0
  20. data/lib/haml/filters.rb +275 -0
  21. data/lib/haml/helpers/action_view_extensions.rb +45 -0
  22. data/lib/haml/helpers/action_view_mods.rb +181 -0
  23. data/lib/haml/helpers.rb +488 -0
  24. data/lib/haml/html.rb +222 -0
  25. data/lib/haml/precompiler.rb +904 -0
  26. data/lib/haml/shared.rb +45 -0
  27. data/lib/haml/template/patch.rb +58 -0
  28. data/lib/haml/template/plugin.rb +72 -0
  29. data/lib/haml/template.rb +42 -0
  30. data/lib/haml/util.rb +88 -0
  31. data/lib/haml/version.rb +47 -0
  32. data/lib/haml.rb +1044 -0
  33. data/lib/sass/css.rb +388 -0
  34. data/lib/sass/engine.rb +495 -0
  35. data/lib/sass/environment.rb +46 -0
  36. data/lib/sass/error.rb +35 -0
  37. data/lib/sass/plugin/merb.rb +56 -0
  38. data/lib/sass/plugin/rails.rb +24 -0
  39. data/lib/sass/plugin.rb +204 -0
  40. data/lib/sass/repl.rb +51 -0
  41. data/lib/sass/script/bool.rb +13 -0
  42. data/lib/sass/script/color.rb +97 -0
  43. data/lib/sass/script/funcall.rb +29 -0
  44. data/lib/sass/script/functions.rb +134 -0
  45. data/lib/sass/script/lexer.rb +148 -0
  46. data/lib/sass/script/literal.rb +82 -0
  47. data/lib/sass/script/number.rb +231 -0
  48. data/lib/sass/script/operation.rb +30 -0
  49. data/lib/sass/script/parser.rb +142 -0
  50. data/lib/sass/script/string.rb +9 -0
  51. data/lib/sass/script/unary_operation.rb +21 -0
  52. data/lib/sass/script/variable.rb +20 -0
  53. data/lib/sass/script.rb +38 -0
  54. data/lib/sass/tree/attr_node.rb +64 -0
  55. data/lib/sass/tree/comment_node.rb +30 -0
  56. data/lib/sass/tree/debug_node.rb +22 -0
  57. data/lib/sass/tree/directive_node.rb +50 -0
  58. data/lib/sass/tree/file_node.rb +27 -0
  59. data/lib/sass/tree/for_node.rb +29 -0
  60. data/lib/sass/tree/if_node.rb +27 -0
  61. data/lib/sass/tree/mixin_def_node.rb +18 -0
  62. data/lib/sass/tree/mixin_node.rb +35 -0
  63. data/lib/sass/tree/node.rb +99 -0
  64. data/lib/sass/tree/rule_node.rb +161 -0
  65. data/lib/sass/tree/variable_node.rb +24 -0
  66. data/lib/sass/tree/while_node.rb +21 -0
  67. data/lib/sass.rb +1062 -0
  68. data/rails/init.rb +1 -0
  69. data/test/benchmark.rb +99 -0
  70. data/test/haml/engine_test.rb +795 -0
  71. data/test/haml/helper_test.rb +228 -0
  72. data/test/haml/html2haml_test.rb +108 -0
  73. data/test/haml/markaby/standard.mab +52 -0
  74. data/test/haml/mocks/article.rb +6 -0
  75. data/test/haml/results/content_for_layout.xhtml +15 -0
  76. data/test/haml/results/eval_suppressed.xhtml +9 -0
  77. data/test/haml/results/filters.xhtml +62 -0
  78. data/test/haml/results/helpers.xhtml +93 -0
  79. data/test/haml/results/helpful.xhtml +10 -0
  80. data/test/haml/results/just_stuff.xhtml +68 -0
  81. data/test/haml/results/list.xhtml +12 -0
  82. data/test/haml/results/nuke_inner_whitespace.xhtml +40 -0
  83. data/test/haml/results/nuke_outer_whitespace.xhtml +148 -0
  84. data/test/haml/results/original_engine.xhtml +20 -0
  85. data/test/haml/results/partial_layout.xhtml +5 -0
  86. data/test/haml/results/partials.xhtml +21 -0
  87. data/test/haml/results/render_layout.xhtml +3 -0
  88. data/test/haml/results/silent_script.xhtml +74 -0
  89. data/test/haml/results/standard.xhtml +162 -0
  90. data/test/haml/results/tag_parsing.xhtml +23 -0
  91. data/test/haml/results/very_basic.xhtml +5 -0
  92. data/test/haml/results/whitespace_handling.xhtml +89 -0
  93. data/test/haml/rhtml/_av_partial_1.rhtml +12 -0
  94. data/test/haml/rhtml/_av_partial_2.rhtml +8 -0
  95. data/test/haml/rhtml/action_view.rhtml +62 -0
  96. data/test/haml/rhtml/standard.rhtml +54 -0
  97. data/test/haml/template_test.rb +204 -0
  98. data/test/haml/templates/_av_partial_1.haml +9 -0
  99. data/test/haml/templates/_av_partial_1_ugly.haml +9 -0
  100. data/test/haml/templates/_av_partial_2.haml +5 -0
  101. data/test/haml/templates/_av_partial_2_ugly.haml +5 -0
  102. data/test/haml/templates/_layout.erb +3 -0
  103. data/test/haml/templates/_layout_for_partial.haml +3 -0
  104. data/test/haml/templates/_partial.haml +8 -0
  105. data/test/haml/templates/_text_area.haml +3 -0
  106. data/test/haml/templates/action_view.haml +47 -0
  107. data/test/haml/templates/action_view_ugly.haml +47 -0
  108. data/test/haml/templates/breakage.haml +8 -0
  109. data/test/haml/templates/content_for_layout.haml +10 -0
  110. data/test/haml/templates/eval_suppressed.haml +11 -0
  111. data/test/haml/templates/filters.haml +66 -0
  112. data/test/haml/templates/helpers.haml +95 -0
  113. data/test/haml/templates/helpful.haml +11 -0
  114. data/test/haml/templates/just_stuff.haml +83 -0
  115. data/test/haml/templates/list.haml +12 -0
  116. data/test/haml/templates/nuke_inner_whitespace.haml +32 -0
  117. data/test/haml/templates/nuke_outer_whitespace.haml +144 -0
  118. data/test/haml/templates/original_engine.haml +17 -0
  119. data/test/haml/templates/partial_layout.haml +3 -0
  120. data/test/haml/templates/partialize.haml +1 -0
  121. data/test/haml/templates/partials.haml +12 -0
  122. data/test/haml/templates/render_layout.haml +2 -0
  123. data/test/haml/templates/silent_script.haml +40 -0
  124. data/test/haml/templates/standard.haml +42 -0
  125. data/test/haml/templates/standard_ugly.haml +42 -0
  126. data/test/haml/templates/tag_parsing.haml +21 -0
  127. data/test/haml/templates/very_basic.haml +4 -0
  128. data/test/haml/templates/whitespace_handling.haml +87 -0
  129. data/test/haml/util_test.rb +87 -0
  130. data/test/linked_rails.rb +12 -0
  131. data/test/sass/css2sass_test.rb +193 -0
  132. data/test/sass/engine_test.rb +709 -0
  133. data/test/sass/functions_test.rb +109 -0
  134. data/test/sass/more_results/more1.css +9 -0
  135. data/test/sass/more_results/more1_with_line_comments.css +26 -0
  136. data/test/sass/more_results/more_import.css +29 -0
  137. data/test/sass/more_templates/_more_partial.sass +2 -0
  138. data/test/sass/more_templates/more1.sass +23 -0
  139. data/test/sass/more_templates/more_import.sass +11 -0
  140. data/test/sass/plugin_test.rb +213 -0
  141. data/test/sass/results/alt.css +4 -0
  142. data/test/sass/results/basic.css +9 -0
  143. data/test/sass/results/compact.css +5 -0
  144. data/test/sass/results/complex.css +87 -0
  145. data/test/sass/results/compressed.css +1 -0
  146. data/test/sass/results/expanded.css +19 -0
  147. data/test/sass/results/import.css +29 -0
  148. data/test/sass/results/line_numbers.css +49 -0
  149. data/test/sass/results/mixins.css +95 -0
  150. data/test/sass/results/multiline.css +24 -0
  151. data/test/sass/results/nested.css +22 -0
  152. data/test/sass/results/parent_ref.css +13 -0
  153. data/test/sass/results/script.css +16 -0
  154. data/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
  155. data/test/sass/results/subdir/subdir.css +3 -0
  156. data/test/sass/results/units.css +11 -0
  157. data/test/sass/script_test.rb +250 -0
  158. data/test/sass/templates/_partial.sass +2 -0
  159. data/test/sass/templates/alt.sass +16 -0
  160. data/test/sass/templates/basic.sass +23 -0
  161. data/test/sass/templates/bork.sass +2 -0
  162. data/test/sass/templates/bork2.sass +2 -0
  163. data/test/sass/templates/compact.sass +17 -0
  164. data/test/sass/templates/complex.sass +309 -0
  165. data/test/sass/templates/compressed.sass +15 -0
  166. data/test/sass/templates/expanded.sass +17 -0
  167. data/test/sass/templates/import.sass +11 -0
  168. data/test/sass/templates/importee.sass +19 -0
  169. data/test/sass/templates/line_numbers.sass +13 -0
  170. data/test/sass/templates/mixins.sass +76 -0
  171. data/test/sass/templates/multiline.sass +20 -0
  172. data/test/sass/templates/nested.sass +25 -0
  173. data/test/sass/templates/parent_ref.sass +25 -0
  174. data/test/sass/templates/script.sass +101 -0
  175. data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
  176. data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
  177. data/test/sass/templates/subdir/subdir.sass +6 -0
  178. data/test/sass/templates/units.sass +11 -0
  179. data/test/test_helper.rb +21 -0
  180. metadata +278 -0
@@ -0,0 +1,45 @@
1
+ require 'strscan'
2
+
3
+ # :stopdoc:
4
+ module Haml
5
+ # This module contains functionality that's shared across Haml and Sass.
6
+ module Shared
7
+ def self.handle_interpolation(str)
8
+ scan = StringScanner.new(str)
9
+ yield scan while scan.scan(/(.*?)(\\*)\#\{/)
10
+ scan.rest
11
+ end
12
+
13
+ def self.balance(scanner, start, finish, count = 0)
14
+ str = ''
15
+ scanner = StringScanner.new(scanner) unless scanner.is_a? StringScanner
16
+ regexp = Regexp.new("(.*?)[\\#{start.chr}\\#{finish.chr}]", Regexp::MULTILINE)
17
+ while scanner.scan(regexp)
18
+ str << scanner.matched
19
+ count += 1 if scanner.matched[-1] == start
20
+ count -= 1 if scanner.matched[-1] == finish
21
+ return [str.strip, scanner.rest] if count == 0
22
+ end
23
+ end
24
+
25
+ def self.human_indentation(indentation, was = false)
26
+ if !indentation.include?(?\t)
27
+ noun = 'space'
28
+ elsif !indentation.include?(?\s)
29
+ noun = 'tab'
30
+ else
31
+ return indentation.inspect + (was ? ' was' : '')
32
+ end
33
+
34
+ singular = indentation.length == 1
35
+ if was
36
+ was = singular ? ' was' : ' were'
37
+ else
38
+ was = ''
39
+ end
40
+
41
+ "#{indentation.length} #{noun}#{'s' unless singular}#{was}"
42
+ end
43
+ end
44
+ end
45
+ # :startdoc:
@@ -0,0 +1,58 @@
1
+ # This file makes Haml work with Rails
2
+ # by monkeypatching the core template-compilation methods.
3
+ # This is necessary for versions <= 2.0.1 because the template handler API
4
+ # wasn't sufficiently powerful to deal with caching and so forth.
5
+
6
+ # This module refers to the ActionView module that's part of Ruby on Rails.
7
+ # Haml can be used as an alternate templating engine for it,
8
+ # and includes several modifications to make it more Haml-friendly.
9
+ # The documentation can be found
10
+ # here[http://rubyonrails.org/api/classes/ActionView/Base.html].
11
+ module ActionView
12
+ class Base # :nodoc:
13
+ def delegate_template_exists_with_haml(template_path)
14
+ template_exists?(template_path, :haml) && [:haml]
15
+ end
16
+ alias_method :delegate_template_exists_without_haml, :delegate_template_exists?
17
+ alias_method :delegate_template_exists?, :delegate_template_exists_with_haml
18
+
19
+ def compile_template_with_haml(extension, template, file_name, local_assigns)
20
+ return compile_haml(template, file_name, local_assigns) if extension.to_s == "haml"
21
+ compile_template_without_haml(extension, template, file_name, local_assigns)
22
+ end
23
+ alias_method :compile_template_without_haml, :compile_template
24
+ alias_method :compile_template, :compile_template_with_haml
25
+
26
+ def compile_haml(template, file_name, local_assigns)
27
+ render_symbol = assign_method_name(:haml, template, file_name)
28
+ locals = local_assigns.keys
29
+
30
+ @@template_args[render_symbol] ||= {}
31
+ locals_keys = @@template_args[render_symbol].keys | locals
32
+ @@template_args[render_symbol] = Haml::Util.to_hash(locals_keys.map {|k| [k, true]})
33
+
34
+ options = Haml::Template.options.dup
35
+ options[:filename] = file_name || 'compiled-template'
36
+
37
+ begin
38
+ Haml::Engine.new(template, options).def_method(CompiledTemplates, render_symbol, *locals_keys)
39
+ rescue Exception => e
40
+ if logger
41
+ logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}"
42
+ logger.debug "Backtrace: #{e.backtrace.join("\n")}"
43
+ end
44
+
45
+ base_path = if defined?(extract_base_path_from)
46
+ # Rails 2.0.x
47
+ extract_base_path_from(file_name) || view_paths.first
48
+ else
49
+ # Rails <=1.2.6
50
+ @base_path
51
+ end
52
+ raise ActionView::TemplateError.new(base_path, file_name || template, @assigns, template, e)
53
+ end
54
+
55
+ @@compile_time[render_symbol] = Time.now
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,72 @@
1
+ # :stopdoc:
2
+ # This file makes Haml work with Rails
3
+ # using the > 2.0.1 template handler API.
4
+
5
+ module Haml
6
+ class Plugin < ActionView::TemplateHandler
7
+ include ActionView::TemplateHandlers::Compilable if defined?(ActionView::TemplateHandlers::Compilable)
8
+
9
+ def compile(template)
10
+ options = Haml::Template.options.dup
11
+
12
+ # template is a template object in Rails >=2.1.0,
13
+ # a source string previously
14
+ if template.respond_to? :source
15
+ options[:filename] = template.filename
16
+ source = template.source
17
+ else
18
+ source = template
19
+ end
20
+
21
+ Haml::Engine.new(source, options).send(:precompiled_with_ambles, [])
22
+ end
23
+
24
+ def cache_fragment(block, name = {}, options = nil)
25
+ @view.fragment_for(block, name, options) do
26
+ eval("_hamlout.buffer", block.binding)
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ if defined? ActionView::Template and ActionView::Template.respond_to? :register_template_handler
33
+ ActionView::Template
34
+ else
35
+ ActionView::Base
36
+ end.register_template_handler(:haml, Haml::Plugin)
37
+
38
+ # In Rails 2.0.2, ActionView::TemplateError took arguments
39
+ # that we can't fill in from the Haml::Plugin context.
40
+ # Thus, we've got to monkeypatch ActionView::Base to catch the error.
41
+ if ActionView::TemplateError.instance_method(:initialize).arity == 5
42
+ class ActionView::Base
43
+ def compile_template(handler, template, file_name, local_assigns)
44
+ render_symbol = assign_method_name(handler, template, file_name)
45
+
46
+ # Move begin up two lines so it captures compilation exceptions.
47
+ begin
48
+ render_source = create_template_source(handler, template, render_symbol, local_assigns.keys)
49
+ line_offset = @@template_args[render_symbol].size + handler.line_offset
50
+
51
+ file_name = 'compiled-template' if file_name.blank?
52
+ CompiledTemplates.module_eval(render_source, file_name, -line_offset)
53
+ rescue Exception => e # errors from template code
54
+ if logger
55
+ logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}"
56
+ logger.debug "Function body: #{render_source}"
57
+ logger.debug "Backtrace: #{e.backtrace.join("\n")}"
58
+ end
59
+
60
+ # There's no way to tell Haml about the filename,
61
+ # so we've got to insert it ourselves.
62
+ e.backtrace[0].gsub!('(haml)', file_name) if e.is_a?(Haml::Error)
63
+
64
+ raise ActionView::TemplateError.new(extract_base_path_from(file_name) || view_paths.first, file_name || template, @assigns, template, e)
65
+ end
66
+
67
+ @@compile_time[render_symbol] = Time.now
68
+ # logger.debug "Compiled template #{file_name || template}\n ==> #{render_symbol}" if logger
69
+ end
70
+ end
71
+ end
72
+ # :startdoc:
@@ -0,0 +1,42 @@
1
+ require 'haml/engine'
2
+
3
+ module Haml
4
+ module Template
5
+ extend self
6
+
7
+ @options = {}
8
+ attr_accessor :options
9
+ end
10
+ end
11
+
12
+ # Decide how we want to load Haml into Rails.
13
+ # Patching was necessary for versions <= 2.0.1,
14
+ # but we can make it a normal handler for higher versions.
15
+ if defined?(ActionView::TemplateHandler)
16
+ require 'haml/template/plugin'
17
+ else
18
+ require 'haml/template/patch'
19
+ end
20
+
21
+ if defined?(RAILS_ROOT)
22
+ # Update init.rb to the current version
23
+ # if it's out of date.
24
+ #
25
+ # We can probably remove this as of v1.9,
26
+ # because the new init file is sufficiently flexible
27
+ # to not need updating.
28
+ rails_init_file = File.join(RAILS_ROOT, 'vendor', 'plugins', 'haml', 'init.rb')
29
+ haml_init_file = Haml.scope('init.rb')
30
+ begin
31
+ if File.exists?(rails_init_file)
32
+ require 'fileutils'
33
+ FileUtils.cp(haml_init_file, rails_init_file) unless FileUtils.cmp(rails_init_file, haml_init_file)
34
+ end
35
+ rescue SystemCallError
36
+ warn <<END
37
+ HAML WARNING:
38
+ #{rails_init_file} is out of date and couldn't be automatically updated.
39
+ Please run `haml --rails #{File.expand_path(RAILS_ROOT)}' to update it.
40
+ END
41
+ end
42
+ end
data/lib/haml/util.rb ADDED
@@ -0,0 +1,88 @@
1
+ require 'erb'
2
+ require 'set'
3
+ require 'enumerator'
4
+
5
+ module Haml
6
+ module Util
7
+ extend self
8
+
9
+ RUBY_VERSION = ::RUBY_VERSION.split(".").map {|s| s.to_i}
10
+
11
+ def to_hash(arr)
12
+ arr.compact.inject({}) {|h, (k, v)| h[k] = v; h}
13
+ end
14
+
15
+ def map_keys(hash)
16
+ to_hash(hash.map {|k, v| [yield(k), v]})
17
+ end
18
+
19
+ def map_vals(hash)
20
+ to_hash(hash.map {|k, v| [k, yield(v)]})
21
+ end
22
+
23
+ def map_hash(hash, &block)
24
+ to_hash(hash.map(&block))
25
+ end
26
+
27
+ def powerset(arr)
28
+ arr.inject([Set.new].to_set) do |powerset, el|
29
+ new_powerset = Set.new
30
+ powerset.each do |subset|
31
+ new_powerset << subset
32
+ new_powerset << subset + [el]
33
+ end
34
+ new_powerset
35
+ end
36
+ end
37
+
38
+ def merge_adjacent_strings(enum)
39
+ e = enum.inject([]) do |a, e|
40
+ if e.is_a?(String) && a.last.is_a?(String)
41
+ a.last << e
42
+ else
43
+ a << e
44
+ end
45
+ a
46
+ end
47
+ end
48
+
49
+ def ruby1_8?
50
+ Haml::Util::RUBY_VERSION[0] == 1 && Haml::Util::RUBY_VERSION[1] < 9
51
+ end
52
+
53
+ def has?(attr, klass, method)
54
+ klass.send("#{attr}s").include?(ruby1_8? ? method.to_s : method.to_sym)
55
+ end
56
+
57
+ def enum_with_index(enum)
58
+ ruby1_8? ? enum.enum_with_index : enum.each_with_index
59
+ end
60
+
61
+ class StaticConditionalContext
62
+ def initialize(set)
63
+ @set = set
64
+ end
65
+
66
+ def method_missing(name, *args, &block)
67
+ super unless args.empty? && block.nil?
68
+ @set.include?(name)
69
+ end
70
+ end
71
+
72
+ def def_static_method(klass, name, args, *vars)
73
+ erb = vars.pop
74
+ powerset(vars).each do |set|
75
+ context = StaticConditionalContext.new(set).instance_eval {binding}
76
+ klass.class_eval(<<METHOD)
77
+ def #{static_method_name(name, *vars.map {|v| set.include?(v)})}(#{args.join(', ')})
78
+ #{ERB.new(erb).result(context)}
79
+ end
80
+ METHOD
81
+ end
82
+ end
83
+
84
+ def static_method_name(name, *vars)
85
+ "#{name}_#{vars.map {|v| !!v}.join('_')}"
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,47 @@
1
+ module Haml
2
+ module Version
3
+ # Returns a hash representing the version of Haml.
4
+ # The :major, :minor, and :teeny keys have their respective numbers.
5
+ # The :string key contains a human-readable string representation of the version.
6
+ # If Haml is checked out from Git,
7
+ # the :rev key will have the revision hash.
8
+ def version
9
+ return @@version if defined?(@@version)
10
+
11
+ numbers = File.read(scope('VERSION')).strip.split('.').map { |n| n.to_i }
12
+ @@version = {
13
+ :major => numbers[0],
14
+ :minor => numbers[1],
15
+ :teeny => numbers[2]
16
+ }
17
+ @@version[:string] = [:major, :minor, :teeny].map { |comp| @@version[comp] }.compact.join('.')
18
+
19
+ if File.exists?(scope('REVISION'))
20
+ rev = File.read(scope('REVISION')).strip
21
+ rev = nil if rev !~ /^([a-f0-9]+|\(.*\))$/
22
+ end
23
+
24
+ if (rev.nil? || rev == '(unknown)') && File.exists?(scope('.git/HEAD'))
25
+ rev = File.read(scope('.git/HEAD')).strip
26
+ if rev =~ /^ref: (.*)$/
27
+ rev = File.read(scope(".git/#{$1}")).strip
28
+ end
29
+ end
30
+
31
+ if rev
32
+ @@version[:rev] = rev
33
+ unless rev[0] == ?(
34
+ @@version[:string] << "."
35
+ @@version[:string] << rev[0...7]
36
+ end
37
+ end
38
+
39
+ @@version
40
+ end
41
+
42
+ # Returns the path of file relative to the Haml root.
43
+ def scope(file) # :nodoc:
44
+ File.expand_path File.join(File.dirname(__FILE__), '..', '..', file)
45
+ end
46
+ end
47
+ end