Module: Quickpress

Defined in:
lib/quickpress.rb,
lib/quickpress/cli.rb,
lib/quickpress/options.rb,
lib/quickpress/version.rb,
lib/quickpress/wordpress.rb

Overview

Controls all operations we can make.

This module’s a mess.

The code sucks, things are not splitted well… There should be delegation up the ass but I couldn’t stop coding.

Gotta study ruby guidelines and see other librarys’ codes to see where I can improve.

Defined Under Namespace

Modules: CLI Classes: Options, Wordpress

Constant Summary collapse

ROOT_DIR =

Main directory where we store everything.

File.expand_path "~/.config/quickpress"
CONFIG_FILE =
"#{ROOT_DIR}/config.yml"
VERSION =
'0.3.0'
VERSION_MAJOR =
VERSION.split('.')[0]
VERSION_MINOR =
VERSION.split('.')[1]
VERSION_PATCH =
VERSION.split('.')[2]
@@inited =

config

nil
@@started =

overall

false
@@ran_first_time =
false
@@default_site =

URL of the default site used to post.

nil
@@default_sitename =

Nice name of the default site.

nil
@@username =
nil
@@password =
nil
@@wp =

Actual Wordpress connection Object

nil
@@supported_markup =

Supported templating languages and their file extensions.

[["markdown"     , '.md'],
["asciidoc"     , '.adoc'],
["erb"          , '.erb'],
["string"       , '.str'],
["erubis"       , '.erubis'],
["haml"         , '.haml'],
["sass"         , '.sass'],
["scss"         , '.scss'],
["less"         , '.less'],
["builder"      , '.builder'],
["liquid"       , '.liquid'],
["markdown"     , '.md'],
["textile"      , '.textile'],
["rdoc"         , '.rdoc'],
["radius"       , '.radius'],
["markaby"      , '.mab'],
["nokogiri"     , '.nokogiri'],
["coffeescript" , '.coffee'],
["creole"       , '.creole'],
["mediawiki"    , '.mw'],
["yajl"         , '.yajl'],
["csv"          , '.rcsv']]

Class Method Summary collapse

Class Method Details

.config_initObject

Loads default site from configuration file



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/quickpress.rb', line 84

