haml 5.0.3 → 5.2.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.
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Haml
3
4
 
4
5
  # This module makes Haml work with Rails using the template handler API.
5
6
  class Plugin
6
7
  def handles_encoding?; true; end
7
8
 
8
- def compile(template)
9
+ def compile(template, source)
9
10
  options = Haml::Template.options.dup
10
11
  if template.respond_to?(:type)
11
12
  options[:mime_type] = template.type
@@ -13,14 +14,16 @@ module Haml
13
14
  options[:mime_type] = template.mime_type
14
15
  end
15
16
  options[:filename] = template.identifier
16
- Haml::Engine.new(template.source, options).compiler.precompiled_with_ambles(
17
+ Haml::Engine.new(source, options).compiler.precompiled_with_ambles(
17
18
  [],
18
19
  after_preamble: '@output_buffer = output_buffer ||= ActionView::OutputBuffer.new if defined?(ActionView::OutputBuffer)',
19
20
  )
20
21
  end
21
22
 
22
- def self.call(template)
23
- new.compile(template)
23
+ def self.call(template, source = nil)
24
+ source ||= template.source
25
+
26
+ new.compile(template, source)
24
27
  end
25
28
 
26
29
  def cache_fragment(block, name = {}, options = nil)
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'haml/template/options'
3
4
 
4
5
  # check for a compatible Rails version when Haml is loaded
5
6
  if (activesupport_spec = Gem.loaded_specs['activesupport'])
6
- if activesupport_spec.version.to_s < '3.2'
7
- raise Exception.new("\n\n** Haml now requires Rails 3.2 and later. Use Haml version 4.0.4\n\n")
7
+ if activesupport_spec.version.to_s < '4.0'
8
+ raise Exception.new("\n\n** Haml now requires Rails 4.0 and later. Use Haml version 4.0.x\n\n")
8
9
  end
9
10
  end
10
11
 
@@ -33,8 +34,7 @@ module Haml
33
34
  # solved by looking for ::Erubi first.
34
35
  # However, in JRuby, the const_defined? finds it anyway, so we must make sure that it's
35
36
  # not just a reference to ::Erubi.
36
- if defined?(::Erubi) && const_defined?('ActionView::Template::Handlers::ERB::Erubi') &&
37
- ActionView::Template::Handlers::ERB::Erubi != ::Erubi
37
+ if defined?(::Erubi) && (::ActionView::Template::Handlers::ERB.const_get('Erubi') != ::Erubi)
38
38
  require "haml/helpers/safe_erubi_template"
39
39
  Haml::Filters::RailsErb.template_class = Haml::SafeErubiTemplate
40
40
  else
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Haml
3
4
  module Filters
4
5
  # This is an extension of Sass::Rails's SassTemplate class that allows
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'haml/template/options'
3
4
  if defined?(ActiveSupport)
4
5
  ActiveSupport.on_load(:action_view) do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # We keep options in its own self-contained file
3
4
  # so that we can load it independently in Rails 3,
4
5
  # where the full template stuff is lazy-loaded.
@@ -1,4 +1,5 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
+
2
3
  require 'temple'
3
4
  require 'haml/escapable'
4
5
  require 'haml/generator'
@@ -13,6 +14,7 @@ module Haml
13
14
  encoding: nil,
14
15
  escape_attrs: true,
15
16
  escape_html: false,
17
+ escape_filter_interpolations: nil,
16
18
  filename: '(haml)',
17
19
  format: :html5,
18
20
  hyphenate_data_attrs: true,
@@ -49,12 +51,12 @@ module Haml
49
51
  # @return [String]
50
52
  def precompiled
51
53
  encoding = Encoding.find(@encoding || '')
52
- return @precompiled.force_encoding(encoding) if encoding == Encoding::ASCII_8BIT
54
+ return @precompiled.dup.force_encoding(encoding) if encoding == Encoding::ASCII_8BIT
53
55
  return @precompiled.encode(encoding)
54
56
  end
55
57
 
56
58
  def precompiled_with_return_value
57
- "#{precompiled};#{precompiled_method_return_value}"
59
+ "#{precompiled};#{precompiled_method_return_value}".dup
58
60
  end
59
61
 
60
62
  # The source code that is evaluated to produce the Haml document.
@@ -64,20 +66,20 @@ module Haml
64
66
  #
65
67
  # @return [String]
66
68
  def precompiled_with_ambles(local_names, after_preamble: '')
67
- preamble = <<END.tr!("\n", ';')
69
+ preamble = <<END.tr("\n", ';')
68
70
  begin
69
71
  extend Haml::Helpers
70
72
  _hamlout = @haml_buffer = Haml::Buffer.new(haml_buffer, #{Options.new(options).for_buffer.inspect})
71
73
  _erbout = _hamlout.buffer
72
74
  #{after_preamble}
73
75
  END
74
- postamble = <<END.tr!("\n", ';')
76
+ postamble = <<END.tr("\n", ';')
75
77
  #{precompiled_method_return_value}
76
78
  ensure
77
79
  @haml_buffer = @haml_buffer.upper if @haml_buffer
78
80
  end
79
81
  END
80
- "#{preamble}#{locals_code(local_names)}#{precompiled}#{postamble}"
82
+ "#{preamble}#{locals_code(local_names)}#{precompiled}#{postamble}".dup
81
83
  end
82
84
 
83
85
  private
@@ -99,12 +101,12 @@ END
99
101
  def locals_code(names)
100
102
  names = names.keys if Hash === names
101
103
 
102
- names.each_with_object('') do |name, code|
104
+ names.map do |name|
103
105
  # Can't use || because someone might explicitly pass in false with a symbol
104
106
  sym_local = "_haml_locals[#{inspect_obj(name.to_sym)}]"
105
107
  str_local = "_haml_locals[#{inspect_obj(name.to_s)}]"
106
- code << "#{name} = #{sym_local}.nil? ? #{str_local} : #{sym_local};"
107
- end
108
+ "#{name} = #{sym_local}.nil? ? #{str_local} : #{sym_local};"
109
+ end.join
108
110
  end
109
111
 
110
112
  def inspect_obj(obj)
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Haml
3
4
  # A module to count lines of expected code. This would be faster than actual code generation
4
5
  # and counting newlines in it.
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  begin
4
4
  require 'erubis/tiny'
@@ -166,7 +166,7 @@ MSG
166
166
  # and the rest of the string.
167
167
  # `["Foo (Bar (Baz bang) bop)", " (Bang (bop bip))"]` in the example above.
168
168
  def balance(scanner, start, finish, count = 0)
169
- str = ''
169
+ str = ''.dup
170
170
  scanner = StringScanner.new(scanner) unless scanner.is_a? StringScanner
171
171
  regexp = Regexp.new("(.*?)[\\#{start.chr}\\#{finish.chr}]", Regexp::MULTILINE)
172
172
  while scanner.scan(regexp)
@@ -199,7 +199,7 @@ MSG
199
199
  end
200
200
 
201
201
  def unescape_interpolation(str, escape_html = nil)
202
- res = ''
202
+ res = ''.dup
203
203
  rest = Haml::Util.handle_interpolation str.dump do |scan|
204
204
  escapes = (scan[2].size - 1) / 2
205
205
  char = scan[3] # '{', '@' or '$'
@@ -212,7 +212,7 @@ MSG
212
212
  else
213
213
  scan.scan(/\w+/)
214
214
  end
215
- content = eval('"' + interpolated + '"')
215
+ content = eval("\"#{interpolated}\"")
216
216
  content.prepend(char) if char == '@' || char == '$'
217
217
  content = "Haml::Helpers.html_escape((#{content}))" if escape_html
218
218
 
@@ -234,7 +234,7 @@ MSG
234
234
  scanner = StringScanner.new(str.dup.force_encoding(Encoding::ASCII_8BIT))
235
235
  bom = scanner.scan(/\xEF\xBB\xBF/n)
236
236
  return bom unless scanner.scan(/-\s*#\s*/n)
237
- if coding = try_parse_haml_emacs_magic_comment(scanner)
237
+ if (coding = try_parse_haml_emacs_magic_comment(scanner))
238
238
  return bom, coding
239
239
  end
240
240
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Haml
3
- VERSION = "5.0.3"
4
+ VERSION = "5.2.0"
4
5
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.3
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Natalie Weizenbaum
8
8
  - Hampton Catlin
9
9
  - Norman Clarke
10
10
  - Akira Matsuda
11
- autorequire:
11
+ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-09-07 00:00:00.000000000 Z
14
+ date: 2020-09-28 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: temple
@@ -97,6 +97,20 @@ dependencies:
97
97
  - - ">="
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
+ - !ruby/object:Gem::Dependency
101
+ name: simplecov
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '='
105
+ - !ruby/object:Gem::Version
106
+ version: 0.17.1
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - '='
112
+ - !ruby/object:Gem::Version
113
+ version: 0.17.1
100
114
  description: |
101
115
  Haml (HTML Abstraction Markup Language) is a layer on top of HTML or XML that's
102
116
  designed to express the structure of documents in a non-repetitive, elegant, and
@@ -105,7 +119,7 @@ description: |
105
119
  but it can function as a stand-alone templating engine.
106
120
  email:
107
121
  - haml@googlegroups.com
108
- - norman@njclarke.com
122
+ - ronnie@dio.jp
109
123
  executables:
110
124
  - haml
111
125
  extensions: []
@@ -163,8 +177,14 @@ files:
163
177
  homepage: http://haml.info/
164
178
  licenses:
165
179
  - MIT
166
- metadata: {}
167
- post_install_message:
180
+ metadata:
181
+ bug_tracker_uri: https://github.com/haml/haml/issues
182
+ changelog_uri: https://github.com/haml/haml/blob/main/CHANGELOG.md
183
+ documentation_uri: http://haml.info/docs.html
184
+ homepage_uri: http://haml.info
185
+ mailing_list_uri: https://groups.google.com/forum/?fromgroups#!forum/haml
186
+ source_code_uri: https://github.com/haml/haml
187
+ post_install_message:
168
188
  rdoc_options: []
169
189
  require_paths:
170
190
  - lib
@@ -179,10 +199,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
199
  - !ruby/object:Gem::Version
180
200
  version: '0'
181
201
  requirements: []
182
- rubyforge_project:
183
- rubygems_version: 2.6.11
184
- signing_key:
202
+ rubygems_version: 3.1.4
203
+ signing_key:
185
204
  specification_version: 4
186
205
  summary: An elegant, structured (X)HTML/XML templating engine.
187
206
  test_files: []
188
- has_rdoc: false