Class: ComfortableMexicanSofa::Content::Tag

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

Defined Under Namespace

Modules: Mixins Classes: Asset, Checkbox, Date, Datetime, Error, File, FileLink, Files, Fragment, Helper, Markdown, Number, PageFileLink, Partial, Snippet, Template, Text, TextArea, Wysiwyg

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Tag.

Parameters:

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


19
20
21
22
23
# File 'lib/comfortable_mexican_sofa/content/tag.rb', line 19

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

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



8
9
10
# File 'lib/comfortable_mexican_sofa/content/tag.rb', line 8

def context
  @context
end

#paramsObject (readonly)

Returns the value of attribute params.



11
12
13
# File 'lib/comfortable_mexican_sofa/content/tag.rb', line 11

def params
  @params
end

#sourceObject (readonly)

Returns the value of attribute source.



14
15
16
# File 'lib/comfortable_mexican_sofa/content/tag.rb', line 14

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)


27
28
29
# File 'lib/comfortable_mexican_sofa/content/tag.rb', line 27

def allow_erb?
  ComfortableMexicanSofa.config.allow_erb
end

#contentString

Returns:

  • (String)

Raises:



41
42
43
# File 'lib/comfortable_mexican_sofa/content/tag.rb', line 41

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

#nodesArray<String, ComfortableMexicanSofa::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:



34
35
36
37
38
# File 'lib/comfortable_mexican_sofa/content/tag.rb', line 34

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

#renderString

Returns:

  • (String)


46
47
48
# File 'lib/comfortable_mexican_sofa/content/tag.rb', line 46

def render
  content
end