Module: Devcenter::Helpers
- Included in:
- Client, Commands::Base
- Defined in:
- lib/devcenter/helpers.rb
Instance Method Summary collapse
- #article_api_path(slug) ⇒ Object
- #article_path(slug) ⇒ Object
- #article_url?(url) ⇒ Boolean
- #devcenter_base_url ⇒ Object
- #html_file_path(slug) ⇒ Object
- #md_file_path(slug) ⇒ Object
- #search_api_path ⇒ Object
- #slug_from_article_url(url) ⇒ Object
- #write_file(filename, content) ⇒ Object
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
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_url ⇒ Object
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.("#{slug}.html") end |
#md_file_path(slug) ⇒ Object
30 31 32 |
# File 'lib/devcenter/helpers.rb', line 30 def md_file_path(slug) File.("#{slug}.md") end |
#search_api_path ⇒ Object
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 |