Module: Ink::Command

Extended by:
Command
Included in:
Command
Defined in:
lib/ink/command.rb

Constant Summary collapse

COMMANDS =
%w[help list show version]

Instance Method Summary collapse

Instance Method Details

#baseObject



28
29
30
# File 'lib/ink/command.rb', line 28

def base
  File.join(Pathname.new(File.dirname(__FILE__)).realpath, "..", "..", "stylesheets")
end

#helpObject



18
19
20
21
22
23
24
25
26
# File 'lib/ink/command.rb', line 18

def help
  puts <<-TXT
Usage:
  ink help        # Display helper info
  ink list        # List all available stylesheets
  ink show [NAME] # Display the stylesheet for the specified name
  ink version     # Prints the ink's version information
TXT
end

#listObject



53
54
55
56
# File 'lib/ink/command.rb', line 53

def list
  puts "Available stylesheets:"
  puts names.collect {|name| " * #{name}"}.join("\n")
end

#namesObject



49
50
51
# File 'lib/ink/command.rb', line 49

def names
  Dir["#{base}/*.css"].collect {|file| File.basename(file).gsub(/\.css$/, "") }
end

#run!Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/ink/command.rb', line 7

def run!
  command = ARGV[0]

  unless COMMANDS.include?(command)
    help
    exit 1
  end

  send(command)
end

#showObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ink/command.rb', line 36

def show
  name = ARGV[1]

  unless names.include?(name)
    puts "ERROR: #{name.inspect} is not a valid name."
    puts ""
    list
    exit 1
  end

  puts File.read(base + "/#{name}.css")
end

#versionObject



32
33
34
# File 'lib/ink/command.rb', line 32

def version
  puts Ink::Version::STRING
end