haml 5.2.2 → 6.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -0
- data/.github/workflows/test.yml +13 -9
- data/.gitignore +16 -16
- data/.yardopts +0 -3
- data/CHANGELOG.md +74 -3
- data/Gemfile +18 -11
- data/MIT-LICENSE +1 -1
- data/README.md +17 -23
- data/REFERENCE.md +63 -138
- 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 +126 -0
- data/lib/haml/compiler/comment_compiler.rb +39 -0
- data/lib/haml/compiler/doctype_compiler.rb +46 -0
- data/lib/haml/compiler/script_compiler.rb +116 -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 +44 -227
- data/lib/haml/error.rb +5 -4
- data/lib/haml/escapable.rb +6 -70
- 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 +49 -0
- data/lib/haml/filters.rb +54 -378
- data/lib/haml/force_escapable.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 +55 -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 +17 -15
- data/lib/haml/version.rb +1 -2
- data/lib/haml.rb +8 -20
- metadata +208 -54
- 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/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
data/Rakefile
CHANGED
@@ -1,36 +1,57 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
#
|
4
|
+
# Prepend DevKit into compilation phase
|
5
|
+
#
|
6
|
+
if Gem.win_platform?
|
7
|
+
desc 'Activates DevKit'
|
8
|
+
task :devkit do
|
9
|
+
begin
|
10
|
+
require 'devkit'
|
11
|
+
rescue LoadError
|
12
|
+
abort 'Failed to load DevKit required for compilation'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
task compile: :devkit
|
16
|
+
end
|
4
17
|
|
5
|
-
|
18
|
+
require 'rake/testtask'
|
19
|
+
if /java/ === RUBY_PLATFORM
|
20
|
+
# require 'rake/javaextensiontask'
|
21
|
+
# Rake::JavaExtensionTask.new(:haml) do |ext|
|
22
|
+
# ext.ext_dir = 'ext/java'
|
23
|
+
# ext.lib_dir = 'lib/haml'
|
24
|
+
# end
|
6
25
|
|
7
|
-
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
Rake::TestTask.new do |t|
|
16
|
-
t.libs << 'test'
|
17
|
-
t.test_files = Dir['test/*_test.rb'] + Dir['test/haml-spec/*_test.rb'] + Dir['test/cases/*_test.rb'] - isolated_test.file_list
|
18
|
-
t.warning = true
|
19
|
-
t.verbose = true
|
26
|
+
task :compile do
|
27
|
+
# dummy for now
|
28
|
+
end
|
29
|
+
else
|
30
|
+
require 'rake/extensiontask'
|
31
|
+
Rake::ExtensionTask.new(:haml) do |ext|
|
32
|
+
ext.lib_dir = 'lib/haml'
|
33
|
+
end
|
20
34
|
end
|
21
35
|
|
22
|
-
|
36
|
+
Dir['benchmark/*.rake'].each { |b| import(b) }
|
23
37
|
|
24
|
-
|
25
|
-
|
26
|
-
|
38
|
+
Rake::TestTask.new do |t|
|
39
|
+
t.libs << 'lib' << 'test'
|
40
|
+
files = Dir['test/haml/**/*_test.rb']
|
41
|
+
t.ruby_opts = %w[-rtest_helper]
|
42
|
+
t.test_files = files
|
43
|
+
t.verbose = true
|
27
44
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
45
|
+
task test: :compile
|
46
|
+
|
47
|
+
desc 'bench task for CI'
|
48
|
+
task bench: :compile do
|
49
|
+
if ENV['SLIM_BENCH'] == '1'
|
50
|
+
cmd = %w[bundle exec ruby benchmark/slim/run-benchmarks.rb]
|
51
|
+
else
|
52
|
+
cmd = ['bin/bench', 'bench', ('-c' if ENV['COMPILE'] == '1'), *ENV['TEMPLATE'].split(',')].compact
|
33
53
|
end
|
54
|
+
exit system(*cmd)
|
34
55
|
end
|
35
56
|
|
36
57
|
namespace :doc do
|
@@ -58,58 +79,4 @@ task(:doc => 'doc:sass') {sh "yard"}
|
|
58
79
|
desc "Generate documentation incrementally"
|
59
80
|
task(:redoc) {sh "yard -c"}
|
60
81
|
|
61
|
-
|
62
|
-
Profile Haml.
|
63
|
-
TIMES=n sets the number of runs. Defaults to 1000.
|
64
|
-
FILE=str sets the file to profile. Defaults to 'standard'
|
65
|
-
OUTPUT=str sets the ruby-prof output format.
|
66
|
-
Can be Flat, CallInfo, or Graph. Defaults to Flat. Defaults to Flat.
|
67
|
-
END
|
68
|
-
task :profile do
|
69
|
-
times = (ENV['TIMES'] || '1000').to_i
|
70
|
-
file = ENV['FILE'] || 'test/templates/standard.haml'
|
71
|
-
|
72
|
-
require 'bundler/setup'
|
73
|
-
require 'ruby-prof'
|
74
|
-
require 'haml'
|
75
|
-
file = File.read(File.expand_path("../#{file}", __FILE__))
|
76
|
-
obj = Object.new
|
77
|
-
Haml::Engine.new(file).def_method(obj, :render)
|
78
|
-
result = RubyProf.profile { times.times { obj.render } }
|
79
|
-
|
80
|
-
RubyProf.const_get("#{(ENV['OUTPUT'] || 'Flat').capitalize}Printer").new(result).print
|
81
|
-
end
|
82
|
-
|
83
|
-
def gemfiles
|
84
|
-
@gemfiles ||= Dir[File.dirname(__FILE__) + '/test/gemfiles/Gemfile.*'].reject {|f| f =~ /\.lock$/}
|
85
|
-
end
|
86
|
-
|
87
|
-
def with_each_gemfile
|
88
|
-
gemfiles.each do |gemfile|
|
89
|
-
Bundler.with_clean_env do
|
90
|
-
puts "Using gemfile: #{gemfile}"
|
91
|
-
ENV['BUNDLE_GEMFILE'] = gemfile
|
92
|
-
yield
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
namespace :test do
|
98
|
-
namespace :bundles do
|
99
|
-
desc "Install all dependencies necessary to test Haml."
|
100
|
-
task :install do
|
101
|
-
with_each_gemfile {sh "bundle"}
|
102
|
-
end
|
103
|
-
|
104
|
-
desc "Update all dependencies for testing Haml."
|
105
|
-
task :update do
|
106
|
-
with_each_gemfile {sh "bundle update"}
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
desc "Test all supported versions of rails. This takes a while."
|
111
|
-
task :rails_compatibility => 'test:bundles:install' do
|
112
|
-
with_each_gemfile {sh "bundle exec rake test"}
|
113
|
-
end
|
114
|
-
task :rc => :rails_compatibility
|
115
|
-
end
|
82
|
+
task default: %w[compile test]
|
data/bin/bench
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'haml'
|
5
|
+
require 'thor'
|
6
|
+
require 'benchmark/ips'
|
7
|
+
require_relative '../benchmark/utils/benchmark_ips_extension'
|
8
|
+
|
9
|
+
class Bench < Thor
|
10
|
+
class_option :show_template, type: :boolean, aliases: ['-t']
|
11
|
+
|
12
|
+
desc 'bench HAML', 'Benchmark haml template'
|
13
|
+
option :compile, type: :boolean, aliases: ['-c']
|
14
|
+
option :show_code, type: :boolean, aliases: ['-s']
|
15
|
+
def bench(*files)
|
16
|
+
files.each { |file| render(file) }
|
17
|
+
files.each { |file| compile(file) if options[:compile] }
|
18
|
+
files.each { |file| code(file) if options[:show_code] }
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'compile HAML', 'Benchmark compilation'
|
22
|
+
def compile(file)
|
23
|
+
puts "#{?= * 49}\n Compilation: #{file}\n#{?= * 49}"
|
24
|
+
haml = File.read(file)
|
25
|
+
|
26
|
+
Benchmark.ips do |x|
|
27
|
+
x.report("haml v#{Haml::VERSION}") { Haml::Engine.new.call(haml) }
|
28
|
+
x.compare!
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'render HAML', 'Benchmark rendering'
|
33
|
+
def render(file)
|
34
|
+
puts "#{?= * 49}\n Rendering: #{file}\n#{?= * 49}"
|
35
|
+
haml = File.read(file)
|
36
|
+
puts haml + "\n" if options[:show_template]
|
37
|
+
object = Object.new
|
38
|
+
ruby_file = file.gsub(/\.haml\z/, '.rb')
|
39
|
+
if File.exist?(ruby_file)
|
40
|
+
object.instance_eval(File.read(ruby_file))
|
41
|
+
end
|
42
|
+
|
43
|
+
object.instance_eval "def haml; #{Haml::Engine.new.call(haml)}; end"
|
44
|
+
|
45
|
+
Benchmark.ips do |x|
|
46
|
+
x.report("haml v#{Haml::VERSION}") { object.haml }
|
47
|
+
x.compare!
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
desc 'code HAML', 'Show compiled code'
|
52
|
+
def code(file)
|
53
|
+
haml = File.read(file)
|
54
|
+
puts "\n#{?= * 49}\n Haml Source: #{file}\n#{?= * 49}"
|
55
|
+
puts Haml::Engine.new.call(haml)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def method_missing(*args)
|
61
|
+
return super if args.length > 1
|
62
|
+
render(args.first.to_s)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
Bench.start
|
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'hamlit'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require 'pry'
|
11
|
+
Pry.start
|
data/bin/ruby
ADDED
data/bin/setup
ADDED
data/bin/stackprof
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'hamlit'
|
5
|
+
require 'stackprof'
|
6
|
+
|
7
|
+
def open_flamegraph(report)
|
8
|
+
temp = `mktemp /tmp/stackflame-XXXXXXXX`.strip
|
9
|
+
data_path = "#{temp}.js"
|
10
|
+
system("mv #{temp} #{data_path}")
|
11
|
+
|
12
|
+
File.open(data_path, 'w') do |f|
|
13
|
+
report.print_flamegraph(f)
|
14
|
+
end
|
15
|
+
|
16
|
+
viewer_path = File.join(`bundle show stackprof`.strip, 'lib/stackprof/flamegraph/viewer.html')
|
17
|
+
url = "file://#{viewer_path}?data=#{data_path}"
|
18
|
+
system(%Q[osascript -e 'open location "#{url}"'])
|
19
|
+
end
|
20
|
+
|
21
|
+
haml = File.read(ARGV.first)
|
22
|
+
StackProf.start(mode: :wall, interval: 1, raw: false)
|
23
|
+
Hamlit::Engine.new.call(haml)
|
24
|
+
StackProf.stop
|
25
|
+
|
26
|
+
report = StackProf::Report.new(StackProf.results)
|
27
|
+
report.print_text(false)
|
data/bin/test
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
VERSIONS=(
|
4
|
+
2.1.10
|
5
|
+
2.2.5
|
6
|
+
2.3.1
|
7
|
+
)
|
8
|
+
|
9
|
+
set -e
|
10
|
+
trap 'echo "${VERSIONS[2]}" > .ruby-version' 0
|
11
|
+
|
12
|
+
function test_with() {
|
13
|
+
version=$1
|
14
|
+
rbenv local $version
|
15
|
+
if ! bundle check > /dev/null; then
|
16
|
+
bundle install
|
17
|
+
fi
|
18
|
+
ruby -v
|
19
|
+
bundle exec rake test
|
20
|
+
}
|
21
|
+
|
22
|
+
for version in ${VERSIONS[@]}; do
|
23
|
+
test_with $version
|
24
|
+
done
|
data/exe/haml
ADDED