Permalink
Browse files

'showoff serve' can take an argument to specify presentation directory

  • Loading branch information...
1 parent dd14958 commit df9e678ecdf36dcfcd8de16f84d8215beffe44e9 @alexch committed Apr 28, 2011
Showing with 11 additions and 10 deletions.
  1. +5 −1 bin/showoff
  2. +6 −9 lib/showoff.rb
View
@@ -66,9 +66,13 @@ command :serve do |c|
c.desc 'Host or ip to run on'
c.default_value "localhost"
c.flag [:h,:host]
+
+ c.desc 'Presentation directory'
+ c.default_value "."
+ c.arg_name "pres_dir"
@davetron5000

davetron5000 May 9, 2011

This will not do what you think. What you want is:

c.desc "Presentation directory"
c.default_value '.'
c.arg_name 'path_to_dir'
c.flag [:pres_dir,:pres-dir] # I like dashes :)
c.action do |global_options,options,args|
  ShowOff.run! :host => options[:h], :port => options[:p].to_i, :pres_dir => options[:pres_dir]
end

What you have works incidentally, but you didn't actually specify a flag named pres_dir so it won't get documented and can't be specified via a command-line option

@alexch

alexch May 9, 2011

Owner

I didn't want it specified via an option... just as an argument, e.g. "showoff serve foo". It felt right as an argument since we are serving that directory. Is there a reason to make it an option instead? Seemed like just more typing to me.

Also, I figured out CLI better and it up to where it's supposed to be in a later commit: 186bedc#L59R59

@davetron5000

davetron5000 May 9, 2011

I see; I didn't see your later commit. I dunno; my opinion is everything should be an option and that the actual arguments should be reserved for glob-friendly things (which, arguably, don't make sense for showoff anyway, so it's probably moot)

c.action do |global_options,options,args|
- ShowOff.run! :host => options[:h], :port => options[:p].to_i
+ ShowOff.run! :host => options[:h], :port => options[:p].to_i, :pres_dir => args[0]
end
end
View
@@ -37,20 +37,20 @@ class ShowOff < Sinatra::Application
set :views, File.dirname(__FILE__) + '/../views'
set :public, File.dirname(__FILE__) + '/../public'
- set :pres_dir, 'example'
def initialize(app=nil)
super(app)
- puts dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
- if Dir.pwd == dir
- options.pres_dir = dir + '/example'
+ showoff_dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+ if Dir.pwd == showoff_dir
+ options.pres_dir = "#{showoff_dir}/example"
@root_path = "."
else
- options.pres_dir = Dir.pwd
+ options.pres_dir ||= Dir.pwd
@root_path = ".."
end
+ options.pres_dir = File.expand_path(options.pres_dir)
+ puts "Serving presentation from #{options.pres_dir}"
@cached_image_size = {}
- puts options.pres_dir
@pres_name = options.pres_dir.split('/').pop
require_ruby_files
end
@@ -107,9 +107,6 @@ def process_markdown(name, content, static=false, pdf=false)
# extract id, defaulting to none
id = nil
content_classes.delete_if { |x| x =~ /^#([\w-]+)/ && id = $1 }
- puts "id: #{id}" if id
- puts "classes: #{content_classes.inspect}"
- puts "transition: #{transition}"
# create html
md += "<div"
md += " id=\"#{id}\"" if id

0 comments on commit df9e678

Please sign in to comment.