Class: RegisteredContent

Inherits:
Object show all
Defined in:
lib/rails_ext/action_controller/content_for_assignments.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, target, *args, &block) ⇒ RegisteredContent

Returns a new instance of RegisteredContent.



60
61
62
63
64
65
66
67
# File 'lib/rails_ext/action_controller/content_for_assignments.rb', line 60

def initialize(id, target, *args, &block)
  @id = id
  @target = target
  @options = args.extract_options!
  @content = block_given? ? block : args.first
  
  normalize_options!
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



58
59
60
# File 'lib/rails_ext/action_controller/content_for_assignments.rb', line 58

def content
  @content
end

#idObject (readonly)

Returns the value of attribute id.



58
59
60
# File 'lib/rails_ext/action_controller/content_for_assignments.rb', line 58

def id
  @id
end

#optionsObject (readonly)

Returns the value of attribute options.



58
59
60
# File 'lib/rails_ext/action_controller/content_for_assignments.rb', line 58

def options
  @options
end

#targetObject (readonly)

Returns the value of attribute target.



58
59
60
# File 'lib/rails_ext/action_controller/content_for_assignments.rb', line 58

def target
  @target
end

Instance Method Details

#applies?(view) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
77
# File 'lib/rails_ext/action_controller/content_for_assignments.rb', line 73

def applies?(view)
  included = options[:only] ? condition_applies?(:only, view) : true
  excluded = options[:except] ? condition_applies?(:except, view) : false
  included and not excluded
end

#render(view) ⇒ Object



69
70
71
# File 'lib/rails_ext/action_controller/content_for_assignments.rb', line 69

def render(view)
  view.content_for(target, eval_content(view)) if applies?(view)
end