Commit b15bb507 authored by Fabio Pelosin's avatar Fabio Pelosin

[pod-list] Presenter now just renders and doesn't puts text directly + related minor changes

parent 081643b0
require 'time'
module Pod
class Command
class List < Command
......@@ -16,7 +15,7 @@ module Pod
def self.options
" --update runs `pod repo update` before list\n" +
SetPresent.options + super
Presenter.options + super
end
extend Executable
......@@ -30,8 +29,9 @@ module Pod
end
def list_all
@presenter.present_sets(all = Source.all_sets)
puts "#{all.count} pods were found"
sets = Source.all_sets
puts @presenter.render(sets)
puts "#{sets.count} pods were found"
puts
end
......@@ -57,21 +57,14 @@ module Pod
sets = groups[d]
next unless sets
puts "Pods added in the last #{d == 1 ? '1 day' : "#{d} days"}".yellow
@presenter.present_sets(sets.sort_by {|set| creation_dates[set.name]})
puts @presenter.render(sets.sort_by {|set| creation_dates[set.name]})
end
end
def run
if @update
puts "\nUpdating Spec Repositories\n".yellow if config.verbose?
Repo.new(ARGV.new(["update"])).run
end
if @new
list_new
else
list_all
end
puts "\nUpdating Spec Repositories\n".yellow if @update && config.verbose?
Repo.new(ARGV.new(["update"])).run if @update
@new ? list_new : list_all
end
end
end
......
......@@ -11,20 +11,23 @@ module Pod
@stats = argv.option('--stats')
end
def present_sets(array)
puts
array.each {|set| present_set(set)}
def render(array)
result = "\n"
array.each {|set| result << render_set(set)}
result
end
def present_set(set)
def render_set(set)
pod = CocoaPod.new(set)
puts "--> #{pod.name} (#{pod.versions})".green
puts wrap_string(pod.summary)
puts_detail('Homepage', pod.homepage)
puts_detail('Source', pod.source_url)
puts_detail('Watchers', pod.github_watchers) if @stats
puts_detail('Forks', pod.github_forks) if @stats
puts
result = "--> #{pod.name} (#{pod.versions})\n".green
result << wrap_string(pod.summary)
result << detail('Homepage', pod.homepage)
result << detail('Source', pod.source_url)
result << detail('Platform', pod.platform) if @stats
result << detail('License', pod.license) if @stats
result << detail('Watchers', pod.github_watchers) if @stats
result << detail('Forks', pod.github_forks) if @stats
result << "\n"
end
private
......@@ -35,12 +38,12 @@ module Pod
txt.strip.gsub(/(.{1,#{col}})( +|$)\n?|(.{#{col}})/, indent + "\\1\\3\n")
end
def puts_detail(title, string, preferred_indentation = 8)
def detail(title, string, preferred_indentation = 8)
# 8 is the length of Homepage
return if !string
return '' if !string
number_of_spaces = ((preferred_indentation - title.length) > 0) ? (preferred_indentation - title.length) : 0
spaces = ' ' * number_of_spaces
puts " - #{title}: #{spaces + string}"
" - #{title}: #{spaces + string}\n"
end
end
end
......
......@@ -38,6 +38,14 @@ module Pod
spec.source.reject {|k,_| k == :commit || k == :tag }.values.first
end
def platform
spec.platform.to_s
end
def license
spec.license[:type] if spec.license
end
def creation_date
Pod::Specification::Statistics.instance.creation_date(@set)
end
......
......@@ -25,7 +25,7 @@ module Pod
def run
sets = Source.search_by_name(@query.strip, @full_text_search)
@presenter.present_sets(sets)
puts @presenter.render(sets)
end
end
end
......
......@@ -20,7 +20,14 @@ module Pod
end
def to_s
name.to_s
case @symbolic_name
when :ios
'iOS'
when :osx
'OS X'
else
'iOS - OS X'
end
end
def to_sym
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment