Class: Maglev::Content::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
app/components/maglev/content/base.rb

Direct Known Subclasses

Checkbox, CollectionItem, Color, Icon, Image, Link, Select, Text

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, content, setting) ⇒ Base

Scope can be either a section or a block



12
13
14
15
16
# File 'app/components/maglev/content/base.rb', line 12

def initialize(scope, content, setting)
  @scope = scope
  @content = content
  @setting = setting
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



9
10
11
# File 'app/components/maglev/content/base.rb', line 9

def content
  @content
end

#scopeObject

Returns the value of attribute scope.



9
10
11
# File 'app/components/maglev/content/base.rb', line 9

def scope
  @scope
end

#settingObject

Returns the value of attribute setting.



9
10
11
# File 'app/components/maglev/content/base.rb', line 9

def setting
  @setting
end

Instance Method Details

#asset_hostObject



40
41
42
43
44
45
46
47
48
49
# File 'app/components/maglev/content/base.rb', line 40

def asset_host
  case config.asset_host
  when nil
    nil
  when String
    config.asset_host
  when Proc
    instance_exec(site, &config.asset_host)
  end
end

#dom_dataObject

rubocop:disable Rails/OutputSafety



19
20
21
# File 'app/components/maglev/content/base.rb', line 19

def dom_data
  "data-maglev-id=\"#{tag_id}\"".html_safe
end

#tag(_view_context, _options) ⇒ Object



36
37
38
# File 'app/components/maglev/content/base.rb', line 36

def tag(_view_context, _options)
  to_s
end

#tag_dataObject

rubocop:enable Rails/OutputSafety



24
25
26
# File 'app/components/maglev/content/base.rb', line 24

def tag_data
  { maglev_id: tag_id }
end

#tag_idObject



28
29
30
# File 'app/components/maglev/content/base.rb', line 28

def tag_id
  "#{scope.id}.#{setting.id}"
end

#to_sObject



32
33
34
# File 'app/components/maglev/content/base.rb', line 32

def to_s
  content || ''
end