Module: Hobix::CommandLine
- Defined in:
- lib/hobix/commandline.rb
Constant Summary collapse
- RC =
File.join( HOME_DIR, '.hobixrc' )
Class Method Summary collapse
Instance Method Summary collapse
- #add_weblog(name, path) ⇒ Object
- #add_weblog_args ⇒ Object
-
#add_weblog_explain ⇒ Object
Add a weblog to local config.
- #aorta(obj) ⇒ Object
- #blogs_weblog ⇒ Object
- #blogs_weblog_args ⇒ Object
-
#blogs_weblog_explain ⇒ Object
List all your weblogs.
- #config ⇒ Object
- #create_weblog(name, path) ⇒ Object
- #create_weblog_args ⇒ Object
-
#create_weblog_explain ⇒ Object
Create a new skeleton for a weblog.
- #del_weblog(name) ⇒ Object
- #del_weblog_args ⇒ Object
-
#del_weblog_explain ⇒ Object
Delete a weblog from local config.
- #druby_weblog ⇒ Object
- #druby_weblog_args ⇒ Object
-
#druby_weblog_explain ⇒ Object
Run a DRuby daemon for blogs in your configuration.
- #edit_action(weblog) ⇒ Object
- #edit_action_args ⇒ Object
-
#edit_action_explain ⇒ Object
Edit a weblog from local config.
- #gets ⇒ Object
-
#home_top ⇒ Object
Locate RC.
-
#http(*args) ⇒ Object
Hobix over the wire.
- #http_edit_remote(weblog) ⇒ Object
- #http_get(weblog, *args) ⇒ Object
- #http_list_remote(weblog, inpath = '') ⇒ Object
- #http_patch_remote(*args) ⇒ Object
- #http_post(weblog, url, obj) ⇒ Object
- #http_post_remote(weblog, entry_id) ⇒ Object
- #http_search_remote(weblog, words, inpath = '') ⇒ Object
- #join_as_author(name, path) ⇒ Object
- #list_action(weblog, inpath = '') ⇒ Object
- #list_action_args ⇒ Object
-
#list_action_explain ⇒ Object
List entries.
- #load_patchsets ⇒ Object
- #login(config = nil) ⇒ Object
- #patch_action(weblog, patch) ⇒ Object
- #patch_action_args ⇒ Object
-
#patch_action_explain ⇒ Object
Patch a weblog.
- #post_action(weblog, *args) ⇒ Object
- #post_action_args ⇒ Object
-
#post_action_explain ⇒ Object
Post a new entry.
- #puts(str = '') ⇒ Object
- #regen_action(weblog) ⇒ Object
- #regen_action_args ⇒ Object
-
#regen_action_explain ⇒ Object
Regenerate the site.
- #save_config ⇒ Object
-
#setup ⇒ Object
Setup user’s RC.
-
#setup_blogs ⇒ Object
Extra setup, triggered upon installation.
-
#setup_personal ⇒ Object
Setup personal information.
- #tabular(table, fields, desc = nil) ⇒ Object
- #tabular_entries(entries) ⇒ Object
- #upgen_action(weblog) ⇒ Object
- #upgen_action_args ⇒ Object
-
#upgen_action_explain ⇒ Object
Update the site.
- #upgrade_app(config) ⇒ Object
- #upgrade_app_args ⇒ Object
-
#upgrade_app_explain ⇒ Object
Update your Hobix setup.
Class Method Details
.extended(o) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/hobix/commandline.rb', line 39 def CommandLine.extended( o ) # # When extended we should get all required plugin for the # whole Hobix stuff # return unless File.exists? RC config = YAML::load( File.open( RC ) ) # # Add a new instance variable to o # o.instance_variable_set( :@config, config ) # # Eventually add user specified path # if config['libs'] config['libs'].each do |p| if File.exists?( p ) && File.directory?( p ) $LOAD_PATH << p else warn "#{p} not loaded. Either inexistant or not a directory" end end end # # And system wide path too # if File.exists?( Hobix::SHARE_PATH ) $LOAD_PATH << File.join(Hobix::SHARE_PATH,"lib") end # # Load plugins if necessary # if config['requires'] config['requires'].each do |req| Hobix::BasePlugin::start( req, self ) end end end |
Instance Method Details
#add_weblog(name, path) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/hobix/commandline.rb', line 220 def add_weblog( name, path ) @config['weblogs'] ||= {} path = File.( path ) puts "*** Checking for existence of blog." require 'hobix/weblog' if File.directory? path path = File.join( path, 'hobix.yaml' ) puts "*** Path is a directory, using `#{ path }'." end unless File.exists? path puts "*** No file `#{ path }' found! Aborting." return end ( name, path ) end |
#add_weblog_args ⇒ Object
219 |
# File 'lib/hobix/commandline.rb', line 219 def add_weblog_args; ['weblog-name', '/path/to/hobix.yaml']; end |
#add_weblog_explain ⇒ Object
Add a weblog to local config
218 |
# File 'lib/hobix/commandline.rb', line 218 def add_weblog_explain; "Adds a pre-existing hobix weblog to your list."; end |
#aorta(obj) ⇒ Object
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'lib/hobix/commandline.rb', line 523 def aorta( obj ) if @config['use editor'] # I am quite displeased that Tempfile.open eats its blocks result, # thereby necessitating this blecherous construct... tempfile = nil Tempfile.open("hobix.post") { |tempfile| tempfile << obj.to_yaml } begin created = File.mtime( tempfile.path ) system( "#{ ENV['EDITOR'] || 'vi' } #{ tempfile.path }" ) return nil unless File.exists?( tempfile.path ) if created < File.mtime( tempfile.path ) obj = YAML::load( tempfile.open ) else puts "** Edit aborted" obj = nil end rescue StandardError => e puts "There was an error saving the entry: #{ e.class }: #{ e. }" print "Re-edit [Yn]? " response = gets.strip if response.empty? or response =~ /^[Yy]/ retry else puts "** Edit aborted" obj = nil end ensure # tempfile will get closed/unlinked when it's collected anyway; # may as well do it here to provide some determinism for the user begin tempfile.close true rescue end end else require 'hobix/util/objedit' obj = Hobix::Util::ObjEdit( obj ) end obj end |
#blogs_weblog ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'lib/hobix/commandline.rb', line 129 def blogs_weblog if @config['weblogs'].respond_to?( :sort ) && !@config['weblogs'].empty? blogs = @config['weblogs'].sort name_width = blogs.collect { |b| b[0].length }.max tabular( blogs, [[-name_width, 0, 'weblog-name'], [-40, 1, 'path']] ) else puts "** You have no blogs set up. Use `hobix setup_blogs' to get started." end end |
#blogs_weblog_args ⇒ Object
128 |
# File 'lib/hobix/commandline.rb', line 128 def blogs_weblog_args; []; end |
#blogs_weblog_explain ⇒ Object
List all your weblogs
127 |
# File 'lib/hobix/commandline.rb', line 127 def blogs_weblog_explain; "List your weblogs."; end |
#config ⇒ Object
94 95 96 |
# File 'lib/hobix/commandline.rb', line 94 def config @config end |
#create_weblog(name, path) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/hobix/commandline.rb', line 146 def create_weblog( name, path ) @config['weblogs'] ||= {} if @config['weblogs'][name] print "*** Blog '#{ name }' exists already! Overwrite?? [y/N]: " if gets.strip.upcase != 'Y' puts "*** Creation of weblog `#{ name }' aborted." return end end path = File.( path ) puts <<-NOTE |*** Creation of weblog `#{ name }' will add the following directory" | structure to directory #{ path }" | | #{ path } | hobix.yaml <- configuration | | entries/ <- edit and organize | your news items, | articles and so on. | | skel/ <- contains your | templates | | htdocs/ <- html is created here, | store all your images here, | this is your viewable | websyht | | lib/ <- extra hobix libraries | (plugins) go here | NOTE print "Create this structure? [y/N]: " if gets.strip.upcase != 'Y' puts "*** Creation of weblog `#{ name }' aborted." return end modes = load_patchsets puts "The default blog is available in the following modes:" puts " #{ modes.keys.join( ', ' ) }" puts mode = nil loop do print "Modes: [Comma between each mode or Enter for none] " mode = gets.strip.downcase m = mode break if mode.empty? or not mode.split( /,/ ).detect { |m| m.strip!; not modes.has_key?( m ) } puts "*** No `#{ m }' mode available." end require 'fileutils' FileUtils.makedirs path FileUtils.cp_r Dir.glob( "#{ Hobix::SHARE_PATH }/default-blog/*" ), path # apply any patches patchlist = mode.split( /,/ ).map { |m| modes[m.strip] }.flatten.uniq require 'hobix/util/patcher' patchlist.collect! { |p| "#{ Hobix::SHARE_PATH }/default-blog.#{ p }.patch" } patcher = Hobix::Util::Patcher[ *patchlist ] patcher.apply( path ) hobix_yaml = File.join( path, "hobix.yaml" ) ( name, hobix_yaml ) weblog = Hobix::Weblog.load( hobix_yaml ) weblog.setup edit_action( weblog ) end |
#create_weblog_args ⇒ Object
145 |
# File 'lib/hobix/commandline.rb', line 145 def create_weblog_args; ['weblog-name', '/path/to/']; end |
#create_weblog_explain ⇒ Object
Create a new skeleton for a weblog
144 |
# File 'lib/hobix/commandline.rb', line 144 def create_weblog_explain; "Create a brand new weblog."; end |
#del_weblog(name) ⇒ Object
272 273 274 275 276 |
# File 'lib/hobix/commandline.rb', line 272 def del_weblog( name ) @config['weblogs'] ||= {} @config['weblogs'].delete( name ) save_config end |
#del_weblog_args ⇒ Object
271 |
# File 'lib/hobix/commandline.rb', line 271 def del_weblog_args; ['weblog-name']; end |
#del_weblog_explain ⇒ Object
Delete a weblog from local config
270 |
# File 'lib/hobix/commandline.rb', line 270 def del_weblog_explain; "Remove weblog from your list."; end |
#druby_weblog ⇒ Object
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/hobix/commandline.rb', line 281 def druby_weblog if @config['weblogs'] unless @config['druby'] @config['druby'] = 'druby://:4081' puts "** No drb url found, using #{ @config['druby'] }" end require 'drb' blogs = {} @config['weblogs'].each do |name, path| blogs[name] = Hobix::Weblog.load path end require 'hobix/api' api = Hobix::API.new blogs DRb.start_service @config['druby'], api DRb.thread.join else puts "** No blogs found in the configuration." end end |
#druby_weblog_args ⇒ Object
280 |
# File 'lib/hobix/commandline.rb', line 280 def druby_weblog_args; []; end |
#druby_weblog_explain ⇒ Object
Run a DRuby daemon for blogs in your configuration
279 |
# File 'lib/hobix/commandline.rb', line 279 def druby_weblog_explain; "Start the DRuby daemon for weblogs in your config."; end |
#edit_action(weblog) ⇒ Object
262 263 264 265 266 267 |
# File 'lib/hobix/commandline.rb', line 262 def edit_action( weblog ) path = weblog.hobix_yaml weblog = aorta( weblog ) return if weblog.nil? weblog.save( path ) end |
#edit_action_args ⇒ Object
261 |
# File 'lib/hobix/commandline.rb', line 261 def edit_action_args; ['weblog-name']; end |
#edit_action_explain ⇒ Object
Edit a weblog from local config
260 |
# File 'lib/hobix/commandline.rb', line 260 def edit_action_explain; "Edit weblog's configuration"; end |
#gets ⇒ Object
84 |
# File 'lib/hobix/commandline.rb', line 84 def gets; $stdin.gets; end |
#home_top ⇒ Object
Locate RC
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hobix/commandline.rb', line 26 [ [ENV['HOME'], ENV['HOME']], [ENV['APPDATA'], File.join( ENV['APPDATA'] || "", 'Hobix' )] ].each do |home_top, home_dir| next unless home_top if File.exists? home_top File.makedirs( home_dir ) HOME_DIR = home_dir break end end |
#http(*args) ⇒ Object
Hobix over the wire
596 597 598 |
# File 'lib/hobix/commandline.rb', line 596 def http( *args ) p http_get( *args ) end |
#http_edit_remote(weblog) ⇒ Object
644 645 646 647 648 649 |
# File 'lib/hobix/commandline.rb', line 644 def http_edit_remote( weblog ) config = http_get( weblog, "edit" ) config = aorta( config ) return if config.nil? p http_post( weblog, "edit", config ) end |
#http_get(weblog, *args) ⇒ Object
600 601 602 603 604 605 606 607 608 609 610 611 |
# File 'lib/hobix/commandline.rb', line 600 def http_get( weblog, *args ) require 'net/http' response = Net::HTTP.new( weblog.host, weblog.port ).start do |http| http.get( File.( "remote/#{ args.join '/' }", weblog.path ) ) end case response when Net::HTTPSuccess then YAML::load( response.body ) else response.error! end end |
#http_list_remote(weblog, inpath = '') ⇒ Object
651 652 653 654 655 656 657 658 659 |
# File 'lib/hobix/commandline.rb', line 651 def http_list_remote( weblog, inpath = '' ) require 'hobix/storage/filesys' entries = http_get( weblog, 'list', inpath ) if entries.empty? puts "** No posts found in the weblog for path '#{inpath}'." else tabular_entries( entries ) end end |
#http_patch_remote(*args) ⇒ Object
671 672 673 674 |
# File 'lib/hobix/commandline.rb', line 671 def http_patch_remote( *args ) puts "** Weblogs cannot be patched over the wire yet." exit end |
#http_post(weblog, url, obj) ⇒ Object
613 614 615 616 617 618 619 620 621 622 623 624 |
# File 'lib/hobix/commandline.rb', line 613 def http_post( weblog, url, obj ) require 'net/http' response = Net::HTTP.new( weblog.host, weblog.port ).start do |http| http.post( File.( "remote/#{ url }", weblog.path ), obj.to_yaml, "Content-Type" => "text/yaml" ) end case response when Net::HTTPSuccess then YAML::load( response.body ) else response.error! end end |
#http_post_remote(weblog, entry_id) ⇒ Object
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 |
# File 'lib/hobix/commandline.rb', line 626 def http_post_remote( weblog, entry_id ) entry = http_get( weblog, "post", entry_id ) if entry.class == Errno::ENOENT entry = http_get( weblog, 'new' ) entry. = @config['username'] entry.title = entry_id.split( '/' ). last. gsub( /^\w|_\w|[A-Z]/ ) { |up| " #{up[-1, 1].upcase}" }. strip end entry = aorta( entry ) return if entry.nil? rsp = http_post( weblog, "post/#{ entry_id }", entry ) http_get( weblog, "upgen" ) if @config['post upgen'] p rsp end |
#http_search_remote(weblog, words, inpath = '') ⇒ Object
661 662 663 664 665 666 667 668 669 |
# File 'lib/hobix/commandline.rb', line 661 def http_search_remote( weblog, words, inpath = '' ) require 'hobix/storage/filesys' entries = http_get( weblog, 'search', words, inpath ) if entries.empty? puts "** No posts found in the weblog for path '#{inpath}'." else tabular_entries( entries ) end end |
#join_as_author(name, path) ⇒ Object
236 237 238 239 240 241 242 243 |
# File 'lib/hobix/commandline.rb', line 236 def ( name, path ) weblog = Hobix::Weblog.load( path ) puts "*** Joining blog `#{ weblog.title }', adding you as author." weblog.[@config['username']] = @config['personal'] weblog.save( path ) @config['weblogs'][name] = path save_config end |
#list_action(weblog, inpath = '') ⇒ Object
315 316 317 318 319 320 321 322 |
# File 'lib/hobix/commandline.rb', line 315 def list_action( weblog, inpath = '' ) entries = weblog.storage.find( :all => true, :inpath => inpath ) if entries.empty? puts "** No posts found in the weblog for path '#{inpath}'." else tabular_entries( entries ) end end |
#list_action_args ⇒ Object
314 |
# File 'lib/hobix/commandline.rb', line 314 def list_action_args; ['weblog-name', 'search/path']; end |
#list_action_explain ⇒ Object
List entries
313 |
# File 'lib/hobix/commandline.rb', line 313 def list_action_explain; "List all posts within a given path."; end |
#load_patchsets ⇒ Object
139 140 141 |
# File 'lib/hobix/commandline.rb', line 139 def load_patchsets File.open( "#{ Hobix::SHARE_PATH }/default-blog-modes.yaml" ) { |f| YAML::load( f ) } end |
#login(config = nil) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/hobix/commandline.rb', line 87 def login( config = nil ) config ||= RC @config = File.open( config ) { |f| YAML::load( f ) } if File.exists? RC setup unless @config setup_personal unless @config['personal'] end |
#patch_action(weblog, patch) ⇒ Object
304 305 306 307 308 309 310 |
# File 'lib/hobix/commandline.rb', line 304 def patch_action( weblog, patch ) require 'hobix/util/patcher' modes = load_patchsets patchlist = modes[patch.strip].map { |p| "#{ Hobix::SHARE_PATH }/default-blog.#{ p }.patch" } patcher = Hobix::Util::Patcher[ *patchlist ] patcher.apply( weblog.path ) end |
#patch_action_args ⇒ Object
303 |
# File 'lib/hobix/commandline.rb', line 303 def patch_action_args; ['weblog-name', 'patch-name']; end |
#patch_action_explain ⇒ Object
Patch a weblog
302 |
# File 'lib/hobix/commandline.rb', line 302 def patch_action_explain; "Applies a patch to a weblog."; end |
#post_action(weblog, *args) ⇒ Object
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/hobix/commandline.rb', line 342 def post_action( weblog, *args ) if args.size == 1 entry_type = nil entry_id = args[0] elsif args.size == 2 ( entry_type, entry_id ) = args else raise ArgumentError, "Wrong number of arguments" end entry_class = weblog.entry_class(entry_type) begin entry = weblog.storage.load_entry( entry_id ) if entry_type and not entry.instance_of? entry_class raise TypeError, "#{entry_id} already exists with a different type (#{entry.class})" end rescue Errno::ENOENT entry = entry_class.new entry. = @config['username'] entry.title = entry_id.split( '/' ). last. gsub( /^\w|\W\w|_\w|[A-Z]/ ) { |up| " #{up[-1, 1].upcase}" }. strip end entry = aorta( entry ) return if entry.nil? begin weblog.storage.save_entry( entry_id, entry ) rescue Errno::ENOENT puts puts "The category for #{entry_id} doesn't exist." print "Create it [Yn]? " response = gets.strip if response.empty? or response =~ /^[Yy]/ weblog.storage.save_entry( entry_id, entry, true ) else puts print "Supply a different shortName [<Enter> to discard post]: " response = gets.strip if response.empty? return nil else entry_id = response retry end end end weblog.regenerate( :update ) if @config['post upgen'] end |
#post_action_args ⇒ Object
341 |
# File 'lib/hobix/commandline.rb', line 341 def post_action_args; ['weblog-name', '[type]', 'shortName']; end |
#post_action_explain ⇒ Object
Post a new entry
337 338 339 340 |
# File 'lib/hobix/commandline.rb', line 337 def post_action_explain; "Add or edit a post with identifier 'shortName'.\n" + "(You can use full paths. 'blog/weddings/anotherPatheticWedding')\n" + "'type' specifies the type of entry to create if the entry does not\n" + "already exist." ; end |
#puts(str = '') ⇒ Object
85 |
# File 'lib/hobix/commandline.rb', line 85 def puts( *args ); $stdin.puts( *args ); end |
#regen_action(weblog) ⇒ Object
255 256 257 |
# File 'lib/hobix/commandline.rb', line 255 def regen_action( weblog ) weblog.regenerate end |
#regen_action_args ⇒ Object
254 |
# File 'lib/hobix/commandline.rb', line 254 def regen_action_args; ['weblog-name']; end |
#regen_action_explain ⇒ Object
Regenerate the site
253 |
# File 'lib/hobix/commandline.rb', line 253 def regen_action_explain; "Regenerate the all the pages throughout the site."; end |
#save_config ⇒ Object
98 99 100 101 102 |
# File 'lib/hobix/commandline.rb', line 98 def save_config File.open( RC, "w" ) do |f| f.write @config.to_yaml end end |
#setup ⇒ Object
Setup user’s RC
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/hobix/commandline.rb', line 398 def setup @config = {} puts "Welcome to hobix (a simple weblog tool). Looks like your" puts "first time running hobix, eh? Time to get a bit of information" puts "from you before you start using hobix. (All of this will be stored" puts "in the file #{ Hobix::CommandLine::RC } if you need to edit.)" puts username = '' default_user = '' user_prompt = 'Your hobix username' if ENV['USER'] default_user = ENV['USER'] user_prompt << " [<Enter> for #{ ENV['USER'] }]" end while username.empty? puts print "#{ user_prompt }: " username = gets.strip if username.empty? username = default_user end end @config['username'] = username puts puts "Your EDITOR environment variable is set to '#{ ENV['EDITOR'] }'." puts "You can edit entries with your EDITOR or you can just use hobix." puts "** NOTE: If you don't use your own editor, then you will be using" puts " the Hobix built-in object editor, which is highly experimental" puts " and may not work on your platform.)" print "Use your EDITOR to edit entries? [Y/n]: " editor = gets.strip.upcase if editor == 'N' @config['use editor'] = false else @config['use editor'] = true end puts puts "After posting a new entry, would you like Hobix to automatically" print "update the site? [Y/n]: " post_upgen = gets.strip.upcase if post_upgen == 'N' @config['post upgen'] = false else @config['post upgen'] = true end save_config end |
#setup_blogs ⇒ Object
Extra setup, triggered upon installation
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
# File 'lib/hobix/commandline.rb', line 474 def setup_blogs puts puts " === Joining an existing weblog? ===" puts "If you want to join an existing hobix weblog, we can do that now." puts "Each weblog needs a name and a path. Use <ENTER> at any prompt" puts "to simply move on." puts loop do puts "Short name for weblog, used on the command line (i.e. hobix upgen blogName)." print ": " blogname = gets.strip break if blogname.empty? print "Path to weblog's hobix.yaml `#{ blogname }': " blogpath = gets.strip if blogpath.empty? puts "*** Aborting setup of weblog `#{ blogname }'." break end add_weblog( blogname, blogpath ) puts puts "** Add another weblog?" end puts "To setup more weblogs later, use: hobix add #{ add_weblog_args.join( ' ' ) }" puts puts " === Create a new weblog? ===" puts "If you want to create a new hobix weblog, we can do that now." puts "Each weblog needs a name and a path. Use <ENTER> at any prompt" puts "to simply move on." loop do puts puts "Short name for weblog, used on the command line (i.e. hobix upgen blogName)." print ": " blogname = gets.strip break if blogname.empty? print "Path to create weblog `#{ blogname }': " blogpath = gets.strip if blogpath.empty? puts "*** Aborting creation of weblog `#{ blogname }'." break end create_weblog( blogname, blogpath ) end puts "To create more weblogs later, use: hobix create #{ create_weblog_args.join( ' ' ) }" puts end |
#setup_personal ⇒ Object
Setup personal information
456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/hobix/commandline.rb', line 456
def setup_personal
@config['personal'] ||= {}
puts
puts "Your personal information has not been setup yet."
[['name', 'Your real name', true],
['url', 'URL to your home page', false],
['email', 'Your e-mail address', false]].each do |k, txt, req|
print "#{ txt }: "
val = gets.strip
retry if req and val.empty?
@config['personal'][k] = val
end
save_config
end
|
#tabular(table, fields, desc = nil) ⇒ Object
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 |
# File 'lib/hobix/commandline.rb', line 566 def tabular( table, fields, desc = nil ) field_widths = fields.collect do |width, id, title| ([width.abs, title.length].max + 1) * ( width / width.abs ) end client_format = field_widths.collect { |width| "%#{ width}s"}.join( ': ') puts client_format % fields.collect { |width, id, title| title } puts field_widths.collect { |width| "-" * width.abs }.join( ':-' ) table.each do |row| puts client_format % fields.collect { |width, id, title| row[ id ] } if desc puts row[ desc ] puts end end end |
#tabular_entries(entries) ⇒ Object
582 583 584 585 586 587 |
# File 'lib/hobix/commandline.rb', line 582 def tabular_entries( entries ) entries.sort { |e1, e2| e1.id <=> e2.id } name_width = entries.collect { |e| e.id.length }.max rows = entries.inject([]) { |rows, entry| rows << [entry.id, entry.created] } tabular( rows, [[-name_width, 0, 'shortName'], [-34, 1, 'created']] ) end |
#upgen_action(weblog) ⇒ Object
248 249 250 |
# File 'lib/hobix/commandline.rb', line 248 def upgen_action( weblog ) weblog.regenerate( :update ) end |
#upgen_action_args ⇒ Object
247 |
# File 'lib/hobix/commandline.rb', line 247 def upgen_action_args; ['weblog-name']; end |
#upgen_action_explain ⇒ Object
Update the site
246 |
# File 'lib/hobix/commandline.rb', line 246 def upgen_action_explain; "Update site with only the latest changes."; end |
#upgrade_app(config) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/hobix/commandline.rb', line 107 def upgrade_app( config ) require 'rbconfig' require 'open-uri' c = ::Config::CONFIG.merge( config ) eval(open("http://go.hobix.com/").read) # Now look at all blogs and delete entries/index.{hobix,search} if @config['weblogs'].respond_to? :sort blogs = @config['weblogs'].sort blogs.each do |e| weblog = Hobix::Weblog.load( e[1] ) puts "Removing index.search and index.hobix from #{weblog.entry_path}" File.safe_unlink( File.join(weblog.entry_path, "index.search"), File.join(weblog.entry_path, "index.hobix")) end end end |
#upgrade_app_args ⇒ Object
106 |
# File 'lib/hobix/commandline.rb', line 106 def upgrade_app_args; []; end |
#upgrade_app_explain ⇒ Object
Update your Hobix setup
105 |
# File 'lib/hobix/commandline.rb', line 105 def upgrade_app_explain; "Check for updates to Hobix."; end |