mini-max-kit 0.0.1

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 (69) hide show
  1. checksums.yaml +7 -0
  2. data/haml-7.2.0/CHANGELOG.md +1705 -0
  3. data/haml-7.2.0/FAQ.md +147 -0
  4. data/haml-7.2.0/Gemfile +25 -0
  5. data/haml-7.2.0/MIT-LICENSE +20 -0
  6. data/haml-7.2.0/README.md +205 -0
  7. data/haml-7.2.0/REFERENCE.md +1309 -0
  8. data/haml-7.2.0/Rakefile +48 -0
  9. data/haml-7.2.0/bin/bench +66 -0
  10. data/haml-7.2.0/bin/console +10 -0
  11. data/haml-7.2.0/bin/ruby +3 -0
  12. data/haml-7.2.0/bin/setup +7 -0
  13. data/haml-7.2.0/bin/stackprof +27 -0
  14. data/haml-7.2.0/bin/test +24 -0
  15. data/haml-7.2.0/exe/haml +6 -0
  16. data/haml-7.2.0/haml.gemspec +45 -0
  17. data/haml-7.2.0/lib/haml/ambles.rb +20 -0
  18. data/haml-7.2.0/lib/haml/attribute_builder.rb +162 -0
  19. data/haml-7.2.0/lib/haml/attribute_compiler.rb +133 -0
  20. data/haml-7.2.0/lib/haml/attribute_parser.rb +116 -0
  21. data/haml-7.2.0/lib/haml/cli.rb +154 -0
  22. data/haml-7.2.0/lib/haml/compiler/children_compiler.rb +155 -0
  23. data/haml-7.2.0/lib/haml/compiler/comment_compiler.rb +51 -0
  24. data/haml-7.2.0/lib/haml/compiler/doctype_compiler.rb +52 -0
  25. data/haml-7.2.0/lib/haml/compiler/script_compiler.rb +114 -0
  26. data/haml-7.2.0/lib/haml/compiler/silent_script_compiler.rb +24 -0
  27. data/haml-7.2.0/lib/haml/compiler/tag_compiler.rb +76 -0
  28. data/haml-7.2.0/lib/haml/compiler.rb +97 -0
  29. data/haml-7.2.0/lib/haml/dynamic_merger.rb +67 -0
  30. data/haml-7.2.0/lib/haml/engine.rb +59 -0
  31. data/haml-7.2.0/lib/haml/error.rb +66 -0
  32. data/haml-7.2.0/lib/haml/escape.rb +13 -0
  33. data/haml-7.2.0/lib/haml/escape_any.rb +21 -0
  34. data/haml-7.2.0/lib/haml/filters/base.rb +12 -0
  35. data/haml-7.2.0/lib/haml/filters/cdata.rb +20 -0
  36. data/haml-7.2.0/lib/haml/filters/coffee.rb +17 -0
  37. data/haml-7.2.0/lib/haml/filters/css.rb +33 -0
  38. data/haml-7.2.0/lib/haml/filters/erb.rb +10 -0
  39. data/haml-7.2.0/lib/haml/filters/escaped.rb +22 -0
  40. data/haml-7.2.0/lib/haml/filters/javascript.rb +33 -0
  41. data/haml-7.2.0/lib/haml/filters/less.rb +20 -0
  42. data/haml-7.2.0/lib/haml/filters/markdown.rb +11 -0
  43. data/haml-7.2.0/lib/haml/filters/plain.rb +29 -0
  44. data/haml-7.2.0/lib/haml/filters/preserve.rb +22 -0
  45. data/haml-7.2.0/lib/haml/filters/ruby.rb +10 -0
  46. data/haml-7.2.0/lib/haml/filters/sass.rb +15 -0
  47. data/haml-7.2.0/lib/haml/filters/scss.rb +15 -0
  48. data/haml-7.2.0/lib/haml/filters/text_base.rb +25 -0
  49. data/haml-7.2.0/lib/haml/filters/tilt_base.rb +59 -0
  50. data/haml-7.2.0/lib/haml/filters.rb +75 -0
  51. data/haml-7.2.0/lib/haml/force_escape.rb +29 -0
  52. data/haml-7.2.0/lib/haml/helpers.rb +15 -0
  53. data/haml-7.2.0/lib/haml/html.rb +22 -0
  54. data/haml-7.2.0/lib/haml/identity.rb +13 -0
  55. data/haml-7.2.0/lib/haml/object_ref.rb +35 -0
  56. data/haml-7.2.0/lib/haml/parser.rb +991 -0
  57. data/haml-7.2.0/lib/haml/rails_helpers.rb +53 -0
  58. data/haml-7.2.0/lib/haml/rails_template.rb +62 -0
  59. data/haml-7.2.0/lib/haml/railtie.rb +10 -0
  60. data/haml-7.2.0/lib/haml/ruby_expression.rb +32 -0
  61. data/haml-7.2.0/lib/haml/string_splitter.rb +140 -0
  62. data/haml-7.2.0/lib/haml/template.rb +20 -0
  63. data/haml-7.2.0/lib/haml/temple_line_counter.rb +31 -0
  64. data/haml-7.2.0/lib/haml/util.rb +262 -0
  65. data/haml-7.2.0/lib/haml/version.rb +4 -0
  66. data/haml-7.2.0/lib/haml/whitespace.rb +8 -0
  67. data/haml-7.2.0/lib/haml.rb +9 -0
  68. data/mini-max-kit.gemspec +12 -0
  69. metadata +108 -0
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: false
2
+ require 'haml/helpers'
3
+
4
+ # There are only helpers that depend on ActionView internals.
5
+ module Haml
6
+ module RailsHelpers
7
+ include Helpers
8
+ extend self
9
+
10
+ DEFAULT_PRESERVE_TAGS = %w[textarea pre code].freeze
11
+
12
+ def find_and_preserve(input = nil, tags = DEFAULT_PRESERVE_TAGS, &block)
13
+ return find_and_preserve(capture_haml(&block), input || tags) if block
14
+
15
+ tags = tags.each_with_object('') do |t, s|
16
+ s << '|' unless s.empty?
17
+ s << Regexp.escape(t)
18
+ end
19
+
20
+ re = /<(#{tags})([^>]*)>(.*?)(<\/\1>)/im
21
+ input.to_s.gsub(re) do |s|
22
+ s =~ re # Can't rely on $1, etc. existing since Rails' SafeBuffer#gsub is incompatible
23
+ "<#{$1}#{$2}>#{preserve($3)}</#{$1}>"
24
+ end
25
+ end
26
+
27
+ def preserve(input = nil, &block)
28
+ return preserve(capture_haml(&block)) if block
29
+ super.html_safe
30
+ end
31
+
32
+ def surround(front, back = front, &block)
33
+ output = capture_haml(&block)
34
+ front = escape_once(front) unless front.html_safe?
35
+ back = escape_once(back) unless back.html_safe?
36
+ "#{front}#{output.chomp}#{back}\n".html_safe
37
+ end
38
+
39
+ def precede(str, &block)
40
+ str = escape_once(str) unless str.html_safe?
41
+ "#{str}#{capture_haml(&block).chomp}\n".html_safe
42
+ end
43
+
44
+ def succeed(str, &block)
45
+ str = escape_once(str) unless str.html_safe?
46
+ "#{capture_haml(&block).chomp}#{str}\n".html_safe
47
+ end
48
+
49
+ def capture_haml(*args, &block)
50
+ capture(*args, &block)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+ require 'temple'
3
+ require 'haml/engine'
4
+ require 'haml/rails_helpers'
5
+ require 'haml/util'
6
+
7
+ module Haml
8
+ class RailsTemplate
9
+ # Compatible with: https://github.com/judofyr/temple/blob/v0.7.7/lib/temple/mixins/options.rb#L15-L24
10
+ class << self
11
+ def options
12
+ @options ||= {
13
+ generator: Temple::Generators::RailsOutputBuffer,
14
+ use_html_safe: true,
15
+ streaming: true,
16
+ buffer_class: 'ActionView::OutputBuffer',
17
+ disable_capture: true,
18
+ }
19
+ end
20
+
21
+ def set_options(opts)
22
+ options.update(opts)
23
+ end
24
+ end
25
+
26
+ def call(template, source = nil)
27
+ source ||= template.source
28
+ options = RailsTemplate.options
29
+
30
+ # Make the filename available in parser etc.
31
+ if template.respond_to?(:identifier)
32
+ options = options.merge(filename: template.identifier)
33
+ end
34
+
35
+ # https://github.com/haml/haml/blob/4.0.7/lib/haml/template/plugin.rb#L19-L20
36
+ # https://github.com/haml/haml/blob/4.0.7/lib/haml/options.rb#L228
37
+ if template.respond_to?(:type) && template.type == 'text/xml'
38
+ options = options.merge(format: :xhtml)
39
+ end
40
+
41
+ if ActionView::Base.try(:annotate_rendered_view_with_filenames) && template.format == :html
42
+ options = options.merge(
43
+ preamble: "<!-- BEGIN #{template.short_identifier} -->",
44
+ postamble: "<!-- END #{template.short_identifier} -->",
45
+ )
46
+ end
47
+
48
+ Engine.new(options).call(source)
49
+ end
50
+
51
+ def supports_streaming?
52
+ RailsTemplate.options[:streaming]
53
+ end
54
+ end
55
+ ActionView::Template.register_template_handler(:haml, RailsTemplate.new)
56
+ end
57
+
58
+ # Haml extends Haml::Helpers in ActionView each time.
59
+ # It costs much, so Haml includes a compatible module at first.
60
+ ActiveSupport.on_load(:action_view) do
61
+ include Haml::RailsHelpers
62
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ require 'rails'
3
+
4
+ module Haml
5
+ class Railtie < ::Rails::Railtie
6
+ initializer :haml, before: :load_config_initializers do |app|
7
+ require 'haml/rails_template'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+ require 'ripper'
3
+
4
+ module Haml
5
+ class RubyExpression < Ripper
6
+ class ParseError < StandardError; end
7
+
8
+ def self.syntax_error?(code)
9
+ self.new(code).parse
10
+ false
11
+ rescue ParseError
12
+ true
13
+ end
14
+
15
+ def self.string_literal?(code)
16
+ return false if syntax_error?(code)
17
+
18
+ type, instructions = Ripper.sexp(code)
19
+ return false if type != :program
20
+ return false if instructions.size > 1
21
+
22
+ type, _ = instructions.first
23
+ type == :string_literal
24
+ end
25
+
26
+ private
27
+
28
+ def on_parse_error(*)
29
+ raise ParseError
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,140 @@
1
+ # frozen_string_literal: true
2
+ begin
3
+ require 'ripper'
4
+ rescue LoadError
5
+ end
6
+
7
+ module Haml
8
+ # Compile [:dynamic, "foo#{bar}"] to [:multi, [:static, 'foo'], [:dynamic, 'bar']]
9
+ class StringSplitter < Temple::Filter
10
+ if defined?(Ripper) && Ripper.respond_to?(:lex)
11
+ class << self
12
+ # `code` param must be valid string literal
13
+ def compile(code)
14
+ [].tap do |exps|
15
+ tokens = Ripper.lex(code.strip)
16
+ tokens.pop while tokens.last && [:on_comment, :on_sp].include?(tokens.last[1])
17
+
18
+ if tokens.size < 2
19
+ raise(Haml::InternalError, "Expected token size >= 2 but got: #{tokens.size}")
20
+ end
21
+ compile_tokens!(exps, tokens)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def strip_quotes!(tokens)
28
+ _, type, beg_str = tokens.shift
29
+ if type != :on_tstring_beg
30
+ raise(Haml::InternalError, "Expected :on_tstring_beg but got: #{type}")
31
+ end
32
+
33
+ _, type, end_str = tokens.pop
34
+ if type != :on_tstring_end
35
+ raise(Haml::InternalError, "Expected :on_tstring_end but got: #{type}")
36
+ end
37
+
38
+ [beg_str, end_str]
39
+ end
40
+
41
+ def compile_tokens!(exps, tokens)
42
+ beg_str, end_str = strip_quotes!(tokens)
43
+
44
+ until tokens.empty?
45
+ _, type, str = tokens.shift
46
+
47
+ case type
48
+ when :on_tstring_content
49
+ beg_str, end_str = escape_quotes(beg_str, end_str)
50
+ exps << [:static, eval("#{beg_str}#{str}#{end_str}").to_s]
51
+ when :on_embexpr_beg
52
+ embedded = shift_balanced_embexpr(tokens)
53
+ exps << [:dynamic, embedded] unless embedded.empty?
54
+ end
55
+ end
56
+ end
57
+
58
+ # Some quotes are split-unsafe. Replace such quotes with null characters.
59
+ def escape_quotes(beg_str, end_str)
60
+ case [beg_str[-1], end_str]
61
+ when ['(', ')'], ['[', ']'], ['{', '}']
62
+ [beg_str.sub(/.\z/) { "\0" }, "\0"]
63
+ else
64
+ [beg_str, end_str]
65
+ end
66
+ end
67
+
68
+ def shift_balanced_embexpr(tokens)
69
+ String.new.tap do |embedded|
70
+ embexpr_open = 1
71
+
72
+ until tokens.empty?
73
+ _, type, str = tokens.shift
74
+ case type
75
+ when :on_embexpr_beg
76
+ embexpr_open += 1
77
+ when :on_embexpr_end
78
+ embexpr_open -= 1
79
+ break if embexpr_open == 0
80
+ end
81
+
82
+ embedded << str
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ def on_dynamic(code)
89
+ return [:dynamic, code] unless string_literal?(code)
90
+ return [:dynamic, code] if code.include?("\n")
91
+
92
+ temple = [:multi]
93
+ StringSplitter.compile(code).each do |type, content|
94
+ case type
95
+ when :static
96
+ temple << [:static, content]
97
+ when :dynamic
98
+ temple << on_dynamic(content)
99
+ end
100
+ end
101
+ temple
102
+ end
103
+
104
+ private
105
+
106
+ def string_literal?(code)
107
+ return false if SyntaxChecker.syntax_error?(code)
108
+
109
+ type, instructions = Ripper.sexp(code)
110
+ return false if type != :program
111
+ return false if instructions.size > 1
112
+
113
+ type, _ = instructions.first
114
+ type == :string_literal
115
+ end
116
+
117
+ class SyntaxChecker < Ripper
118
+ class ParseError < StandardError; end
119
+
120
+ def self.syntax_error?(code)
121
+ self.new(code).parse
122
+ false
123
+ rescue ParseError
124
+ true
125
+ end
126
+
127
+ private
128
+
129
+ def on_parse_error(*)
130
+ raise ParseError
131
+ end
132
+ end
133
+ else
134
+ # Do nothing if ripper is unavailable
135
+ def call(ast)
136
+ ast
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: false
2
+ require 'temple'
3
+ require 'haml/engine'
4
+ require 'haml/helpers'
5
+
6
+ module Haml
7
+ Template = Temple::Templates::Tilt.create(
8
+ Haml::Engine,
9
+ register_as: [:haml, :haml],
10
+ )
11
+
12
+ module TemplateExtension
13
+ # Activate Haml::Helpers for tilt templates.
14
+ # https://github.com/judofyr/temple/blob/v0.7.6/lib/temple/mixins/template.rb#L7-L11
15
+ def compile(*)
16
+ "extend Haml::Helpers; #{super}"
17
+ end
18
+ end
19
+ Template.send(:extend, TemplateExtension)
20
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+ module Haml
3
+ # A module to count lines of expected code. This would be faster than actual code generation
4
+ # and counting newlines in it.
5
+ module TempleLineCounter
6
+ class UnexpectedExpression < StandardError; end
7
+
8
+ def self.count_lines(exp)
9
+ type, *args = exp
10
+ case type
11
+ when :multi
12
+ args.map { |a| count_lines(a) }.reduce(:+) || 0
13
+ when :dynamic, :code
14
+ args.first.count("\n")
15
+ when :static
16
+ 0 # It has not real newline "\n" but escaped "\\n".
17
+ when :case
18
+ arg, *cases = args
19
+ arg.count("\n") + cases.map do |cond, e|
20
+ (cond == :else ? 0 : cond.count("\n")) + count_lines(e)
21
+ end.reduce(:+)
22
+ when :escape
23
+ count_lines(args[1])
24
+ when :newline
25
+ 1
26
+ else
27
+ raise UnexpectedExpression.new("[HAML BUG] Unexpected Temple expression '#{type}' is given!")
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,262 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'erubis/tiny'
5
+ rescue LoadError
6
+ require 'erb'
7
+ end
8
+ require 'set'
9
+ require 'stringio'
10
+ require 'strscan'
11
+
12
+ module Haml
13
+ # A module containing various useful functions.
14
+ module Util
15
+ extend self
16
+
17
+ begin # Ruby 3.2+ or ERB 4+
18
+ require 'erb/escape'
19
+
20
+ define_singleton_method(:escape_html, ERB::Escape.instance_method(:html_escape))
21
+ rescue LoadError
22
+ require 'cgi/escape'
23
+
24
+ def self.escape_html(html)
25
+ CGI.escapeHTML(html.to_s)
26
+ end
27
+ end
28
+
29
+ # TODO: Remove unescape_interpolation's workaround and get rid of `respond_to?`.
30
+ def self.escape_html_safe(html)
31
+ html = html.to_s
32
+ (html.respond_to?(:html_safe?) && html.html_safe?) ? html : escape_html(html)
33
+ end
34
+
35
+ # Silence all output to STDERR within a block.
36
+ #
37
+ # @yield A block in which no output will be printed to STDERR
38
+ def silence_warnings
39
+ the_real_stderr, $stderr = $stderr, StringIO.new
40
+ yield
41
+ ensure
42
+ $stderr = the_real_stderr
43
+ end
44
+
45
+ ## Rails XSS Safety
46
+
47
+ # Whether or not ActionView's XSS protection is available and enabled,
48
+ # as is the default for Rails 3.0+, and optional for version 2.3.5+.
49
+ # Overridden in haml/template.rb if this is the case.
50
+ #
51
+ # @return [Boolean]
52
+ def rails_xss_safe?
53
+ false
54
+ end
55
+
56
+ # Checks that the encoding of a string is valid
57
+ # and cleans up potential encoding gotchas like the UTF-8 BOM.
58
+ # If it's not, yields an error string describing the invalid character
59
+ # and the line on which it occurs.
60
+ #
61
+ # @param str [String] The string of which to check the encoding
62
+ # @yield [msg] A block in which an encoding error can be raised.
63
+ # Only yields if there is an encoding error
64
+ # @yieldparam msg [String] The error message to be raised
65
+ # @return [String] `str`, potentially with encoding gotchas like BOMs removed
66
+ def check_encoding(str)
67
+ if str.valid_encoding?
68
+ # Get rid of the Unicode BOM if possible
69
+ # Shortcut for UTF-8 which might be the majority case
70
+ if str.encoding == Encoding::UTF_8
71
+ return str.gsub(/\A\uFEFF/, '')
72
+ elsif /^UTF-(16|32)(BE|LE)?$/.match?(str.encoding.name)
73
+ return str.gsub(Regexp.new("\\A\uFEFF".encode(str.encoding)), '')
74
+ else
75
+ return str
76
+ end
77
+ end
78
+
79
+ encoding = str.encoding
80
+ newlines = Regexp.new("\r\n|\r|\n".encode(encoding).force_encoding(Encoding::ASCII_8BIT))
81
+ str.force_encoding(Encoding::ASCII_8BIT).split(newlines).each_with_index do |line, i|
82
+ begin
83
+ line.encode(encoding)
84
+ rescue Encoding::UndefinedConversionError => e
85
+ yield <<MSG.rstrip, i + 1
86
+ Invalid #{encoding.name} character #{e.error_char.dump}
87
+ MSG
88
+ end
89
+ end
90
+ return str
91
+ end
92
+
93
+ # Like {\#check\_encoding}, but also checks for a Ruby-style `-# coding:` comment
94
+ # at the beginning of the template and uses that encoding if it exists.
95
+ #
96
+ # The Haml encoding rules are simple.
97
+ # If a `-# coding:` comment exists,
98
+ # we assume that that's the original encoding of the document.
99
+ # Otherwise, we use whatever encoding Ruby has.
100
+ #
101
+ # Haml uses the same rules for parsing coding comments as Ruby.
102
+ # This means that it can understand Emacs-style comments
103
+ # (e.g. `-*- encoding: "utf-8" -*-`),
104
+ # and also that it cannot understand non-ASCII-compatible encodings
105
+ # such as `UTF-16` and `UTF-32`.
106
+ #
107
+ # @param str [String] The Haml template of which to check the encoding
108
+ # @yield [msg] A block in which an encoding error can be raised.
109
+ # Only yields if there is an encoding error
110
+ # @yieldparam msg [String] The error message to be raised
111
+ # @return [String] The original string encoded properly
112
+ # @raise [ArgumentError] if the document declares an unknown encoding
113
+ def check_haml_encoding(str, &block)
114
+ str = str.dup if str.frozen?
115
+
116
+ bom, encoding = parse_haml_magic_comment(str)
117
+ if encoding; str.force_encoding(encoding)
118
+ elsif bom; str.force_encoding(Encoding::UTF_8)
119
+ end
120
+
121
+ return check_encoding(str, &block)
122
+ end
123
+
124
+ # Like `Object#inspect`, but preserves non-ASCII characters rather than escaping them.
125
+ # This is necessary so that the precompiled Haml template can be `#encode`d into `@options[:encoding]`
126
+ # before being evaluated.
127
+ #
128
+ # @param obj {Object}
129
+ # @return {String}
130
+ def inspect_obj(obj)
131
+ case obj
132
+ when String
133
+ %Q!"#{obj.gsub(/[\x00-\x7F]+/) {|s| s.dump[1...-1]}}"!
134
+ when Symbol
135
+ ":#{inspect_obj(obj.to_s)}"
136
+ else
137
+ obj.inspect
138
+ end
139
+ end
140
+
141
+ # Scans through a string looking for the interoplation-opening `#{`
142
+ # and, when it's found, yields the scanner to the calling code
143
+ # so it can handle it properly.
144
+ #
145
+ # The scanner will have any backslashes immediately in front of the `#{`
146
+ # as the second capture group (`scan[2]`),
147
+ # and the text prior to that as the first (`scan[1]`).
148
+ #
149
+ # @yieldparam scan [StringScanner] The scanner scanning through the string
150
+ # @return [String] The text remaining in the scanner after all `#{`s have been processed
151
+ def handle_interpolation(str)
152
+ scan = StringScanner.new(str)
153
+ yield scan while scan.scan(/(.*?)(\\*)#([\{@$])/)
154
+ scan.rest
155
+ end
156
+
157
+ # Moves a scanner through a balanced pair of characters.
158
+ # For example:
159
+ #
160
+ # Foo (Bar (Baz bang) bop) (Bang (bop bip))
161
+ # ^ ^
162
+ # from to
163
+ #
164
+ # @param scanner [StringScanner] The string scanner to move
165
+ # @param start [String] The character opening the balanced pair.
166
+ # @param finish [String] The character closing the balanced pair.
167
+ # @param count [Fixnum] The number of opening characters matched
168
+ # before calling this method
169
+ # @return [(String, String)] The string matched within the balanced pair
170
+ # and the rest of the string.
171
+ # `["Foo (Bar (Baz bang) bop)", " (Bang (bop bip))"]` in the example above.
172
+ def balance(scanner, start, finish, count = 0)
173
+ str = ''.dup
174
+ scanner = StringScanner.new(scanner) unless scanner.is_a? StringScanner
175
+ regexp = Regexp.new("(.*?)[\\#{start.chr}\\#{finish.chr}]", Regexp::MULTILINE)
176
+ while scanner.scan(regexp)
177
+ str << scanner.matched
178
+ count += 1 if scanner.matched[-1] == start
179
+ count -= 1 if scanner.matched[-1] == finish
180
+ return [str.strip, scanner.rest] if count == 0
181
+ end
182
+ end
183
+
184
+ # Formats a string for use in error messages about indentation.
185
+ #
186
+ # @param indentation [String] The string used for indentation
187
+ # @return [String] The name of the indentation (e.g. `"12 spaces"`, `"1 tab"`)
188
+ def human_indentation(indentation)
189
+ if !indentation.include?(?\t)
190
+ noun = 'space'
191
+ elsif !indentation.include?(?\s)
192
+ noun = 'tab'
193
+ else
194
+ return indentation.inspect
195
+ end
196
+
197
+ singular = indentation.length == 1
198
+ "#{indentation.length} #{noun}#{'s' unless singular}"
199
+ end
200
+
201
+ def contains_interpolation?(str)
202
+ /#[\{$@]/ === str
203
+ end
204
+
205
+ def unescape_interpolation(str, escape_html = nil)
206
+ res = ''.dup
207
+ rest = Haml::Util.handle_interpolation str.dump do |scan|
208
+ escapes = (scan[2].size - 1) / 2
209
+ char = scan[3] # '{', '@' or '$'
210
+ res << scan.matched[0...-3 - escapes]
211
+ if escapes % 2 == 1
212
+ res << "\##{char}"
213
+ else
214
+ interpolated = if char == '{'
215
+ balance(scan, ?{, ?}, 1)[0][0...-1]
216
+ else
217
+ scan.scan(/\w+/)
218
+ end
219
+ content = eval("\"#{interpolated}\"")
220
+ content = "#{char}#{content}" if char == '@' || char == '$'
221
+ content = "Haml::Util.escape_html_safe((#{content}).to_s)" if escape_html
222
+
223
+ res << "\#{#{content}}"
224
+ end
225
+ end
226
+ res + rest
227
+ end
228
+
229
+ private
230
+
231
+ # Parses a magic comment at the beginning of a Haml file.
232
+ # The parsing rules are basically the same as Ruby's.
233
+ #
234
+ # @return [(Boolean, String or nil)]
235
+ # Whether the document begins with a UTF-8 BOM,
236
+ # and the declared encoding of the document (or nil if none is declared)
237
+ def parse_haml_magic_comment(str)
238
+ scanner = StringScanner.new(str.dup.force_encoding(Encoding::ASCII_8BIT))
239
+ bom = scanner.scan(/\xEF\xBB\xBF/n)
240
+ return bom unless scanner.scan(/-\s*#\s*/n)
241
+ if (coding = try_parse_haml_emacs_magic_comment(scanner))
242
+ return bom, coding
243
+ end
244
+
245
+ return bom unless scanner.scan(/.*?coding[=:]\s*([\w-]+)/in)
246
+ return bom, scanner[1]
247
+ end
248
+
249
+ def try_parse_haml_emacs_magic_comment(scanner)
250
+ pos = scanner.pos
251
+ return unless scanner.scan(/.*?-\*-\s*/n)
252
+ # From Ruby's parse.y
253
+ return unless scanner.scan(/([^\s'":;]+)\s*:\s*("(?:\\.|[^"])*"|[^"\s;]+?)[\s;]*-\*-/n)
254
+ name, val = scanner[1], scanner[2]
255
+ return unless /(en)?coding/in.match?(name)
256
+ val = $1 if val =~ /^"(.*)"$/n
257
+ return val
258
+ ensure
259
+ scanner.pos = pos
260
+ end
261
+ end
262
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module Haml
3
+ VERSION = '7.2.0'
4
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ module Haml
3
+ class Whitespace < Temple::Filter
4
+ def on_whitespace
5
+ [:static, "\n"]
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ require 'haml/engine'
3
+ require 'haml/error'
4
+ require 'haml/version'
5
+ require 'haml/template'
6
+
7
+ if File.basename($0) != 'haml'
8
+ require 'haml/railtie' if defined?(Rails::Railtie)
9
+ end
@@ -0,0 +1,12 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "mini-max-kit"
3
+ s.version = "0.0.1"
4
+ s.summary = "Research test"
5
+ s.description = "University research based on haml"
6
+ s.authors = ["Andrey78"]
7
+ s.email = ["cakoc614@gmail.com"]
8
+ s.files = Dir.glob("**/*").reject { |f| f.end_with?('.gem') }
9
+ s.homepage = "https://rubygems.org/profiles/Andrey78"
10
+ s.license = "MIT"
11
+ s.metadata = { "source_code_uri" => "https://github.com/Andrey78/mini-max-kit" }
12
+ end