Class: Buttonize::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/buttonize/cli.rb

Instance Method Summary collapse

Instance Method Details

#button(text, outfile = nil) ⇒ Object



36
37
38
39
40
# File 'lib/buttonize/cli.rb', line 36

def button(text,outfile=nil)
  options = {"style_file" => File.join(File.dirname(__FILE__),"../../examples/default/styles.rb"), "style_set" => :default}.update(self.options)
  style = get_style(options["style_file"],options["style_set"],options["style"])
  Buttonize::Button.new(style).generate(text,outfile)
end

#generate(buttonset) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/buttonize/cli.rb', line 11

def generate(buttonset)
  options = self.options.inject({}){|mem,h| mem[h[0].to_sym] = h[1]; mem}
    
  target_path = options[:target_path]
  if !target_path
    target_path = File.join(Dir.pwd,"buttons")
    FileUtils.mkdir_p(target_path) if !File.directory?(target_path)
  end

  options[:target_path] ||= target_path

  Buttonize.run_in_cli!
    
  # Load the buttonset
  require buttonset    
  raise "Are you sure #{buttonset} is a buttonset file?" if !ButtonSet.current
  
  puts "Generating buttons...."
  ButtonSet.current.send(:generate_buttons,options)
end