starapor-slippers 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'spec/rake/spectask'
3
3
 
4
4
  desc "Run all examples"
5
5
  Spec::Rake::SpecTask.new('examples') do |t|
6
- t.spec_files = FileList['engine/spec/**/*.rb']
6
+ t.spec_files = FileList['spec/**/*.rb']
7
7
  end
8
8
 
9
9
  desc "Generate HTML report for failing examples"
@@ -25,6 +25,8 @@ begin
25
25
  gem.authors = ["Sarah Taraporewalla"]
26
26
  gem.files = FileList["[A-Z]*", "{bin,lib,spec,examples}/**/*"]
27
27
  gem.add_dependency 'schacon-git'
28
+ gem.add_dependency 'active_support'
29
+ gem.add_dependency 'treetop'
28
30
  end
29
31
  rescue LoadError
30
32
  puts "Slippers, or one of its dependencies, is not available. Install it with: sudo gem install starapor-slippers -s http://gems.github.com"
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 0
3
- :major: 0
4
2
  :minor: 0
3
+ :patch: 1
4
+ :major: 0
@@ -11,7 +11,9 @@ module Slippers
11
11
 
12
12
  def render(object_to_render=nil)
13
13
  parser = SlippersParser.new
14
- parser.parse(@main_template.template).eval(object_to_render, @template_group)
14
+ parse_tree = parser.parse(@main_template.template)
15
+ return '' unless parse_tree
16
+ parse_tree.eval(object_to_render, @template_group)
15
17
  end
16
18
 
17
19
  def eql?(other)
@@ -5,7 +5,7 @@ grammar Slippers
5
5
  end
6
6
 
7
7
  rule templated_expression
8
- "$" foo "$" <TemplatedExpressionNode>
8
+ delimiter foo delimiter <TemplatedExpressionNode>
9
9
  end
10
10
 
11
11
  rule foo
@@ -21,7 +21,7 @@ grammar Slippers
21
21
  end
22
22
 
23
23
  rule known_template
24
- template_path "()" <TemplateNode>
24
+ template_path brackets <TemplateNode>
25
25
  end
26
26
 
27
27
  rule anonymous_template
@@ -29,22 +29,14 @@ grammar Slippers
29
29
  end
30
30
 
31
31
  rule attribute
32
- word <AttributeNode>
32
+ anything_except_keywords <AttributeNode>
33
33
  end
34
34
 
35
35
  rule some_text
