Class: Content::Sublayout
- Inherits:
-
Object
- Object
- Content::Sublayout
- Defined in:
- lib/content/sublayout.rb
Instance Attribute Summary collapse
-
#containers ⇒ Object
Returns the value of attribute containers.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path) ⇒ Sublayout
constructor
A new instance of Sublayout.
- #to_param ⇒ Object
Constructor Details
#initialize(path) ⇒ Sublayout
Returns a new instance of Sublayout.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/content/sublayout.rb', line 28 def initialize(path) @path = path @name = @path.gsub('.html.erb', '').gsub('/', ' > ').humanize.titleize @containers = returning [] do |tainers| File.open("app/views/sublayouts/#{@path}", File::RDONLY) do |fd| fd.each do |line| tainers << ($2 || "contents").to_sym if line =~ /yield[ \t]*(\(?[ \t]*:([a-z]+)[ \t]*\)?)?%/i end end end end |
Instance Attribute Details
#containers ⇒ Object
Returns the value of attribute containers.
3 4 5 |
# File 'lib/content/sublayout.rb', line 3 def containers @containers end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/content/sublayout.rb', line 3 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/content/sublayout.rb', line 3 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/content/sublayout.rb', line 3 def path @path end |
Class Method Details
.all ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/content/sublayout.rb', line 5 def self.all index = 0 @sublayouts ||= Dir.glob("app/views/sublayouts/**/*.erb").collect {|path| path = path.gsub("app/views/sublayouts/", "") path unless path.match '/_' or path == "application.html.erb" }.compact.collect {|path| Sublayout.new(path) }.collect {|sublayout| if sublayout.containers.length > 0 sublayout.id = index = index + 1 sublayout end }.compact end |
.find(index) ⇒ Object
20 21 22 |
# File 'lib/content/sublayout.rb', line 20 def self.find(index) all[index.to_i - 1] end |
.find_by_path(path) ⇒ Object
24 25 26 |
# File 'lib/content/sublayout.rb', line 24 def self.find_by_path(path) all.reject {|item| item.path != path }.first end |
Instance Method Details
#to_param ⇒ Object
40 41 42 |
# File 'lib/content/sublayout.rb', line 40 def to_param id.to_s end |