Class: Occams::Content::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/occams/content/tag.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context:, params: [], source: nil) ⇒ Tag

Returns a new instance of Tag.

Parameters:

  • context (Occams::Cms::WithFragments)
  • params (Array<String, {String => String}>) (defaults to: [])
  • source (String, nil) (defaults to: nil)


18
19
20
21
22
# File 'lib/occams/content/tag.rb', line 18

def initialize(context:, params: [], source: nil)
  @context  = context
  @params   = params
  @source   = source
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



7
8
9
# File 'lib/occams/content/tag.rb', line 7

def context
  @context
end

#paramsObject (readonly)

Returns the value of attribute params.



10
11
12
# File 'lib/occams/content/tag.rb', line 10

def params
  @params
end

#sourceObject (readonly)

Returns the value of attribute source.



13
14
15
# File 'lib/occams/content/tag.rb', line 13

def source
  @source
end

Instance Method Details

#allow_erb?Boolean

Making sure we don’t leak erb from tags by accident. Tag classes can override this, like partials/helpers tags.

Returns:

  • (Boolean)


26
27
28
# File 'lib/occams/content/tag.rb', line 26

def allow_erb?
  Occams.config.allow_erb
end

#contentString

Returns:

  • (String)

Raises:



40
41
42
# File 'lib/occams/content/tag.rb', line 40

def content
  raise Error, 'This is a base class. It holds no content'
end

#nodesArray<String, Occams::Content::Tag>

Normally it’s a (String). However, if tag content has tags, we need to expand them and that produces potentially more stuff.

Returns:



33
34
35
36
37
# File 'lib/occams/content/tag.rb', line 33

def nodes
  template  = Occams::Content::Renderer.new(@context)
  tokens    = template.tokenize(content)
  template.nodes(tokens)
end

#renderString

Returns:

  • (String)


45
46
47
# File 'lib/occams/content/tag.rb', line 45

def render
  content
end