Sha256: 61bb6032eea37d7e542073b65f5b04641420249d98574cb1ee192f9102d4fc38

Contents?: true

Size: 1.78 KB

Versions: 4

Compression:

Stored size: 1.78 KB

Contents

# frozen_string_literal: true

module Maglev
  module EditorHelper
    # Path to the editor but without the locale
    def site_base_editor_path
      base_editor_path
    end

    def site_editor_path
      editor_path(locale: maglev_site.default_locale)
    end

    def site_leave_editor_path
      leave_editor_path
    end

    def api_base_path
      "#{root_path}api"
    end

    def editor_window_title
      maglev_config.title.presence || 'Maglev - EDITOR'
    end

    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

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

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

    def editor_favicon_url
      editor_asset_path(maglev_config.favicon, 'favicon.png')
    end

    def editor_site_publishable
      !!maglev_config.site_publishable
    end

    def editor_asset_path(source, default_source)
      if source.blank?
        asset_path("maglev/#{default_source}")
      else
        ActionController::Base.helpers.asset_path(source)
      end
    end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
maglevcms-1.0.0 app/helpers/maglev/editor_helper.rb
maglevcms-1.0.0.rc3 app/helpers/maglev/editor_helper.rb
maglevcms-1.0.0.rc2 app/helpers/maglev/editor_helper.rb
maglevcms-1.0.0.rc1 app/helpers/maglev/editor_helper.rb