lib/space/helpers.rb in space-0.0.3 vs lib/space/helpers.rb in space-0.0.4

- old
+ new

@@ -1,29 +1,48 @@ # encoding: UTF-8 require 'ansi/core' -require 'core_ext/string' +require 'core_ext/string/wrap' module Space module Helpers def project_title - "Project: #{app.name}".ansi(:bold) + "Project: #{name}".ansi(:bold) end - def repo_title - title = "#{repo.name.ansi(:bold)} [#{git.branch}, #{git.commit}] [#{repo.number}]" - title += " *" if repo_selected? - title + def tableize(string) + string.split(' ') + project.local_repos.join(', ') end + def repo_name + repo.name.ansi(:bold) + end + + def repo_status + [git.branch, git.commit, repo_local].compact.join(', ') + end + + def repo_local + 'L'.ansi(:bold, :red) if repo_local? + end + + def repo_local? + project.local_repos.include?(repo.name) + end + def repo_selected? - app.repos.scoped? && app.repos.include?(repo) + repos.scoped? && repos.scope.include?(repo) end def git_status - "Git: #{format_boolean(git.clean?)}" + "Git: #{format_boolean(git.clean?)}#{git_ahead if git.ahead?}" end + def git_ahead + " #{git.ahead} commit#{'s' if git.ahead > 1} ahead".ansi(:yellow) + end + def bundle_status "Bundle: #{format_boolean(bundle.clean?)}" end def bundle_info @@ -32,22 +51,18 @@ def bundle_deps bundle.deps.map { |dep| "• #{dep.ref} #{format_boolean(dep.fresh?)} #{dep.name}" }.join("\n") end - def bundle_local - repos = bundle.local_repos - "\nLocal: #{repos.join(', ')}\n" unless repos.empty? - end - def format_boolean(value) value ? '✔'.ansi(:green, :bold) : '⚡'.ansi(:red, :bold) end - def i(string) + def i(string, width = 2) lines = string.split("\n") lines = lines.map { |line| line.wrap(80).split("\n") }.flatten - lines = lines.map { |line| " #{line}" } + lines = lines.map { |line| [' ' * width, line].join } lines.join("\n") end end end +