hamlit 1.7.2 → 2.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.
- checksums.yaml +4 -4
- data/.gitignore +4 -3
- data/.gitmodules +3 -0
- data/.travis.yml +25 -37
- data/CHANGELOG.md +18 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +23 -2
- data/README.md +106 -48
- data/REFERENCE.md +222 -0
- data/Rakefile +77 -19
- data/benchmark/boolean_attribute.haml +6 -0
- data/benchmark/class_attribute.haml +5 -0
- data/benchmark/common_attribute.haml +3 -0
- data/benchmark/data_attribute.haml +4 -0
- data/benchmark/dynamic_attributes/boolean_attribute.haml +4 -0
- data/benchmark/dynamic_attributes/class_attribute.haml +4 -0
- data/benchmark/dynamic_attributes/common_attribute.haml +2 -0
- data/benchmark/dynamic_attributes/data_attribute.haml +2 -0
- data/benchmark/dynamic_attributes/id_attribute.haml +2 -0
- data/benchmark/etc/attribute_builder.haml +5 -0
- data/benchmark/etc/real_sample.haml +888 -0
- data/benchmark/etc/real_sample.rb +11 -0
- data/benchmark/etc/static_analyzer.haml +1 -0
- data/benchmark/etc/tags.haml +3 -0
- data/benchmark/ext/build_data.rb +15 -0
- data/benchmark/ext/build_id.rb +13 -0
- data/benchmark/id_attribute.haml +3 -0
- data/benchmark/plain.haml +4 -0
- data/benchmark/script.haml +4 -0
- data/benchmark/slim/LICENSE +21 -0
- data/{benchmarks → benchmark/slim}/context.rb +2 -4
- data/benchmark/slim/run-benchmarks.rb +94 -0
- data/{benchmarks → benchmark/slim}/view.erb +3 -3
- data/{benchmarks → benchmark/slim}/view.haml +0 -0
- data/{benchmarks/view.escaped.slim → benchmark/slim/view.slim} +1 -1
- data/benchmark/string_interpolation.haml +2 -0
- data/benchmark/utils/benchmark_ips_extension.rb +43 -0
- data/bin/bench +85 -0
- data/bin/clone +14 -0
- data/bin/console +11 -0
- data/bin/lineprof +48 -0
- data/bin/ruby +3 -0
- data/bin/setup +7 -0
- data/bin/stackprof +27 -0
- data/{test → bin/test} +6 -10
- data/{bin → exe}/hamlit +0 -0
- data/ext/hamlit/extconf.rb +14 -0
- data/ext/hamlit/hamlit.c +512 -0
- data/ext/hamlit/houdini/.gitignore +3 -0
- data/ext/hamlit/houdini/COPYING +7 -0
- data/ext/hamlit/houdini/Makefile +79 -0
- data/ext/hamlit/houdini/README.md +59 -0
- data/ext/hamlit/houdini/buffer.c +249 -0
- data/ext/hamlit/houdini/buffer.h +113 -0
- data/ext/hamlit/houdini/houdini.h +46 -0
- data/ext/hamlit/houdini/houdini_href_e.c +115 -0
- data/ext/hamlit/houdini/houdini_html_e.c +90 -0
- data/ext/hamlit/houdini/houdini_html_u.c +122 -0
- data/ext/hamlit/houdini/houdini_js_e.c +90 -0
- data/ext/hamlit/houdini/houdini_js_u.c +60 -0
- data/ext/hamlit/houdini/houdini_uri_e.c +107 -0
- data/ext/hamlit/houdini/houdini_uri_u.c +68 -0
- data/ext/hamlit/houdini/houdini_xml_e.c +136 -0
- data/ext/hamlit/houdini/html_unescape.gperf +258 -0
- data/ext/hamlit/houdini/html_unescape.h +754 -0
- data/ext/hamlit/houdini/tools/build_table.py +13 -0
- data/ext/hamlit/houdini/tools/build_tables.c +51 -0
- data/ext/hamlit/houdini/tools/wikipedia_table.txt +2025 -0
- data/hamlit.gemspec +30 -31
- data/lib/hamlit.rb +3 -1
- data/lib/hamlit/attribute_builder.rb +12 -0
- data/lib/hamlit/cli.rb +44 -43
- data/lib/hamlit/compiler.rb +92 -16
- data/lib/hamlit/compiler/attribute_compiler.rb +148 -0
- data/lib/hamlit/compiler/children_compiler.rb +111 -0
- data/lib/hamlit/compiler/comment_compiler.rb +36 -0
- data/lib/hamlit/compiler/doctype_compiler.rb +45 -0
- data/lib/hamlit/compiler/script_compiler.rb +97 -0
- data/lib/hamlit/compiler/silent_script_compiler.rb +24 -0
- data/lib/hamlit/compiler/tag_compiler.rb +69 -0
- data/lib/hamlit/engine.rb +12 -7
- data/lib/hamlit/error.rb +14 -0
- data/lib/hamlit/escapable.rb +12 -0
- data/lib/hamlit/filters.rb +65 -0
- data/lib/hamlit/filters/base.rb +4 -62
- data/lib/hamlit/filters/coffee.rb +9 -7
- data/lib/hamlit/filters/css.rb +25 -8
- data/lib/hamlit/filters/erb.rb +4 -6
- data/lib/hamlit/filters/escaped.rb +11 -9
- data/lib/hamlit/filters/javascript.rb +25 -8
- data/lib/hamlit/filters/less.rb +9 -7
- data/lib/hamlit/filters/markdown.rb +5 -6
- data/lib/hamlit/filters/plain.rb +11 -15
- data/lib/hamlit/filters/preserve.rb +15 -5
- data/lib/hamlit/filters/ruby.rb +3 -5
- data/lib/hamlit/filters/sass.rb +9 -7
- data/lib/hamlit/filters/scss.rb +9 -7
- data/lib/hamlit/filters/text_base.rb +24 -0
- data/lib/hamlit/filters/tilt_base.rb +47 -0
- data/lib/hamlit/hash_parser.rb +107 -0
- data/lib/hamlit/html.rb +9 -6
- data/lib/hamlit/identity.rb +12 -0
- data/lib/hamlit/object_ref.rb +29 -0
- data/lib/hamlit/parser.rb +25 -142
- data/lib/hamlit/parser/MIT-LICENSE +20 -0
- data/lib/hamlit/parser/README.md +28 -0
- data/lib/hamlit/parser/haml_buffer.rb +348 -0
- data/lib/hamlit/parser/haml_compiler.rb +553 -0
- data/lib/hamlit/parser/haml_error.rb +61 -0
- data/lib/hamlit/parser/haml_helpers.rb +727 -0
- data/lib/hamlit/parser/haml_options.rb +286 -0
- data/lib/hamlit/parser/haml_parser.rb +801 -0
- data/lib/hamlit/parser/haml_util.rb +283 -0
- data/lib/hamlit/parser/haml_xss_mods.rb +109 -0
- data/lib/hamlit/{helpers.rb → rails_helpers.rb} +2 -7
- data/lib/hamlit/rails_template.rb +30 -0
- data/lib/hamlit/railtie.rb +1 -12
- data/lib/hamlit/ruby_expression.rb +31 -0
- data/lib/hamlit/static_analyzer.rb +49 -0
- data/lib/hamlit/string_interpolation.rb +69 -0
- data/lib/hamlit/template.rb +8 -0
- data/lib/hamlit/utils.rb +9 -0
- data/lib/hamlit/version.rb +1 -1
- metadata +116 -324
- data/.rspec +0 -2
- data/benchmarks/benchmark.rb +0 -110
- data/benchmarks/view.slim +0 -17
- data/doc/README.md +0 -19
- data/doc/engine/indent.md +0 -48
- data/doc/engine/new_attribute.md +0 -77
- data/doc/engine/old_attributes.md +0 -198
- data/doc/engine/silent_script.md +0 -97
- data/doc/engine/tag.md +0 -48
- data/doc/engine/text.md +0 -64
- data/doc/faml/README.md +0 -16
- data/doc/faml/engine/indent.md +0 -48
- data/doc/faml/engine/old_attributes.md +0 -111
- data/doc/faml/engine/silent_script.md +0 -97
- data/doc/faml/engine/text.md +0 -59
- data/doc/faml/filters/erb.md +0 -24
- data/doc/faml/filters/javascript.md +0 -27
- data/doc/faml/filters/less.md +0 -57
- data/doc/faml/filters/plain.md +0 -25
- data/doc/filters/erb.md +0 -31
- data/doc/filters/javascript.md +0 -83
- data/doc/filters/less.md +0 -57
- data/doc/filters/markdown.md +0 -31
- data/doc/filters/plain.md +0 -25
- data/doc/haml/README.md +0 -15
- data/doc/haml/engine/new_attribute.md +0 -77
- data/doc/haml/engine/old_attributes.md +0 -142
- data/doc/haml/engine/tag.md +0 -48
- data/doc/haml/engine/text.md +0 -29
- data/doc/haml/filters/erb.md +0 -26
- data/doc/haml/filters/javascript.md +0 -76
- data/doc/haml/filters/markdown.md +0 -31
- data/lib/hamlit/attribute.rb +0 -78
- data/lib/hamlit/compilers/attributes.rb +0 -108
- data/lib/hamlit/compilers/comment.rb +0 -13
- data/lib/hamlit/compilers/doctype.rb +0 -39
- data/lib/hamlit/compilers/filter.rb +0 -53
- data/lib/hamlit/compilers/new_attribute.rb +0 -115
- data/lib/hamlit/compilers/old_attribute.rb +0 -241
- data/lib/hamlit/compilers/runtime_attribute.rb +0 -58
- data/lib/hamlit/compilers/script.rb +0 -31
- data/lib/hamlit/compilers/strip.rb +0 -19
- data/lib/hamlit/compilers/text.rb +0 -111
- data/lib/hamlit/concerns/attribute_builder.rb +0 -22
- data/lib/hamlit/concerns/balanceable.rb +0 -68
- data/lib/hamlit/concerns/deprecation.rb +0 -20
- data/lib/hamlit/concerns/error.rb +0 -31
- data/lib/hamlit/concerns/escapable.rb +0 -17
- data/lib/hamlit/concerns/included.rb +0 -28
- data/lib/hamlit/concerns/indentable.rb +0 -117
- data/lib/hamlit/concerns/lexable.rb +0 -32
- data/lib/hamlit/concerns/line_reader.rb +0 -62
- data/lib/hamlit/concerns/registerable.rb +0 -24
- data/lib/hamlit/concerns/string_interpolation.rb +0 -48
- data/lib/hamlit/concerns/whitespace.rb +0 -91
- data/lib/hamlit/filters/tilt.rb +0 -41
- data/lib/hamlit/parsers/attribute.rb +0 -71
- data/lib/hamlit/parsers/comment.rb +0 -30
- data/lib/hamlit/parsers/doctype.rb +0 -18
- data/lib/hamlit/parsers/filter.rb +0 -18
- data/lib/hamlit/parsers/multiline.rb +0 -58
- data/lib/hamlit/parsers/script.rb +0 -126
- data/lib/hamlit/parsers/tag.rb +0 -83
- data/lib/hamlit/parsers/text.rb +0 -28
- data/lib/hamlit/temple.rb +0 -9
- data/release +0 -6
- data/spec/Rakefile +0 -72
- data/spec/hamlit/engine/comment_spec.rb +0 -56
- data/spec/hamlit/engine/doctype_spec.rb +0 -19
- data/spec/hamlit/engine/error_spec.rb +0 -135
- data/spec/hamlit/engine/indent_spec.rb +0 -42
- data/spec/hamlit/engine/multiline_spec.rb +0 -44
- data/spec/hamlit/engine/new_attribute_spec.rb +0 -110
- data/spec/hamlit/engine/old_attributes_spec.rb +0 -404
- data/spec/hamlit/engine/script_spec.rb +0 -116
- data/spec/hamlit/engine/silent_script_spec.rb +0 -213
- data/spec/hamlit/engine/tag_spec.rb +0 -295
- data/spec/hamlit/engine/text_spec.rb +0 -239
- data/spec/hamlit/engine_spec.rb +0 -58
- data/spec/hamlit/filters/coffee_spec.rb +0 -60
- data/spec/hamlit/filters/css_spec.rb +0 -33
- data/spec/hamlit/filters/erb_spec.rb +0 -16
- data/spec/hamlit/filters/javascript_spec.rb +0 -82
- data/spec/hamlit/filters/less_spec.rb +0 -37
- data/spec/hamlit/filters/markdown_spec.rb +0 -30
- data/spec/hamlit/filters/plain_spec.rb +0 -15
- data/spec/hamlit/filters/ruby_spec.rb +0 -24
- data/spec/hamlit/filters/sass_spec.rb +0 -33
- data/spec/hamlit/filters/scss_spec.rb +0 -37
- data/spec/hamlit/haml_spec.rb +0 -910
- data/spec/rails/.gitignore +0 -18
- data/spec/rails/.rspec +0 -2
- data/spec/rails/Gemfile +0 -19
- data/spec/rails/README.rdoc +0 -28
- data/spec/rails/Rakefile +0 -6
- data/spec/rails/app/assets/images/.keep +0 -0
- data/spec/rails/app/assets/javascripts/application.js +0 -15
- data/spec/rails/app/assets/stylesheets/application.css +0 -15
- data/spec/rails/app/controllers/application_controller.rb +0 -8
- data/spec/rails/app/controllers/concerns/.keep +0 -0
- data/spec/rails/app/controllers/users_controller.rb +0 -23
- data/spec/rails/app/helpers/application_helper.rb +0 -2
- data/spec/rails/app/mailers/.keep +0 -0
- data/spec/rails/app/models/.keep +0 -0
- data/spec/rails/app/models/concerns/.keep +0 -0
- data/spec/rails/app/views/application/index.html.haml +0 -18
- data/spec/rails/app/views/layouts/application.html.haml +0 -12
- data/spec/rails/app/views/users/capture.html.haml +0 -5
- data/spec/rails/app/views/users/capture_haml.html.haml +0 -5
- data/spec/rails/app/views/users/form.html.haml +0 -2
- data/spec/rails/app/views/users/helpers.html.haml +0 -10
- data/spec/rails/app/views/users/index.html.haml +0 -9
- data/spec/rails/app/views/users/inline.html.haml +0 -6
- data/spec/rails/app/views/users/old_attributes.html.haml +0 -5
- data/spec/rails/app/views/users/safe_buffer.html.haml +0 -4
- data/spec/rails/app/views/users/whitespace.html.haml +0 -4
- data/spec/rails/bin/bundle +0 -3
- data/spec/rails/bin/rails +0 -8
- data/spec/rails/bin/rake +0 -8
- data/spec/rails/bin/setup +0 -29
- data/spec/rails/bin/spring +0 -15
- data/spec/rails/config.ru +0 -4
- data/spec/rails/config/application.rb +0 -34
- data/spec/rails/config/boot.rb +0 -3
- data/spec/rails/config/database.yml +0 -25
- data/spec/rails/config/environment.rb +0 -5
- data/spec/rails/config/environments/development.rb +0 -41
- data/spec/rails/config/environments/production.rb +0 -79
- data/spec/rails/config/environments/test.rb +0 -42
- data/spec/rails/config/initializers/assets.rb +0 -11
- data/spec/rails/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails/config/initializers/cookies_serializer.rb +0 -3
- data/spec/rails/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/rails/config/initializers/inflections.rb +0 -16
- data/spec/rails/config/initializers/mime_types.rb +0 -4
- data/spec/rails/config/initializers/session_store.rb +0 -3
- data/spec/rails/config/initializers/wrap_parameters.rb +0 -14
- data/spec/rails/config/locales/en.yml +0 -24
- data/spec/rails/config/routes.rb +0 -16
- data/spec/rails/config/secrets.yml +0 -22
- data/spec/rails/db/schema.rb +0 -16
- data/spec/rails/db/seeds.rb +0 -7
- data/spec/rails/lib/assets/.keep +0 -0
- data/spec/rails/lib/tasks/.keep +0 -0
- data/spec/rails/log/.keep +0 -0
- data/spec/rails/public/404.html +0 -67
- data/spec/rails/public/422.html +0 -67
- data/spec/rails/public/500.html +0 -66
- data/spec/rails/public/favicon.ico +0 -0
- data/spec/rails/public/robots.txt +0 -5
- data/spec/rails/spec/hamlit_spec.rb +0 -123
- data/spec/rails/spec/rails_helper.rb +0 -56
- data/spec/rails/spec/spec_helper.rb +0 -91
- data/spec/rails/vendor/assets/javascripts/.keep +0 -0
- data/spec/rails/vendor/assets/stylesheets/.keep +0 -0
- data/spec/spec_helper.rb +0 -36
- data/spec/spec_helper/document_generator.rb +0 -93
- data/spec/spec_helper/render_helper.rb +0 -120
- data/spec/spec_helper/test_case.rb +0 -55
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
require 'ripper'
|
|
2
|
-
|
|
3
|
-
module Hamlit
|
|
4
|
-
module Concerns
|
|
5
|
-
module Lexable
|
|
6
|
-
TYPE_POSITION = 1
|
|
7
|
-
|
|
8
|
-
def skip_tokens!(tokens, *types)
|
|
9
|
-
while types.include?(type_of(tokens.first))
|
|
10
|
-
tokens.shift
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def type_of(token)
|
|
15
|
-
return nil unless token
|
|
16
|
-
token[TYPE_POSITION]
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# Convert ripper's position to StringScanner's one.
|
|
20
|
-
def convert_position(text, row, col)
|
|
21
|
-
return col if row <= 1
|
|
22
|
-
|
|
23
|
-
pos = col
|
|
24
|
-
lines = text.split("\n")
|
|
25
|
-
(0..(row - 2)).each do |row_index|
|
|
26
|
-
pos += lines[row_index].bytesize + 1
|
|
27
|
-
end
|
|
28
|
-
pos
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
module Hamlit
|
|
2
|
-
module Concerns
|
|
3
|
-
module LineReader
|
|
4
|
-
def reset_lines(lines)
|
|
5
|
-
@lines = lines
|
|
6
|
-
@current_lineno = -1
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def current_line
|
|
10
|
-
@lines[@current_lineno]
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
# Return nearest line ignoring empty lines.
|
|
14
|
-
def next_line
|
|
15
|
-
lineno = @current_lineno + 1
|
|
16
|
-
while @lines[lineno] && empty_line?(@lines[lineno])
|
|
17
|
-
lineno += 1
|
|
18
|
-
end
|
|
19
|
-
@lines[lineno]
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def empty_line?(line)
|
|
23
|
-
line = line.rest if line.respond_to?(:rest)
|
|
24
|
-
line =~ /\A *\Z/
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def skip_lines
|
|
28
|
-
while next_line && next_indent >= @current_indent
|
|
29
|
-
@current_lineno += 1
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def read_lines
|
|
34
|
-
lines = []
|
|
35
|
-
while read_line?
|
|
36
|
-
lines << @lines[@current_lineno + 1]
|
|
37
|
-
@current_lineno += 1
|
|
38
|
-
end
|
|
39
|
-
trim_lines(lines)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
private
|
|
43
|
-
|
|
44
|
-
def trim_lines(lines)
|
|
45
|
-
size = (lines.first || '').index(/[^\s]/) || 0
|
|
46
|
-
lines.map { |line| line.gsub(/\A {#{size}}/, '') }
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def read_line?
|
|
50
|
-
return false unless next_line
|
|
51
|
-
return true if next_line.index(/^#{@indent_logs.last}[ \t]/)
|
|
52
|
-
|
|
53
|
-
line = @lines[@current_lineno + 1]
|
|
54
|
-
return false unless line
|
|
55
|
-
|
|
56
|
-
# NOTE: preserve filter also requires an empty line
|
|
57
|
-
line.gsub(/ /, '').length == 0
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
module Hamlit
|
|
2
|
-
class NotFound < StandardError
|
|
3
|
-
def initialize(name)
|
|
4
|
-
super(%Q{Filter "#{name}" is not defined.})
|
|
5
|
-
end
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
module Concerns
|
|
9
|
-
module Registerable
|
|
10
|
-
def registered
|
|
11
|
-
@registered ||= {}
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def register(name, compiler)
|
|
15
|
-
registered[name.to_sym] = compiler
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def find(name)
|
|
19
|
-
raise NotFound.new(name) unless registered[name.to_sym]
|
|
20
|
-
registered[name.to_sym]
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
module Hamlit
|
|
2
|
-
module Concerns
|
|
3
|
-
module StringInterpolation
|
|
4
|
-
def string_literal(str)
|
|
5
|
-
res = ''
|
|
6
|
-
rest = handle_interpolation(str.inspect) do |scan|
|
|
7
|
-
escapes = (scan[2].size - 1) / 2
|
|
8
|
-
res << scan.matched[0...-3 - escapes]
|
|
9
|
-
res << (escapes.odd? ? '#{' : unescape_interpolation(scan))
|
|
10
|
-
end
|
|
11
|
-
res + rest
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def contains_interpolation?(str)
|
|
15
|
-
/#[\{$@]/ === str
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
-
def unescape_interpolation(scan)
|
|
21
|
-
content = eval('"' + balance(scan, ?{, ?}, 1)[0][0...-1] + '"')
|
|
22
|
-
'#{' + content + '}'
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def handle_interpolation(str)
|
|
26
|
-
scan = StringScanner.new(str)
|
|
27
|
-
yield scan while scan.scan(/(.*?)(\\*)\#\{/)
|
|
28
|
-
scan.rest
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def balance(scanner, start, finish, count = 0)
|
|
32
|
-
str = ''
|
|
33
|
-
while balanced_scan(scanner, start, finish)
|
|
34
|
-
str << scanner.matched
|
|
35
|
-
count += 1 if scanner.matched[-1] == start
|
|
36
|
-
count -= 1 if scanner.matched[-1] == finish
|
|
37
|
-
return [str.strip, scanner.rest] if count == 0
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def balanced_scan(scanner, start, finish)
|
|
42
|
-
regexp = Regexp.new("(.*?)[\\#{start.chr}\\#{finish.chr}]", Regexp::MULTILINE)
|
|
43
|
-
scanner = StringScanner.new(scanner) unless scanner.is_a?(StringScanner)
|
|
44
|
-
scanner.scan(regexp)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
require 'set'
|
|
2
|
-
|
|
3
|
-
# Hamlit::Concerns::Whitespace cares about "whitespace removal",
|
|
4
|
-
# which is achieved by '<' or '>' after html tag.
|
|
5
|
-
# NOTE: Whitespace means [:static, "\n"] because it is rendered
|
|
6
|
-
# as whitespace on browsers.
|
|
7
|
-
module Hamlit
|
|
8
|
-
module Concerns
|
|
9
|
-
module Whitespace
|
|
10
|
-
def parse_whitespace_removal(scanner)
|
|
11
|
-
if scanner.match?(/</)
|
|
12
|
-
inner_removal = parse_inner_removal(scanner)
|
|
13
|
-
parse_outer_removal(scanner)
|
|
14
|
-
else
|
|
15
|
-
parse_outer_removal(scanner)
|
|
16
|
-
inner_removal = parse_inner_removal(scanner)
|
|
17
|
-
end
|
|
18
|
-
inner_removal
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# `<` removes spaces inside script or silent script recursively.
|
|
22
|
-
def remove_first_space!(exps)
|
|
23
|
-
deleted = false
|
|
24
|
-
|
|
25
|
-
exps.delete_if do |exp|
|
|
26
|
-
name, *args = exp
|
|
27
|
-
case name
|
|
28
|
-
when :static
|
|
29
|
-
break if args != ["\n"]
|
|
30
|
-
deleted = true
|
|
31
|
-
next true
|
|
32
|
-
when :code
|
|
33
|
-
next false
|
|
34
|
-
when :newline
|
|
35
|
-
next false
|
|
36
|
-
when :haml
|
|
37
|
-
# recursive call for script
|
|
38
|
-
remove_last_space!(exp) if args.first == :script
|
|
39
|
-
when :multi
|
|
40
|
-
break if exp == :multi
|
|
41
|
-
# to flatten multi
|
|
42
|
-
remove_last_space!(exp)
|
|
43
|
-
end
|
|
44
|
-
break
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# recursive call for silent script
|
|
48
|
-
remove_last_space!(exps) if deleted
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def remove_last_space!(exps)
|
|
52
|
-
exps.reverse!
|
|
53
|
-
remove_first_space!(exps)
|
|
54
|
-
ensure
|
|
55
|
-
exps.reverse!
|
|
56
|
-
exps
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
private
|
|
60
|
-
|
|
61
|
-
def reset_outer_removal
|
|
62
|
-
@outer_removal = Set.new
|
|
63
|
-
@tag_indent = 0
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def with_tag_nested(&block)
|
|
67
|
-
@tag_indent += 1
|
|
68
|
-
with_indented { block.call }
|
|
69
|
-
ensure
|
|
70
|
-
@outer_removal.delete(@tag_indent)
|
|
71
|
-
@tag_indent -= 1
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def parse_inner_removal(scanner)
|
|
75
|
-
scanner.scan(/</)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def parse_outer_removal(scanner)
|
|
79
|
-
if scanner.scan(/>/)
|
|
80
|
-
@outer_removal.add(@tag_indent)
|
|
81
|
-
else
|
|
82
|
-
@outer_removal.delete(@tag_indent)
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def outer_remove?
|
|
87
|
-
@outer_removal.include?(@tag_indent)
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
data/lib/hamlit/filters/tilt.rb
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
require 'tilt'
|
|
2
|
-
require 'hamlit/concerns/string_interpolation'
|
|
3
|
-
require 'hamlit/filters/base'
|
|
4
|
-
|
|
5
|
-
module Hamlit
|
|
6
|
-
module Filters
|
|
7
|
-
class Tilt < Filters::Base
|
|
8
|
-
include Concerns::StringInterpolation
|
|
9
|
-
|
|
10
|
-
def self.render(name, source, indent_width: 2)
|
|
11
|
-
result = ::Tilt["t.#{name}"].new { source }.render
|
|
12
|
-
indent_source(result, indent_width: indent_width)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
def compile_with_tilt(name, source, ast, indent_width: 2)
|
|
18
|
-
if contains_interpolation?(source)
|
|
19
|
-
return runtime_compile(name, source, ast, indent_width: indent_width)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
content = [:static, Filters::Tilt.render(name, source, indent_width: indent_width)]
|
|
23
|
-
build_ast(ast, content)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def runtime_compile(name, source, ast, indent_width: 2)
|
|
27
|
-
literal = string_literal(source)
|
|
28
|
-
code = "::Hamlit::Filters::Tilt.render(#{name.inspect}, #{literal}, indent_width: #{indent_width})"
|
|
29
|
-
content = [:dynamic, code]
|
|
30
|
-
build_ast(ast, content)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def build_ast(ast, content)
|
|
34
|
-
return content if ast.empty?
|
|
35
|
-
|
|
36
|
-
content = [:multi, [:static, "\n"], content]
|
|
37
|
-
ast << content
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
require 'ripper'
|
|
2
|
-
require 'hamlit/concerns/balanceable'
|
|
3
|
-
require 'hamlit/concerns/lexable'
|
|
4
|
-
|
|
5
|
-
module Hamlit
|
|
6
|
-
module Parsers
|
|
7
|
-
module Attribute
|
|
8
|
-
include Concerns::Balanceable
|
|
9
|
-
include Concerns::Lexable
|
|
10
|
-
|
|
11
|
-
ATTRIBUTE_BEGIN = '{'.freeze
|
|
12
|
-
METHOD_CALL_PREFIX = 'a('.freeze
|
|
13
|
-
BALANCE_START_COUNT = 1
|
|
14
|
-
|
|
15
|
-
def parse_attributes(scanner)
|
|
16
|
-
if scanner.match?(/{/)
|
|
17
|
-
parse_old_attributes(scanner) + parse_new_attributes(scanner)
|
|
18
|
-
else
|
|
19
|
-
parse_new_attributes(scanner) + parse_old_attributes(scanner)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
private
|
|
24
|
-
|
|
25
|
-
# NOTE: Old attributes are not valid as Ruby expression.
|
|
26
|
-
# So Ripper is broken if you give an original expression to it.
|
|
27
|
-
# This method bypasses it by changing expression to method call.
|
|
28
|
-
# Ideally you should implement an original lexer for haml old attributes.
|
|
29
|
-
def parse_old_attributes(scanner)
|
|
30
|
-
return [] unless scanner.match?(/{/)
|
|
31
|
-
|
|
32
|
-
tokens = try_lex(scanner.rest.sub(ATTRIBUTE_BEGIN, METHOD_CALL_PREFIX))
|
|
33
|
-
until balanced_embexprs_exist?(tokens, start_count: BALANCE_START_COUNT)
|
|
34
|
-
@current_lineno += 1
|
|
35
|
-
break unless @lines[@current_lineno]
|
|
36
|
-
scanner.concat(current_line)
|
|
37
|
-
tokens = try_lex(scanner.rest.sub(ATTRIBUTE_BEGIN, METHOD_CALL_PREFIX))
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
tokens = fetch_balanced_embexprs(tokens, start_count: BALANCE_START_COUNT)
|
|
41
|
-
scanner.pos += tokens.last.first.last
|
|
42
|
-
[tokens.map(&:last).join.sub(METHOD_CALL_PREFIX, ATTRIBUTE_BEGIN)]
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def parse_new_attributes(scanner)
|
|
46
|
-
return [] unless scanner.match?(/\(/)
|
|
47
|
-
|
|
48
|
-
tokens = Ripper.lex(scanner.rest)
|
|
49
|
-
until balanced_parens_exist?(tokens)
|
|
50
|
-
@current_lineno += 1
|
|
51
|
-
break unless @lines[@current_lineno]
|
|
52
|
-
scanner.concat("\n#{current_line}")
|
|
53
|
-
tokens = Ripper.lex(scanner.rest)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
tokens = fetch_balanced_parentheses(tokens)
|
|
57
|
-
text = tokens.map(&:last).join
|
|
58
|
-
scanner.pos += convert_position(text, *tokens.last.first) + 1
|
|
59
|
-
[text]
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
# Ripper.lex pulls invalid tokens first.
|
|
63
|
-
# This method rejects these invalid tokens.
|
|
64
|
-
def try_lex(str)
|
|
65
|
-
Ripper.lex(str).reject do |(row, col), type, str|
|
|
66
|
-
row == 0
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
require 'hamlit/concerns/error'
|
|
2
|
-
require 'hamlit/concerns/indentable'
|
|
3
|
-
|
|
4
|
-
module Hamlit
|
|
5
|
-
module Parsers
|
|
6
|
-
module Comment
|
|
7
|
-
include Concerns::Indentable
|
|
8
|
-
|
|
9
|
-
def parse_comment(scanner)
|
|
10
|
-
assert_scan!(scanner, /\//)
|
|
11
|
-
|
|
12
|
-
ast = [:html, :comment]
|
|
13
|
-
text = (scanner.scan(/.+/) || '').strip
|
|
14
|
-
|
|
15
|
-
if text.empty?
|
|
16
|
-
content = with_indented { parse_lines }
|
|
17
|
-
return ast << [:multi, [:static, "\n"], *content]
|
|
18
|
-
elsif !text.match(/\[.*\]/)
|
|
19
|
-
if has_block?
|
|
20
|
-
syntax_error!('Illegal nesting: nesting within a tag that already has content is illegal.')
|
|
21
|
-
end
|
|
22
|
-
return ast << [:static, " #{text} "]
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
content = with_indented { parse_lines }
|
|
26
|
-
[:haml, :comment, text, content]
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
require 'hamlit/concerns/error'
|
|
2
|
-
|
|
3
|
-
module Hamlit
|
|
4
|
-
module Parsers
|
|
5
|
-
module Doctype
|
|
6
|
-
def parse_doctype(scanner)
|
|
7
|
-
assert_scan!(scanner, /!!!/)
|
|
8
|
-
|
|
9
|
-
type = nil
|
|
10
|
-
if scanner.scan(/ +/) && scanner.rest?
|
|
11
|
-
type = scanner.rest.strip
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
[:haml, :doctype, options[:format], type]
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
require 'hamlit/concerns/error'
|
|
2
|
-
require 'hamlit/concerns/indentable'
|
|
3
|
-
|
|
4
|
-
module Hamlit
|
|
5
|
-
module Parsers
|
|
6
|
-
module Filter
|
|
7
|
-
include Concerns::Indentable
|
|
8
|
-
|
|
9
|
-
def parse_filter(scanner)
|
|
10
|
-
assert_scan!(scanner, /:/)
|
|
11
|
-
|
|
12
|
-
name = scanner.scan(/.+/).strip
|
|
13
|
-
lines = with_indented { read_lines }
|
|
14
|
-
[:haml, :filter, name, lines]
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|