class Stormy::Chunk
Attributes
body[R]
content[R]
details[R]
Public Class Methods
new(app,details,params={})
click to toggle source
# File lib/stormy/chunk.rb, line 6 def initialize(app,details,params={}) @app = app @params = params @details = ActiveSupport::HashWithIndifferentAccess.new(app.defaults) @details.merge!(details) @body = details[:body] @content = {} @template = app.template(details[:path],@details) if @body end
Public Instance Methods
resolve_content()
click to toggle source
# File lib/stormy/chunk.rb, line 24 def resolve_content pieces = details[:content] pieces = [ pieces ] unless pieces.is_a?(Array) pieces.each do |piece| if !resolve_piece(piece) @invalid_content = true end end self.content end
resolve_content_list(name,type,piece)
click to toggle source
# File lib/stormy/chunk.rb, line 58 def resolve_content_list(name,type,piece) content_list = @app.content_list(type,piece) content[name] = content_list.items end
resolve_content_piece(name,type,piece)
click to toggle source
# File lib/stormy/chunk.rb, line 45 def resolve_content_piece(name,type,piece) key = if piece[:key].is_a?(Symbol) details[piece[:key]] else piece[:key] end content_chunk = @app.content(type,key) if content_chunk && content_chunk.valid? content[name] = content_chunk.render end end
resolve_piece(piece)
click to toggle source
# File lib/stormy/chunk.rb, line 35 def resolve_piece(piece) name = (piece[:name] || piece[:type]).to_sym type = piece[:type] if piece[:key].present? resolve_content_piece(name,type,piece) else resolve_content_list(name,type,piece) end end
valid?()
click to toggle source
# File lib/stormy/chunk.rb, line 19 def valid? @template.present? && !@invalid_content end