garterbelt 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +38 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +21 -0
- data/Rakefile +46 -0
- data/TODO +3 -0
- data/VERSION +1 -0
- data/garterbelt.gemspec +165 -0
- data/lib/garterbelt.rb +23 -0
- data/lib/page.rb +46 -0
- data/lib/renderers/cache.rb +35 -0
- data/lib/renderers/closed_tag.rb +60 -0
- data/lib/renderers/comment.rb +14 -0
- data/lib/renderers/content_rendering.rb +41 -0
- data/lib/renderers/content_tag.rb +36 -0
- data/lib/renderers/doctype.rb +24 -0
- data/lib/renderers/renderer.rb +33 -0
- data/lib/renderers/text.rb +28 -0
- data/lib/renderers/xml.rb +9 -0
- data/lib/stocking.rb +11 -0
- data/lib/support/string.rb +165 -0
- data/lib/view.rb +341 -0
- data/spec/benchmark/templates/erector.rb +37 -0
- data/spec/benchmark/templates/garterbelt.rb +37 -0
- data/spec/benchmark/vs_erector.rb +53 -0
- data/spec/garterbelt_spec.rb +49 -0
- data/spec/integration/expectations/general_view.html +17 -0
- data/spec/integration/expectations/variables/view_with_user_and_params.html +23 -0
- data/spec/integration/expectations/variables/view_with_user_email.html +23 -0
- data/spec/integration/expectations/view_partial_nest.html +24 -0
- data/spec/integration/expectations/view_with_tags.html +19 -0
- data/spec/integration/templates/view_partial_nest.rb +22 -0
- data/spec/integration/templates/view_with_cache.rb +30 -0
- data/spec/integration/templates/view_with_partial.rb +36 -0
- data/spec/integration/templates/view_with_partial_2.rb +36 -0
- data/spec/integration/templates/view_with_tags.rb +26 -0
- data/spec/integration/templates/view_with_vars.rb +32 -0
- data/spec/integration/view_spec.rb +57 -0
- data/spec/page_spec.rb +99 -0
- data/spec/renderers/cache_spec.rb +85 -0
- data/spec/renderers/closed_tag_spec.rb +172 -0
- data/spec/renderers/comment_spec.rb +68 -0
- data/spec/renderers/content_tag_spec.rb +150 -0
- data/spec/renderers/doctype_spec.rb +46 -0
- data/spec/renderers/text_spec.rb +68 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/mock_view.rb +14 -0
- data/spec/support/puters.rb +10 -0
- data/spec/view/view_basics_spec.rb +106 -0
- data/spec/view/view_caching_spec.rb +132 -0
- data/spec/view/view_partial_spec.rb +63 -0
- data/spec/view/view_rails_type_helpers.rb +148 -0
- data/spec/view/view_render_spec.rb +408 -0
- data/spec/view/view_variables_spec.rb +159 -0
- metadata +367 -0
@@ -0,0 +1,132 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Garterbelt::View, "Caching" do
|
4
|
+
class Cached < Garterbelt::View
|
5
|
+
end
|
6
|
+
|
7
|
+
class SpecialCached < Garterbelt::View
|
8
|
+
def self.cache_store_key
|
9
|
+
:foo
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'cache access' do
|
14
|
+
describe 'class level #cache_store_key' do
|
15
|
+
it 'defaults to :default' do
|
16
|
+
Garterbelt::View.cache_store_key.should == :default
|
17
|
+
Cached.cache_store_key.should == :default
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'can be customized' do
|
21
|
+
SpecialCached.cache_store_key.should == :foo
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'instance level #cache_store_key' do
|
26
|
+
it 'defaults to the class' do
|
27
|
+
Cached.new.cache_store_key.should == :default
|
28
|
+
SpecialCached.new.cache_store_key.should == :foo
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'can be set independently' do
|
32
|
+
cached = Cached.new
|
33
|
+
cached.cache_store_key = :boo
|
34
|
+
cached.cache_store_key.should == :boo
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'cache_store' do
|
39
|
+
it 'returns a cache object' do
|
40
|
+
Cached.new.cache_store.should == Garterbelt.cache
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'uses the instance level cache_store_key' do
|
44
|
+
cached = Cached.new
|
45
|
+
Garterbelt.cache_hash[:foo] = 'foo'
|
46
|
+
cached.cache_store_key = :foo
|
47
|
+
cached.cache_store.should == 'foo'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'cache key base' do
|
52
|
+
describe 'class level' do
|
53
|
+
it 'is the underscored version of the class by default' do
|
54
|
+
Cached.cache_key_base.should == 'cached'
|
55
|
+
SpecialCached.cache_key_base.should == 'special_cached'
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'can be customized' do
|
59
|
+
Cached.cache_key_base = 'custom_cache_key_base'
|
60
|
+
Cached.cache_key_base.should == 'custom_cache_key_base'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'instance level' do
|
65
|
+
it 'defaults to the class' do
|
66
|
+
Cached.cache_key_base = 'cached'
|
67
|
+
Cached.new.cache_key_base.should == 'cached'
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'can be customized, which is probably a bad idea, but maybe necessary in crappy code' do
|
71
|
+
Cached.cache_key_base.should == 'cached'
|
72
|
+
cached = Cached.new
|
73
|
+
cached.cache_key_base = 'foo'
|
74
|
+
cached.cache_key_base.should == 'foo'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#cache_key' do
|
80
|
+
it 'it contains the instance level base' do
|
81
|
+
cache = Cached.new
|
82
|
+
cache.cache_key.should include "cached"
|
83
|
+
cache.cache_key_base = 'foo'
|
84
|
+
cache.cache_key.should include 'foo'
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'has a default _default argument that is concatenated' do
|
88
|
+
cache = Cached.new
|
89
|
+
cache.cache_key.should == 'cached_default'
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'takes a custom key argument' do
|
93
|
+
cache = Cached.new
|
94
|
+
cache.cache_key(:foo).should == 'cached_foo'
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'uses the default when passed nil' do
|
98
|
+
cache = Cached.new
|
99
|
+
cache.cache_key(nil).should == 'cached_default'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#cache' do
|
105
|
+
before do
|
106
|
+
@view = Cached.new
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'makes a Cache object' do
|
110
|
+
Garterbelt::Cache.should_receive(:new).and_return('foo')
|
111
|
+
@view.cache("user_8") do
|
112
|
+
puts "bar"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'passes the correct key and the view' do
|
117
|
+
Garterbelt::Cache.should_receive(:new).with(:view => @view, :key => "cached_user_8").and_return('foo')
|
118
|
+
@view.cache("user_8") do
|
119
|
+
puts "bar"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'adds the Cache object to the render buffer' do
|
124
|
+
@view.cache("foo_you") do
|
125
|
+
puts "bar"
|
126
|
+
end
|
127
|
+
cache = @view.buffer.last
|
128
|
+
cache.is_a?(Garterbelt::Cache).should be_true
|
129
|
+
cache.key.should == 'cached_foo_you'
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Garterbelt::View, 'Partials' do
|
4
|
+
describe '#partial' do
|
5
|
+
before do
|
6
|
+
@view = Garterbelt::View.new
|
7
|
+
@view.output = "Foo You!\n"
|
8
|
+
@view.level = 3
|
9
|
+
@view.buffer = ['foo', 'bar']
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'with an instance' do
|
13
|
+
before do
|
14
|
+
@child_instance = Garterbelt::View.new
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'sets the curator of the instance to the current view' do
|
18
|
+
@child_instance.should_receive(:curator=).with(@view)
|
19
|
+
@view.partial(@child_instance)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'adds the instance to the curator view buffer' do
|
23
|
+
@view.partial(@child_instance)
|
24
|
+
@view.buffer.should include @child_instance
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'with a class and initialization options' do
|
29
|
+
class PartedOut < Garterbelt::View
|
30
|
+
needs :x => 'x'
|
31
|
+
def content
|
32
|
+
text "foo #{x}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'constructs a new instance' do
|
37
|
+
@part = PartedOut.new
|
38
|
+
PartedOut.should_receive(:new).and_return(@part)
|
39
|
+
@view.partial(PartedOut, :x => '!= x')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'adds the instance to the buffer' do
|
43
|
+
@view.partial(PartedOut, :x => '!= y?')
|
44
|
+
partial = @view.buffer.last
|
45
|
+
partial.is_a?(PartedOut).should be_true
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
it 'has the curator as the current view' do
|
50
|
+
@view.partial(PartedOut, :x => 'what about z?')
|
51
|
+
partial = @view.buffer.last
|
52
|
+
partial.curator.should == @view
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'has the correct initalization options' do
|
56
|
+
@view.partial(PartedOut, :x => '= foo')
|
57
|
+
partial = @view
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'passes along the block, wait do views take blocks right now?'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Garterbelt::View, "Rails Style Helpers" do
|
4
|
+
describe 'inputs' do
|
5
|
+
describe '#input' do
|
6
|
+
it 'defaults to type of text'
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'checkbox' do
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#form' do
|
15
|
+
describe 'method option' do
|
16
|
+
describe ':put' do
|
17
|
+
it 'builds _method hidden input with the correct attribute'
|
18
|
+
it 'sets the form method attribute to post'
|
19
|
+
end
|
20
|
+
|
21
|
+
describe ':delete' do
|
22
|
+
it 'builds _method hidden input with the correct attribute'
|
23
|
+
it 'sets the form method attribute to post'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'defaults to :post when none is given'
|
27
|
+
it 'can be set to :get too'
|
28
|
+
it 'has that Rails fraud detector thingy when available'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#image' do
|
33
|
+
describe 'class level image path' do
|
34
|
+
it 'has a default class image path /images'
|
35
|
+
it 'class level image path can be customized'
|
36
|
+
it 'class level image path is inherited'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'takes the file name as first argument constructs a full path for the img src'
|
40
|
+
|
41
|
+
describe 'alt text' do
|
42
|
+
it 'humanizes the file name by default'
|
43
|
+
it 'can be customize through options'
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'takes other attributes'
|
47
|
+
|
48
|
+
describe 'expiration tagging' do
|
49
|
+
it 'includes one related to the file updated time in seconds'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#auto_discovery' do
|
54
|
+
# auto_discovery_link_tag # =>
|
55
|
+
# <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.currenthost.com/controller/action" />
|
56
|
+
# auto_discovery_link_tag(:atom) # =>
|
57
|
+
# <link rel="alternate" type="application/atom+xml" title="ATOM" href="http://www.currenthost.com/controller/action" />
|
58
|
+
# auto_discovery_link_tag(:rss, {:action => "feed"}) # =>
|
59
|
+
# <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.currenthost.com/controller/feed" />
|
60
|
+
# auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "My RSS"}) # =>
|
61
|
+
# <link rel="alternate" type="application/rss+xml" title="My RSS" href="http://www.currenthost.com/controller/feed" />
|
62
|
+
# auto_discovery_link_tag(:rss, {:controller => "news", :action => "feed"}) # =>
|
63
|
+
# <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.currenthost.com/news/feed" />
|
64
|
+
# auto_discovery_link_tag(:rss, "http://www.example.com/feed.rss", {:title => "Example RSS"}) # =>
|
65
|
+
# <link rel="alternate" type="application/rss+xml" title="Example RSS" href="http://www.example.com/feed" />
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#script_include' do
|
69
|
+
# javascript_include_tag "xmlhr" # =>
|
70
|
+
# <script type="text/javascript" src="/javascripts/xmlhr.js"></script>
|
71
|
+
#
|
72
|
+
# javascript_include_tag "xmlhr.js" # =>
|
73
|
+
# <script type="text/javascript" src="/javascripts/xmlhr.js"></script>
|
74
|
+
#
|
75
|
+
# javascript_include_tag "common.javascript", "/elsewhere/cools" # =>
|
76
|
+
# <script type="text/javascript" src="/javascripts/common.javascript"></script>
|
77
|
+
# <script type="text/javascript" src="/elsewhere/cools.js"></script>
|
78
|
+
#
|
79
|
+
# javascript_include_tag "http://www.railsapplication.com/xmlhr" # =>
|
80
|
+
# <script type="text/javascript" src="http://www.railsapplication.com/xmlhr.js"></script>
|
81
|
+
#
|
82
|
+
# javascript_include_tag "http://www.railsapplication.com/xmlhr.js" # =>
|
83
|
+
# <script type="text/javascript" src="http://www.railsapplication.com/xmlhr.js"></script>
|
84
|
+
#
|
85
|
+
# javascript_include_tag :defaults # =>
|
86
|
+
# <script type="text/javascript" src="/javascripts/prototype.js"></script>
|
87
|
+
# <script type="text/javascript" src="/javascripts/effects.js"></script>
|
88
|
+
# ...
|
89
|
+
# <script type="text/javascript" src="/javascripts/application.js"></script>
|
90
|
+
#
|
91
|
+
# * = The application.js file is only referenced if it exists
|
92
|
+
#
|
93
|
+
# Though it's not really recommended practice, if you need to extend the default JavaScript set for any reason
|
94
|
+
# (e.g., you're going to be using a certain .js file in every action), then take a look at the register_javascript_include_default method.
|
95
|
+
#
|
96
|
+
# You can also include all javascripts in the javascripts directory using <tt>:all</tt> as the source:
|
97
|
+
#
|
98
|
+
# javascript_include_tag :all # =>
|
99
|
+
# <script type="text/javascript" src="/javascripts/prototype.js"></script>
|
100
|
+
# <script type="text/javascript" src="/javascripts/effects.js"></script>
|
101
|
+
# ...
|
102
|
+
# <script type="text/javascript" src="/javascripts/application.js"></script>
|
103
|
+
# <script type="text/javascript" src="/javascripts/shop.js"></script>
|
104
|
+
# <script type="text/javascript" src="/javascripts/checkout.js"></script>
|
105
|
+
#
|
106
|
+
# Note that the default javascript files will be included first. So Prototype and Scriptaculous are available to
|
107
|
+
# all subsequently included files.
|
108
|
+
#
|
109
|
+
# If you want Rails to search in all the subdirectories under javascripts, you should explicitly set <tt>:recursive</tt>:
|
110
|
+
#
|
111
|
+
# javascript_include_tag :all, :recursive => true
|
112
|
+
#
|
113
|
+
# == Caching multiple javascripts into one
|
114
|
+
#
|
115
|
+
# You can also cache multiple javascripts into one file, which requires less HTTP connections to download and can better be
|
116
|
+
# compressed by gzip (leading to faster transfers). Caching will only happen if config.perform_caching
|
117
|
+
# is set to <tt>true</tt> (which is the case by default for the Rails production environment, but not for the development
|
118
|
+
# environment).
|
119
|
+
#
|
120
|
+
# ==== Examples
|
121
|
+
# javascript_include_tag :all, :cache => true # when config.perform_caching is false =>
|
122
|
+
# <script type="text/javascript" src="/javascripts/prototype.js"></script>
|
123
|
+
# <script type="text/javascript" src="/javascripts/effects.js"></script>
|
124
|
+
# ...
|
125
|
+
# <script type="text/javascript" src="/javascripts/application.js"></script>
|
126
|
+
# <script type="text/javascript" src="/javascripts/shop.js"></script>
|
127
|
+
# <script type="text/javascript" src="/javascripts/checkout.js"></script>
|
128
|
+
#
|
129
|
+
# javascript_include_tag :all, :cache => true # when config.perform_caching is true =>
|
130
|
+
# <script type="text/javascript" src="/javascripts/all.js"></script>
|
131
|
+
#
|
132
|
+
# javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when config.perform_caching is false =>
|
133
|
+
# <script type="text/javascript" src="/javascripts/prototype.js"></script>
|
134
|
+
# <script type="text/javascript" src="/javascripts/cart.js"></script>
|
135
|
+
# <script type="text/javascript" src="/javascripts/checkout.js"></script>
|
136
|
+
#
|
137
|
+
# javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when config.perform_caching is true =>
|
138
|
+
# <script type="text/javascript" src="/javascripts/shop.js"></script
|
139
|
+
end
|
140
|
+
|
141
|
+
describe '#stylesheet_include' do
|
142
|
+
# same as above but for stylesheets
|
143
|
+
end
|
144
|
+
|
145
|
+
describe 'favicon' do
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|