Module: Hyde::CLI::Helpers

Included in:
Hyde::CLI
Defined in:
lib/hyde/cli/helpers.rb

Instance Method Summary collapse

Instance Method Details

#gem_name(e) ⇒ Object

Gets the gem name from a LoadError exception.



60
61
62
63
64
65
# File 'lib/hyde/cli/helpers.rb', line 60

def gem_name(e)
  name = e.message.split(' ').last
  name = 'RedCloth'  if name == 'redcloth'
  name = 'haml'  if name == 'sass/plugin'
  name
end

#no_projectObject



46
47
48
49
50
51
52
53
# File 'lib/hyde/cli/helpers.rb', line 46

def no_project
  "Error: no Hyde config file found.\n" +
  "(Looked for #{Hyde::CONFIG_FILES.join(', ')})\n\n" +
  "You start by creating a config file for this project:\n" +
  "  $ #{executable} create .\n\n" +
  "You may also create an empty project in a new directory:\n" +
  "  $ #{executable} create NAME\n"
end

#other_tasksObject



22
23
24
# File 'lib/hyde/cli/helpers.rb', line 22

def other_tasks
  tasks.select { |name, t| t.category.nil? }
end

#projectObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/hyde/cli/helpers.rb', line 67

def project
  @project ||= begin
    pass no_project unless project?
    Dir.chdir File.dirname(@hydefile)

    begin
      project = Hyde::Project.new
      pass no_project  unless project.config_file?
    rescue LegacyError
      err "This is a legacy Hyde project."
      err "To force it, try editing `hyde.conf` and upgrade the version line to `hyde_requirement: 0.1`."
      pass
    rescue VersionError => e
      err e.message
      pass
    end

    project
  end
end

#project?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/hyde/cli/helpers.rb', line 55

def project?
  !! @hydefile
end

#say_error(str) ⇒ Object



30
31
32
# File 'lib/hyde/cli/helpers.rb', line 30

def say_error(str)
  say_status 'error', str, 31
end

#say_info(str) ⇒ Object



26
27
28
# File 'lib/hyde/cli/helpers.rb', line 26

def say_info(str)
  say_status '*', str, 30
end

#say_status(what, cmd, color = 32) ⇒ Object



34
35
36
37
38
# File 'lib/hyde/cli/helpers.rb', line 34

def say_status(what, cmd, color=32)
  c1 = "\033[0;#{color}m"
  c0 = "\033[0;m"
  puts "#{c1}%10s#{c0}  %s" % [ what, cmd ]
end

#show_help_for(name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/hyde/cli/helpers.rb', line 4

def show_help_for(name)
  task = task(name)
  pass "No such command. Try: #{executable} help"  unless task

  help = task.help
  if help
    help.each { |line| err line }
    err
  else
    err "Usage: #{executable} #{task.usage || name}"
    err "#{task.description}."  if task.description
  end
end

#show_needed_gem(name) ⇒ Object



40
41
42
43
44
# File 'lib/hyde/cli/helpers.rb', line 40

def show_needed_gem(name)
  err
  say_error "You will need additional gems for this project."
  say_info "To install: gem install #{name}"
end

#tasks_for(category) ⇒ Object



18
19
20
# File 'lib/hyde/cli/helpers.rb', line 18

def tasks_for(category)
  tasks.select { |name, t| t.category == category }
end