Module: Maglev::EditorHelper

Defined in:
app/helpers/maglev/editor_helper.rb

Instance Method Summary collapse

Instance Method Details

#api_base_pathObject



18
19
20
# File 'app/helpers/maglev/editor_helper.rb', line 18

def api_base_path
  api_root_path
end

#editor_asset_path(source, default_source) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'app/helpers/maglev/editor_helper.rb', line 78

def editor_asset_path(source, default_source)
  if source.blank?
    vite_asset_path("images/#{default_source}")
  elsif source =~ %r{^(https?://|/)}
    source
  else
    # rely on Sprockets by default
    ActionController::Base.helpers.asset_path(source)
  end
end

#editor_custom_translationsObject



89
90
91
92
93
# File 'app/helpers/maglev/editor_helper.rb', line 89

def editor_custom_translations
  I18n.available_locales.index_with do |locale|
    ::I18n.t('maglev', locale: locale, default: nil)
  end
end

#editor_favicon_urlObject



63
64
65
66
67
68
69
70
71
72
# File 'app/helpers/maglev/editor_helper.rb', line 63

def editor_favicon_url
  case maglev_config.favicon
  when nil
    editor_asset_path(nil, 'favicon.svg')
  when String
    editor_asset_path(maglev_config.favicon, 'favicon.svg')
  when Proc
    instance_exec(maglev_site, &maglev_config.favicon)
  end
end

#editor_logo_urlObject



52
53
54
55
56
57
58
59
60
61
# File 'app/helpers/maglev/editor_helper.rb', line 52

def editor_logo_url
  case maglev_config.
  when nil
    editor_asset_path(nil, 'logo.svg')
  when String
    editor_asset_path(maglev_config., 'logo.svg')
  when Proc
    instance_exec(maglev_site, &maglev_config.)
  end
end

#editor_primary_hex_colorObject



33
34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/maglev/editor_helper.rb', line 33

def editor_primary_hex_color
  color = maglev_config.primary_color
  if color =~ /^\#(\d)(\d)(\d)$/
    r_value = ''.rjust(2, Regexp.last_match(1))
    g_value = ''.rjust(2, Regexp.last_match(2))
    b_value = ''.rjust(2, Regexp.last_match(3))
    "##{r_value}#{g_value}#{b_value}"
  else
    color
  end
end

#editor_primary_rgb_colorObject



45
46
47
48
49
50
# File 'app/helpers/maglev/editor_helper.rb', line 45

def editor_primary_rgb_color
  editor_primary_hex_color
    .gsub('#', '')
    .scan(/.{2}/)
    .map { |value| value.to_i(16) }
end

#editor_site_publishableObject



74
75
76
# File 'app/helpers/maglev/editor_helper.rb', line 74

def editor_site_publishable
  !!maglev_config.site_publishable
end

#editor_window_titleObject



22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/maglev/editor_helper.rb', line 22

def editor_window_title
  case maglev_config.title
  when nil
    'Maglev - EDITOR'
  when String
    maglev_config.title
  when Proc
    instance_exec(maglev_site, &maglev_config.title)
  end
end

#site_base_editor_pathObject

Path to the editor but without the locale



6
7
8
# File 'app/helpers/maglev/editor_helper.rb', line 6

def site_base_editor_path
  base_editor_path
end

#site_editor_pathObject



10
11
12
# File 'app/helpers/maglev/editor_helper.rb', line 10

def site_editor_path
  editor_path(locale: maglev_site.default_locale)
end

#site_leave_editor_pathObject



14
15
16
# File 'app/helpers/maglev/editor_helper.rb', line 14

def site_leave_editor_path
  leave_editor_path
end