Class: Maglev::Content::Base

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

Direct Known Subclasses

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Inspector

#inspect

Constructor Details

#initialize(scope, content, setting) ⇒ Base

Scope can be either a section or a block



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

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

Instance Attribute Details

#contentObject

Returns the value of attribute content.



11
12
13
# File 'app/components/maglev/content/base.rb', line 11

def content
  @content
end

#scopeObject

Returns the value of attribute scope.



11
12
13
# File 'app/components/maglev/content/base.rb', line 11

def scope
  @scope
end

#settingObject

Returns the value of attribute setting.



11
12
13
# File 'app/components/maglev/content/base.rb', line 11

def setting
  @setting
end

Instance Method Details

#asset_hostObject



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

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



21
22
23
# File 'app/components/maglev/content/base.rb', line 21

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

#tag(_view_context, _options) ⇒ Object



38
39
40
# File 'app/components/maglev/content/base.rb', line 38

def tag(_view_context, _options)
  to_s
end

#tag_dataObject

rubocop:enable Rails/OutputSafety



26
27
28
# File 'app/components/maglev/content/base.rb', line 26

def tag_data
  { maglev_id: tag_id }
end

#tag_idObject



30
31
32
# File 'app/components/maglev/content/base.rb', line 30

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

#to_sObject



34
35
36
# File 'app/components/maglev/content/base.rb', line 34

def to_s
  content || ''
end