fu 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,7 +36,14 @@ module Fu
36
36
  # Returns a tag-tree of nested arrays reflecting the structure of the
37
37
  # document. E.g. ["<p>",["<em>", "Italicized text", "</em>"],"</p>"]
38
38
  def render_children(node)
39
- node.children.map { |child| self.send("render_#{child.type}", child) }
39
+ node.children.each_with_index.inject([]) do |rendered, (child, i)|
40
+ rendered << self.send("render_#{child.type}", child)
41
+ next_sibling = node.children[i+1]
42
+ if child.type == :text && !next_sibling.nil? && [:mustache, :text].include?(next_sibling.type)
43
+ rendered << " "
44
+ end
45
+ rendered
46
+ end
40
47
  end
41
48
 
42
49
  def render_text(node)
@@ -16,6 +16,9 @@ module Fu
16
16
  private
17
17
 
18
18
  def parse_children(parent, scanner, parent_indent = -1)
19
+ if scanner.check(/\S/).nil?
20
+ scanner.scan(/(\s*\n)*/) #consume blank lines
21
+ end
19
22
  indent = (scanner.check(/\ +/) || '').size
20
23
  while indent > parent_indent && !scanner.eos? do
21
24
  node = parse_line(parent, scanner)
@@ -1,3 +1,3 @@
1
1
  module Fu
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -100,6 +100,52 @@ describe Fu::Mustache do
100
100
  END
101
101
  end
102
102
 
103
+ it "handles mustache sections" do
104
+ result = Fu.to_mustache <<-END
105
+ {{#children}}
106
+ {{name}} and {{address}}
107
+ END
108
+ result.should eq "{{#children}}{{name}} and {{address}}{{/children}}"
109
+ end
110
+
111
+ it "treats blank line after tag as a single space" do
112
+ result = Fu.to_mustache <<-END
113
+ %p
114
+ {{#children}} {{firstname}}
115
+ {{lastname}}
116
+ and {{address}}
117
+ END
118
+ result.should eq "<p>{{#children}}{{firstname}} {{lastname}} and {{address}}{{/children}}</p>"
119
+ end
120
+
121
+ it "it ignores blank lines" do
122
+ result = Fu.to_mustache <<-END
123
+ %p
124
+
125
+ Hello
126
+
127
+ {{#children}}
128
+ {{firstname}}
129
+
130
+ {{lastname}}
131
+
132
+ and {{address}}
133
+ END
134
+ result.should eq '<p>Hello {{#children}}{{firstname}} {{lastname}} and {{address}}{{/children}}</p>'
135
+ end
136
+
137
+ it "inserts whitespace where newline separates mustache sections" do
138
+ result = Fu.to_mustache <<-END
139
+ %p {{this}}
140
+ {{is}}
141
+ Another
142
+ {{#funky}}
143
+ {{mega}}
144
+ {{test}}
145
+ END
146
+ result.should eq "<p>{{this}} {{is}}</p>Another {{#funky}}{{mega}} {{test}}{{/funky}}"
147
+ end
148
+
103
149
  it "never escapes the gt-character of include-statements" do
104
150
  Fu.to_mustache("Bingo{{>partial}}bongo").should eq "Bingo{{>partial}}bongo"
105
151
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.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: 2011-12-14 00:00:00.000000000Z
12
+ date: 2012-01-30 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70187449764540 !ruby/object:Gem::Requirement
16
+ requirement: &70186053869080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70187449764540
24
+ version_requirements: *70186053869080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sinatra
27
- requirement: &70187449763300 !ruby/object:Gem::Requirement
27
+ requirement: &70186053868400 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70187449763300
35
+ version_requirements: *70186053868400
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rack-test
38
- requirement: &70187449762160 !ruby/object:Gem::Requirement
38
+ requirement: &70186053867620 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70187449762160
46
+ version_requirements: *70186053867620
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: mustache
49
- requirement: &70187449750660 !ruby/object:Gem::Requirement
49
+ requirement: &70186053866700 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70187449750660
57
+ version_requirements: *70186053866700
58
58
  description: Fu combines the logic–less portability of Mustache with the terse utility
59
59
  of Haml.
60
60
  email: