Class: Devcenter::Commands::Preview

Inherits:
Base
  • Object
show all
Defined in:
lib/devcenter/commands/preview.rb

Instance Method Summary collapse

Methods inherited from Base

run

Methods included from Helpers

#article_api_path, #article_path, #article_url?, #broken_link_checks_path, #devcenter_base_url, #get_oauth_token, #html_file_path, #md_file_path, #netrc_path, #search_api_path, #slug_from_article_url, #update_article_path, #validate_article_path, #write_file

Methods included from Logger

active=, active?, #log

Constructor Details

#initialize(*args) ⇒ Preview

Returns a new instance of Preview.



5
6
7
8
9
10
11
# File 'lib/devcenter/commands/preview.rb', line 5

def initialize(*args)
  @slug = args[0].to_s.gsub(/.md\z/, '') # maybe the user provides the filename by mistake
  @host = args[1]
  @port = args[2]
  @md_path = md_file_path(@slug)
  super
end

Instance Method Details

#runObject



23
24
25
# File 'lib/devcenter/commands/preview.rb', line 23

def run
  ::Devcenter::Previewer.preview(@slug, @md_path, @host, @port)
end

#validateObject



13
14
15
16
17
18
19
20
21
# File 'lib/devcenter/commands/preview.rb', line 13

def validate
  empty_slug = @slug.nil? || @slug.to_s.strip.empty?
  file_exists = !empty_slug && File.exists?(@md_path)
  if empty_slug
    @validation_errors << 'Please provide an article slug'
  elsif !file_exists
    @validation_errors << "Can't find #{@md_path} file - you may want to `devcenter pull #{@slug}`"
  end
end