haml 5.0.4 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.github/workflows/test.yml +40 -0
  4. data/.gitignore +16 -15
  5. data/CHANGELOG.md +62 -1
  6. data/Gemfile +18 -14
  7. data/MIT-LICENSE +2 -2
  8. data/README.md +4 -5
  9. data/REFERENCE.md +46 -12
  10. data/Rakefile +93 -103
  11. data/bin/bench +66 -0
  12. data/bin/console +11 -0
  13. data/bin/ruby +3 -0
  14. data/bin/setup +7 -0
  15. data/bin/stackprof +27 -0
  16. data/bin/test +24 -0
  17. data/exe/haml +6 -0
  18. data/ext/haml/extconf.rb +10 -0
  19. data/ext/haml/haml.c +537 -0
  20. data/ext/haml/hescape.c +108 -0
  21. data/ext/haml/hescape.h +20 -0
  22. data/haml.gemspec +39 -30
  23. data/lib/haml/ambles.rb +20 -0
  24. data/lib/haml/attribute_builder.rb +140 -128
  25. data/lib/haml/attribute_compiler.rb +86 -181
  26. data/lib/haml/attribute_parser.rb +86 -124
  27. data/lib/haml/cli.rb +154 -0
  28. data/lib/haml/compiler/children_compiler.rb +126 -0
  29. data/lib/haml/compiler/comment_compiler.rb +39 -0
  30. data/lib/haml/compiler/doctype_compiler.rb +46 -0
  31. data/lib/haml/compiler/script_compiler.rb +116 -0
  32. data/lib/haml/compiler/silent_script_compiler.rb +24 -0
  33. data/lib/haml/compiler/tag_compiler.rb +76 -0
  34. data/lib/haml/compiler.rb +64 -298
  35. data/lib/haml/dynamic_merger.rb +67 -0
  36. data/lib/haml/engine.rb +43 -219
  37. data/lib/haml/error.rb +29 -27
  38. data/lib/haml/escapable.rb +6 -42
  39. data/lib/haml/filters/base.rb +12 -0
  40. data/lib/haml/filters/cdata.rb +20 -0
  41. data/lib/haml/filters/coffee.rb +17 -0
  42. data/lib/haml/filters/css.rb +33 -0
  43. data/lib/haml/filters/erb.rb +10 -0
  44. data/lib/haml/filters/escaped.rb +22 -0
  45. data/lib/haml/filters/javascript.rb +33 -0
  46. data/lib/haml/filters/less.rb +20 -0
  47. data/lib/haml/filters/markdown.rb +11 -0
  48. data/lib/haml/filters/plain.rb +29 -0
  49. data/lib/haml/filters/preserve.rb +22 -0
  50. data/lib/haml/filters/ruby.rb +10 -0
  51. data/lib/haml/filters/sass.rb +15 -0
  52. data/lib/haml/filters/scss.rb +15 -0
  53. data/lib/haml/filters/text_base.rb +25 -0
  54. data/lib/haml/filters/tilt_base.rb +49 -0
  55. data/lib/haml/filters.rb +55 -378
  56. data/lib/haml/force_escapable.rb +29 -0
  57. data/lib/haml/helpers.rb +4 -696
  58. data/lib/haml/html.rb +22 -0
  59. data/lib/haml/identity.rb +13 -0
  60. data/lib/haml/object_ref.rb +30 -0
  61. data/lib/haml/parser.rb +208 -43
  62. data/lib/haml/rails_helpers.rb +51 -0
  63. data/lib/haml/rails_template.rb +55 -0
  64. data/lib/haml/railtie.rb +7 -40
  65. data/lib/haml/ruby_expression.rb +32 -0
  66. data/lib/haml/string_splitter.rb +20 -0
  67. data/lib/haml/template.rb +15 -33
  68. data/lib/haml/temple_line_counter.rb +2 -0
  69. data/lib/haml/util.rb +23 -21
  70. data/lib/haml/version.rb +1 -1
  71. data/lib/haml.rb +8 -19
  72. metadata +222 -50
  73. data/.gitmodules +0 -3
  74. data/.travis.yml +0 -54
  75. data/.yardopts +0 -23
  76. data/TODO +0 -24
  77. data/benchmark.rb +0 -66
  78. data/bin/haml +0 -9
  79. data/lib/haml/.gitattributes +0 -1
  80. data/lib/haml/buffer.rb +0 -235
  81. data/lib/haml/exec.rb +0 -348
  82. data/lib/haml/generator.rb +0 -41
  83. data/lib/haml/helpers/action_view_extensions.rb +0 -59
  84. data/lib/haml/helpers/action_view_mods.rb +0 -129
  85. data/lib/haml/helpers/action_view_xss_mods.rb +0 -59
  86. data/lib/haml/helpers/safe_erubi_template.rb +0 -19
  87. data/lib/haml/helpers/safe_erubis_template.rb +0 -32
  88. data/lib/haml/helpers/xss_mods.rb +0 -110
  89. data/lib/haml/options.rb +0 -273
  90. data/lib/haml/plugin.rb +0 -34
  91. data/lib/haml/sass_rails_filter.rb +0 -46
  92. data/lib/haml/template/options.rb +0 -26
  93. data/lib/haml/temple_engine.rb +0 -121
  94. data/yard/default/.gitignore +0 -1
  95. data/yard/default/fulldoc/html/css/common.sass +0 -15
  96. data/yard/default/layout/html/footer.erb +0 -12
