actionview_template_inheritance 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +3 -0
- data/lib/actionview_template_inheritance.rb +48 -0
- metadata +57 -0
data/Gemfile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module ActionViewTemplateInheritance
|
2
|
+
module ActionView
|
3
|
+
def blocks
|
4
|
+
@inheritance_blocks ||= { :appends => {} }
|
5
|
+
end
|
6
|
+
|
7
|
+
def block(name, value = nil, &block)
|
8
|
+
raise ArgumentError, "Block has to have a name!" if name.nil?
|
9
|
+
raise ArgumentError, "You have to provide value or block, not both of them!" if value && block
|
10
|
+
self.blocks[name] ||= block ? capture(&block) : value
|
11
|
+
if self.blocks[:appends][name]
|
12
|
+
appends = self.blocks[:appends][name].join("\n").html_safe
|
13
|
+
end
|
14
|
+
return (self.blocks[name] || "") + (appends || "")
|
15
|
+
end
|
16
|
+
|
17
|
+
def enhance_block(name, value = nil, &block)
|
18
|
+
raise ArgumentError, "Block has to have a name!" if name.nil?
|
19
|
+
raise ArgumentError, "You have to provide value or block, not both of them!" if value && block
|
20
|
+
self.blocks[:appends][name] ||= []
|
21
|
+
self.blocks[:appends][name].unshift(block ? capture(&block) : value)
|
22
|
+
end
|
23
|
+
|
24
|
+
def clear_block(name)
|
25
|
+
block(name, "")
|
26
|
+
end
|
27
|
+
|
28
|
+
def inherit(options = {}, &block)
|
29
|
+
# We accept a shorthand syntax -- if options is a string, render as a file.
|
30
|
+
return inherit({:file => options}, &block) if options.is_a?(String)
|
31
|
+
|
32
|
+
bind = options[:binding]
|
33
|
+
|
34
|
+
# Get our differences and additions to the view we're inheriting.
|
35
|
+
if block_given?
|
36
|
+
capture(&block)
|
37
|
+
bind ||= block.binding
|
38
|
+
end
|
39
|
+
|
40
|
+
raise "Important: inherit() requires a block. Empty one ({}) is fine though." unless bind
|
41
|
+
|
42
|
+
# Render our parent view.
|
43
|
+
render(options)
|
44
|
+
end
|
45
|
+
|
46
|
+
::ActionView::Base.send :include, self
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: actionview_template_inheritance
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tomasz Werbicki
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-15 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: actionpack
|
16
|
+
requirement: &15022280 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *15022280
|
25
|
+
description:
|
26
|
+
email:
|
27
|
+
executables: []
|
28
|
+
extensions: []
|
29
|
+
extra_rdoc_files: []
|
30
|
+
files:
|
31
|
+
- Gemfile
|
32
|
+
- lib/actionview_template_inheritance.rb
|
33
|
+
homepage:
|
34
|
+
licenses: []
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.8.6
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: A set of methods implementing django-like template inheritance in ActionView.
|
57
|
+
test_files: []
|