Sha256: 3704e52fa242fecf541278e1f4c752814ed392bb852552fdd397e3a0bd7fd3dd

Contents?: true

Size: 988 Bytes

Versions: 1

Compression:

Stored size: 988 Bytes

Contents

module Devcenter::Helpers

  def devcenter_base_url
    ENV['DEVCENTER_BASE_URL'] || 'https://devcenter.heroku.com'
  end

  def article_path(slug)
    "/articles/#{slug}"
  end

  def article_api_path(slug)
    "#{article_path(slug)}.json"
  end

  def search_api_path
    "/articles.json"
  end

  def validate_article_path(id)
    "/api/v1/private/articles/#{id}/validate.json"
  end

  def update_article_path(id)
    "/api/v1/private/articles/#{id}.json"
  end

  def article_url?(url)
    escaped_base_url = devcenter_base_url.gsub('/','\\/')
    url.match(/\A#{escaped_base_url}\/articles\/.+/)
    true
  end

  def slug_from_article_url(url)
    return nil unless url
    url.split('/articles/').last.split('?').first.split('#').first
  end

  def md_file_path(slug)
    File.expand_path("#{slug}.md")
  end

  def html_file_path(slug)
    File.expand_path("#{slug}.html")
  end

  def write_file(filename, content)
    File.open(filename, 'w'){ |f| f.write(content) }
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
devcenter-1.1.0rc1 lib/devcenter/helpers.rb