haml 5.2.2 → 6.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/workflows/test.yml +13 -14
  4. data/.gitignore +16 -16
  5. data/.yardopts +0 -3
  6. data/CHANGELOG.md +116 -3
  7. data/Gemfile +18 -11
  8. data/MIT-LICENSE +1 -1
  9. data/README.md +17 -23
  10. data/REFERENCE.md +69 -145
  11. data/Rakefile +48 -81
  12. data/bin/bench +66 -0
  13. data/bin/console +11 -0
  14. data/bin/ruby +3 -0
  15. data/bin/setup +7 -0
  16. data/bin/stackprof +27 -0
  17. data/bin/test +24 -0
  18. data/exe/haml +6 -0
  19. data/ext/haml/extconf.rb +10 -0
  20. data/ext/haml/haml.c +537 -0
  21. data/ext/haml/hescape.c +108 -0
  22. data/ext/haml/hescape.h +20 -0
  23. data/haml.gemspec +39 -37
  24. data/lib/haml/ambles.rb +20 -0
  25. data/lib/haml/attribute_builder.rb +134 -179
  26. data/lib/haml/attribute_compiler.rb +85 -194
  27. data/lib/haml/attribute_parser.rb +92 -126
  28. data/lib/haml/cli.rb +154 -0
  29. data/lib/haml/compiler/children_compiler.rb +155 -0
  30. data/lib/haml/compiler/comment_compiler.rb +51 -0
  31. data/lib/haml/compiler/doctype_compiler.rb +46 -0
  32. data/lib/haml/compiler/script_compiler.rb +114 -0
  33. data/lib/haml/compiler/silent_script_compiler.rb +24 -0
  34. data/lib/haml/compiler/tag_compiler.rb +76 -0
  35. data/lib/haml/compiler.rb +63 -296
  36. data/lib/haml/dynamic_merger.rb +67 -0
  37. data/lib/haml/engine.rb +48 -227
  38. data/lib/haml/error.rb +5 -4
  39. data/lib/haml/escape.rb +13 -0
  40. data/lib/haml/escape_any.rb +21 -0
  41. data/lib/haml/filters/base.rb +12 -0
  42. data/lib/haml/filters/cdata.rb +20 -0
  43. data/lib/haml/filters/coffee.rb +17 -0
  44. data/lib/haml/filters/css.rb +33 -0
  45. data/lib/haml/filters/erb.rb +10 -0
  46. data/lib/haml/filters/escaped.rb +22 -0
  47. data/lib/haml/filters/javascript.rb +33 -0
  48. data/lib/haml/filters/less.rb +20 -0
  49. data/lib/haml/filters/markdown.rb +11 -0
  50. data/lib/haml/filters/plain.rb +29 -0
  51. data/lib/haml/filters/preserve.rb +22 -0
  52. data/lib/haml/filters/ruby.rb +10 -0
  53. data/lib/haml/filters/sass.rb +15 -0
  54. data/lib/haml/filters/scss.rb +15 -0
  55. data/lib/haml/filters/text_base.rb +25 -0
  56. data/lib/haml/filters/tilt_base.rb +59 -0
  57. data/lib/haml/filters.rb +54 -378
  58. data/lib/haml/force_escape.rb +29 -0
  59. data/lib/haml/helpers.rb +3 -697
  60. data/lib/haml/html.rb +22 -0
  61. data/lib/haml/identity.rb +13 -0
  62. data/lib/haml/object_ref.rb +35 -0
  63. data/lib/haml/parser.rb +157 -22
  64. data/lib/haml/rails_helpers.rb +53 -0
  65. data/lib/haml/rails_template.rb +57 -0
  66. data/lib/haml/railtie.rb +3 -46
  67. data/lib/haml/ruby_expression.rb +32 -0
  68. data/lib/haml/string_splitter.rb +140 -0
  69. data/lib/haml/template.rb +15 -34
  70. data/lib/haml/temple_line_counter.rb +2 -1
  71. data/lib/haml/util.rb +18 -15
  72. data/lib/haml/version.rb +1 -2
  73. data/lib/haml/whitespace.rb +8 -0
  74. data/lib/haml.rb +8 -20
  75. metadata +211 -55
  76. data/.gitmodules +0 -3
  77. data/TODO +0 -24
  78. data/benchmark.rb +0 -70
  79. data/bin/haml +0 -9
  80. data/lib/haml/.gitattributes +0 -1
  81. data/lib/haml/buffer.rb +0 -182
  82. data/lib/haml/escapable.rb +0 -77
  83. data/lib/haml/exec.rb +0 -347
  84. data/lib/haml/generator.rb +0 -42
  85. data/lib/haml/helpers/action_view_extensions.rb +0 -60
  86. data/lib/haml/helpers/action_view_mods.rb +0 -132
  87. data/lib/haml/helpers/action_view_xss_mods.rb +0 -60
  88. data/lib/haml/helpers/safe_erubi_template.rb +0 -20
  89. data/lib/haml/helpers/safe_erubis_template.rb +0 -33
  90. data/lib/haml/helpers/xss_mods.rb +0 -114
  91. data/lib/haml/options.rb +0 -273
  92. data/lib/haml/plugin.rb +0 -54
  93. data/lib/haml/sass_rails_filter.rb +0 -47
  94. data/lib/haml/template/options.rb +0 -27
  95. data/lib/haml/temple_engine.rb +0 -124
  96. data/yard/default/.gitignore +0 -1
  97. data/yard/default/fulldoc/html/css/common.sass +0 -15
  98. data/yard/default/layout/html/footer.erb +0 -12
