Skip to content

Commit

Permalink
format commands
Browse files Browse the repository at this point in the history
  • Loading branch information
cldwalker committed Apr 4, 2011
1 parent b8df265 commit e96d961
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions lib/tux/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

module Tux
module Commands
SETTINGS = %w{methodoverride inline_templates}

def routes
Tux.app_class.routes.inject([]) {|arr, (k,v)|
arr += v.map {|e|
[ k, (str = e[0].inspect[%r{/\^(.*)\$/}, 1]) ? str.tr('\\', '') : e[0] ]
[k, (str = e[0].inspect[%r{/\^(.*)\$/}, 1]) ? str.tr('\\', '') : e[0]]
}
}
end

def settings
meths = (class << Tux.app_class; self; end).instance_methods(false).sort.map(&:to_s).
select {|e| e[/=$/] }.map {|e| e[0..-2] } - %w{methodoverride inline_templates}
meths = (class << Tux.app_class; self; end).instance_methods(false).
sort.map(&:to_s).select {|e| e[/=$/] }.map {|e| e[0..-2] } - SETTINGS
meths.map {|meth| [meth, Tux.app_class.send(meth)] }
end

Expand All @@ -25,5 +27,22 @@ def app
end
end
end

module CommandsFormatted
def self.format(arr)
arr = arr.map {|e| [e[0], e[1].inspect] }
max1 = arr.map {|e| e[0].length }.max
max2 = arr.map {|e| e[1].length }.max
arr.map {|k,v| "%-*s %-*s" % [max1, k, max2, v] }
end

def routes
puts CommandsFormatted.format(super)
end

def settings
puts CommandsFormatted.format(super)
end
end
end
Ripl::Commands.include Tux::Commands
Ripl::Commands.include Tux::CommandsFormatted, Tux::Commands

0 comments on commit e96d961

Please sign in to comment.