Class: MagicReveal::Cli

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/magic_reveal/cli.rb,
lib/magic_reveal/cli/options.rb

Defined Under Namespace

Classes: Options

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#creatorObject



44
45
46
# File 'lib/magic_reveal/cli.rb', line 44

def creator
  @creator ||= Creator.new(Dir.getwd)
end

Class Method Details

.run(args = ARGV) ⇒ Object

Helper method



21
22
23
# File 'lib/magic_reveal/cli.rb', line 21

def self.run args=ARGV
  self.new.run args
end

Instance Method Details

#avenge_programmerObject



73
74
75
76
77
# File 'lib/magic_reveal/cli.rb', line 73

def avenge_programmer
  puts "The programmer messed up."
  puts "Please file a bug at https://github.com/docwhat/magic_reveal"
  exit 13
end

#create_staticObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/magic_reveal/cli.rb', line 55

def create_static
  slides = Pathname.pwd + 'slides.md'
  markdown =  SlideRenderer.markdown_renderer
  libber = IndexLibber.new
  config = ProjectConfig.new(Pathname.pwd + 'config.json')

  libber.author = Identifier.name
  libber.slides = markdown.render slides.read

  libber.add_github_forkme config.json['github'] if config.json.key? 'github'

  index_html = Pathname.pwd + 'index.html'
  index_html.open('w') { |f| f.print libber }

  js_file = Pathname.pwd + 'index.js'
  js_file.open('w') { |f| f.print config.to_js }
end

#optionsObject



79
80
81
# File 'lib/magic_reveal/cli.rb', line 79

def options
  @options ||= Options.new
end

#run(args = ARGV) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/magic_reveal/cli.rb', line 83

def run args=ARGV
  options.parse args

  case command
  when :new
    creator.create_project(project)
  when :force_reload
    theyre_sure = (ask('This may overwrite customizations. Are you sure? (y/N) ') { |q| q.limit = 1; q.case = :downcase }) == 'y'
    creator.update_project(Dir.getwd) if theyre_sure
  when :start
    start_server
  when :static
    create_static
  when :help
    show_help
  else
    avenge_programmer
  end
end

#show_helpObject

Action Classes



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/magic_reveal/cli.rb', line 26

def show_help
  puts "Usage: #{program_name} <command>"
  puts
  puts '  new <name>'
  puts '    Creates new presentation in directory <name>'
  puts
  puts '  force-reload'
  puts '    Refreshes the reveal.js files. WARNING: This may override customizations!'
  puts
  puts '  start [options]'
  puts '    Starts serving the presentation in the current directory'
  puts
  puts '  static'
  puts '    Creates a static index.html file from your slides'
  puts
  exit
end

#start_serverObject



48
49
50
51
52
53
# File 'lib/magic_reveal/cli.rb', line 48

def start_server
  require 'rack'
  ARGV.shift
  Rack::Server.start
  exit
end