haml2handlebars 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,71 @@
1
1
  require 'haml'
2
2
  require 'haml2handlebars/attributes_parser'
3
3
 
4
- module Haml::Parser
5
- START_BLOCK_KEYWORDS << "each"
6
- START_BLOCK_KEYWORD_REGEX = /(?:\w+(?:,\s*\w+)*\s*=\s*)?(#{START_BLOCK_KEYWORDS.join('|')})/
7
- BLOCK_KEYWORD_REGEX = /^-\s*(?:(#{MID_BLOCK_KEYWORDS.join('|')})|#{START_BLOCK_KEYWORD_REGEX.source})\b/
4
+ module Haml
5
+ module Parser
6
+ START_BLOCK_KEYWORDS << "each"
7
+ START_BLOCK_KEYWORD_REGEX = /(?:\w+(?:,\s*\w+)*\s*=\s*)?(#{START_BLOCK_KEYWORDS.join('|')})/
8
+ BLOCK_KEYWORD_REGEX = /^-\s*(?:(#{MID_BLOCK_KEYWORDS.join('|')})|#{START_BLOCK_KEYWORD_REGEX.source})\b/
9
+ end
10
+
11
+ module Compiler
12
+ def self.build_attributes(is_html, attr_wrapper, escape_attrs, attributes = {})
13
+ quote_escape = attr_wrapper == '"' ? "&quot;" : "&apos;"
14
+ other_quote_char = attr_wrapper == '"' ? "'" : '"'
15
+
16
+ if attributes['data'].is_a?(Hash)
17
+ attributes = attributes.dup
18
+ attributes =
19
+ Haml::Util.map_keys(attributes.delete('data')) {|name| "data-#{name}"}.merge(attributes)
20
+ end
21
+
22
+ result = attributes.collect do |attr, value|
23
+ next if value.nil?
24
+
25
+ value = filter_and_join(value, ' ') if attr == 'class'
26
+ value = filter_and_join(value, '_') if attr == 'id'
27
+
28
+ if value == true
29
+ next " #{attr}" if is_html
30
+ next " #{attr}=#{attr_wrapper}#{attr}#{attr_wrapper}"
31
+ elsif value == false
32
+ next
33
+ end
34
+
35
+ escaped =
36
+ if escape_attrs == :once
37
+ Haml::Helpers.escape_once(value.to_s)
38
+ elsif escape_attrs
39
+ Haml::Helpers.html_escape(value.to_s)
40
+ else
41
+ value.to_s
42
+ end
43
+ value = Haml::Helpers.preserve(escaped)
44
+ if escape_attrs
45
+ # We want to decide whether or not to escape quotes
46
+ value = value.gsub('&quot;', '"')
47
+ this_attr_wrapper = attr_wrapper
48
+ if value.include? attr_wrapper
49
+ if value.include? other_quote_char
50
+ value = value.gsub(attr_wrapper, quote_escape)
51
+ else
52
+ this_attr_wrapper = other_quote_char
53
+ end
54
+ end
55
+ else
56
+ this_attr_wrapper = attr_wrapper
57
+ end
58
+
59
+ if attr =~ /^hb-/
60
+ attr = attr[3..-1]
61
+ " {{#{attr} #{value}}}"
62
+ else
63
+ " #{attr}=#{this_attr_wrapper}#{value}#{this_attr_wrapper}"
64
+ end
65
+ end
66
+ result.compact.sort.join
67
+ end
68
+ end
8
69
  end
9
70
 
10
71
  module Haml2Handlebars
@@ -1,3 +1,3 @@
1
1
  module Haml2Handlebars
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -35,6 +35,11 @@ haml = %q{
35
35
  %aside.right
36
36
  %section#tweets(data-widget="twitter")
37
37
  %section#hammurabi
38
+
39
+ .helper
40
+ = action edit article on="mouseover"
41
+ .attribute-helper
42
+ %a(href="#" hb-action="edit article on='mouseover'") ZOMG
38
43
  }
39
44
 
40
45
  handlebars = %q{<!DOCTYPE html>
@@ -70,6 +75,12 @@ handlebars = %q{<!DOCTYPE html>
70
75
  <aside class='right'>
71
76
  <section data-widget='twitter' id='tweets'></section>
72
77
  <section id='hammurabi'></section>
78
+ <div class='helper'>
79
+ {{action edit article on="mouseover"}}
80
+ </div>
81
+ <div class='attribute-helper'>
82
+ <a href='#' {{action edit article on='mouseover'}}>ZOMG</a>
83
+ </div>
73
84
  </aside>
74
85
  </body>
75
86
  </html>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml2handlebars
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-26 00:00:00.000000000 Z
13
+ date: 2012-10-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: haml
@@ -94,15 +94,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
94
  - - ! '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ segments:
98
+ - 0
99
+ hash: -725347375
97
100
  required_rubygems_version: !ruby/object:Gem::Requirement
98
101
  none: false
99
102
  requirements:
100
103
  - - ! '>='
101
104
  - !ruby/object:Gem::Version
102
105
  version: '0'
106
+ segments:
107
+ - 0
108
+ hash: -725347375
103
109
  requirements: []
104
110
  rubyforge_project: haml2handlebars
105
- rubygems_version: 1.8.22
111
+ rubygems_version: 1.8.24
106
112
  signing_key:
107
113
  specification_version: 3
108
114
  summary: Convert Haml templates to Handlebars!