Class: NicePartials::Partial::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/nice_partials/partial/content.rb

Direct Known Subclasses

Section

Defined Under Namespace

Classes: Options

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view_context, content = nil) ⇒ Content

Returns a new instance of Content.



12
13
14
15
# File 'lib/nice_partials/partial/content.rb', line 12

def initialize(view_context, content = nil)
  @view_context, @options = view_context, Options.new(view_context)
  @content = ActiveSupport::SafeBuffer.new and concat content
end

Instance Attribute Details

#optionsObject (readonly)

Contains options passed to a partial:

<% partial.title class: "post-title" %> # partial.title.options # => { class: "post-title" }

# Automatically runs `tag.attributes` when `to_s` is called, e.g.:
<h1 <% partial.title.options %>> # => <h1 class="post-title">


24
25
26
# File 'lib/nice_partials/partial/content.rb', line 24

def options
  @options
end

Instance Method Details

#writeObject



31
32
33
34
# File 'lib/nice_partials/partial/content.rb', line 31

def write(...)
  write?(...)
  self
end

#write?(content = nil, **new_options, &block) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/nice_partials/partial/content.rb', line 26

def write?(content = nil, **new_options, &block)
  @options.merge! new_options
  append content or capture block
end