haml 5.2.2 → 6.1.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.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +3 -0
- data/.github/workflows/test.yml +13 -14
- data/.gitignore +16 -16
- data/.yardopts +0 -3
- data/CHANGELOG.md +116 -3
- data/Gemfile +18 -11
- data/MIT-LICENSE +1 -1
- data/README.md +17 -23
- data/REFERENCE.md +69 -145
- data/Rakefile +48 -81
- data/bin/bench +66 -0
- data/bin/console +11 -0
- data/bin/ruby +3 -0
- data/bin/setup +7 -0
- data/bin/stackprof +27 -0
- data/bin/test +24 -0
- data/exe/haml +6 -0
- data/ext/haml/extconf.rb +10 -0
- data/ext/haml/haml.c +537 -0
- data/ext/haml/hescape.c +108 -0
- data/ext/haml/hescape.h +20 -0
- data/haml.gemspec +39 -37
- data/lib/haml/ambles.rb +20 -0
- data/lib/haml/attribute_builder.rb +134 -179
- data/lib/haml/attribute_compiler.rb +85 -194
- data/lib/haml/attribute_parser.rb +92 -126
- data/lib/haml/cli.rb +154 -0
- data/lib/haml/compiler/children_compiler.rb +155 -0
- data/lib/haml/compiler/comment_compiler.rb +51 -0
- data/lib/haml/compiler/doctype_compiler.rb +46 -0
- data/lib/haml/compiler/script_compiler.rb +114 -0
- data/lib/haml/compiler/silent_script_compiler.rb +24 -0
- data/lib/haml/compiler/tag_compiler.rb +76 -0
- data/lib/haml/compiler.rb +63 -296
- data/lib/haml/dynamic_merger.rb +67 -0
- data/lib/haml/engine.rb +48 -227
- data/lib/haml/error.rb +5 -4
- data/lib/haml/escape.rb +13 -0
- data/lib/haml/escape_any.rb +21 -0
- data/lib/haml/filters/base.rb +12 -0
- data/lib/haml/filters/cdata.rb +20 -0
- data/lib/haml/filters/coffee.rb +17 -0
- data/lib/haml/filters/css.rb +33 -0
- data/lib/haml/filters/erb.rb +10 -0
- data/lib/haml/filters/escaped.rb +22 -0
- data/lib/haml/filters/javascript.rb +33 -0
- data/lib/haml/filters/less.rb +20 -0
- data/lib/haml/filters/markdown.rb +11 -0
- data/lib/haml/filters/plain.rb +29 -0
- data/lib/haml/filters/preserve.rb +22 -0
- data/lib/haml/filters/ruby.rb +10 -0
- data/lib/haml/filters/sass.rb +15 -0
- data/lib/haml/filters/scss.rb +15 -0
- data/lib/haml/filters/text_base.rb +25 -0
- data/lib/haml/filters/tilt_base.rb +59 -0
- data/lib/haml/filters.rb +54 -378
- data/lib/haml/force_escape.rb +29 -0
- data/lib/haml/helpers.rb +3 -697
- data/lib/haml/html.rb +22 -0
- data/lib/haml/identity.rb +13 -0
- data/lib/haml/object_ref.rb +35 -0
- data/lib/haml/parser.rb +157 -22
- data/lib/haml/rails_helpers.rb +53 -0
- data/lib/haml/rails_template.rb +57 -0
- data/lib/haml/railtie.rb +3 -46
- data/lib/haml/ruby_expression.rb +32 -0
- data/lib/haml/string_splitter.rb +140 -0
- data/lib/haml/template.rb +15 -34
- data/lib/haml/temple_line_counter.rb +2 -1
- data/lib/haml/util.rb +18 -15
- data/lib/haml/version.rb +1 -2
- data/lib/haml/whitespace.rb +8 -0
- data/lib/haml.rb +8 -20
- metadata +211 -55
- data/.gitmodules +0 -3
- data/TODO +0 -24
- data/benchmark.rb +0 -70
- data/bin/haml +0 -9
- data/lib/haml/.gitattributes +0 -1
- data/lib/haml/buffer.rb +0 -182
- data/lib/haml/escapable.rb +0 -77
- data/lib/haml/exec.rb +0 -347
- data/lib/haml/generator.rb +0 -42
- data/lib/haml/helpers/action_view_extensions.rb +0 -60
- data/lib/haml/helpers/action_view_mods.rb +0 -132
- data/lib/haml/helpers/action_view_xss_mods.rb +0 -60
- data/lib/haml/helpers/safe_erubi_template.rb +0 -20
- data/lib/haml/helpers/safe_erubis_template.rb +0 -33
- data/lib/haml/helpers/xss_mods.rb +0 -114
- data/lib/haml/options.rb +0 -273
- data/lib/haml/plugin.rb +0 -54
- data/lib/haml/sass_rails_filter.rb +0 -47
- data/lib/haml/template/options.rb +0 -27
- data/lib/haml/temple_engine.rb +0 -124
- data/yard/default/.gitignore +0 -1
- data/yard/default/fulldoc/html/css/common.sass +0 -15
- data/yard/default/layout/html/footer.erb +0 -12
@@ -1,114 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Haml
|
4
|
-
module Helpers
|
5
|
-
# This module overrides Haml helpers to work properly
|
6
|
-
# in the context of ActionView.
|
7
|
-
# Currently it's only used for modifying the helpers
|
8
|
-
# to work with Rails' XSS protection methods.
|
9
|
-
module XssMods
|
10
|
-
def self.included(base)
|
11
|
-
%w[find_and_preserve preserve list_of surround
|
12
|
-
precede succeed capture_haml haml_concat haml_internal_concat haml_indent].each do |name|
|
13
|
-
base.send(:alias_method, "#{name}_without_haml_xss", name)
|
14
|
-
base.send(:alias_method, name, "#{name}_with_haml_xss")
|
15
|
-
end
|
16
|
-
# Those two always have _without_haml_xss
|
17
|
-
%w[html_escape escape_once].each do |name|
|
18
|
-
base.send(:alias_method, name, "#{name}_with_haml_xss")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# Don't escape text that's already safe,
|
23
|
-
# output is always HTML safe
|
24
|
-
def html_escape_with_haml_xss(text)
|
25
|
-
str = text.to_s
|
26
|
-
return text if str.html_safe?
|
27
|
-
Haml::Util.html_safe(html_escape_without_haml_xss(str))
|
28
|
-
end
|
29
|
-
|
30
|
-
# Output is always HTML safe
|
31
|
-
def find_and_preserve_with_haml_xss(*args, &block)
|
32
|
-
Haml::Util.html_safe(find_and_preserve_without_haml_xss(*args, &block))
|
33
|
-
end
|
34
|
-
|
35
|
-
# Output is always HTML safe
|
36
|
-
def preserve_with_haml_xss(*args, &block)
|
37
|
-
Haml::Util.html_safe(preserve_without_haml_xss(*args, &block))
|
38
|
-
end
|
39
|
-
|
40
|
-
# Output is always HTML safe
|
41
|
-
def list_of_with_haml_xss(*args, &block)
|
42
|
-
Haml::Util.html_safe(list_of_without_haml_xss(*args, &block))
|
43
|
-
end
|
44
|
-
|
45
|
-
# Input is escaped, output is always HTML safe
|
46
|
-
def surround_with_haml_xss(front, back = front, &block)
|
47
|
-
Haml::Util.html_safe(
|
48
|
-
surround_without_haml_xss(
|
49
|
-
haml_xss_html_escape(front),
|
50
|
-
haml_xss_html_escape(back),
|
51
|
-
&block))
|
52
|
-
end
|
53
|
-
|
54
|
-
# Input is escaped, output is always HTML safe
|
55
|
-
def precede_with_haml_xss(str, &block)
|
56
|
-
Haml::Util.html_safe(precede_without_haml_xss(haml_xss_html_escape(str), &block))
|
57
|
-
end
|
58
|
-
|
59
|
-
# Input is escaped, output is always HTML safe
|
60
|
-
def succeed_with_haml_xss(str, &block)
|
61
|
-
Haml::Util.html_safe(succeed_without_haml_xss(haml_xss_html_escape(str), &block))
|
62
|
-
end
|
63
|
-
|
64
|
-
# Output is always HTML safe
|
65
|
-
def capture_haml_with_haml_xss(*args, &block)
|
66
|
-
Haml::Util.html_safe(capture_haml_without_haml_xss(*args, &block))
|
67
|
-
end
|
68
|
-
|
69
|
-
# Input will be escaped unless this is in a `with_raw_haml_concat`
|
70
|
-
# block. See #Haml::Helpers::ActionViewExtensions#with_raw_haml_concat.
|
71
|
-
def haml_concat_with_haml_xss(text = "")
|
72
|
-
raw = instance_variable_defined?(:@_haml_concat_raw) ? @_haml_concat_raw : false
|
73
|
-
if raw
|
74
|
-
haml_internal_concat_raw text
|
75
|
-
else
|
76
|
-
haml_internal_concat text
|
77
|
-
end
|
78
|
-
ErrorReturn.new("haml_concat")
|
79
|
-
end
|
80
|
-
|
81
|
-
# Input is escaped
|
82
|
-
def haml_internal_concat_with_haml_xss(text="", newline=true, indent=true)
|
83
|
-
haml_internal_concat_without_haml_xss(haml_xss_html_escape(text), newline, indent)
|
84
|
-
end
|
85
|
-
private :haml_internal_concat_with_haml_xss
|
86
|
-
|
87
|
-
# Output is always HTML safe
|
88
|
-
def haml_indent_with_haml_xss
|
89
|
-
Haml::Util.html_safe(haml_indent_without_haml_xss)
|
90
|
-
end
|
91
|
-
|
92
|
-
# Output is always HTML safe
|
93
|
-
def escape_once_with_haml_xss(*args)
|
94
|
-
Haml::Util.html_safe(escape_once_without_haml_xss(*args))
|
95
|
-
end
|
96
|
-
|
97
|
-
private
|
98
|
-
|
99
|
-
# Escapes the HTML in the text if and only if
|
100
|
-
# Rails XSS protection is enabled *and* the `:escape_html` option is set.
|
101
|
-
def haml_xss_html_escape(text)
|
102
|
-
return text unless Haml::Util.rails_xss_safe? && haml_buffer.options[:escape_html]
|
103
|
-
html_escape(text)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
class ErrorReturn
|
108
|
-
# Any attempt to treat ErrorReturn as a string should cause it to blow up.
|
109
|
-
alias_method :html_safe, :to_s
|
110
|
-
alias_method :html_safe?, :to_s
|
111
|
-
alias_method :html_safe!, :to_s
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
data/lib/haml/options.rb
DELETED
@@ -1,273 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Haml
|
4
|
-
# This class encapsulates all of the configuration options that Haml
|
5
|
-
# understands. Please see the {file:REFERENCE.md#options Haml Reference} to
|
6
|
-
# learn how to set the options.
|
7
|
-
class Options
|
8
|
-
@valid_formats = [:html4, :html5, :xhtml]
|
9
|
-
@buffer_option_keys = [:autoclose, :preserve, :attr_wrapper, :format,
|
10
|
-
:encoding, :escape_html, :escape_filter_interpolations, :escape_attrs, :hyphenate_data_attrs, :cdata]
|
11
|
-
|
12
|
-
class << self
|
13
|
-
# The default option values.
|
14
|
-
# @return Hash
|
15
|
-
def defaults
|
16
|
-
@defaults ||= Haml::TempleEngine.options.to_hash.merge(encoding: 'UTF-8')
|
17
|
-
end
|
18
|
-
|
19
|
-
# An array of valid values for the `:format` option.
|
20
|
-
# @return Array
|
21
|
-
attr_reader :valid_formats
|
22
|
-
|
23
|
-
# An array of keys that will be used to provide a hash of options to
|
24
|
-
# {Haml::Buffer}.
|
25
|
-
# @return Hash
|
26
|
-
attr_reader :buffer_option_keys
|
27
|
-
|
28
|
-
# Returns a subset of defaults: those that {Haml::Buffer} cares about.
|
29
|
-
# @return [{Symbol => Object}] The options hash
|
30
|
-
def buffer_defaults
|
31
|
-
@buffer_defaults ||= buffer_option_keys.inject({}) do |hash, key|
|
32
|
-
hash.merge(key => defaults[key])
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def wrap(options)
|
37
|
-
if options.is_a?(Options)
|
38
|
-
options
|
39
|
-
else
|
40
|
-
Options.new(options)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# The character that should wrap element attributes. This defaults to `'`
|
46
|
-
# (an apostrophe). Characters of this type within the attributes will be
|
47
|
-
# escaped (e.g. by replacing them with `'`) if the character is an
|
48
|
-
# apostrophe or a quotation mark.
|
49
|
-
attr_reader :attr_wrapper
|
50
|
-
|
51
|
-
# A list of tag names that should be automatically self-closed if they have
|
52
|
-
# no content. This can also contain regular expressions that match tag names
|
53
|
-
# (or any object which responds to `#===`). Defaults to `['meta', 'img',
|
54
|
-
# 'link', 'br', 'hr', 'input', 'area', 'param', 'col', 'base']`.
|
55
|
-
attr_accessor :autoclose
|
56
|
-
|
57
|
-
# The encoding to use for the HTML output.
|
58
|
-
# This can be a string or an `Encoding` Object. Note that Haml **does not**
|
59
|
-
# automatically re-encode Ruby values; any strings coming from outside the
|
60
|
-
# application should be converted before being passed into the Haml
|
61
|
-
# template. Defaults to `Encoding.default_internal`; if that's not set,
|
62
|
-
# defaults to the encoding of the Haml template; if that's `US-ASCII`,
|
63
|
-
# defaults to `"UTF-8"`.
|
64
|
-
attr_reader :encoding
|
65
|
-
|
66
|
-
# Sets whether or not to escape HTML-sensitive characters in attributes. If
|
67
|
-
# this is true, all HTML-sensitive characters in attributes are escaped. If
|
68
|
-
# it's set to false, no HTML-sensitive characters in attributes are escaped.
|
69
|
-
# If it's set to `:once`, existing HTML escape sequences are preserved, but
|
70
|
-
# other HTML-sensitive characters are escaped.
|
71
|
-
#
|
72
|
-
# Defaults to `true`.
|
73
|
-
attr_accessor :escape_attrs
|
74
|
-
|
75
|
-
# Sets whether or not to escape HTML-sensitive characters in script. If this
|
76
|
-
# is true, `=` behaves like {file:REFERENCE.md#escaping_html `&=`};
|
77
|
-
# otherwise, it behaves like {file:REFERENCE.md#unescaping_html `!=`}. Note
|
78
|
-
# that if this is set, `!=` should be used for yielding to subtemplates and
|
79
|
-
# rendering partials. See also {file:REFERENCE.md#escaping_html Escaping HTML} and
|
80
|
-
# {file:REFERENCE.md#unescaping_html Unescaping HTML}.
|
81
|
-
#
|
82
|
-
# Defaults to false.
|
83
|
-
attr_accessor :escape_html
|
84
|
-
|
85
|
-
# Sets whether or not to escape HTML-sensitive characters in interpolated strings.
|
86
|
-
# See also {file:REFERENCE.md#escaping_html Escaping HTML} and
|
87
|
-
# {file:REFERENCE.md#unescaping_html Unescaping HTML}.
|
88
|
-
#
|
89
|
-
# Defaults to the current value of `escape_html`.
|
90
|
-
attr_accessor :escape_filter_interpolations
|
91
|
-
|
92
|
-
# The name of the Haml file being parsed.
|
93
|
-
# This is only used as information when exceptions are raised. This is
|
94
|
-
# automatically assigned when working through ActionView, so it's really
|
95
|
-
# only useful for the user to assign when dealing with Haml programatically.
|
96
|
-
attr_accessor :filename
|
97
|
-
|
98
|
-
# If set to `true`, Haml will convert underscores to hyphens in all
|
99
|
-
# {file:REFERENCE.md#html5_custom_data_attributes Custom Data Attributes} As
|
100
|
-
# of Haml 4.0, this defaults to `true`.
|
101
|
-
attr_accessor :hyphenate_data_attrs
|
102
|
-
|
103
|
-
# The line offset of the Haml template being parsed. This is useful for
|
104
|
-
# inline templates, similar to the last argument to `Kernel#eval`.
|
105
|
-
attr_accessor :line
|
106
|
-
|
107
|
-
# Determines the output format. The default is `:html5`. The other options
|
108
|
-
# are `:html4` and `:xhtml`. If the output is set to XHTML, then Haml
|
109
|
-
# automatically generates self-closing tags and wraps the output of the
|
110
|
-
# Javascript and CSS-like filters inside CDATA. When the output is set to
|
111
|
-
# `:html5` or `:html4`, XML prologs are ignored. In all cases, an appropriate
|
112
|
-
# doctype is generated from `!!!`.
|
113
|
-
#
|
114
|
-
# If the mime_type of the template being rendered is `text/xml` then a
|
115
|
-
# format of `:xhtml` will be used even if the global output format is set to
|
116
|
-
# `:html4` or `:html5`.
|
117
|
-
attr :format
|
118
|
-
|
119
|
-
# The mime type that the rendered document will be served with. If this is
|
120
|
-
# set to `text/xml` then the format will be overridden to `:xhtml` even if
|
121
|
-
# it has set to `:html4` or `:html5`.
|
122
|
-
attr_accessor :mime_type
|
123
|
-
|
124
|
-
# A list of tag names that should automatically have their newlines
|
125
|
-
# preserved using the {Haml::Helpers#preserve} helper. This means that any
|
126
|
-
# content given on the same line as the tag will be preserved. For example,
|
127
|
-
# `%textarea= "Foo\nBar"` compiles to `<textarea>Foo
Bar</textarea>`.
|
128
|
-
# Defaults to `['textarea', 'pre']`. See also
|
129
|
-
# {file:REFERENCE.md#whitespace_preservation Whitespace Preservation}.
|
130
|
-
attr_accessor :preserve
|
131
|
-
|
132
|
-
# If set to `true`, all tags are treated as if both
|
133
|
-
# {file:REFERENCE.md#whitespace_removal__and_ whitespace removal} options
|
134
|
-
# were present. Use with caution as this may cause whitespace-related
|
135
|
-
# formatting errors.
|
136
|
-
#
|
137
|
-
# Defaults to `false`.
|
138
|
-
attr_accessor :remove_whitespace
|
139
|
-
|
140
|
-
# Whether or not attribute hashes and Ruby scripts designated by `=` or `~`
|
141
|
-
# should be evaluated. If this is `true`, said scripts are rendered as empty
|
142
|
-
# strings.
|
143
|
-
#
|
144
|
-
# Defaults to `false`.
|
145
|
-
attr_accessor :suppress_eval
|
146
|
-
|
147
|
-
# Whether to include CDATA sections around javascript and css blocks when
|
148
|
-
# using the `:javascript` or `:css` filters.
|
149
|
-
#
|
150
|
-
# This option also affects the `:sass`, `:scss`, `:less` and `:coffeescript`
|
151
|
-
# filters.
|
152
|
-
#
|
153
|
-
# Defaults to `false` for html, `true` for xhtml. Cannot be changed when using
|
154
|
-
# xhtml.
|
155
|
-
attr_accessor :cdata
|
156
|
-
|
157
|
-
# The parser class to use. Defaults to Haml::Parser.
|
158
|
-
attr_accessor :parser_class
|
159
|
-
|
160
|
-
# The compiler class to use. Defaults to Haml::Compiler.
|
161
|
-
attr_accessor :compiler_class
|
162
|
-
|
163
|
-
# Enable template tracing. If true, it will add a 'data-trace' attribute to
|
164
|
-
# each tag generated by Haml. The value of the attribute will be the
|
165
|
-
# source template name and the line number from which the tag was generated,
|
166
|
-
# separated by a colon. On Rails applications, the path given will be a
|
167
|
-
# relative path as from the views directory. On non-Rails applications,
|
168
|
-
# the path will be the full path.
|
169
|
-
attr_accessor :trace
|
170
|
-
|
171
|
-
# Key is filter name in String and value is Class to use. Defaults to {}.
|
172
|
-
attr_accessor :filters
|
173
|
-
|
174
|
-
def initialize(values = {})
|
175
|
-
defaults.each {|k, v| instance_variable_set :"@#{k}", v}
|
176
|
-
values.each {|k, v| send("#{k}=", v) if defaults.has_key?(k) && !v.nil?}
|
177
|
-
yield if block_given?
|
178
|
-
end
|
179
|
-
|
180
|
-
# Retrieve an option value.
|
181
|
-
# @param key The value to retrieve.
|
182
|
-
def [](key)
|
183
|
-
send key
|
184
|
-
end
|
185
|
-
|
186
|
-
# Set an option value.
|
187
|
-
# @param key The key to set.
|
188
|
-
# @param value The value to set for the key.
|
189
|
-
def []=(key, value)
|
190
|
-
send "#{key}=", value
|
191
|
-
end
|
192
|
-
|
193
|
-
[:escape_attrs, :hyphenate_data_attrs, :remove_whitespace, :suppress_eval].each do |method|
|
194
|
-
class_eval(<<-END)
|
195
|
-
def #{method}?
|
196
|
-
!! @#{method}
|
197
|
-
end
|
198
|
-
END
|
199
|
-
end
|
200
|
-
|
201
|
-
# @return [Boolean] Whether or not the format is XHTML.
|
202
|
-
def xhtml?
|
203
|
-
not html?
|
204
|
-
end
|
205
|
-
|
206
|
-
# @return [Boolean] Whether or not the format is any flavor of HTML.
|
207
|
-
def html?
|
208
|
-
html4? or html5?
|
209
|
-
end
|
210
|
-
|
211
|
-
# @return [Boolean] Whether or not the format is HTML4.
|
212
|
-
def html4?
|
213
|
-
format == :html4
|
214
|
-
end
|
215
|
-
|
216
|
-
# @return [Boolean] Whether or not the format is HTML5.
|
217
|
-
def html5?
|
218
|
-
format == :html5
|
219
|
-
end
|
220
|
-
|
221
|
-
def attr_wrapper=(value)
|
222
|
-
@attr_wrapper = value || self.class.defaults[:attr_wrapper]
|
223
|
-
end
|
224
|
-
|
225
|
-
# Undef :format to suppress warning. It's defined above with the `:attr`
|
226
|
-
# macro in order to make it appear in Yard's list of instance attributes.
|
227
|
-
undef :format
|
228
|
-
def format
|
229
|
-
mime_type == "text/xml" ? :xhtml : @format
|
230
|
-
end
|
231
|
-
|
232
|
-
def format=(value)
|
233
|
-
unless self.class.valid_formats.include?(value)
|
234
|
-
raise Haml::Error, "Invalid output format #{value.inspect}"
|
235
|
-
end
|
236
|
-
@format = value
|
237
|
-
end
|
238
|
-
|
239
|
-
undef :cdata
|
240
|
-
def cdata
|
241
|
-
xhtml? || @cdata
|
242
|
-
end
|
243
|
-
|
244
|
-
def encoding=(value)
|
245
|
-
return unless value
|
246
|
-
@encoding = value.is_a?(Encoding) ? value.name : value.to_s
|
247
|
-
@encoding = "UTF-8" if @encoding.upcase == "US-ASCII"
|
248
|
-
end
|
249
|
-
|
250
|
-
# Returns a non-default subset of options: those that {Haml::Buffer} cares about.
|
251
|
-
# All of the values here are such that when `#inspect` is called on the hash,
|
252
|
-
# it can be `Kernel#eval`ed to get the same result back.
|
253
|
-
#
|
254
|
-
# See {file:REFERENCE.md#options the Haml options documentation}.
|
255
|
-
#
|
256
|
-
# @return [{Symbol => Object}] The options hash
|
257
|
-
def for_buffer
|
258
|
-
self.class.buffer_option_keys.inject({}) do |hash, key|
|
259
|
-
value = public_send(key)
|
260
|
-
if self.class.buffer_defaults[key] != value
|
261
|
-
hash[key] = value
|
262
|
-
end
|
263
|
-
hash
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
private
|
268
|
-
|
269
|
-
def defaults
|
270
|
-
self.class.defaults
|
271
|
-
end
|
272
|
-
end
|
273
|
-
end
|
data/lib/haml/plugin.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Haml
|
4
|
-
|
5
|
-
# This module makes Haml work with Rails using the template handler API.
|
6
|
-
class Plugin
|
7
|
-
class << self
|
8
|
-
attr_accessor :annotate_rendered_view_with_filenames
|
9
|
-
end
|
10
|
-
self.annotate_rendered_view_with_filenames = false
|
11
|
-
|
12
|
-
def handles_encoding?; true; end
|
13
|
-
|
14
|
-
def compile(template, source)
|
15
|
-
options = Haml::Template.options.dup
|
16
|
-
if template.respond_to?(:type)
|
17
|
-
options[:mime_type] = template.type
|
18
|
-
elsif template.respond_to? :mime_type
|
19
|
-
options[:mime_type] = template.mime_type
|
20
|
-
end
|
21
|
-
options[:filename] = template.identifier
|
22
|
-
|
23
|
-
preamble = '@output_buffer = output_buffer ||= ActionView::OutputBuffer.new if defined?(ActionView::OutputBuffer);'
|
24
|
-
postamble = ''
|
25
|
-
|
26
|
-
if self.class.annotate_rendered_view_with_filenames
|
27
|
-
# short_identifier is only available in Rails 6+. On older versions, 'inspect' gives similar results.
|
28
|
-
ident = template.respond_to?(:short_identifier) ? template.short_identifier : template.inspect
|
29
|
-
preamble += "haml_concat '<!-- BEGIN #{ident} -->'.html_safe;"
|
30
|
-
postamble += "haml_concat '<!-- END #{ident} -->'.html_safe;"
|
31
|
-
end
|
32
|
-
|
33
|
-
Haml::Engine.new(source, options).compiler.precompiled_with_ambles(
|
34
|
-
[],
|
35
|
-
after_preamble: preamble,
|
36
|
-
before_postamble: postamble
|
37
|
-
)
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.call(template, source = nil)
|
41
|
-
source ||= template.source
|
42
|
-
|
43
|
-
new.compile(template, source)
|
44
|
-
end
|
45
|
-
|
46
|
-
def cache_fragment(block, name = {}, options = nil)
|
47
|
-
@view.fragment_for(block, name, options) do
|
48
|
-
eval("_hamlout.buffer", block.binding)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
ActionView::Template.register_template_handler(:haml, Haml::Plugin)
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Haml
|
4
|
-
module Filters
|
5
|
-
# This is an extension of Sass::Rails's SassTemplate class that allows
|
6
|
-
# Rails's asset helpers to be used inside Haml Sass filter.
|
7
|
-
class SassRailsTemplate < ::Sass::Rails::SassTemplate
|
8
|
-
if Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new('3.0.0')
|
9
|
-
def render(scope=Object.new, locals={}, &block)
|
10
|
-
environment = ::Sprockets::Railtie.build_environment(::Rails.application)
|
11
|
-
scope = environment.context_class.new(
|
12
|
-
environment: environment,
|
13
|
-
filename: "/",
|
14
|
-
metadata: {}
|
15
|
-
)
|
16
|
-
super
|
17
|
-
end
|
18
|
-
else
|
19
|
-
def render(scope=Object.new, locals={}, &block)
|
20
|
-
scope = ::Rails.application.assets.context_class.new(::Rails.application.assets, "/", "/")
|
21
|
-
super
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def sass_options(scope)
|
26
|
-
options = super
|
27
|
-
options[:custom][:resolver] = ::ActionView::Base.new
|
28
|
-
options
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# This is an extension of Sass::Rails's SassTemplate class that allows
|
33
|
-
# Rails's asset helpers to be used inside a Haml SCSS filter.
|
34
|
-
class ScssRailsTemplate < SassRailsTemplate
|
35
|
-
self.default_mime_type = 'text/css'
|
36
|
-
|
37
|
-
def syntax
|
38
|
-
:scss
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
remove_filter :Sass
|
43
|
-
remove_filter :Scss
|
44
|
-
register_tilt_filter "Sass", :extend => "Css", :template_class => SassRailsTemplate
|
45
|
-
register_tilt_filter "Scss", :extend => "Css", :template_class => ScssRailsTemplate
|
46
|
-
end
|
47
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# We keep options in its own self-contained file
|
4
|
-
# so that we can load it independently in Rails 3,
|
5
|
-
# where the full template stuff is lazy-loaded.
|
6
|
-
|
7
|
-
module Haml
|
8
|
-
module Template
|
9
|
-
extend self
|
10
|
-
|
11
|
-
class Options < Hash
|
12
|
-
def []=(key, value)
|
13
|
-
super
|
14
|
-
if Haml::Options.buffer_defaults.key?(key)
|
15
|
-
Haml::Options.buffer_defaults[key] = value
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
@options = ::Haml::Template::Options.new
|
21
|
-
# The options hash for Haml when used within Rails.
|
22
|
-
# See {file:REFERENCE.md#options the Haml options documentation}.
|
23
|
-
#
|
24
|
-
# @return [Haml::Template::Options<Symbol => Object>]
|
25
|
-
attr_accessor :options
|
26
|
-
end
|
27
|
-
end
|
data/lib/haml/temple_engine.rb
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'temple'
|
4
|
-
require 'haml/escapable'
|
5
|
-
require 'haml/generator'
|
6
|
-
|
7
|
-
module Haml
|
8
|
-
class TempleEngine < Temple::Engine
|
9
|
-
define_options(
|
10
|
-
attr_wrapper: "'",
|
11
|
-
autoclose: %w(area base basefont br col command embed frame
|
12
|
-
hr img input isindex keygen link menuitem meta
|
13
|
-
param source track wbr),
|
14
|
-
encoding: nil,
|
15
|
-
escape_attrs: true,
|
16
|
-
escape_html: false,
|
17
|
-
escape_filter_interpolations: nil,
|
18
|
-
filename: '(haml)',
|
19
|
-
format: :html5,
|
20
|
-
hyphenate_data_attrs: true,
|
21
|
-
line: 1,
|
22
|
-
mime_type: 'text/html',
|
23
|
-
preserve: %w(textarea pre code),
|
24
|
-
remove_whitespace: false,
|
25
|
-
suppress_eval: false,
|
26
|
-
cdata: false,
|
27
|
-
parser_class: ::Haml::Parser,
|
28
|
-
compiler_class: ::Haml::Compiler,
|
29
|
-
trace: false,
|
30
|
-
filters: {},
|
31
|
-
)
|
32
|
-
|
33
|
-
use :Parser, -> { options[:parser_class] }
|
34
|
-
use :Compiler, -> { options[:compiler_class] }
|
35
|
-
use Escapable
|
36
|
-
filter :ControlFlow
|
37
|
-
filter :MultiFlattener
|
38
|
-
filter :StaticMerger
|
39
|
-
use Generator
|
40
|
-
|
41
|
-
def compile(template)
|
42
|
-
initialize_encoding(template, options[:encoding])
|
43
|
-
@precompiled = call(template)
|
44
|
-
end
|
45
|
-
|
46
|
-
# The source code that is evaluated to produce the Haml document.
|
47
|
-
#
|
48
|
-
# This is automatically converted to the correct encoding
|
49
|
-
# (see {file:REFERENCE.md#encodings the `:encoding` option}).
|
50
|
-
#
|
51
|
-
# @return [String]
|
52
|
-
def precompiled
|
53
|
-
encoding = Encoding.find(@encoding || '')
|
54
|
-
return @precompiled.dup.force_encoding(encoding) if encoding == Encoding::ASCII_8BIT
|
55
|
-
return @precompiled.encode(encoding)
|
56
|
-
end
|
57
|
-
|
58
|
-
def precompiled_with_return_value
|
59
|
-
"#{precompiled};#{precompiled_method_return_value}".dup
|
60
|
-
end
|
61
|
-
|
62
|
-
# The source code that is evaluated to produce the Haml document.
|
63
|
-
#
|
64
|
-
# This is automatically converted to the correct encoding
|
65
|
-
# (see {file:REFERENCE.md#encodings the `:encoding` option}).
|
66
|
-
#
|
67
|
-
# @return [String]
|
68
|
-
def precompiled_with_ambles(local_names, after_preamble: '', before_postamble: '')
|
69
|
-
preamble = <<END.tr("\n", ';')
|
70
|
-
begin
|
71
|
-
extend Haml::Helpers
|
72
|
-
_hamlout = @haml_buffer = Haml::Buffer.new(haml_buffer, #{Options.new(options).for_buffer.inspect})
|
73
|
-
_erbout = _hamlout.buffer
|
74
|
-
#{after_preamble}
|
75
|
-
END
|
76
|
-
postamble = <<END.tr("\n", ';')
|
77
|
-
#{before_postamble}
|
78
|
-
#{precompiled_method_return_value}
|
79
|
-
ensure
|
80
|
-
@haml_buffer = @haml_buffer.upper if @haml_buffer
|
81
|
-
end
|
82
|
-
END
|
83
|
-
"#{preamble}#{locals_code(local_names)}#{precompiled}#{postamble}".dup
|
84
|
-
end
|
85
|
-
|
86
|
-
private
|
87
|
-
|
88
|
-
def initialize_encoding(template, given_value)
|
89
|
-
if given_value
|
90
|
-
@encoding = given_value
|
91
|
-
else
|
92
|
-
@encoding = Encoding.default_internal || template.encoding
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
# Returns the string used as the return value of the precompiled method.
|
97
|
-
# This method exists so it can be monkeypatched to return modified values.
|
98
|
-
def precompiled_method_return_value
|
99
|
-
"_erbout"
|
100
|
-
end
|
101
|
-
|
102
|
-
def locals_code(names)
|
103
|
-
names = names.keys if Hash === names
|
104
|
-
|
105
|
-
names.map do |name|
|
106
|
-
# Can't use || because someone might explicitly pass in false with a symbol
|
107
|
-
sym_local = "_haml_locals[#{inspect_obj(name.to_sym)}]"
|
108
|
-
str_local = "_haml_locals[#{inspect_obj(name.to_s)}]"
|
109
|
-
"#{name} = #{sym_local}.nil? ? #{str_local} : #{sym_local};"
|
110
|
-
end.join
|
111
|
-
end
|
112
|
-
|
113
|
-
def inspect_obj(obj)
|
114
|
-
case obj
|
115
|
-
when String
|
116
|
-
%Q!"#{obj.gsub(/[\x00-\x7F]+/) {|s| s.inspect[1...-1]}}"!
|
117
|
-
when Symbol
|
118
|
-
":#{inspect_obj(obj.to_s)}"
|
119
|
-
else
|
120
|
-
obj.inspect
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
data/yard/default/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
*.css
|
@@ -1,15 +0,0 @@
|
|
1
|
-
#filecontents
|
2
|
-
*:target, dt:target + dd
|
3
|
-
background-color: #ccf
|
4
|
-
border: 1px solid #88b
|
5
|
-
dt
|
6
|
-
font-weight: bold
|
7
|
-
dd
|
8
|
-
margin:
|
9
|
-
left: 0
|
10
|
-
bottom: 0.7em
|
11
|
-
padding-left: 3em
|
12
|
-
dt:target
|
13
|
-
border-bottom-style: none
|
14
|
-
& + dd
|
15
|
-
border-top-style: none
|
@@ -1,12 +0,0 @@
|
|
1
|
-
<%= superb :footer %>
|
2
|
-
<% if ENV["ANALYTICS"] %>
|
3
|
-
<script type="text/javascript">
|
4
|
-
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
5
|
-
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
6
|
-
</script>
|
7
|
-
<script type="text/javascript">
|
8
|
-
try {
|
9
|
-
var pageTracker = _gat._getTracker("<%= ENV["ANALYTICS"] %>");
|
10
|
-
pageTracker._trackPageview();
|
11
|
-
} catch(err) {}</script>
|
12
|
-
<% end %>
|