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