Skip to content

Commit

Permalink
adding some render opts, github tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
cldwalker committed Sep 28, 2009
1 parent a1977bb commit c9e8647
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion boson/commands/alias.rb
Expand Up @@ -3,7 +3,7 @@ def self.config
command_aliases = YAML::load_file(File.expand_path("~/.alias.yml"))[:aliases][:instance_method]["Alias::Console"] rescue {}
search_options = {:type=>:string, :alias=>:string, :class=>:string, :name=>:string}
create_options = {:pretend=>false, :force=>false}
commands = {'search_aliases'=>{:options=>search_options}, 'create_aliases'=>{:options=>create_options}}
commands = {'search_aliases'=>{:options=>search_options, :args=>'*'}, 'create_aliases'=>{:options=>create_options, :args=>3}}
{:command_aliases=>command_aliases, :commands=>commands}
end

Expand Down
2 changes: 1 addition & 1 deletion boson/commands/boson.rb
Expand Up @@ -38,7 +38,7 @@ def index(options={})

# Get command object by name or alias
def boson_command(name)
Boson.command(name) || Boson.command(name, :alias)
Boson::Command.find(name)
end

# Get library object by name or alias
Expand Down
11 changes: 4 additions & 7 deletions boson/commands/history.rb
Expand Up @@ -4,7 +4,7 @@
# consider copy history like http://pastie.org/501623
module History
class<<self; attr_accessor :original_history_size ; end

def self.included(mod)
require 'readline'
if Object.const_defined?(:IRB_PROCS)
Expand All @@ -14,18 +14,15 @@ def self.included(mod)
end
end

# @options :return_array=>:boolean, :edit=>:boolean, [:eval, :x]=>:boolean
# @render_options :number=>true
# @options :edit=>:boolean, [:eval, :x]=>:boolean
# Print, eval, edit console history specified by slice arguments or multislice string
def history(*args)
options = args[-1].is_a?(Hash) ? args.pop : {}
list = history_list_or_slice(*args)
list = edit :string=>list.join("\n") if options[:edit]
console_eval(list.is_a?(Array) ? list.join("\n") : list) if options[:eval]
if options[:return_array] || list.is_a?(String)
list
else
render list.compact, :number=>true
end
list
end

private
Expand Down
19 changes: 12 additions & 7 deletions boson/commands/site/github.rb
Expand Up @@ -3,16 +3,16 @@ def self.included(mod)
require 'httparty'
end

def user_feed(user='cldwalker')
HTTParty.get("http://github.com/api/v2/json/repos/show/#{user}")
end

def user_table(user='cldwalker')
render user_feed(user)['repositories'].select {|e| !e['private']}, :fields=>%w{name watchers forks homepage description}
# @render_options :fields=>{:default=>%w{name watchers forks homepage description},
# :values=>["name", "watchers", "private", "url", "forks", "fork", "description", "homepage", "open_issues"]}
# @options :user=>'cldwalker', :fork_included=>true
def user_table(options={})
repos = user_repos(options[:user])
!options[:fork_included] ? repos.select {|e| ! e['fork'] } : repos
end

def issues(user='cldwalker')
result = user_feed(user)['repositories'].map do |e|
result = user_repos(user).map do |e|
puts "Fetching open issues on #{e['name']}..."
[e['name'], HTTParty.get("http://github.com/api/v2/json/issues/list/#{user}/#{e['name']}/open")['issues'] ]
end
Expand Down Expand Up @@ -42,4 +42,9 @@ def repo(user_repo, file=nil)
repo_url += "/" + file if file
browser repo_url
end

private
def user_repos(user)
HTTParty.get("http://github.com/api/v2/json/repos/show/#{user}")['repositories']
end
end
18 changes: 10 additions & 8 deletions boson/commands/xmms2.rb
@@ -1,13 +1,15 @@
module Xmms2
def songs(query)
render search_songs(query), :fields=>[:track, :title, :time]
end

# @render_options :fields=>{:default=>[:track, :title, :time]}
# @options :menu=>true
# Searches for songs, displays results in menu and lets you jump to chosen song
def songs_jump(query)
def songs_jump(query, options={})
results = search_songs(query)
if (chosen = menu(results, :fields=>[:track, :title, :time], :validate_one=>true))
system('xmms2', 'jump', chosen[:track].to_s)
if options[:menu]
if (chosen = menu(results, :fields=>[:track, :title, :time], :validate_one=>true))
system('xmms2', 'jump', chosen[:track].to_s)
end
else
results
end
end

Expand All @@ -20,7 +22,7 @@ def play(*dirs)
end

private
def search_songs(query)
def search_songs(query, options={})
parse_songs `xmms2 list |grep #{query}`.split("\n")
end

Expand Down

0 comments on commit c9e8647

Please sign in to comment.