Class: Devcenter::Commands::Preview
- Defined in:
- lib/devcenter/commands/preview.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ Preview
constructor
A new instance of Preview.
- #run ⇒ Object
- #validate ⇒ Object
Methods inherited from Base
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
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
#run ⇒ Object
23 24 25 |
# File 'lib/devcenter/commands/preview.rb', line 23 def run ::Devcenter::Previewer.preview(@slug, @md_path, @host, @port) end |
#validate ⇒ Object
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 |