data/.gitmodules DELETED
@@ -1,3 +0,0 @@
1
- [submodule "test/haml-spec"]
2
- path = test/haml-spec
3
- url = git://github.com/haml/haml-spec.git
data/TODO DELETED
@@ -1,24 +0,0 @@
1
- # -*- mode: org -*-
2
- #+STARTUP: nofold
3
-
4
- * Documentation
5
- Redo tutorial?
6
- Using helpers
7
- haml_concat and haml_tag in particular
8
- Syntax highlighting?
9
-
10
- * Code
11
- Keep track of error offsets everywhere
12
- Use this to show error location in messages
13
- ** Haml
14
- Support finer-grained HTML-escaping in filters
15
- Speed
16
- Make tags with dynamic attributes pre-render as much as possible
17
- Including the attribute name where doable
18
- :html improvements
19
- Ignore closing tags where we can
20
- http://code.google.com/speed/articles/optimizing-html.html
21
- Requires Haml parsing refactor
22
- Don't quote attributes that don't require it
23
- http://www.w3.org/TR/REC-html40/intro/sgmltut.html#h-3.2.2
24
- http://www.w3.org/TR/html5/syntax.html#attributes
data/benchmark.rb DELETED
@@ -1,70 +0,0 @@
1
- require "bundler/setup"
2
- require "haml"
3
- require "rbench"
4
-
5
- times = (ARGV.first || 1000).to_i
6
-
7
- if times == 0 # Invalid parameter
8
- puts <<END
9
- ruby #$0 [times=1000]
10
- Benchmark Haml against various other templating languages.
11
- END
12
- exit 1
13
- end
14
-
15
- %w[erb erubi rails active_support action_controller
16
- action_view action_pack haml/template rbench].each {|dep| require(dep)}
17
-
18
- def view
19
- base = ActionView::Base.new
20
- base.view_paths << File.join(File.dirname(__FILE__), '/test')
21
- base
22
- end
23
-
24
- def render(view, file)
25
- view.render :file => file
26
- end
27
-
28
- RBench.run(times) do
29
- column :haml, :title => "Haml"
30
- column :erb, :title => "ERB"
31
- column :erubi, :title => "Erubi"
32
-
33
- template_name = 'standard'
34
- haml_template = File.read("#{File.dirname(__FILE__)}/test/templates/#{template_name}.haml")
35
- erb_template = File.read("#{File.dirname(__FILE__)}/test/erb/#{template_name}.erb")
36
-
37
- report "Cached" do
38
- obj = Object.new
39
-
40
- Haml::Engine.new(haml_template).def_method(obj, :haml)
41
- if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
42
- obj.instance_eval("def erb; #{ERB.new(erb_template, trim_mode: '-').src}; end")
43
- else
44
- obj.instance_eval("def erb; #{ERB.new(erb_template, nil, '-').src}; end")
45
- end
46
- obj.instance_eval("def erubi; #{Erubi::Engine.new(erb_template).src}; end")
47
-
48
- haml { obj.haml }
49
- erb { obj.erb }
50
- erubi { obj.erubi }
51
- end
52
-
53
- report "ActionView" do
54
- # To cache the template
55
- render view, 'templates/standard'
56
- render view, 'erb/standard'
57
-
58
- haml { render view, 'templates/standard' }
59
- erubi { render view, 'erb/standard' }
60
- end
61
-
62
- report "ActionView with deep partials" do
63
- # To cache the template
64
- render view, 'templates/action_view'
65
- render view, 'erb/action_view'
66
-
67
- haml { render view, 'templates/action_view' }
68
- erubi { render view, 'erb/action_view' }
69
- end
70
- end
data/bin/haml DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # The command line Haml parser.
3
-
4
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
5
- require 'haml'
6
- require 'haml/exec'
7
-
8
- opts = Haml::Exec::Haml.new(ARGV)
9
- opts.parse!
@@ -1 +0,0 @@
1
- version.rb merge=ours
data/lib/haml/buffer.rb DELETED
@@ -1,182 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Haml
4
- # This class is used only internally. It holds the buffer of HTML that
5
- # is eventually output as the resulting document.
6
- # It's called from within the precompiled code,
7
- # and helps reduce the amount of processing done within `instance_eval`ed code.
8
- class Buffer
9
- include Haml::Helpers
10
- include Haml::Util
11
-
12
- # The string that holds the compiled HTML. This is aliased as
13
- # `_erbout` for compatibility with ERB-specific code.
14
- #
15
- # @return [String]
16
- attr_accessor :buffer
17
-
18
- # The options hash passed in from {Haml::Engine}.
19
- #
20
- # @return [{String => Object}]
21
- # @see Haml::Options#for_buffer
22
- attr_accessor :options
23
-
24
- # The {Buffer} for the enclosing Haml document.
25
- # This is set for partials and similar sorts of nested templates.
26
- # It's `nil` at the top level (see \{#toplevel?}).
27
- #
28
- # @return [Buffer]
29
- attr_accessor :upper
30
-
31
- # nil if there's no capture_haml block running,
32
- # and the position at which it's beginning the capture if there is one.
33
- #
34
- # @return [Fixnum, nil]
35
- attr_accessor :capture_position
36
-
37
- # @return [Boolean]
38
- # @see #active?
39
- attr_writer :active
40
-
41
- # @return [Boolean] Whether or not the format is XHTML
42
- def xhtml?
43
- not html?
44
- end
45
-
46
- # @return [Boolean] Whether or not the format is any flavor of HTML
47
- def html?
48
- html4? or html5?
49
- end
50
-
51
- # @return [Boolean] Whether or not the format is HTML4
52
- def html4?
53
- @options[:format] == :html4
54
- end
55
-
56
- # @return [Boolean] Whether or not the format is HTML5.
57
- def html5?
58
- @options[:format] == :html5
59
- end
60
-
61
- # @return [Boolean] Whether or not this buffer is a top-level template,
62
- # as opposed to a nested partial
63
- def toplevel?
64
- upper.nil?
65
- end
66
-
67
- # Whether or not this buffer is currently being used to render a Haml template.
68
- # Returns `false` if a subtemplate is being rendered,
69
- # even if it's a subtemplate of this buffer's template.
70
- #
71
- # @return [Boolean]
72
- def active?
73
- @active
74
- end
75
-
76
- # @return [Fixnum] The current indentation level of the document
77
- def tabulation
78
- @real_tabs + @tabulation
79
- end
80
-
81
- # Sets the current tabulation of the document.
82
- #
83
- # @param val [Fixnum] The new tabulation
84
- def tabulation=(val)
85
- val = val - @real_tabs
86
- @tabulation = val > -1 ? val : 0
87
- end
88
-
89
- # @param upper [Buffer] The parent buffer
90
- # @param options [{Symbol => Object}] An options hash.
91
- # See {Haml::Engine#options\_for\_buffer}
92
- def initialize(upper = nil, options = {})
93
- @active = true
94
- @upper = upper
95
- @options = Options.buffer_defaults
96
- @options = @options.merge(options) unless options.empty?
97
- @buffer = new_encoded_string
98
- @tabulation = 0
99
-
100
- # The number of tabs that Engine thinks we should have
101
- # @real_tabs + @tabulation is the number of tabs actually output
102
- @real_tabs = 0
103
- end
104
-
105
- # Appends text to the buffer, properly tabulated.
106
- # Also modifies the document's indentation.
107
- #
108
- # @param text [String] The text to append
109
- # @param tab_change [Fixnum] The number of tabs by which to increase
110
- # or decrease the document's indentation
111
- # @param dont_tab_up [Boolean] If true, don't indent the first line of `text`
112
- def push_text(text, tab_change, dont_tab_up)
113
- if @tabulation > 0
114
- # Have to push every line in by the extra user set tabulation.
115
- # Don't push lines with just whitespace, though,
116
- # because that screws up precompiled indentation.
117
- text.gsub!(/^(?!\s+$)/m, tabs)
118
- text.sub!(tabs, '') if dont_tab_up
119
- end
120
-
121
- @real_tabs += tab_change
122
- @buffer << text
123
- end
124
-
125
- # Modifies the indentation of the document.
126
- #
127
- # @param tab_change [Fixnum] The number of tabs by which to increase
128
- # or decrease the document's indentation
129
- def adjust_tabs(tab_change)
130
- @real_tabs += tab_change
131
- end
132
-
133
- # Remove the whitespace from the right side of the buffer string.
134
- # Doesn't do anything if we're at the beginning of a capture_haml block.
135
- def rstrip!
136
- if capture_position.nil?
137
- buffer.rstrip!
138
- return
139
- end
140
-
141
- buffer << buffer.slice!(capture_position..-1).rstrip
142
- end
143
-
144
- # Works like #{find_and_preserve}, but allows the first newline after a
145
- # preserved opening tag to remain unencoded, and then outdents the content.
146
- # This change was motivated primarily by the change in Rails 3.2.3 to emit
147
- # a newline after textarea helpers.
148
- #
149
- # @param input [String] The text to process
150
- # @since Haml 4.0.1
151
- # @private
152
- def fix_textareas!(input)
153
- return input unless input.include?('<textarea'.freeze)
154
-
155
- pattern = /<(textarea)([^>]*)>(\n|&#x000A;)(.*?)<\/textarea>/im
156
- input.gsub!(pattern) do |s|
157
- match = pattern.match(s)
158
- content = match[4]
159
- if match[3] == '&#x000A;'
160
- content.sub!(/\A /, '&#x0020;')
161
- else
162
- content.sub!(/\A[ ]*/, '')
163
- end
164
- "<#{match[1]}#{match[2]}>\n#{content}</#{match[1]}>"
165
- end
166
- input
167
- end
168
-
169
- private
170
-
171
- def new_encoded_string
172
- "".encode(options[:encoding])
173
- end
174
-
175
- @@tab_cache = {}
176
- # Gets `count` tabs. Mostly for internal use.
177
- def tabs(count = 0)
178
- tabs = [count + @tabulation, 0].max
179
- @@tab_cache[tabs] ||= ' ' * tabs
180
- end
181
- end
182
- end
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Haml
4
- # Like Temple::Filters::Escapable, but with support for escaping by
5
- # Haml::Herlpers.html_escape and Haml::Herlpers.escape_once.
6
- class Escapable < Temple::Filter
7
- # Special value of `flag` to ignore html_safe?
8
- EscapeSafeBuffer = Struct.new(:value)
9
-
10
- def initialize(*)
11
- super
12
- @escape = false
13
- @escape_safe_buffer = false
14
- end
15
-
16
- def on_escape(flag, exp)
17
- old_escape, old_escape_safe_buffer = @escape, @escape_safe_buffer
18
- @escape_safe_buffer = flag.is_a?(EscapeSafeBuffer)
19
- @escape = @escape_safe_buffer ? flag.value : flag
20
- compile(exp)
21
- ensure
22
- @escape, @escape_safe_buffer = old_escape, old_escape_safe_buffer
23
- end
24
-
25
- # The same as Haml::AttributeBuilder.build_attributes
26
- def on_static(value)
27
- [:static,
28
- if @escape == :once
29
- escape_once(value)
30
- elsif @escape
31
- escape(value)
32
- else
33
- value
34
- end
35
- ]
36
- end
37
-
38
- # The same as Haml::AttributeBuilder.build_attributes
39
- def on_dynamic(value)
40
- [:dynamic,
41
- if @escape == :once
42
- escape_once_code(value)
43
- elsif @escape
44
- escape_code(value)
45
- else
46
- "(#{value}).to_s"
47
- end
48
- ]
49
- end
50
-
51
- private
52
-
53
- def escape_once(value)
54
- if @escape_safe_buffer
55
- ::Haml::Helpers.escape_once_without_haml_xss(value)
56
- else
57
- ::Haml::Helpers.escape_once(value)
58
- end
59
- end
60
-
61
- def escape(value)
62
- if @escape_safe_buffer
63
- ::Haml::Helpers.html_escape_without_haml_xss(value)
64
- else
65
- ::Haml::Helpers.html_escape(value)
66
- end
67
- end
68
-
69
- def escape_once_code(value)
70
- "::Haml::Helpers.escape_once#{('_without_haml_xss' if @escape_safe_buffer)}((#{value}))"
71
- end
72
-
73
- def escape_code(value)
74
- "::Haml::Helpers.html_escape#{('_without_haml_xss' if @escape_safe_buffer)}((#{value}))"
75
- end
76
- end
77
- end