ruby-haml-js 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -0
- data/lib/ruby-haml-js/template.rb +3 -1
- data/lib/ruby-haml-js/version.rb +1 -1
- data/vendor/assets/javascripts/haml.js +55 -2
- metadata +33 -13
data/README.md
CHANGED
@@ -85,6 +85,14 @@ RubyHamlJs::Template.custom_escape = "App.escape_html"
|
|
85
85
|
This will use the given function and will not generate custom escape code inside each template.
|
86
86
|
But you need to make sure that the function is defined before using the templates in JavaScript.
|
87
87
|
|
88
|
+
## Custom haml.js
|
89
|
+
|
90
|
+
If you need a custom version of haml.js library you may specify it using the haml_path
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
RubyHamlJs::Template.haml_path = "path/to/haml.js"
|
94
|
+
```
|
95
|
+
|
88
96
|
# Development
|
89
97
|
|
90
98
|
- Source hosted at [GitHub](https://github.com/dnagir/ruby-haml-js)
|
@@ -50,10 +50,12 @@ module RubyHamlJs
|
|
50
50
|
|
51
51
|
class << self
|
52
52
|
attr_accessor :custom_escape
|
53
|
+
attr_accessor :haml_path
|
53
54
|
|
54
55
|
def haml_source
|
55
56
|
# Haml source is an asset
|
56
|
-
@
|
57
|
+
@haml_path = File.expand_path('../../../vendor/assets/javascripts/haml.js', __FILE__) if @haml_path.nil?
|
58
|
+
@haml_source ||= IO.read @haml_path
|
57
59
|
end
|
58
60
|
|
59
61
|
end
|
data/lib/ruby-haml-js/version.rb
CHANGED
@@ -311,6 +311,7 @@ var Haml;
|
|
311
311
|
regexp: /^(\s*):if\s+(.*)\s*$/i,
|
312
312
|
process: function () {
|
313
313
|
var condition = this.matches[2];
|
314
|
+
this.pushIfCondition([condition]);
|
314
315
|
return '(function () { ' +
|
315
316
|
'if (' + condition + ') { ' +
|
316
317
|
'return (\n' + (this.render_contents() || '') + '\n);' +
|
@@ -318,6 +319,47 @@ var Haml;
|
|
318
319
|
}
|
319
320
|
},
|
320
321
|
|
322
|
+
// else if statements
|
323
|
+
{
|
324
|
+
name: "else if",
|
325
|
+
regexp: /^(\s*):else if\s+(.*)\s*$/i,
|
326
|
+
process: function () {
|
327
|
+
var condition = this.matches[2],
|
328
|
+
conditionsArray = this.getIfConditions()[this.getIfConditions().length - 1],
|
329
|
+
ifArray = [],
|
330
|
+
ifStatement;
|
331
|
+
for (var i=0, l=conditionsArray.length; i<l; i++) {
|
332
|
+
ifArray.push('! (' + conditionsArray[i]+')');
|
333
|
+
}
|
334
|
+
conditionsArray.push(condition);
|
335
|
+
ifArray.push(condition);
|
336
|
+
ifStatement = 'if (' + ifArray.join(' && ') + ') { ';
|
337
|
+
return '(function () { ' +
|
338
|
+
ifStatement +
|
339
|
+
'return (\n' + (this.render_contents() || '') + '\n);' +
|
340
|
+
'} else { return ""; } }).call(this)';
|
341
|
+
}
|
342
|
+
},
|
343
|
+
|
344
|
+
// else statements
|
345
|
+
{
|
346
|
+
name: "else",
|
347
|
+
regexp: /^(\s*):else\s*$/i,
|
348
|
+
process: function () {
|
349
|
+
var conditionsArray = this.popIfCondition(),
|
350
|
+
ifArray = [],
|
351
|
+
ifStatement;
|
352
|
+
for (var i=0, l=conditionsArray.length; i<l; i++) {
|
353
|
+
ifArray.push('! (' + conditionsArray[i]+')');
|
354
|
+
}
|
355
|
+
ifStatement = 'if (' + ifArray.join(' && ') + ') { ';
|
356
|
+
return '(function () { ' +
|
357
|
+
ifStatement +
|
358
|
+
'return (\n' + (this.render_contents() || '') + '\n);' +
|
359
|
+
'} else { return ""; } }).call(this)';
|
360
|
+
}
|
361
|
+
},
|
362
|
+
|
321
363
|
// silent-comments
|
322
364
|
{
|
323
365
|
name: "silent-comments",
|
@@ -443,7 +485,8 @@ var Haml;
|
|
443
485
|
|
444
486
|
function compile(lines) {
|
445
487
|
var block = false,
|
446
|
-
output = []
|
488
|
+
output = [],
|
489
|
+
ifConditions = [];
|
447
490
|
|
448
491
|
// If lines is a string, turn it into an array
|
449
492
|
if (typeof lines === 'string') {
|
@@ -475,6 +518,15 @@ var Haml;
|
|
475
518
|
matches: match,
|
476
519
|
check_indent: new RegExp("^(?:\\s*|" + match[1] + " (.*))$"),
|
477
520
|
process: matcher.process,
|
521
|
+
getIfConditions: function() {
|
522
|
+
return ifConditions;
|
523
|
+
},
|
524
|
+
pushIfCondition: function(condition) {
|
525
|
+
ifConditions.push(condition);
|
526
|
+
},
|
527
|
+
popIfCondition: function() {
|
528
|
+
return ifConditions.pop();
|
529
|
+
},
|
478
530
|
render_contents: function () {
|
479
531
|
return compile(this.contents);
|
480
532
|
}
|
@@ -483,7 +535,7 @@ var Haml;
|
|
483
535
|
}
|
484
536
|
}
|
485
537
|
});
|
486
|
-
|
538
|
+
|
487
539
|
// Match plain text
|
488
540
|
if (!found) {
|
489
541
|
output.push(function () {
|
@@ -649,3 +701,4 @@ var Haml;
|
|
649
701
|
if (typeof module !== 'undefined') {
|
650
702
|
module.exports = Haml;
|
651
703
|
}
|
704
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-haml-js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-04-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sprockets
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 2.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.0
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: execjs
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rspec
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: rails
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,7 +69,12 @@ dependencies:
|
|
54
69
|
version: 3.1.1
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 3.1.1
|
58
78
|
description: ruby-haml-js provides a Tilt template that you can use to compile HAML-JS
|
59
79
|
templates into JS functions. Handy for using it wth Bakcbone.js, Spine.js etc.
|
60
80
|
email:
|
@@ -127,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
147
|
version: '0'
|
128
148
|
segments:
|
129
149
|
- 0
|
130
|
-
hash:
|
150
|
+
hash: 2655100921178513378
|
131
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
152
|
none: false
|
133
153
|
requirements:
|
@@ -136,10 +156,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
156
|
version: '0'
|
137
157
|
segments:
|
138
158
|
- 0
|
139
|
-
hash:
|
159
|
+
hash: 2655100921178513378
|
140
160
|
requirements: []
|
141
161
|
rubyforge_project: ruby-haml-js
|
142
|
-
rubygems_version: 1.8.
|
162
|
+
rubygems_version: 1.8.24
|
143
163
|
signing_key:
|
144
164
|
specification_version: 3
|
145
165
|
summary: Precompile HAML-JS templates with or without Rails 3.1 assets pipeline
|