simonmenke-view_slots 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE.txt +20 -0
- data/README.rdoc +13 -0
- data/lib/view_slots/helper.rb +14 -0
- data/lib/view_slots/namespace.rb +31 -0
- data/lib/view_slots/slot.rb +40 -0
- data/lib/view_slots.rb +30 -0
- data/rails/init.rb +4 -0
- data/tasks/view_slots_tasks.rake +4 -0
- data/test/test_helper.rb +3 -0
- data/test/view_slots_test.rb +8 -0
- metadata +63 -0
data/MIT-LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Simon Menke
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module ViewSlots
|
2
|
+
module Helper
|
3
|
+
|
4
|
+
def slot(name, options={})
|
5
|
+
return '' unless slot = ::ViewSlots.find(name)
|
6
|
+
returning "" do |content|
|
7
|
+
slot.templates.each do |template|
|
8
|
+
content.concat render(options.merge(:partial => template))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ViewSlots
|
2
|
+
class Namespace
|
3
|
+
|
4
|
+
def initialize(name, parent=nil)
|
5
|
+
@parent, @name = parent, name.to_s
|
6
|
+
end
|
7
|
+
|
8
|
+
def add(*args)
|
9
|
+
::ViewSlots.add(__path__, *args)
|
10
|
+
end
|
11
|
+
|
12
|
+
def remove(*args)
|
13
|
+
::ViewSlots.remove(__path__, *args)
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(m, *args)
|
17
|
+
namespace = ::ViewSlots::Namespace.new(m, self)
|
18
|
+
yield(namespace) if block_given?
|
19
|
+
namespace
|
20
|
+
end
|
21
|
+
|
22
|
+
def __path__
|
23
|
+
if @parent
|
24
|
+
"#{@parent.__path__}:#{@name}"
|
25
|
+
else
|
26
|
+
@name
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module ViewSlots
|
2
|
+
class Slot
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@order = []
|
6
|
+
@templates = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def add(name, template, options={})
|
10
|
+
if @templates[name.to_s]
|
11
|
+
@templates[name.to_s] = template
|
12
|
+
return true
|
13
|
+
end
|
14
|
+
@templates[name.to_s] = template
|
15
|
+
if before = options.delete(:before)
|
16
|
+
idx = @order.index(before.to_s) || -1
|
17
|
+
@order.insert(idx, template)
|
18
|
+
elsif after = options.delete(:after)
|
19
|
+
idx = @order.index(after.to_s) || -1
|
20
|
+
@order.insert(idx+1, template)
|
21
|
+
else
|
22
|
+
@order.push(name.to_s)
|
23
|
+
end
|
24
|
+
@ordered_templates = nil
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
def remove(name)
|
29
|
+
@templates.delete(name.to_s)
|
30
|
+
@order.delete(name.to_s)
|
31
|
+
@ordered_templates = nil
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
def templates
|
36
|
+
@ordered_templates ||= @order.collect { |name| @templates[name] }
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/lib/view_slots.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
module ViewSlots
|
3
|
+
|
4
|
+
mattr_accessor :view_slots
|
5
|
+
self.view_slots ||= {}
|
6
|
+
|
7
|
+
def self.setup
|
8
|
+
yield self
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.method_missing(m, *args)
|
12
|
+
namespace = ::ViewSlots::Namespace.new(m)
|
13
|
+
yield(namespace) if block_given?
|
14
|
+
namespace
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.add(slot, name, template, options={})
|
18
|
+
view_slots[slot] ||= ::ViewSlots::Slot.new
|
19
|
+
view_slots[slot].add(name, template, options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.remove(slot, name)
|
23
|
+
view_slots[slot].remove(name) if view_slots[slot]
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.find(slot)
|
27
|
+
view_slots[slot]
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/rails/init.rb
ADDED
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simonmenke-view_slots
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Simon Menke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-07 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: simon.menke@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- test/test_helper.rb
|
26
|
+
- test/view_slots_test.rb
|
27
|
+
- lib/view_slots/helper.rb
|
28
|
+
- lib/view_slots/namespace.rb
|
29
|
+
- lib/view_slots/slot.rb
|
30
|
+
- lib/view_slots.rb
|
31
|
+
- rails/init.rb
|
32
|
+
- tasks/view_slots_tasks.rake
|
33
|
+
- MIT-LICENSE.txt
|
34
|
+
- README.rdoc
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://github.com/simonmenke/view_slots
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project: view_slots
|
57
|
+
rubygems_version: 1.2.0
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: A view slots infrastructure.
|
61
|
+
test_files:
|
62
|
+
- test/test_helper.rb
|
63
|
+
- test/view_slots_test.rb
|