From 6d4d35b54b134514f2ee8987c8496ea5bfb1f81b Mon Sep 17 00:00:00 2001 From: Nikolay Shebanov Date: Mon, 15 Apr 2013 21:43:08 +0400 Subject: [PATCH] Open slides in browser from console Add Launchy dependency Use Launchy.open to call browser window with the generated presentation --- keydown.gemspec | 1 + lib/keydown.rb | 1 + lib/keydown/tasks/slides.rb | 7 ++++--- spec/spec_helper.rb | 6 ++++++ spec/tasks/slides_spec.rb | 12 +++++++++++- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/keydown.gemspec b/keydown.gemspec index 41bb246..3645771 100644 --- a/keydown.gemspec +++ b/keydown.gemspec @@ -18,6 +18,7 @@ Gem::Specification.new do |s| s.add_dependency 'sass' s.add_dependency 'compass' s.add_dependency 'github-markdown' + s.add_dependency 'launchy' s.add_development_dependency "rake" s.add_development_dependency "rspec" diff --git a/lib/keydown.rb b/lib/keydown.rb index 4002270..9fec17d 100644 --- a/lib/keydown.rb +++ b/lib/keydown.rb @@ -1,6 +1,7 @@ require 'ostruct' require 'digest/sha1' require 'tilt' +require 'launchy' require 'version' require 'keydown/html_helpers' diff --git a/lib/keydown/tasks/slides.rb b/lib/keydown/tasks/slides.rb index 5060c29..b99c60a 100644 --- a/lib/keydown/tasks/slides.rb +++ b/lib/keydown/tasks/slides.rb @@ -7,7 +7,6 @@ class Tasks < Thor desc "slides FILE", "Convert a Keydown FILE into an HTML presentation" def slides(file) - file += '.md' unless file.match(/\.md$/) unless File.exist?(file) @@ -36,9 +35,11 @@ def slides(file) presentation = file.gsub('md', 'html') - create_file presentation, :force => true do + output = create_file presentation, :force => true do slide_deck.to_html end + + Launchy.open File.join(Dir.pwd, presentation) end end -end \ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1bbdbdb..b49102f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,3 +12,9 @@ def capture_output ensure $stdout = STDOUT end + +RSpec.configure do |config| + config.before(:each) do + Launchy.stub(:open) + end +end diff --git a/spec/tasks/slides_spec.rb b/spec/tasks/slides_spec.rb index 6602463..f05bb67 100644 --- a/spec/tasks/slides_spec.rb +++ b/spec/tasks/slides_spec.rb @@ -19,7 +19,7 @@ end let :tmp_dir do - "#{Dir.tmpdir}/keydown_test" + "#{File.realdirpath(Dir.tmpdir)}/keydown_test" end let :project_dir do @@ -64,6 +64,16 @@ system "cp -r spec/fixtures/with_title.md #{project_dir}" end + it "should open resulting html file in the browser" do + Launchy.should_receive(:open).with("#{project_dir}/with_title.html") + + capture_output do + Dir.chdir project_dir do + @thor.invoke Keydown::Tasks, ["slides", "with_title.md"] + end + end + end + describe "should generate an html file that" do before(:each) do capture_output do