haml2erb 0.3.0.pre.2 → 0.3.0.pre.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,7 @@ module Haml2Erb
9
9
  end
10
10
  attr_reader :pairs, :attributes
11
11
 
12
- CONTENTS = /^, \{(.*)\}$/
12
+ CONTENTS = /^, \{?(.*)\}?$/
13
13
  ROCKET = '\=\>'
14
14
 
15
15
  SYMBOL_TEXT = '[\w_]+'
@@ -18,14 +18,14 @@ module Haml2Erb
18
18
  SYMBOL_KEY = /^(?:\:(#{SYMBOL_TEXT})\s*#{ROCKET}|(#{SYMBOL_TEXT}):)\s*/
19
19
  STRING_KEY = /^(?:'(#{STRING_TEXT})'|"(#{STRING_TEXT})")\s*#{ROCKET}\s*/
20
20
 
21
- STRING_VALUE = /^:(#{SYMBOL_TEXT})\s*/
22
- SYMBOL_VALUE = /^(?:"([^"]+)"|'([^']+)')\s*/
21
+ SYMBOL_VALUE = /^:(#{SYMBOL_TEXT})\s*/
22
+ STRING_VALUE = /^(?:"([^"]+)"|'([^']+)')\s*/
23
+ STRING_INTERPOLATION = /^("[^\\]*)#\{/
23
24
 
24
25
  def parse!
25
26
  rest = attributes.strip.scan(CONTENTS).flatten.first
26
-
27
27
  begin
28
- while not rest.empty?
28
+ while rest and not(rest.empty?)
29
29
  if rest =~ SYMBOL_KEY
30
30
  key = $1 || $2
31
31
  rest.gsub! SYMBOL_KEY, ''
@@ -38,6 +38,7 @@ module Haml2Erb
38
38
 
39
39
  if rest =~ STRING_VALUE
40
40
  value = $1
41
+ raise DynamicAttributes if rest =~ STRING_INTERPOLATION
41
42
  elsif rest =~ SYMBOL_VALUE
42
43
  value = $1 || $2
43
44
  else
@@ -56,6 +57,12 @@ module Haml2Erb
56
57
  @dynamic
57
58
  end
58
59
 
60
+ def self.hash_to_html hash
61
+ hash.each_pair.map do |key, value|
62
+ " #{key}='#{value.gsub("'", ''')}'"
63
+ end.join('')
64
+ end
65
+
59
66
  def to_html
60
67
  if attributes.strip.empty?
61
68
  return ''
@@ -67,9 +74,9 @@ module Haml2Erb
67
74
  hash.gsub! /\s*,$/, ''
68
75
  " <%= tag_options({#{hash}}, false) %>"
69
76
  else
70
- ' ' << pairs.map do |(key, value)|
77
+ pairs.map do |(key, value)|
71
78
  "#{key}='#{value.gsub("'", '&#x27;')}'"
72
- end.join(' ')
79
+ end.join('')
73
80
  end
74
81
  end
75
82
  end
@@ -1,6 +1,7 @@
1
1
  require 'haml'
2
2
  require 'haml2erb/attributes_parser'
3
3
 
4
+
4
5
  module Haml2Erb
5
6
  class Engine < Haml::Engine
6
7
 
@@ -140,6 +141,7 @@ module Haml2Erb
140
141
  end
141
142
  end
142
143
 
144
+
143
145
  def compile_tag
144
146
  t = @node.value
145
147
 
@@ -184,7 +186,6 @@ module Haml2Erb
184
186
  @dont_indent_next_line = dont_indent_next_line
185
187
  return if tag_closed
186
188
  else
187
- # raise attributes_hashes.inspect unless attributes_hashes.empty?
188
189
  if attributes_hashes.empty?
189
190
  attributes_hashes = ''
190
191
  elsif attributes_hashes.size == 1
@@ -199,7 +200,8 @@ module Haml2Erb
199
200
  # push_generated_script(
200
201
  # "_hamlout.attributes(#{inspect_obj(t[:attributes])}, #{object_ref}#{attributes_hashes})")
201
202
  # NOW: attempt a simplistic parse of the attributes
202
- concat_merged_text AttributesParser.new(attributes_hashes).to_html
203
+ concat_merged_text AttributesParser.hash_to_html(t[:attributes])+
204
+ AttributesParser.new(attributes_hashes).to_html
203
205
 
204
206
  concat_merged_text(
205
207
  if t[:self_closing] && xhtml?
@@ -1,3 +1,3 @@
1
1
  module Haml2Erb
2
- VERSION = '0.3.0.pre.2'
2
+ VERSION = '0.3.0.pre.3'
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml2erb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1923831965
4
+ hash: 1923831967
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
9
  - 0
10
10
  - pre
11
- - 2
12
- version: 0.3.0.pre.2
11
+ - 3
12
+ version: 0.3.0.pre.3
13
13
  platform: ruby
14
14
  authors:
15
15
  - Elia Schito
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-11-15 00:00:00 Z
20
+ date: 2011-11-17 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  type: :runtime