Sha256: 7bd447689f7169b6978fc71bdcef9df65de3ebab2408738514c1ea9f68fa0df4

Contents?: true

Size: 1.97 KB

Versions: 23

Compression:

Stored size: 1.97 KB

Contents

class Footer
  attr_reader :items

  def initialize(items: nil)
    @items = items

    after_initialize!
  end

  def footer_from_config(config)
    config = YAML.safe_load(open_config(config))
    {
      name: config['name'],
      subtitle: config['subtitle'],
      logo_path: config['assets']['footer_logo']['path'],
      logo_alt: config['assets']['footer_logo']['alt'],
      status: config['footer']['links']['status'],
      social_links: config['footer']['links']['social'],
      navigation_links: config['footer']['links']['navigation'],
      support_links: config['footer']['links']['support'],
    }
  end

  def self.navigation_category_titleize(title)
    if title.include?('-')
      title_split = title.split('-').map do |word|
        word == 'api' ? word.upcase : word.titleize
      end
      title = title_split.join(' ')
    else
      title = title.titleize
    end
    title
  end

  def self.navigation_link(link)
    link.values.join(' ')
  end

  def self.navigation_link_text(link)
    text = link.keys.join(' ')
    if text.include?('-')
      link_split = text.split('-').map do |word|
        if word == 'api'
          word.upcase
        elsif word == 'apis'
          'APIs'
        else
          word.titleize
        end
      end
      link = link_split.join(' ')
    elsif text == 'sms'
      link = text.upcase
    else
      link = text.titleize
    end
    link
  end

  def self.support_link(link)
    if link.include?('@')
      "mailto:#{link}"
    else
      link
    end
  end

  def self.support_link_text(link)
    link.titleize
  end

  def open_config(config)
    File.open(config)
  end

  def config_exist?(path)
    File.exist?(path)
  end

  private

  def after_initialize!
    raise 'You must provide a config/business_info.yml file in your documentation path.' unless config_exist?("#{Rails.configuration.docs_base_path}/config/business_info.yml")

    @items = footer_from_config("#{Rails.configuration.docs_base_path}/config/business_info.yml")
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
station-0.0.120 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.119 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.118 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.115 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.114 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.113 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.112 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.111 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.110 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.109 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.108 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.107 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.106 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.105 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.104 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.103 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.102 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.101 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.100 lib/nexmo_developer/app/presenters/footer.rb
station-0.0.97 lib/nexmo_developer/app/presenters/footer.rb