def config_init

  # Reading config file if exists
  if File.exists? CONFIG_FILE
    CLI::with_status("Initializing...") do

      raw = File.read CONFIG_FILE
      settings = YAML.load raw
      settings = {} if not settings

      @@default_site = settings["default_site"]
      @@default_sitename = @@default_site.gsub(/htt(p|ps):\/\//, "").gsub(/\//, '-')
    end
    @@inited = true
  end

  FileUtils.mkdir_p ROOT_DIR if not File.exists? ROOT_DIR
end

.date(format = nil) ⇒ Object

Returns a Time Object according to String ‘format`.

The acceptable date formats are:

  • ‘minute:hour`

  • ‘minute:hour day`

  • ‘minute:hour day-month`

  • ‘minute:hour day-month-year`

Whenever there’s a non-specified field (like year, for example) we’ll get from the current date.

So if you only provide ‘minute:hour`, it’ll return a Time Object with the current day, month and year.



589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
# File 'lib/quickpress.rb', line 589

def date(format=nil)

  # When sending [] as `:post_date` it tells Wordpress
  # to post instantly.
  return [] if format.nil?

  # Allowed date formats
  full_fmt  = /(\d{1,2}):(\d{2}) (\d{1,2})-(\d{1,2})-(\d{4})/
  month_fmt = /(\d{1,2}):(\d{2}) (\d{1,2})-(\d{1,2})/
  day_fmt   = /(\d{1,2}):(\d{2}) (\d{1,2})/
  hours_fmt = /(\d{1,2}):(\d{2})/

  time = nil
  case format
  when full_fmt
    year   = format[full_fmt, 5].to_i
    month  = format[full_fmt, 4].to_i
    day    = format[full_fmt, 3].to_i
    minute = format[full_fmt, 2].to_i
    hour   = format[full_fmt, 1].to_i

    time = Time.new(year, month, day, hour, minute)

  when month_fmt then
    month  = format[month_fmt, 4].to_i
    day    = format[month_fmt, 3].to_i
    minute = format[month_fmt, 2].to_i
    hour   = format[month_fmt, 1].to_i

    time = Time.new(Time.now.year,
                    month, day, hour, minute)

  when day_fmt then
    day    = format[day_fmt, 3].to_i
    minute = format[day_fmt, 2].to_i
    hour   = format[day_fmt, 1].to_i

    time = Time.new(Time.now.year, Time.now.month,
                    day, hour, minute)

  when hours_fmt then
    minute = format[hours_fmt, 2].to_i
    hour   = format[hours_fmt, 1].to_i

    time = Time.new(Time.now.year, Time.now.month, Time.now.day,
                    hour, minute)

  else
    fail "* Invalid data format '#{format}'.\n"
          "See `qp help new-post` for details."
  end

  time
end

.delete(what, ids) ⇒ Object

Deletes comma-separated list of posts/pages with ‘ids`. A single number is ok too.



815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
# File 'lib/quickpress.rb', line 815

def delete(what, ids)
  Quickpress::startup

  ids.split(',').each do |id|

    thing = nil

    CLI::with_status("Hold on a sec...") do

      if what == :post
        thing = @@wp.get_post id.to_i
      elsif what == :page
        thing = @@wp.get_page id.to_i
      end

    end

    puts <<-END.remove_starting!
      Will delete the following #{what}:

      ID:      #{thing["post_id"]}
      Title:   #{thing["post_title"]}
      Date:    #{thing["post_date"].to_time}
      Status:  #{thing["post_status"]}
      URL:     #{thing["link"]}

    END

    if not $options[:force]
      answer = CLI::ask("Is that right?")

      if not answer
        puts "Alright, then!"
        next
      end
    end

    CLI::with_status("Deleting...") do
      case what
      when :post then @@wp.delete_post id.to_i
      when :page then @@wp.delete_page id.to_i
      end
    end
    puts "Deleted!"
  end
end

.edit(what, id, filename = nil) ⇒ Object

Entrance for when we’re editing a page or a post with numerical ‘id` (`what` says so).



662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
# File 'lib/quickpress.rb', line 662

def edit(what, id, filename=nil)
  Quickpress::startup

  # Get previous content
  old_content = nil
  if what == :post
    post = @@wp.get_post id

    old_content = post["post_content"]
  else
    page = @@wp.get_page id

    old_content = page["post_content"]
  end

  if filename.nil?

    # Get editor to open temporary file
    editor = ENV["EDITOR"]
    if editor.nil?
      editor = get("Which text editor we'll use?")
    end

    # Create draft file
    tempfile = Tempfile.new ['quickpress', '.html']
    tempfile.write old_content
    tempfile.flush

    # Oh yeah, baby
    `#{editor} #{tempfile.path}`

    if tempfile.size.zero?
      puts "Empty file: did nothing"
      tempfile.close
      exit 666
    end

    tempfile.close  # Apparently, calling `tempfile.flush`
    tempfile.open   # won't do it. Need to close and reopen.

    md5old = Digest::MD5.hexdigest old_content
    md5new = Digest::MD5.hexdigest tempfile.read

    if (md5old == md5new) and (not $options[:force])
      puts "Contents unchanged: skipping"
      puts "(use --force if you want to do it anyway)"
      return
    end

    puts "File: '#{tempfile.path}'" if $options[:debug]

    edit_file(what, id, tempfile.path)
    tempfile.close

  else

    md5old = Digest::MD5.hexdigest old_content
    md5new = Digest::MD5.hexdigest File.read(filename)

    if (md5old == md5new) and (not $options[:force])
      puts "Contents unchanged: skipping"
      puts "(use --force if you want to do it anyway)"
      return
    end

    edit_file(what, id, filename)
  end
end

.edit_file(what, id, filename) ⇒ Object

Actually edits post/page ‘filename` to the blog.



732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
# File 'lib/quickpress.rb', line 732

def edit_file(what, id, filename)

  html = Tilt.new(filename).render

  link = nil

  old_title = nil
  case what
  when :post
    post = @@wp.get_post id
    old_title = post["post_title"]

  when :page
    page = @@wp.get_page id
    old_title = page["post_title"]
  end

  title = $options[:title]
  if title.nil?
    title = CLI::get("New Title:", true)
  end

  # Falling back to current title if empty
  title = old_title if title.empty?

  date   = Quickpress::date $options[:date]
  status = Quickpress::status $options[:status]

  case what
  when :post
    # Only thing that makes posts different from pages
    # are categories.

    categories = $options[:category]
    if categories.nil?
      puts "Existing blog categories:"
      Quickpress::list_categories
      puts
      puts "Use a comma-separated list (eg. 'cat1, cat2, cat3')"
      puts "Tab-completion works."
      puts "(will create non-existing categories automatically)"
      puts "(leave empty to keep current categories)"

      categories = CLI::tab_complete("Post categories:", @@wp.categories)
    end

    cats = categories.split(',').map { |c| c.lstrip.strip }

    CLI::with_status("Editing post...") do
      link = @@wp.edit_post(:post_id => id,
                            :content => {
                              :post_content => html,
                              :post_title => title,
                              :post_status => status,
                              :terms_names => {
                                :category => cats
                              }
                            })
    end

  when :page
    CLI::with_status("Editing Page...") do
      link = @@wp.edit_post(:post_id => id,
                            :filter => {
                              :post_type => 'page'
                            },
                            :content => {
                              :post_content => html,
                              :post_title => title,
                              :post_status => status
                            })
    end
  end

  puts <<-END.remove_starting!
    Edit successful!
    link: #{link}
  END
end

.first_timeObject

Executes at the first time, when there’s no configuration directories.

Asks stuff.



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/quickpress.rb', line 108

def first_time
  puts <<-END.remove_starting!
    Hello!
    It looks like this is the first time you're
    running quickpress.

    Let's connect to your Wordpress(.com/.org) site.
  END
  puts

  Quickpress::new_site(nil)
  @@ran_first_time = true
end

.forget_site(ids) ⇒ Object



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/quickpress.rb', line 252

def forget_site ids

  # Hey, there's no sites added yet!
  if not File.exists? CONFIG_FILE
    puts "No sites managed with quickpress yet!"
    puts "Add them with `qp new-site`"
    exit 666
  end

  # Getting all sites from config file
  raw = File.read CONFIG_FILE

  settings = {}
  settings.merge!(YAML.load(raw))

  max_id = settings["sites"].size - 1
  ids_to_delete = []

  # Here we go!
  ids.split(',').each do |id|

    if not (0..max_id).include? id.to_i
      puts "Invalid id!"
      puts "Must be between 0 and #{max_id}."
      next
    end

    puts "Will delete the following site:"
    puts
    puts settings["sites"][id.to_i]

    if not $options[:force]
      answer = CLI::ask("Is that right?")
      if not answer
        puts "Alright, then!"
        next
      end
    end

    ids_to_delete << id.to_i
  end

  # Forgetting a lot of sites at once
  # Note: Is there a better way to do this?
  #       Once I delete an id, all the others change!
  #       I can't simply `each do delete` them.

  ids_to_delete.each {|i| settings["sites"][i] = "will_delete" }

  settings["sites"].reject! { |s| s == "will_delete" }

  # Just in case we've just deleted the default site,
  # let's grab the first one left
  if not settings["sites"].include? @@default_site
    if not settings["sites"].empty?
      settings["default_site"] = settings["sites"].first
    end
  end

  File.write(CONFIG_FILE, YAML.dump(settings))
  puts "Forgotten"

  # Ooh, boy
  # We've just ran out of sites! Better delete that config file!
  if settings["sites"].empty?
    FileUtils.rm_f CONFIG_FILE
  end
end

.list(what, ammount) ⇒ Object

Show last ‘ammount` of posts/pages in reverse order of publication.



865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
# File 'lib/quickpress.rb', line 865

def list(what, ammount)
  Quickpress::startup

  elements = nil
  if what == :post
    CLI::with_status("Retrieving posts...") do
      elements = @@wp.get_posts ammount
    end

  elsif what == :page
    CLI::with_status("Retrieving pages...") do
      elements = @@wp.get_pages ammount
    end
  end

  # Ugly as fuark :(
  puts "+-----+---------------------------------------+-----------------------+--------+"
  puts "|   ID|Title                                  |Date                   |Status  |"
  puts "+-----+---------------------------------------+-----------------------+--------+"
  elements.each do |post|
    puts sprintf("|%5d|%-39s|%s|%-8s|", post["post_id"].to_i,
                 post["post_title"],
                 post["post_date"].to_time,
                 post["post_status"])
  end
  puts "+-----+---------------------------------------+-----------------------+--------+"
end

.list_categoriesObject

Pretty-prints categories list.



433
434
435
436
437
438
439
440
441
442
# File 'lib/quickpress.rb', line 433

def list_categories
  Quickpress::startup

  # Will show categories in columns of n
  columns = 5
  table = @@wp.categories.each_slice(columns).to_a

  puts
  Thor::Shell::Basic.new.print_table table
end

.list_markupObject



893
894
895
896
897
898
899
900
# File 'lib/quickpress.rb', line 893

def list_markup
  puts "Name (file extension)"
  puts

  @@supported_markup.each do |m|
    puts "* #{m[0]} (#{m[1]})"
  end
end

.list_mediaObject

Shows all uploaded items.



561
562
563
564
565
566
567
568
569
570
571
# File 'lib/quickpress.rb', line 561

def list_media
  Quickpress::startup
  media = @@wp.get_all_media
  if media.empty?
    puts "No items uploaded 'til now."
    return
  end

  table = [["ID", "Filename", "Link"]] + media
  Thor::Shell::Basic.new.print_table table
end

.list_optionsObject

Pretty-prints all options of the Wordpress site.



445
446
447
448
449
450
451
# File 'lib/quickpress.rb', line 445

def list_options
  Quickpress::startup
  options = @@wp.get_options

  puts
  Thor::Shell::Basic.new.print_table options
end

.list_sitesObject

Shows all saved sites.



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/quickpress.rb', line 223

def list_sites

  # Hey, this is our first site!
  if not File.exists? CONFIG_FILE
    puts "No sites stored yet!"
    puts
    puts "Run `qp new-site` to create your first!"

  else
    raw = File.read CONFIG_FILE

    settings = {}
    settings.merge!(YAML.load(raw))

    puts "Sites currently managed by quickpress:"
    puts

    settings["sites"].each_with_index do |site, i|

      if @@default_site == site
        puts (" %3d. %s <== default site" % [i, site])
      else
        puts (" %3d. %s" % [i, site])
      end
    end
  end

end

.list_usersObject

Pretty-prints all users currently registered on the site.



454
455
456
457
458
459
460
461
462
# File 'lib/quickpress.rb', line 454

def list_users
  Quickpress::startup
  users = @@wp.get_users

  users.each do |user|
    puts
    Thor::Shell::Basic.new.print_table user
  end
end

.new(what, filename = nil) ⇒ Object

Entrance for when we’re creating a page or a post (‘what` says so).



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
394
395
396
397
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
# File 'lib/quickpress.rb', line 356

def new(what, filename=nil)
  if filename.nil?

    # Get editor to open temporary file
    editor = ENV["EDITOR"]
    if editor.nil?
      editor = get("Which text editor we'll use?")
    end

    extension = nil

    # No markup passed as argument
    if $options[:markup].nil?
      puts "Choose your templating language."
      puts

      @@supported_markup.each_with_index do |m, i|
        puts (" %2d. %s (%s)" % [i, m[0], m[1]])
      end
      puts

      id = CLI::get("Which one?").to_i

      max_id = @@supported_markup.size - 1

      if not (0..max_id).include? id
        puts "Invalid id!"
        puts "Must be between 0 and #{max_id}."
        exit 666
      end

      extension = @@supported_markup[id][1]

    # User specified filename to post
    else
      markup_id = nil
      @@supported_markup.each_with_index do |m, i|

        if m[0].casecmp($options[:markup]).zero?
          markup_id = i
          break
        end
      end

      if markup_id.nil?
        fail "Unknown markup laguage '#{$options[:markup]}'"
      end

      extension = @@supported_markup[markup_id][1]
    end

    # Create draft file
    tempfile = Tempfile.new ['quickpress', extension]
    tempfile.write "# Leave this file empty to cancel"
    tempfile.flush

    # Oh yeah, baby
    `#{editor} #{tempfile.path}`

    if tempfile.size.zero?
      puts "Empty file: did nothing"
      tempfile.close
      exit 666
    end

    puts "File: '#{tempfile.path}'" if $options[:debug]

    new_file(what, tempfile.path)
    tempfile.close

  else
    # Post file and copy it to posted directory.
    new_file(what, filename)
  end
end

.new_file(what, filename) ⇒ Object

Actually sends post/page ‘filename` to the blog.



465
466
467
468
469
470
471
472
473
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
522
523
524
525
526
527
528
# File 'lib/quickpress.rb', line 465

def new_file(what, filename)
  Quickpress::startup
  html = Tilt.new(filename).render

  # If successful, will store page id and link
  id, link = nil, nil

  title = $options[:title]
  if title.nil?
    title = CLI::get "Title:"
  end

  date = Quickpress::date $options[:date]
  status = Quickpress::status $options[:status]

  if what == :post

    categories = $options[:category]
    if categories.nil?
      puts "Existing blog categories:"
      Quickpress::list_categories
      puts
      puts "Use a comma-separated list (eg. 'cat1, cat2, cat3')"
      puts "Tab-completion works."
      puts "(will create non-existing categories automatically)"

      categories = CLI::tab_complete("Post categories:", @@wp.categories)
    end

    cats = []
    categories.split(',').each { |c| cats << c.lstrip.strip }

    CLI::with_status("Posting...") do

      id, link = @@wp.new_post(:post_status  => 'publish',
                               :post_date    => date,
                               :post_title   => title,
                               :post_content => html,
                               :post_status  => status,
                               :terms_names  => {
                                 :category => cats
                               })
    end
    puts "Post successful!"

  elsif what == :page

    CLI::with_status("Creating page...") do

      id, link = @@wp.new_post(:post_status  => 'publish',
                               :post_date    => [],
                               :post_title   => title,
                               :post_content => html,
                               :post_status  => status,
                               :post_type    => 'page')
    end
    puts "Page created!"
  end

  puts <<-END.remove_starting!
    id:   #{id}
    link: #{link}
  END
end

.new_media(filename) ⇒ Object

Uploads ‘filename` to the blog.



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
# File 'lib/quickpress.rb', line 532

def new_media filename

  if not File.exists? filename
    fail "File '#{filename}' doesn't exist"
  end
  if File.directory? filename
    fail "Are you nuts? '#{filename}' is a directory"
  end
  if File.stat(filename).size.zero?
    fail "File '#{filename}' is empty"
  end

  Quickpress::startup

  id, link, name = nil, nil

  CLI::with_status("Uploading '#{filename}'...") do
    id, link, name = @@wp.new_media filename
  end

  puts <<-END.remove_starting!
    File uploaded!
    id:   #{id}
    link: #{link}
    name: #{name}
  END
end

.new_site(addr = nil) ⇒ Object

Adds site with URL ‘addr` to quickpress. If it’s ‘nil`, will prompt the user for it.



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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
216
217
218
219
220
# File 'lib/quickpress.rb', line 124

def new_site(addr=nil)
  return if @@ran_first_time
  address = nil

  # If retrying, go back here.
  begin
    address = addr.dup if not addr.nil? # cannot .dup NilClass
    address ||= CLI::get("Address:")

    address.gsub!(/http:\/\//, "")
    address.gsub!(/www\./, "")
    address.gsub!(/\/$/, "")

    # Checking if site already exists
    if File.exists? CONFIG_FILE
      raw = File.read CONFIG_FILE

      settings = {}
      settings.merge!(YAML.load(raw))

      settings["sites"].each do |s|
        if address == s
          puts
          puts "There's already a site with address '#{address}'"
          puts "Check it with `qp list-sites`."

          if @@default_site == s
            puts
            puts "It's your default site, by the way"
          end
          exit 666
        end
      end
    end

    Quickpress::authenticate

    # Will try to connect here.
    # Might take a while.
    CLI::with_status("Connecting...") do
      @@wp = Wordpress.new(address, @@username, @@password)
    end

    puts <<-END.remove_starting!

      Title:    #{@@wp.title}
      Tagline:  #{@@wp.tagline}
      Url:      #{@@wp.url}
    END

    answer = CLI::ask "Is that right?"
    fail "will retry" if not answer

    # Last site added becomes the default
    @@default_site = address

    # Hey, this is our first site!
    if not File.exists? CONFIG_FILE

      # For a @@default_site like "http://myblog.com/this/dir"
      #
      # The @@default_sitename must be "myblog.com-this-dir"
      @@default_sitename = address.gsub(/htt(p|ps):\/\//, "").gsub(/\//, '-')

      # Saving to config file
      settings = {}

      settings["sites"] ||= []
      settings["sites"] << @@default_site

      settings["default_site"] = @@default_site

      File.write(CONFIG_FILE, YAML.dump(settings))

    # Config file exists
    else

      raw = File.read CONFIG_FILE

      settings = {}
      settings.merge!(YAML.load(raw))

      settings["sites"] ||= []
      settings["sites"] << @@default_site

      settings["default_site"] = @@default_site

      File.write(CONFIG_FILE, YAML.dump(settings))
    end
    puts "Site added"

  rescue StandardError => e
    retry if e.message =~ /will retry/

    raise e
  end
end

.status(string = nil) ⇒ Object

Note:

Falls back to ‘publish`.

Checks if ‘string` is a valid status for a post.



647
648
649
650
651
652
653
654
655
656
657
# File 'lib/quickpress.rb', line 647

def status(string=nil)
  case string
  when nil        then return "publish"
  when /draft/i   then return string
  when /publish/i then return string
  when /private/i then return string
  else
    fail "* Invalid status format '#{format}'.\n"
         "See `qp help new-post` for details."
  end
end

.status_categoriesObject



911
912
913
914
915
916
917
918
919
920
921
# File 'lib/quickpress.rb', line 911

def status_categories
  Quickpress::startup
  status = @@wp.get_category_status

  if $options[:"non-empty"]
    status.reject! { |s| s[1].zero? }
  end

  puts
  Thor::Shell::Basic.new.print_table status
end

.status_commentsObject

Shows comment count according to their status.



903
904
905
906
907
908
909
# File 'lib/quickpress.rb', line 903

def status_comments
  Quickpress::startup
  status = @@wp.get_comment_status

  puts
  Thor::Shell::Basic.new.print_table status
end

.use_site(id) ⇒ Object



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/quickpress.rb', line 321

def use_site id
  Quickpress::first_time if @@default_site.nil?
  return if @@ran_first_time

  # Hey, there's no sites added yet!
  if not File.exists? CONFIG_FILE
    puts "No sites managed with quickpress yet!"
    puts ""
    exit 666
  end

  # Getting all sites from config file
  raw = File.read CONFIG_FILE

  settings = {}
  settings.merge!(YAML.load(raw))

  max_id = settings["sites"].size - 1

  if not (0..max_id).include? id.to_i
    puts "Invalid id!"
    puts "Must be between 0 and #{max_id}."
    exit 666
  end

  site = settings["sites"][id]

  puts "Default site: #{site}"
  settings["default_site"] = site
  File.write(CONFIG_FILE, YAML.dump(settings))
end