view_slots 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- 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 +65 -0
@@ -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,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: view_slots
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Simon Menke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-26 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A view slots infrastructure.
|
17
|
+
email: simon.menke@gmail.com
|
18
|
+
engine_dependencies: {}
|
19
|
+
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
26
|
+
files:
|
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
|
+
- test/test_helper.rb
|
34
|
+
- test/view_slots_test.rb
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://github.com/simonmenke/view_slots
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.3.3
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: A view slots infrastructure.
|
63
|
+
test_files:
|
64
|
+
- test/test_helper.rb
|
65
|
+
- test/view_slots_test.rb
|