Module: Devcenter::Helpers

Included in:
Client, Commands::Base
Defined in:
lib/devcenter/helpers.rb

Instance Method Summary collapse

Instance Method Details

#article_api_path(slug) ⇒ Object



11
12
13
# File 'lib/devcenter/helpers.rb', line 11

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

#article_path(slug) ⇒ Object



7
8
9
# File 'lib/devcenter/helpers.rb', line 7

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

#article_url?(url) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/devcenter/helpers.rb', line 19

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

#devcenter_base_urlObject



3
4
5
# File 'lib/devcenter/helpers.rb', line 3

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

#html_file_path(slug) ⇒ Object



34
35
36
# File 'lib/devcenter/helpers.rb', line 34

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

#md_file_path(slug) ⇒ Object



30
31
32
# File 'lib/devcenter/helpers.rb', line 30

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

#search_api_pathObject



15
16
17
# File 'lib/devcenter/helpers.rb', line 15

def search_api_path
  "/articles.json"
end

#slug_from_article_url(url) ⇒ Object



25
26
27
28
# File 'lib/devcenter/helpers.rb', line 25

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

#write_file(filename, content) ⇒ Object



38
39
40
# File 'lib/devcenter/helpers.rb', line 38

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