36
36
  not_delimiter* {
37
- def eval(*args)
38
- to_s
39
- end
40
- def to_s
41
- text_value
42
- end
43
- }
44
- end
45
-
46
- rule not_delimiter
47
- !"$" . {
37
+ def eval(*args)
38
+ to_s
39
+ end
48
40
  def to_s
49
41
  text_value
50
42
  end
@@ -60,25 +52,28 @@ grammar Slippers
60
52
  end
61
53
 
62
54
  rule template_path
63
- word_with_underscore ("/" word_with_underscore)? {
55
+ anything_except_keywords {
64
56
  def to_s
65
57
  text_value
66
58
  end
67
59
  }
68
60
  end
69
61
 
70
- rule word_with_underscore
71
- word ("_" word)*
72
- end
73
-
74
- rule not_curly
75
- !("{" / "}") . {
62
+ rule anything_except_keywords
63
+ not_keyword* {
64
+ def eval(*args)
65
+ to_s
66
+ end
76
67
  def to_s
77
68
  text_value
78
69
  end
79
70
  }
80
71
  end
81
72
 
73
+ rule word_with_underscore
74
+ word ("_" word)*
75
+ end
76
+
82
77
  rule word
83
78
  [a-zA-Z]+ {
84
79
  def to_s
@@ -105,5 +100,57 @@ grammar Slippers
105
100
  end
106
101
  }
107
102
  end
103
+
104
+ rule delimiter
105
+ '$' {
106
+ def to_s
107
+ text_value
108
+ end
109
+ }
110
+ end
111
+
112
+ rule brackets
113
+ '()' {
114
+ def to_s
115
+ text_value
116
+ end
117
+ }
118
+ end
119
+
120
+ rule escape
121
+ '\\'
122
+ end
123
+
124
+ rule not_delimiter
125
+ escape delimiter / !delimiter . {
126
+ def to_s
127
+ text_value
128
+ end
129
+ }
130
+ end
131
+
132
+ rule not_apply_op
133
+ !apply_op . {
134
+ def to_s
135
+ text_value
136
+ end
137
+ }
138
+ end
139
+
140
+ rule not_keyword
141
+ !(apply_op / delimiter / brackets) . {
142
+ def to_s
143
+ text_value
144
+ end
145
+ }
146
+ end
147
+
148
+ rule not_curly
149
+ !("{" / "}") . {
150
+ def to_s
151
+ text_value
152
+ end
153
+ }
154
+ end
108
155
 
109
156
  end
@@ -6,6 +6,7 @@ module Slippers
6
6
  end
7
7
 
8
8
  def value_of(item)
9
+ return '' if to_s == ''
9
10
  return item.send(to_s) if item.respond_to?(to_s)
10
11
  return item[to_sym] if item.respond_to?('[]'.to_sym) && item[to_sym]
11
12
  ''
@@ -83,7 +84,7 @@ module Slippers
83
84
  class ExpressionNode < Treetop::Runtime::SyntaxNode
84
85
 
85
86
  def eval(object_to_render, template_group=nil)
86
- before.eval + templated_expression.eval(object_to_render, template_group) + space.eval + after.eval(object_to_render, template_group)
87
+ before.eval(object_to_render, template_group) + templated_expression.eval(object_to_render, template_group) + space.eval + after.eval(object_to_render, template_group)
87
88
  end
88
89
 
89
90
  end
@@ -1,11 +1,11 @@
1
1
  From 5a6c869d4709ce84d7c07b5dd33cf06e39c0111e Mon Sep 17 00:00:00 2001
2
2
  From: Sarah Taraporewalla <sarah.tarap@gmail.com>
3
3
  Date: Mon, 16 Feb 2009 20:44:08 +0000
4
- Subject: [PATCH] SarahTaraporewalla: adding new template file for slippers template engine
4
+ Subject: [PATCH 1] SarahTaraporewalla: adding new template file for slippers template engine
5
5
 
6
6
  ---
7
7
  lib/ramaze/template.rb | 2 +-
8
- 1 files changed, 1 insertions(+), 1 deletions(-)
8
+ 2 files changed, 26 insertions(+), 1 deletions(-)
9
9
 
10
10
  diff --git a/lib/ramaze/template.rb b/lib/ramaze/template.rb
11
11
  index 096816b..99f1f94 100644
@@ -21,5 +21,38 @@ index 096816b..99f1f94 100644
21
21
 
22
22
  AVAILABLE_ENGINES.each do |const|
23
23
  --
24
+
25
+ diff --git a/lib/ramaze/template/slippers.rb b/lib/ramaze/template/slippers.rb
26
+ new file mode 100755
27
+ index 0000000..e9981b4
28
+ --- /dev/null
29
+ +++ b/lib/ramaze/template/slippers.rb
30
+ @@ -0,0 +1,25 @@
31
+ +require 'slippers'
32
+ +
33
+ +module Ramaze
34
+ + module Template
35
+ + class Slippers < Template
36
+ +
37
+ + ENGINES[self] = %w[ st ]
38
+ + class << self
39
+ + def transform(action)
40
+ + slippers = wrap_compile(action)
41
+ + object_to_render = ::Slippers::BindingWrapper.new(action.binding)
42
+ + slippers.render(object_to_render)
43
+ + end
44
+ +
45
+ + def compile(action, template)
46
+ + subtemplates = action.controller.trait[:slippers_options] || {}
47
+ +
48
+ + template_group_directory = ::Slippers::TemplateGroupDirectory.new(Global.view_root)
49
+ + template_group = ::Slippers::TemplateGroup.new(:super_group => template_group_directory, :templates => subtemplates)
50
+ + ::Slippers::Engine.new(template, :template_group => template_group)
51
+ + end
52
+ + end
53
+ + end
54
+ + end
55
+ +end
56
+ --
24
57
  1.6.1
25
58
 
@@ -1,4 +1,4 @@
1
- require '/Users/starapor/Development/slippers/slippers'
1
+ require 'slippers'
2
2
 
3
3
  module Ramaze
4
4
  module Template
@@ -66,6 +66,11 @@ describe Slippers::Engine do
66
66
  engine = Slippers::Engine.new(template, :template_group => template_group)
67
67
  engine.render(Slippers::BindingWrapper.new(binding)).should eql('Say: Hello fred flinstone Hello barney rubble ')
68
68
  end
69
+
70
+ it 'should render empty string if the template can not be evaluated' do
71
+ engine = Slippers::Engine.new('$this_is_bad')
72
+ engine.render(stub('object')).should eql('')
73
+ end
69
74
  end
70
75
 
71
76
  class AgeRenderer
@@ -5,6 +5,9 @@ class Person
5
5
  @first, @last = first, last
6
6
  end
7
7
  attr_reader :first, :last
8
+ def full_name
9
+ to_s
10
+ end
8
11
  def to_s
9
12
  first + ' ' + last
10
13
  end
@@ -26,19 +29,23 @@ describe SlippersParser do
26
29
  end
27
30
 
28
31
  it 'should find the keyword within the delimiters' do
29
- message = OpenStruct.new({:message => 'the message', :name => 'fred'})
32
+ message = OpenStruct.new({:message => 'the message', :message2 => 'the second message', :name => 'fred', :full_name => 'fred flinstone'})
30
33
  @parser.parse('$message$').eval(message).should eql('the message')
31
34
  @parser.parse('$message$ for $name$').eval(message).should eql('the message for fred')
32
35
  @parser.parse('we want to find $message$').eval(message).should eql('we want to find the message')
33
36
  @parser.parse('$message$ has spoken').eval(message).should eql('the message has spoken')
34
37
  @parser.parse('Yes! $message$ has spoken').eval(message).should eql('Yes! the message has spoken')
38
+ @parser.parse('Yes! $full_name$ has spoken').eval(message).should eql('Yes! fred flinstone has spoken')
39
+ @parser.parse('Yes! $message2$ has spoken').eval(message).should eql('Yes! the second message has spoken')
40
+ @parser.parse('$$').eval(message).should eql('')
35
41
  end
36
42
 
37
43
  it 'should parse the subtemplate found within the delimiters' do
38
44
  template = Slippers::Engine.new('template for this')
39
45
  template_with_underscore = Slippers::Engine.new('template with underscore')
40
- template_group = Slippers::TemplateGroup.new(:templates => {:template => template, :template_with_underscore => template_with_underscore})
46
+ template_group = Slippers::TemplateGroup.new(:templates => {:template => template, :template_with_underscore => template_with_underscore, :template2 => template})
41
47
  @parser.parse('$template()$').eval(nil, template_group).should eql('template for this')
48
+ @parser.parse('$template2()$').eval(nil, template_group).should eql('template for this')
42
49
  @parser.parse('Stuff before $template()$ and after').eval(nil, template_group).should eql('Stuff before template for this and after')
43
50
  @parser.parse('then there is $template_with_underscore()$').eval(nil, template_group).should eql('then there is template with underscore')
44
51
  end
@@ -56,7 +63,7 @@ describe SlippersParser do
56
63
  end
57
64
 
58
65
  it 'should not match on escaped delimiters' do
59
- #@parser.parse('stuff \$notmatched\$').eval.should eql('stuff \$notmatched\$')
66
+ @parser.parse('stuff \$notmatched\$').eval(stub(:nothing)).should eql('stuff \$notmatched\$')
60
67
  end
61
68
 
62
69
  it "should render a list of objects" do
@@ -105,6 +112,14 @@ describe SlippersParser do
105
112
  template_group = Slippers::TemplateGroup.new(:templates => {:not_a_renderer => stub('renderer')})
106
113
  @parser.parse("$not_a_renderer()$").eval(stub('object'), template_group).should eql('')
107
114
  end
115
+
116
+ it 'should return an empty string if the template is not correctly formed' do
117
+ @parser.parse("$not_properly_formed").should eql(nil)
118
+ end
119
+
120
+ it 'should render an empty string if it cannot find the attribute to render' do
121
+ @parser.parse("$not_me$").eval(Person.new('fred', 'flinestone')).should eql('')
122
+ end
108
123
 
109
124
  end
110
125
 
@@ -2,7 +2,7 @@ require 'spec'
2
2
 
3
3
  $LOAD_PATH.unshift(File.dirname(__FILE__))
4
4
 
5
- require 'slippers'
5
+ require 'lib/slippers'
6
6
  require 'ostruct'
7
7
  require 'date'
8
8
  require 'mocha'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: starapor-slippers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sarah Taraporewalla
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-25 00:00:00 -08:00
12
+ date: 2009-03-31 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,6 +22,26 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: active_support
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: treetop
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
25
45
  description: A strict templating library for ruby
26
46
  email: me@sarahtaraporewalla.com
27
47
  executables: []