slippers 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/Rakefile +1 -2
- data/VERSION.yml +2 -2
- data/lib/engine/slippers_nodes.rb +2 -2
- data/spec/parse_attributes.rb +3 -2
- data/spec/template_group.rb +3 -1
- metadata +3 -13
data/README
CHANGED
@@ -2,7 +2,7 @@ There are many template engines that you can choose for the generation of views
|
|
2
2
|
|
3
3
|
All we want our template engine to do is read a string which has holes in it, and replace those holes with the desired string, much like mail merge. String Template is a template engine originally for Java but now ported to C# and python, which enforces strict separation of model and view by only supporting these strings with holes. Unfortunately, it has not been ported to ruby...until now.
|
4
4
|
|
5
|
-
Introducing...Slippers, a strict template engine for ruby. Slippers supports the syntax from string template.
|
5
|
+
Introducing...Slippers, a strict template engine for ruby. Slippers supports the syntax from string template including anonymous templates, named templates and template group directories but also goes beyond this to allow you to use your own renderers.
|
6
6
|
|
7
7
|
Examples
|
8
8
|
1. Rendering template of a string without any holes
|
data/Rakefile
CHANGED
@@ -11,11 +11,10 @@ begin
|
|
11
11
|
gem.name = "slippers"
|
12
12
|
gem.summary = "A strict templating library for Ruby"
|
13
13
|
gem.email = "me@sarahtaraporewalla.com"
|
14
|
-
gem.homepage = "http://
|
14
|
+
gem.homepage = "http://slippersrb.com"
|
15
15
|
gem.description = "A strict templating library for ruby"
|
16
16
|
gem.authors = ["Sarah Taraporewalla"]
|
17
17
|
gem.files = FileList["[A-Z]*", "{bin,lib,spec,examples}/**/*"]
|
18
|
-
gem.add_dependency 'schacon-git'
|
19
18
|
gem.add_dependency 'treetop'
|
20
19
|
end
|
21
20
|
Jeweler::GemcutterTasks.new
|
data/VERSION.yml
CHANGED
@@ -8,7 +8,7 @@ module Slippers
|
|
8
8
|
def value_of(item, template_group)
|
9
9
|
return default_string(template_group) if attribute == ''
|
10
10
|
return item.to_s if attribute == 'it'
|
11
|
-
return item[to_sym] if item.respond_to?(
|
11
|
+
return item[to_sym] if item.respond_to?(:[]) && item[to_sym]
|
12
12
|
return item.send(attribute) if item.respond_to?(attribute)
|
13
13
|
default_string(template_group)
|
14
14
|
end
|
@@ -16,7 +16,7 @@ module Slippers
|
|
16
16
|
def render(object_to_render, template_group)
|
17
17
|
substitue_null_values(object_to_render)
|
18
18
|
return template_group.render(object_to_render) if template_group && template_group.has_registered?(object_to_render.class)
|
19
|
-
return object_to_render.compact.join(seperator) if
|
19
|
+
return object_to_render.compact.join(seperator) if object_to_render.respond_to?('join')
|
20
20
|
object_to_render.to_s
|
21
21
|
end
|
22
22
|
|
data/spec/parse_attributes.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# coding:utf-8
|
1
2
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
3
|
|
3
4
|
describe SlippersParser do
|
@@ -41,13 +42,13 @@ describe SlippersParser do
|
|
41
42
|
it "should render the default string when the attribute cannot be found on the object to render and there is no template group" do
|
42
43
|
Slippers::Engine::DEFAULT_STRING.should eql('')
|
43
44
|
@parser.parse("This is the $adjective$ template with $message$.").eval(OpenStruct.new).should eql("This is the template with .")
|
44
|
-
@parser.parse("$not_me$").eval(
|
45
|
+
@parser.parse("$not_me$").eval(stub()).should eql('')
|
45
46
|
end
|
46
47
|
|
47
48
|
it "should render the default string of the template group when the attribute cannot be found on the object to render" do
|
48
49
|
template_group = Slippers::TemplateGroup.new(:default_string => "foo" )
|
49
50
|
template_group.default_string.should eql('foo')
|
50
|
-
@parser.parse("$not_me$").eval(
|
51
|
+
@parser.parse("$not_me$").eval(stub(), template_group).should eql('foo')
|
51
52
|
end
|
52
53
|
|
53
54
|
it "should convert attribute to string" do
|
data/spec/template_group.rb
CHANGED
@@ -32,7 +32,9 @@ describe Slippers::TemplateGroup do
|
|
32
32
|
it 'should render an item if its class is registered' do
|
33
33
|
date = Date.new(DateTime.now.year, 2, 4)
|
34
34
|
rendered_text = "rendered text"
|
35
|
-
|
35
|
+
renderer = mock('date_renderer')
|
36
|
+
renderer.expects(:render).with(date).returns(rendered_text)
|
37
|
+
template_group = Slippers::TemplateGroup.new(:templates => {Date => renderer})
|
36
38
|
|
37
39
|
template_group.has_registered?(date.class).should be_true
|
38
40
|
template_group.render(date).should eql(rendered_text)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slippers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sarah Taraporewalla
|
@@ -9,19 +9,9 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-05 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: schacon-git
|
17
|
-
type: :runtime
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: "0"
|
24
|
-
version:
|
25
15
|
- !ruby/object:Gem::Dependency
|
26
16
|
name: treetop
|
27
17
|
type: :runtime
|
@@ -145,7 +135,7 @@ files:
|
|
145
135
|
- spec/views/person/date_renderer.rb
|
146
136
|
- spec/views/person/name.st
|
147
137
|
has_rdoc: true
|
148
|
-
homepage: http://
|
138
|
+
homepage: http://slippersrb.com
|
149
139
|
licenses: []
|
150
140
|
|
151
141
|
post_install_message:
|