fast_haml 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d18511a93b15141a266bc26d9fda1c988c6ed09a
4
- data.tar.gz: adb2246bc9102aa0983ef003b1351e5effa3a80c
3
+ metadata.gz: 8b27cfffdd8647b6badef2bce9bc9696c5fabdac
4
+ data.tar.gz: bd9776dd0a37157e8fabfcfb1d81a90d7f84f341
5
5
  SHA512:
6
- metadata.gz: e9ba91139b2222b4d8c4e172c8e694f6d8dc107c474402cb8e115f0d8869886a89659eb35a1b4aa84010943675ebfe235539dfd872b610a27b63caa068096d6f
7
- data.tar.gz: 1b111f4bf03b525f4ca15201907103654a8213fd1d20d47ac8b36412af2c70acfc3b6aaae462b7a9eb37ab5c587bff9420c92693c3a3e493523532526252a3ff
6
+ metadata.gz: 268d5ce19f97c7b2c5fdd6ef20fa2f4e5ac490ef2b974f4c8ea3db50d59fecd5c661f49fc2966bd432fa44c77126495f71c0ec1452f6ab0db2f905b79609c07c
7
+ data.tar.gz: 71dbcabdf836323d3a23070ec9d443f9e94912b05b6715fa455640f70a698741337105442e3692a0436de2a8cc2f208b950fcfef7d0513170c98ff906b3c8c7e
data/.travis.yml CHANGED
@@ -10,6 +10,8 @@ gemfile:
10
10
  - gemfiles/rails_4.1.gemfile
11
11
  - gemfiles/rails_4.2.gemfile
12
12
  - gemfiles/rails_edge.gemfile
13
+ after_script:
14
+ - bundle exec rake benchmark:rendering
13
15
  matrix:
14
16
  allow_failures:
15
17
  - rvm: ruby-head
data/CHANGELOG.md CHANGED
@@ -1,2 +1,6 @@
1
+ ## 0.1.1 (2015-02-23)
2
+ - Fix attribute parsing with `%span {foo}` or `%span (foo)` cases.
3
+ - Fix comparison with statically-compilable class attributes like `%span.foo{class: bar}` .
4
+
1
5
  ## 0.1.0 (2015-02-23)
2
6
  - Initial release
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # FastHaml
2
+ [![Gem Version](https://badge.fury.io/rb/fast_haml.svg)](http://badge.fury.io/rb/fast_haml)
2
3
  [![Build Status](https://travis-ci.org/eagletmt/fast_haml.svg)](https://travis-ci.org/eagletmt/fast_haml)
3
4
  [![Coverage Status](https://coveralls.io/repos/eagletmt/fast_haml/badge.svg)](https://coveralls.io/r/eagletmt/fast_haml)
4
5
  [![Code Climate](https://codeclimate.com/github/eagletmt/fast_haml/badges/gpa.svg)](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
@@ -0,0 +1,5 @@
1
+ - h = { 'user' => { id: 1234, name: 'eagletmt' }, book_id: 5432 }
2
+ - c = %w[content active]
3
+
4
+ %span.book{data: h, class: c}
5
+ Book
@@ -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.lstrip)
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)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module FastHaml
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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&quot;y&#39;z'>hello</span>\n})
35
44
  end
@@ -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.0
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-22 00:00:00.000000000 Z
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