fast_haml 0.1.0 → 0.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/.travis.yml +2 -0
- data/CHANGELOG.md +4 -0
- data/README.md +1 -0
- data/Rakefile +17 -0
- data/benchmark/attribute_builder.haml +5 -0
- data/lib/fast_haml/compiler.rb +2 -2
- data/lib/fast_haml/element_parser.rb +1 -1
- data/lib/fast_haml/railtie.rb +5 -0
- data/lib/fast_haml/version.rb +1 -1
- data/spec/render/attribute_spec.rb +9 -0
- data/spec/render/element_spec.rb +5 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b27cfffdd8647b6badef2bce9bc9696c5fabdac
|
4
|
+
data.tar.gz: bd9776dd0a37157e8fabfcfb1d81a90d7f84f341
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 268d5ce19f97c7b2c5fdd6ef20fa2f4e5ac490ef2b974f4c8ea3db50d59fecd5c661f49fc2966bd432fa44c77126495f71c0ec1452f6ab0db2f905b79609c07c
|
7
|
+
data.tar.gz: 71dbcabdf836323d3a23070ec9d443f9e94912b05b6715fa455640f70a698741337105442e3692a0436de2a8cc2f208b950fcfef7d0513170c98ff906b3c8c7e
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# FastHaml
|
2
|
+
[](http://badge.fury.io/rb/fast_haml)
|
2
3
|
[](https://travis-ci.org/eagletmt/fast_haml)
|
3
4
|
[](https://coveralls.io/r/eagletmt/fast_haml)
|
4
5
|
[](https://codeclimate.com/github/eagletmt/fast_haml)
|
data/Rakefile
CHANGED
@@ -9,3 +9,20 @@ end
|
|
9
9
|
|
10
10
|
require 'rspec/core/rake_task'
|
11
11
|
RSpec::Core::RakeTask.new(:spec)
|
12
|
+
|
13
|
+
namespace :benchmark do
|
14
|
+
task :rendering => ['benchmark:rendering:haml', 'benchmark:rendering:attributes']
|
15
|
+
namespace :rendering do
|
16
|
+
desc "Run benchmark with Haml's standard template"
|
17
|
+
task :haml do
|
18
|
+
haml_gem = Gem::Specification.find_by_name('haml')
|
19
|
+
standard_haml_path = File.join(haml_gem.gem_dir, 'test', 'templates', 'standard.haml')
|
20
|
+
sh 'ruby', 'benchmark/rendering.rb', standard_haml_path
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Run benchmark for attribute builder"
|
24
|
+
task :attributes do
|
25
|
+
sh 'ruby', 'benchmark/rendering.rb', File.join('benchmark/attribute_builder.haml')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/fast_haml/compiler.rb
CHANGED
@@ -252,10 +252,10 @@ module FastHaml
|
|
252
252
|
def build_optimized_attributes(parser, static_id, static_class)
|
253
253
|
static_attributes = {}
|
254
254
|
parser.static_attributes.each do |k, v|
|
255
|
-
static_attributes[k.to_s] = v
|
255
|
+
static_attributes[k.to_s] = v
|
256
256
|
end
|
257
257
|
unless static_class.empty?
|
258
|
-
static_attributes['class'] = [static_class.split(/ +/), static_attributes['class']].compact.flatten.sort.join(' ')
|
258
|
+
static_attributes['class'] = [static_class.split(/ +/), static_attributes['class']].compact.flatten.map(&:to_s).sort.join(' ')
|
259
259
|
end
|
260
260
|
unless static_id.empty?
|
261
261
|
static_attributes['id'] = [static_id, static_attributes['id']].compact.join('_')
|
@@ -25,7 +25,7 @@ module FastHaml
|
|
25
25
|
element.static_class, element.static_id = parse_class_and_id(m[2])
|
26
26
|
rest = m[3] || ''
|
27
27
|
|
28
|
-
element.attributes, rest = parse_attributes(rest
|
28
|
+
element.attributes, rest = parse_attributes(rest)
|
29
29
|
element.nuke_inner_whitespace, element.nuke_outer_whitespace, rest = parse_nuke_whitespace(rest)
|
30
30
|
element.self_closing, rest = parse_self_closing(rest)
|
31
31
|
element.oneline_child = parse_oneline_child(rest)
|
data/lib/fast_haml/railtie.rb
CHANGED
@@ -2,6 +2,11 @@ module FastHaml
|
|
2
2
|
class Railtie < ::Rails::Railtie
|
3
3
|
initializer :fast_haml do |app|
|
4
4
|
require 'fast_haml/rails_handler'
|
5
|
+
begin
|
6
|
+
# Load Haml::Plugin earlier to overwrite template handler with fast_haml.
|
7
|
+
require 'haml/plugin'
|
8
|
+
rescue LoadError
|
9
|
+
end
|
5
10
|
ActionView::Template.register_template_handler(:haml, FastHaml::RailsHandler.new)
|
6
11
|
end
|
7
12
|
end
|
data/lib/fast_haml/version.rb
CHANGED
@@ -30,6 +30,15 @@ RSpec.describe 'Attributes rendering', type: :render do
|
|
30
30
|
HAML
|
31
31
|
end
|
32
32
|
|
33
|
+
it 'strigify non-string classes' do
|
34
|
+
expect(render_string('%span.foo{class: :bar} hello')).to eq("<span class='bar foo'>hello</span>\n")
|
35
|
+
expect(render_string('%span.foo{class: 1} hello')).to eq("<span class='1 foo'>hello</span>\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'strigify non-string ids' do
|
39
|
+
expect(render_string('%span.#foo{id: :bar} hello')).to eq("<span id='foo_bar'>hello</span>\n")
|
40
|
+
end
|
41
|
+
|
33
42
|
it 'escapes' do
|
34
43
|
expect(render_string(%q|%span{class: "x\"y'z"} hello|)).to eq(%Q{<span class='x"y'z'>hello</span>\n})
|
35
44
|
end
|
data/spec/render/element_spec.rb
CHANGED
@@ -63,6 +63,11 @@ HAML
|
|
63
63
|
expect(render_string('%span.foo#foo-bar.bar hello')).to eq(%Q{<span class='foo bar' id='foo-bar'>hello</span>\n})
|
64
64
|
end
|
65
65
|
|
66
|
+
it "doesn't skip spaces before attribute list" do
|
67
|
+
expect(render_string('%span {hello}')).to eq("<span>{hello}</span>\n")
|
68
|
+
expect(render_string('%span (hello)')).to eq("<span>(hello)</span>\n")
|
69
|
+
end
|
70
|
+
|
66
71
|
context 'with invalid tag name' do
|
67
72
|
it 'raises error' do
|
68
73
|
expect { render_string('%.foo') }.to raise_error(FastHaml::SyntaxError)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_haml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kohei Suzuki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|
@@ -211,6 +211,7 @@ files:
|
|
211
211
|
- LICENSE.txt
|
212
212
|
- README.md
|
213
213
|
- Rakefile
|
214
|
+
- benchmark/attribute_builder.haml
|
214
215
|
- benchmark/rendering.rb
|
215
216
|
- bin/fast_haml
|
216
217
|
- ext/attribute_builder/attribute_builder.c
|