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 module Pod
class Command class Command
class List < Command class List < Command
...@@ -16,22 +15,23 @@ module Pod ...@@ -16,22 +15,23 @@ module Pod
def self.options def self.options
" --update runs `pod repo update` before list\n" + " --update runs `pod repo update` before list\n" +
SetPresent.options + super Presenter.options + super
end end
extend Executable extend Executable
executable :git executable :git
def initialize(argv) def initialize(argv)
@update = argv.option('--update') @update = argv.option('--update')
@new = argv.option('new') @new = argv.option('new')
@presenter = Presenter.new(argv) @presenter = Presenter.new(argv)
super unless argv.empty? super unless argv.empty?
end end
def list_all def list_all
@presenter.present_sets(all = Source.all_sets) sets = Source.all_sets
puts "#{all.count} pods were found" puts @presenter.render(sets)
puts "#{sets.count} pods were found"
puts puts
end end
...@@ -57,21 +57,14 @@ module Pod ...@@ -57,21 +57,14 @@ module Pod
sets = groups[d] sets = groups[d]
next unless sets next unless sets
puts "Pods added in the last #{d == 1 ? '1 day' : "#{d} days"}".yellow 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
end end
def run def run
if @update puts "\nUpdating Spec Repositories\n".yellow if @update && config.verbose?
puts "\nUpdating Spec Repositories\n".yellow if config.verbose? Repo.new(ARGV.new(["update"])).run if @update
Repo.new(ARGV.new(["update"])).run @new ? list_new : list_all
end
if @new
list_new
else
list_all
end
end end
end end
end end
......
...@@ -11,20 +11,23 @@ module Pod ...@@ -11,20 +11,23 @@ module Pod
@stats = argv.option('--stats') @stats = argv.option('--stats')
end end
def present_sets(array) def render(array)
puts result = "\n"
array.each {|set| present_set(set)} array.each {|set| result << render_set(set)}
result
end end
def present_set(set) def render_set(set)
pod = CocoaPod.new(set) pod = CocoaPod.new(set)
puts "--> #{pod.name} (#{pod.versions})".green result = "--> #{pod.name} (#{pod.versions})\n".green
puts wrap_string(pod.summary) result << wrap_string(pod.summary)
puts_detail('Homepage', pod.homepage) result << detail('Homepage', pod.homepage)
puts_detail('Source', pod.source_url) result << detail('Source', pod.source_url)
puts_detail('Watchers', pod.github_watchers) if @stats result << detail('Platform', pod.platform) if @stats
puts_detail('Forks', pod.github_forks) if @stats result << detail('License', pod.license) if @stats
puts result << detail('Watchers', pod.github_watchers) if @stats
result << detail('Forks', pod.github_forks) if @stats
result << "\n"
end end
private private
...@@ -35,12 +38,12 @@ module Pod ...@@ -35,12 +38,12 @@ module Pod
txt.strip.gsub(/(.{1,#{col}})( +|$)\n?|(.{#{col}})/, indent + "\\1\\3\n") txt.strip.gsub(/(.{1,#{col}})( +|$)\n?|(.{#{col}})/, indent + "\\1\\3\n")
end end
def puts_detail(title, string, preferred_indentation = 8) def detail(title, string, preferred_indentation = 8)
# 8 is the length of Homepage # 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 number_of_spaces = ((preferred_indentation - title.length) > 0) ? (preferred_indentation - title.length) : 0
spaces = ' ' * number_of_spaces spaces = ' ' * number_of_spaces
puts " - #{title}: #{spaces + string}" " - #{title}: #{spaces + string}\n"
end end
end end
end end
......
...@@ -38,6 +38,14 @@ module Pod ...@@ -38,6 +38,14 @@ module Pod
spec.source.reject {|k,_| k == :commit || k == :tag }.values.first spec.source.reject {|k,_| k == :commit || k == :tag }.values.first
end end
def platform
spec.platform.to_s
end
def license
spec.license[:type] if spec.license
end
def creation_date def creation_date
Pod::Specification::Statistics.instance.creation_date(@set) Pod::Specification::Statistics.instance.creation_date(@set)
end end
......
...@@ -25,7 +25,7 @@ module Pod ...@@ -25,7 +25,7 @@ module Pod
def run def run
sets = Source.search_by_name(@query.strip, @full_text_search) sets = Source.search_by_name(@query.strip, @full_text_search)
@presenter.present_sets(sets) puts @presenter.render(sets)
end end
end end
end end
......
module Pod module Pod
class Platform class Platform
attr_reader :options attr_reader :options
def initialize(symbolic_name, options = {}) def initialize(symbolic_name, options = {})
@symbolic_name = symbolic_name @symbolic_name = symbolic_name
@options = options @options = options
end end
def name def name
@symbolic_name @symbolic_name
end end
def ==(other_platform_or_symbolic_name) def ==(other_platform_or_symbolic_name)
if other_platform_or_symbolic_name.is_a?(Symbol) if other_platform_or_symbolic_name.is_a?(Symbol)
@symbolic_name == other_platform_or_symbolic_name @symbolic_name == other_platform_or_symbolic_name
...@@ -18,25 +18,32 @@ module Pod ...@@ -18,25 +18,32 @@ module Pod
self == (other_platform_or_symbolic_name.name) self == (other_platform_or_symbolic_name.name)
end end
end end
def to_s def to_s
name.to_s case @symbolic_name
when :ios
'iOS'
when :osx
'OS X'
else
'iOS - OS X'
end
end end
def to_sym def to_sym
name name
end end
def nil? def nil?
name.nil? name.nil?
end end
def deployment_target def deployment_target
if (opt = options[:deployment_target]) if (opt = options[:deployment_target])
Pod::Version.new(opt) Pod::Version.new(opt)
end end
end end
def requires_legacy_ios_archs? def requires_legacy_ios_archs?
return unless deployment_target return unless deployment_target
(name == :ios) && (deployment_target < Pod::Version.new("4.3")) (name == :ios) && (deployment_target < Pod::Version.new("4.3"))
......
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