fu 0.0.2 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -36,21 +36,9 @@ A contrived example using all aspects of the syntax:
36
36
  Usage
37
37
  =====
38
38
 
39
- Direct:
40
-
41
39
  Fu.to_mustache("%p Hello {{mustache}}")
42
40
 
43
- With Sinatra and Tilt:
44
-
45
- require 'fu/tilt'
46
-
47
- Stick your fu-templates in your views-folder with the extension `.fu`.
48
-
49
- Then, in your app:
50
-
51
- get "/some_action" do
52
- fu :some_template, :locals => {...}
53
- end
41
+ Sinatra w/Tilt? See https://github.com/benglerpebbles/fu-tilt#readme
54
42
 
55
43
  Todo
56
44
  ====
data/fu.gemspec CHANGED
@@ -21,7 +21,6 @@ Gem::Specification.new do |s|
21
21
  # specify any dependencies here; for example:
22
22
  s.add_development_dependency "rspec"
23
23
  s.add_development_dependency "sinatra"
24
- s.add_development_dependency "sinatra"
25
24
  s.add_development_dependency "rack-test"
26
25
  s.add_development_dependency "mustache"
27
26
 
data/lib/fu/mustache.rb CHANGED
@@ -7,19 +7,20 @@ module Fu
7
7
  attr_reader :mustache
8
8
  SELF_CLOSING_TAGS = %w(meta img link br hr input area param col base)
9
9
  BLOCK_ACTIONS = %w(# ^) # <- Mustache actions that take a block
10
- NO_SPACE_CHARS = /[{}<>]/ # <- Characters that do not need to be separated by a space
10
+ NO_SPACE_CHARS = /[{}<>\s]|^$/ # <- Characters that do not need to be separated by a space
11
11
  # when joining elements (e.g. "<p>!</p>", not "<p> ! </p>")
12
12
 
13
13
  def initialize(root)
14
- @mustache = flatten(render_children(root))
14
+ @mustache = flatten(render_children(root).compact)
15
15
  end
16
16
 
17
17
  private
18
18
 
19
19
  # Flatten the tag_tree inserting spaces only where they have to be.
20
20
  def flatten(tag_tree)
21
- tag_tree.flatten.inject("") do |result, element|
22
- if result[-1] =~ NO_SPACE_CHARS || element[0] =~ NO_SPACE_CHARS
21
+ tag_tree.flatten.inject("") do |result, element|
22
+ tail, incoming = result[-1], element[0]
23
+ if tail.nil? || (tail+incoming) =~ NO_SPACE_CHARS
23
24
  "#{result}#{element}"
24
25
  else
25
26
  "#{result} #{element}"
@@ -27,6 +28,11 @@ module Fu
27
28
  end
28
29
  end
29
30
 
31
+ # Restore include tags that have been destroyed by escaping
32
+ def escape_html(text)
33
+ CGI.escapeHTML(text).gsub(/\{\{\s*\&gt\;/, "{{>")
34
+ end
35
+
30
36
  # Returns a tag-tree of nested arrays reflecting the structure of the
31
37
  # document. E.g. ["<p>",["<em>", "Italicized text", "</em>"],"</p>"]
32
38
  def render_children(node)
@@ -34,7 +40,7 @@ module Fu
34
40
  end
35
41
 
36
42
  def render_text(node)
37
- [CGI.escapeHTML(node.text), render_children(node)].compact
43
+ [escape_html(node.text), render_children(node)].compact
38
44
  end
39
45
 
40
46
  def render_blank(node); end
data/lib/fu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fu
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.1"
3
3
  end
data/spec/fu_spec.rb CHANGED
@@ -84,7 +84,6 @@ describe Fu::Mustache do
84
84
  result.should eq "{{^children}}{{name}} and {{address}}{{/children}}"
85
85
  end
86
86
 
87
-
88
87
  it "handles mustache in attributes" do
89
88
  Fu.to_mustache('%p(data-bingo="{{bingo}}")').should eq '<p data-bingo="{{bingo}}"></p>'
90
89
  end
@@ -101,4 +100,7 @@ describe Fu::Mustache do
101
100
  END
102
101
  end
103
102
 
103
+ it "never escapes the gt-character of include-statements" do
104
+ Fu.to_mustache("Bingo{{>partial}}bongo").should eq "Bingo{{>partial}}bongo"
105
+ end
104
106
  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.0.2
4
+ version: 0.1.1
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-13 00:00:00.000000000Z
12
+ date: 2011-12-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70092482432980 !ruby/object:Gem::Requirement
16
+ requirement: &70312003890400 !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: *70092482432980
24
+ version_requirements: *70312003890400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sinatra
27
- requirement: &70092482432440 !ruby/object:Gem::Requirement
27
+ requirement: &70312003889520 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,21 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70092482432440
36
- - !ruby/object:Gem::Dependency
37
- name: sinatra
38
- requirement: &70092482431880 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
44
- type: :development
45
- prerelease: false
46
- version_requirements: *70092482431880
35
+ version_requirements: *70312003889520
47
36
  - !ruby/object:Gem::Dependency
48
37
  name: rack-test
49
- requirement: &70092482431340 !ruby/object:Gem::Requirement
38
+ requirement: &70312003888900 !ruby/object:Gem::Requirement
50
39
  none: false
51
40
  requirements:
52
41
  - - ! '>='
@@ -54,10 +43,10 @@ dependencies:
54
43
  version: '0'
55
44
  type: :development
56
45
  prerelease: false
57
- version_requirements: *70092482431340
46
+ version_requirements: *70312003888900
58
47
  - !ruby/object:Gem::Dependency
59
48
  name: mustache
60
- requirement: &70092482430780 !ruby/object:Gem::Requirement
49
+ requirement: &70312003888480 !ruby/object:Gem::Requirement
61
50
  none: false
62
51
  requirements:
63
52
  - - ! '>='
@@ -65,7 +54,7 @@ dependencies:
65
54
  version: '0'
66
55
  type: :development
67
56
  prerelease: false
68
- version_requirements: *70092482430780
57
+ version_requirements: *70312003888480
69
58
  description: Fu combines the logic–less portability of Mustache with the terse utility
70
59
  of Haml.
71
60
  email:
@@ -83,11 +72,9 @@ files:
83
72
  - lib/fu/error.rb
84
73
  - lib/fu/mustache.rb
85
74
  - lib/fu/parser.rb
86
- - lib/fu/tilt.rb
87
75
  - lib/fu/version.rb
88
76
  - spec/fixtures/views/list.fu
89
77
  - spec/fu_spec.rb
90
- - spec/fu_tilt_spec.rb
91
78
  - spec/spec_helper.rb
92
79
  homepage: ''
93
80
  licenses: []
@@ -116,5 +103,4 @@ summary: Fu template engine
116
103
  test_files:
117
104
  - spec/fixtures/views/list.fu
118
105
  - spec/fu_spec.rb
119
- - spec/fu_tilt_spec.rb
120
106
  - spec/spec_helper.rb
data/lib/fu/tilt.rb DELETED
@@ -1,31 +0,0 @@
1
- # Makes Fu available through Tilt, also contains a utility
2
- # function that will be added to Sinatra if Sinatra is
3
- # defined.
4
- require 'fu'
5
- require 'tilt'
6
- require 'mustache'
7
-
8
- module Tilt
9
- class FuTemplate < Template
10
- self.default_mime_type = "text/html"
11
- def initialize_engine
12
- return if defined? ::Fu
13
- require_template_library 'fu'
14
- end
15
-
16
- def prepare; end
17
-
18
- def evaluate(scope, locals, &block)
19
- Mustache.render(Fu.to_mustache(data), locals.merge(scope.is_a?(Hash) ? scope : {}).merge({:yield => block.nil? ? '' : block.call}))
20
- end
21
- end
22
- register FuTemplate, 'fu'
23
- end
24
-
25
- if defined?(Sinatra)
26
- module Sinatra::Templates
27
- def fu(template, options={}, locals={})
28
- render :fu, template, options, locals
29
- end
30
- end
31
- end
data/spec/fu_tilt_spec.rb DELETED
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
- require 'sinatra'
3
- require 'rack/test'
4
- require 'fu/tilt'
5
-
6
- class FuApp < Sinatra::Base
7
- set :root, File.dirname(__FILE__)+"/fixtures"
8
- get "/list" do
9
- fu :list, :locals => {:children => [{:name => "Arne"}, {:name => "Bjarne"}]}
10
- end
11
- end
12
-
13
- describe "API v1 posts" do
14
- include Rack::Test::Methods
15
-
16
- def app
17
- FuApp
18
- end
19
-
20
- it "'s alive" do
21
- get "/list"
22
- last_response.body.should eq "<ul><li>Arne</li><li>Bjarne</li></ul>"
23
- end
24
- end