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



71
72
73
74
75
76
77
78
79
80
# File 'app/helpers/maglev/editor_helper.rb', line 71

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



82
83
84
85
86
# File 'app/helpers/maglev/editor_helper.rb', line 82

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

#editor_favicon_urlObject



56
57
58
59
60
61
62
63
64
65
# File 'app/helpers/maglev/editor_helper.rb', line 56

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

#editor_logo_urlObject



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

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

#editor_primary_hex_colorObject



26
27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/maglev/editor_helper.rb', line 26

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



38
39
40
41
42
43
# File 'app/helpers/maglev/editor_helper.rb', line 38

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

#editor_site_publishableObject



67
68
69
# File 'app/helpers/maglev/editor_helper.rb', line 67

def editor_site_publishable
  !!maglev_config.site_publishable
end

#editor_window_titleObject



22
23
24
# File 'app/helpers/maglev/editor_helper.rb', line 22

def editor_window_title
  maglev_config.title.presence || 'Maglev - EDITOR'
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