data/.travis.yml DELETED
@@ -1,54 +0,0 @@
1
- sudo: false
2
- dist: trusty
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - ruby-head
7
- - 2.4.2
8
- - 2.3.5
9
- - 2.2.8
10
- - 2.1.10
11
- - 2.0.0
12
- - jruby-9.1.12.0
13
- - rbx-3
14
- gemfile:
15
- - test/gemfiles/Gemfile.rails-5.1.x
16
- - test/gemfiles/Gemfile.rails-5.0.x
17
- - test/gemfiles/Gemfile.rails-5.0.x.erubi
18
- - test/gemfiles/Gemfile.rails-4.2.x
19
- - test/gemfiles/Gemfile.rails-4.1.x
20
- - test/gemfiles/Gemfile.rails-4.0.x
21
- matrix:
22
- exclude:
23
- - rvm: 2.0.0
24
- gemfile: test/gemfiles/Gemfile.rails-5.1.x
25
- - rvm: 2.1.10
26
- gemfile: test/gemfiles/Gemfile.rails-5.1.x
27
- - rvm: 2.0.0
28
- gemfile: test/gemfiles/Gemfile.rails-5.0.x
29
- - rvm: 2.0.0
30
- gemfile: test/gemfiles/Gemfile.rails-5.0.x.erubi
31
- - rvm: 2.1.10
32
- gemfile: test/gemfiles/Gemfile.rails-5.0.x
33
- - rvm: 2.1.10
34
- gemfile: test/gemfiles/Gemfile.rails-5.0.x.erubi
35
- - rvm: 2.4.2
36
- gemfile: test/gemfiles/Gemfile.rails-4.0.x
37
- - rvm: 2.4.2
38
- gemfile: test/gemfiles/Gemfile.rails-4.1.x
39
- - rvm: 2.4.2
40
- gemfile: test/gemfiles/Gemfile.rails-4.2.x
41
- - rvm: ruby-head
42
- gemfile: test/gemfiles/Gemfile.rails-4.0.x
43
- - rvm: ruby-head
44
- gemfile: test/gemfiles/Gemfile.rails-4.1.x
45
- - rvm: ruby-head
46
- gemfile: test/gemfiles/Gemfile.rails-4.2.x
47
- include:
48
- - rvm: 2.4.2
49
- gemfile: test/gemfiles/Gemfile.rails-edge
50
- allow_failures:
51
- - rvm: rbx-3
52
- - gemfile: test/gemfiles/Gemfile.rails-edge
53
- fast_finish: true
54
- script: "bundle exec rake submodules test"
data/.yardopts DELETED
@@ -1,23 +0,0 @@
1
- --charset utf-8
2
- --readme README.md
3
- --markup markdown
4
- --markup-provider kramdown
5
- --template-path yard
6
- --default-return ""
7
- --title "Haml Documentation"
8
- --query 'object.type != :classvariable'
9
- --query 'object.type != :constant || @api && @api.text == "public"'
10
- --exclude lib/haml/template/patch.rb
11
- --exclude lib/haml/template/plugin.rb
12
- --exclude lib/haml/railtie.rb
13
- --exclude lib/haml/helpers/action_view_mods.rb
14
- --exclude lib/haml/helpers/xss_mods.rb
15
- --hide-void-return
16
- --protected
17
- --no-private
18
- --no-highlight
19
- -
20
- FAQ.md
21
- CHANGELOG.md
22
- REFERENCE.md
23
- MIT-LICENSE
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,66 +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 erubis 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 :erubis, :title => "Erubis"
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
- Erubis::Eruby.new(erb_template).def_method(obj, :erubis)
42
- obj.instance_eval("def erb; #{ERB.new(erb_template, nil, '-').src}; end")
43
-
44
- haml { obj.haml }
45
- erb { obj.erb }
46
- erubis { obj.erubis }
47
- end
48
-
49
- report "ActionView" do
50
- # To cache the template
51
- render view, 'templates/standard'
52
- render view, 'erb/standard'
53
-
54
- haml { render view, 'templates/standard' }
55
- erb { render view, 'erb/standard' }
56
- end
57
-
58
- report "ActionView with deep partials" do
59
- # To cache the template
60
- render view, 'templates/action_view'
61
- render view, 'erb/action_view'
62
-
63
- haml { render view, 'templates/action_view' }
64
- erb { render view, 'erb/action_view' }
65
- end
66
- 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,235 +0,0 @@
1
- # frozen_string_literal: true
2
- module Haml
3
- # This class is used only internally. It holds the buffer of HTML that
4
- # is eventually output as the resulting document.
5
- # It's called from within the precompiled code,
6
- # and helps reduce the amount of processing done within `instance_eval`ed code.
7
- class Buffer
8
- include Haml::Helpers
9
- include Haml::Util
10
-
11
- # The string that holds the compiled HTML. This is aliased as
12
- # `_erbout` for compatibility with ERB-specific code.
13
- #
14
- # @return [String]
15
- attr_accessor :buffer
16
-
17
- # The options hash passed in from {Haml::Engine}.
18
- #
19
- # @return [{String => Object}]
20
- # @see Haml::Options#for_buffer
21
- attr_accessor :options
22
-
23
- # The {Buffer} for the enclosing Haml document.
24
- # This is set for partials and similar sorts of nested templates.
25
- # It's `nil` at the top level (see \{#toplevel?}).
26
- #
27
- # @return [Buffer]
28
- attr_accessor :upper
29
-
30
- # nil if there's no capture_haml block running,
31
- # and the position at which it's beginning the capture if there is one.
32
- #
33
- # @return [Fixnum, nil]
34
- attr_accessor :capture_position
35
-
36
- # @return [Boolean]
37
- # @see #active?
38
- attr_writer :active
39
-
40
- # @return [Boolean] Whether or not the format is XHTML
41
- def xhtml?
42
- not html?
43
- end
44
-
45
- # @return [Boolean] Whether or not the format is any flavor of HTML
46
- def html?
47
- html4? or html5?
48
- end
49
-
50
- # @return [Boolean] Whether or not the format is HTML4
51
- def html4?
52
- @options[:format] == :html4
53
- end
54
-
55
- # @return [Boolean] Whether or not the format is HTML5.
56
- def html5?
57
- @options[:format] == :html5
58
- end
59
-
60
- # @return [Boolean] Whether or not this buffer is a top-level template,
61
- # as opposed to a nested partial
62
- def toplevel?
63
- upper.nil?
64
- end
65
-
66
- # Whether or not this buffer is currently being used to render a Haml template.
67
- # Returns `false` if a subtemplate is being rendered,
68
- # even if it's a subtemplate of this buffer's template.
69
- #
70
- # @return [Boolean]
71
- def active?
72
- @active
73
- end
74
-
75
- # @return [Fixnum] The current indentation level of the document
76
- def tabulation
77
- @real_tabs + @tabulation
78
- end
79
-
80
- # Sets the current tabulation of the document.
81
- #
82
- # @param val [Fixnum] The new tabulation
83
- def tabulation=(val)
84
- val = val - @real_tabs
85
- @tabulation = val > -1 ? val : 0
86
- end
87
-
88
- # @param upper [Buffer] The parent buffer
89
- # @param options [{Symbol => Object}] An options hash.
90
- # See {Haml::Engine#options\_for\_buffer}
91
- def initialize(upper = nil, options = {})
92
- @active = true
93
- @upper = upper
94
- @options = Options.buffer_defaults
95
- @options = @options.merge(options) unless options.empty?
96
- @buffer = new_encoded_string
97
- @tabulation = 0
98
-
99
- # The number of tabs that Engine thinks we should have
100
- # @real_tabs + @tabulation is the number of tabs actually output
101
- @real_tabs = 0
102
- end
103
-
104
- # Appends text to the buffer, properly tabulated.
105
- # Also modifies the document's indentation.
106
- #
107
- # @param text [String] The text to append
108
- # @param tab_change [Fixnum] The number of tabs by which to increase
109
- # or decrease the document's indentation
110
- # @param dont_tab_up [Boolean] If true, don't indent the first line of `text`
111
- def push_text(text, tab_change, dont_tab_up)
112
- if @tabulation > 0
113
- # Have to push every line in by the extra user set tabulation.
114
- # Don't push lines with just whitespace, though,
115
- # because that screws up precompiled indentation.
116
- text.gsub!(/^(?!\s+$)/m, tabs)
117
- text.sub!(tabs, '') if dont_tab_up
118
- end
119
-
120
- @real_tabs += tab_change
121
- @buffer << text
122
- end
123
-
124
- # Modifies the indentation of the document.
125
- #
126
- # @param tab_change [Fixnum] The number of tabs by which to increase
127
- # or decrease the document's indentation
128
- def adjust_tabs(tab_change)
129
- @real_tabs += tab_change
130
- end
131
-
132
- def attributes(class_id, obj_ref, *attributes_hashes)
133
- attributes = class_id
134
- attributes_hashes.each do |old|
135
- AttributeBuilder.merge_attributes!(attributes, Hash[old.map {|k, v| [k.to_s, v]}])
136
- end
137
- AttributeBuilder.merge_attributes!(attributes, parse_object_ref(obj_ref)) if obj_ref
138
- AttributeBuilder.build_attributes(
139
- html?, @options[:attr_wrapper], @options[:escape_attrs], @options[:hyphenate_data_attrs], attributes)
140
- end
141
-
142
- # Remove the whitespace from the right side of the buffer string.
143
- # Doesn't do anything if we're at the beginning of a capture_haml block.
144
- def rstrip!
145
- if capture_position.nil?
146
- buffer.rstrip!
147
- return
148
- end
149
-
150
- buffer << buffer.slice!(capture_position..-1).rstrip
151
- end
152
-
153
- # Works like #{find_and_preserve}, but allows the first newline after a
154
- # preserved opening tag to remain unencoded, and then outdents the content.
155
- # This change was motivated primarily by the change in Rails 3.2.3 to emit
156
- # a newline after textarea helpers.
157
- #
158
- # @param input [String] The text to process
159
- # @since Haml 4.0.1
160
- # @private
161
- def fix_textareas!(input)
162
- return input unless input.include?('<textarea'.freeze)
163
-
164
- pattern = /<(textarea)([^>]*)>(\n|&#x000A;)(.*?)<\/textarea>/im
165
- input.gsub!(pattern) do |s|
166
- match = pattern.match(s)
167
- content = match[4]
168
- if match[3] == '&#x000A;'
169
- content.sub!(/\A /, '&#x0020;')
170
- else
171
- content.sub!(/\A[ ]*/, '')
172
- end
173
- "<#{match[1]}#{match[2]}>\n#{content}</#{match[1]}>"
174
- end
175
- input
176
- end
177
-
178
- private
179
-
180
- def new_encoded_string
181
- "".encode(options[:encoding])
182
- end
183
-
184
- @@tab_cache = {}
185
- # Gets `count` tabs. Mostly for internal use.
186
- def tabs(count = 0)
187
- tabs = [count + @tabulation, 0].max
188
- @@tab_cache[tabs] ||= ' ' * tabs
189
- end
190
-
191
- # Takes an array of objects and uses the class and id of the first
192
- # one to create an attributes hash.
193
- # The second object, if present, is used as a prefix,
194
- # just like you can do with `dom_id()` and `dom_class()` in Rails
195
- def parse_object_ref(ref)
196
- prefix = ref[1]
197
- ref = ref[0]
198
- # Let's make sure the value isn't nil. If it is, return the default Hash.
199
- return {} if ref.nil?
200
- class_name =
201
- if ref.respond_to?(:haml_object_ref)
202
- ref.haml_object_ref
203
- else
204
- underscore(ref.class)
205
- end
206
- ref_id =
207
- if ref.respond_to?(:to_key)
208
- key = ref.to_key
209
- key.join('_') unless key.nil?
210
- else
211
- ref.id
212
- end
213
- id = "#{class_name}_#{ref_id || 'new'}"
214
- if prefix
215
- class_name = "#{ prefix }_#{ class_name}"
216
- id = "#{ prefix }_#{ id }"
217
- end
218
-
219
- { 'id'.freeze => id, 'class'.freeze => class_name }
220
- end
221
-
222
- # Changes a word from camel case to underscores.
223
- # Based on the method of the same name in Rails' Inflector,
224
- # but copied here so it'll run properly without Rails.
225
- def underscore(camel_cased_word)
226
- word = camel_cased_word.to_s.dup
227
- word.gsub!(/::/, '_')
228
- word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
229
- word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
230
- word.tr!('-', '_')
231
- word.downcase!
232
- word
233
- end
234
- end
235
- end