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



41
42
43
44
45
# File 'lib/buttonize/cli.rb', line 41

def button(text,outfile=nil)
  options = {"style_file" => EXAMPLE_STYLE_FILE, "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



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

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
  
  if !ButtonSet.current.options[:style_file]
    require EXAMPLE_STYLE_FILE
  end
  
  puts "Generating buttons...."
  ButtonSet.current.send(:generate_buttons,options)
end