wpb 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +9 -3
- data/bin/wpb +3 -5
- data/doc/Bash.html +222 -0
- data/doc/Comment.html +411 -0
- data/doc/Gemfile.html +110 -0
- data/doc/Page.html +315 -0
- data/doc/PagePost.html +422 -0
- data/doc/Post.html +164 -0
- data/doc/Rakefile.html +107 -0
- data/doc/Setting.html +164 -0
- data/doc/User.html +415 -0
- data/doc/WPB.html +188 -0
- data/doc/WPB/AddType.html +254 -0
- data/doc/WPB/App.html +231 -0
- data/doc/bin/wpb.html +54 -0
- data/doc/created.rid +13 -0
- data/doc/index.html +114 -0
- data/doc/lib/wpb/bash_rb.html +56 -0
- data/doc/lib/wpb/comment_rb.html +54 -0
- data/doc/lib/wpb/page_rb.html +203 -0
- data/doc/lib/wpb/pagepost_rb.html +54 -0
- data/doc/lib/wpb/post_rb.html +52 -0
- data/doc/lib/wpb/setting_rb.html +54 -0
- data/doc/lib/wpb/user_rb.html +54 -0
- data/doc/lib/wpb/version_rb.html +52 -0
- data/doc/lib/wpb_rb.html +68 -0
- data/doc/rdoc.css +706 -0
- data/lib/wpb.rb +36 -29
- data/lib/wpb/bash.rb +18 -0
- data/lib/wpb/clamp/attribute.rb +37 -0
- data/lib/wpb/clamp/attribute_declaration.rb +40 -0
- data/lib/wpb/clamp/command.rb +137 -0
- data/lib/wpb/clamp/errors.rb +26 -0
- data/lib/wpb/clamp/help.rb +69 -0
- data/lib/wpb/clamp/option.rb +77 -0
- data/lib/wpb/clamp/option/declaration.rb +58 -0
- data/lib/wpb/clamp/option/parsing.rb +45 -0
- data/lib/wpb/clamp/parameter.rb +70 -0
- data/lib/wpb/clamp/parameter/declaration.rb +28 -0
- data/lib/wpb/clamp/parameter/parsing.rb +28 -0
- data/lib/wpb/clamp/subcommand.rb +23 -0
- data/lib/wpb/clamp/subcommand/declaration.rb +40 -0
- data/lib/wpb/clamp/subcommand/execution.rb +37 -0
- data/lib/wpb/clamp/version.rb +3 -0
- data/lib/wpb/comment.rb +51 -5
- data/lib/wpb/page.rb +46 -0
- data/lib/wpb/pagepost.rb +29 -16
- data/lib/wpb/user.rb +25 -0
- data/lib/wpb/version.rb +4 -1
- metadata +43 -2
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'clamp/attribute_declaration'
|
2
|
+
require 'clamp/option'
|
3
|
+
|
4
|
+
module Clamp
|
5
|
+
class Option
|
6
|
+
|
7
|
+
module Declaration
|
8
|
+
|
9
|
+
include Clamp::AttributeDeclaration
|
10
|
+
|
11
|
+
def option(switches, type, description, opts = {}, &block)
|
12
|
+
option = Clamp::Option.new(switches, type, description, opts)
|
13
|
+
declared_options << option
|
14
|
+
define_accessors_for(option, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def has_options?
|
18
|
+
!documented_options.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_option(switch)
|
22
|
+
recognised_options.find { |o| o.handles?(switch) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def declared_options
|
26
|
+
@declared_options ||= []
|
27
|
+
end
|
28
|
+
|
29
|
+
def documented_options
|
30
|
+
declared_options + inherited_declared_options
|
31
|
+
end
|
32
|
+
|
33
|
+
def recognised_options
|
34
|
+
documented_options + standard_options
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def inherited_declared_options
|
40
|
+
ancestors.inject([]) do |options, ancestor|
|
41
|
+
if ancestor.kind_of?(Clamp::Option::Declaration)
|
42
|
+
options + ancestor.declared_options
|
43
|
+
else
|
44
|
+
options
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
HELP_OPTION = Clamp::Option.new("--help", :flag, "print help", :attribute_name => :help_requested)
|
50
|
+
|
51
|
+
def standard_options
|
52
|
+
[HELP_OPTION]
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Clamp
|
2
|
+
class Option
|
3
|
+
|
4
|
+
module Parsing
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
def parse_options
|
9
|
+
while remaining_arguments.first =~ /^-/
|
10
|
+
|
11
|
+
switch = remaining_arguments.shift
|
12
|
+
break if switch == "--"
|
13
|
+
|
14
|
+
case switch
|
15
|
+
when /^(-\w)(.+)$/ # combined short options
|
16
|
+
switch = $1
|
17
|
+
remaining_arguments.unshift("-#{$2}")
|
18
|
+
when /^(--[^=]+)=(.*)/
|
19
|
+
switch = $1
|
20
|
+
remaining_arguments.unshift($2)
|
21
|
+
end
|
22
|
+
|
23
|
+
option = find_option(switch)
|
24
|
+
value = option.extract_value(switch, remaining_arguments)
|
25
|
+
|
26
|
+
begin
|
27
|
+
send("#{option.attribute_name}=", value)
|
28
|
+
rescue ArgumentError => e
|
29
|
+
signal_usage_error "option '#{switch}': #{e.message}"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def find_option(switch)
|
38
|
+
self.class.find_option(switch) ||
|
39
|
+
signal_usage_error("Unrecognised option '#{switch}'")
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'clamp/attribute'
|
2
|
+
|
3
|
+
module Clamp
|
4
|
+
|
5
|
+
class Parameter < Attribute
|
6
|
+
|
7
|
+
def initialize(name, description, options = {})
|
8
|
+
@name = name
|
9
|
+
@description = description
|
10
|
+
infer_attribute_name_and_multiplicity
|
11
|
+
if options.has_key?(:attribute_name)
|
12
|
+
@attribute_name = options[:attribute_name].to_s
|
13
|
+
end
|
14
|
+
if options.has_key?(:default)
|
15
|
+
@default_value = options[:default]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_reader :name, :attribute_name
|
20
|
+
|
21
|
+
def help_lhs
|
22
|
+
name
|
23
|
+
end
|
24
|
+
|
25
|
+
def consume(arguments)
|
26
|
+
if required? && arguments.empty?
|
27
|
+
raise ArgumentError, "no value provided"
|
28
|
+
end
|
29
|
+
if multivalued?
|
30
|
+
arguments.shift(arguments.length)
|
31
|
+
else
|
32
|
+
arguments.shift
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
NAME_PATTERN = "([A-Za-z0-9_-]+)"
|
39
|
+
|
40
|
+
def infer_attribute_name_and_multiplicity
|
41
|
+
case @name
|
42
|
+
when /^\[#{NAME_PATTERN}\]$/
|
43
|
+
@attribute_name = $1
|
44
|
+
when /^\[#{NAME_PATTERN}\] ...$/
|
45
|
+
@attribute_name = "#{$1}_list"
|
46
|
+
@multivalued = true
|
47
|
+
when /^#{NAME_PATTERN} ...$/
|
48
|
+
@attribute_name = "#{$1}_list"
|
49
|
+
@multivalued = true
|
50
|
+
@required = true
|
51
|
+
when /^#{NAME_PATTERN}$/
|
52
|
+
@attribute_name = @name
|
53
|
+
@required = true
|
54
|
+
else
|
55
|
+
raise "invalid parameter name: '#{name}'"
|
56
|
+
end
|
57
|
+
@attribute_name = @attribute_name.downcase.tr('-', '_')
|
58
|
+
end
|
59
|
+
|
60
|
+
def multivalued?
|
61
|
+
@multivalued
|
62
|
+
end
|
63
|
+
|
64
|
+
def required?
|
65
|
+
@required
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'clamp/attribute_declaration'
|
2
|
+
require 'clamp/parameter'
|
3
|
+
|
4
|
+
module Clamp
|
5
|
+
class Parameter
|
6
|
+
|
7
|
+
module Declaration
|
8
|
+
|
9
|
+
include Clamp::AttributeDeclaration
|
10
|
+
|
11
|
+
def parameters
|
12
|
+
@parameters ||= []
|
13
|
+
end
|
14
|
+
|
15
|
+
def has_parameters?
|
16
|
+
!parameters.empty?
|
17
|
+
end
|
18
|
+
|
19
|
+
def parameter(name, description, options = {}, &block)
|
20
|
+
parameter = Parameter.new(name, description, options)
|
21
|
+
parameters << parameter
|
22
|
+
define_accessors_for(parameter, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Clamp
|
2
|
+
class Parameter
|
3
|
+
|
4
|
+
module Parsing
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
def parse_parameters
|
9
|
+
|
10
|
+
self.class.parameters.each do |parameter|
|
11
|
+
begin
|
12
|
+
value = parameter.consume(remaining_arguments)
|
13
|
+
send("#{parameter.attribute_name}=", value) unless value.nil?
|
14
|
+
rescue ArgumentError => e
|
15
|
+
signal_usage_error "parameter '#{parameter.name}': #{e.message}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
unless remaining_arguments.empty?
|
20
|
+
signal_usage_error "too many arguments"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Clamp
|
2
|
+
|
3
|
+
class Subcommand < Struct.new(:name, :description, :subcommand_class)
|
4
|
+
|
5
|
+
def initialize(names, description, subcommand_class)
|
6
|
+
@names = Array(names)
|
7
|
+
@description = description
|
8
|
+
@subcommand_class = subcommand_class
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :names, :description, :subcommand_class
|
12
|
+
|
13
|
+
def is_called?(name)
|
14
|
+
names.member?(name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def help
|
18
|
+
[names.join(", "), description]
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'clamp/subcommand'
|
2
|
+
|
3
|
+
module Clamp
|
4
|
+
class Subcommand
|
5
|
+
|
6
|
+
module Declaration
|
7
|
+
|
8
|
+
def recognised_subcommands
|
9
|
+
@recognised_subcommands ||= []
|
10
|
+
end
|
11
|
+
|
12
|
+
def subcommand(name, description, subcommand_class = self, &block)
|
13
|
+
has_subcommands!
|
14
|
+
if block
|
15
|
+
# generate a anonymous sub-class
|
16
|
+
subcommand_class = Class.new(subcommand_class, &block)
|
17
|
+
end
|
18
|
+
recognised_subcommands << Subcommand.new(name, description, subcommand_class)
|
19
|
+
end
|
20
|
+
|
21
|
+
def has_subcommands?
|
22
|
+
!recognised_subcommands.empty?
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_subcommand(name)
|
26
|
+
recognised_subcommands.find { |sc| sc.is_called?(name) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def has_subcommands!
|
30
|
+
unless @has_subcommands
|
31
|
+
parameter "[SUBCOMMAND]", "subcommand name", :attribute_name => :subcommand_name
|
32
|
+
parameter "[ARGS] ...", "subcommand arguments", :attribute_name => :subcommand_arguments
|
33
|
+
@has_subcommands = true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Clamp
|
2
|
+
class Subcommand
|
3
|
+
|
4
|
+
module Execution
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
def execute_subcommand
|
9
|
+
if subcommand_name
|
10
|
+
subcommand_class = find_subcommand_class(subcommand_name)
|
11
|
+
subcommand = subcommand_class.new("#{invocation_path} #{subcommand_name}", context)
|
12
|
+
self.class.recognised_options.each do |option|
|
13
|
+
option_set = instance_variable_defined?(option.ivar_name)
|
14
|
+
if option_set && subcommand.respond_to?(option.write_method)
|
15
|
+
subcommand.send(option.write_method, self.send(option.read_method))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
subcommand.run(subcommand_arguments)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def find_subcommand(name)
|
25
|
+
self.class.find_subcommand(name) ||
|
26
|
+
signal_usage_error("No such sub-command '#{name}'")
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_subcommand_class(name)
|
30
|
+
subcommand = find_subcommand(name)
|
31
|
+
subcommand.subcommand_class if subcommand
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/lib/wpb/comment.rb
CHANGED
@@ -1,5 +1,44 @@
|
|
1
1
|
require "active_record"
|
2
2
|
|
3
|
+
##
|
4
|
+
# This class is used for getting the comments from the wordpress database
|
5
|
+
#
|
6
|
+
# == Examples:
|
7
|
+
# User.find(1).comments
|
8
|
+
# <em>The above will find the user with id of 1 and retrieve all of the comments they have ever made</em>
|
9
|
+
# Post.find(1).comments
|
10
|
+
# <em>The above will find the post with id of 1 and retrieve all of the comments from that post</em>
|
11
|
+
# Comment.find(1)
|
12
|
+
# <em>The above will find the comment with id of 1</em>
|
13
|
+
#
|
14
|
+
# == Inherited methods
|
15
|
+
# [find <em>id</em>] Retrieves the comment with the sepcified id
|
16
|
+
# [all] Retrieves all of the comments in the database
|
17
|
+
#
|
18
|
+
# == Database Keys
|
19
|
+
# [comment_ID <em>alias: id</em>] The comments id
|
20
|
+
# [comment_post_ID <em>alias: post.id</em>]
|
21
|
+
# The post id where the comment was posted
|
22
|
+
# Comment.find(1).post
|
23
|
+
# <em>The above returns the Post that the comment belongs to</em>
|
24
|
+
# [comment_author] The name of the auther (could be stored in user.name, User#name)
|
25
|
+
# [comment_author_email] The email of the author (could be stored in user.email, User#email)
|
26
|
+
# [comment_author_url] The url of the author (could be stored in user.url, User#url)
|
27
|
+
# [comment_author_IP] The ip of the author
|
28
|
+
# [comment_date] The date the comment was posted
|
29
|
+
# [comment_date_gmt] The date the comment was posted in gmt/utc time
|
30
|
+
# [comment_content <em>alias: Comment#content</em>] The content of the comment
|
31
|
+
# [comment_karma] The comment karma
|
32
|
+
# [comment_approved] If the comment has been approved or not
|
33
|
+
# [comment_agent] The agent of the comment
|
34
|
+
# [comment_type] The type of comment
|
35
|
+
# [comment_parent] The parent comment id if any
|
36
|
+
# [user_id]
|
37
|
+
# The user id of the author (0 if not registered user)
|
38
|
+
# Comment.find(1).user
|
39
|
+
# <em>The above returns the User that posted the comment if user_id isn't 0</em>
|
40
|
+
|
41
|
+
|
3
42
|
class Comment < ActiveRecord::Base
|
4
43
|
set_table_name :wp_comments
|
5
44
|
set_primary_key :comment_ID
|
@@ -11,17 +50,24 @@ class Comment < ActiveRecord::Base
|
|
11
50
|
|
12
51
|
before_create :set_default_values
|
13
52
|
|
14
|
-
|
15
|
-
|
16
|
-
self.comment_date = t
|
17
|
-
self.comment_date_gmt = t.gmtime
|
18
|
-
end
|
53
|
+
##
|
54
|
+
# Grab the content of the selected comment
|
19
55
|
|
20
56
|
def content
|
21
57
|
comment_content
|
22
58
|
end
|
23
59
|
|
60
|
+
##
|
61
|
+
# Set the content of the selected comment
|
62
|
+
|
24
63
|
def content= new_content
|
25
64
|
self.comment_content = new_content
|
26
65
|
end
|
66
|
+
|
67
|
+
private
|
68
|
+
def set_default_values
|
69
|
+
t = Time.now
|
70
|
+
self.comment_date = t
|
71
|
+
self.comment_date_gmt = t.gmtime
|
72
|
+
end
|
27
73
|
end
|
data/lib/wpb/page.rb
CHANGED
@@ -1,3 +1,49 @@
|
|
1
|
+
##
|
2
|
+
# This class is used for getting the pages from the wordpress database
|
3
|
+
#
|
4
|
+
# == Examples:
|
5
|
+
# User.find(1).pages
|
6
|
+
# <em>The above will find the user with id of 1 and retrieve all of the pages they have ever made</em>
|
7
|
+
# Page.find(1)
|
8
|
+
# <em>The above will find the pge with id of 1</em>
|
9
|
+
#
|
10
|
+
# == Inherited methods
|
11
|
+
# [find <em>id</em>] Retrieves the page with the sepcified id
|
12
|
+
# [all] Retrieves all of the pages in the database
|
13
|
+
# [title] The title of the page
|
14
|
+
# [title= <em>title</em>] Set the title of the page
|
15
|
+
# [content] The content of the page
|
16
|
+
# [content=] Set the content of the page
|
17
|
+
#
|
18
|
+
# == Database Keys
|
19
|
+
# [ID <em>alias: id</em>] The pages` id
|
20
|
+
# [post_author <em>alias: user.id</em>]
|
21
|
+
# The User id of who created the Page
|
22
|
+
# Page.find(1).user
|
23
|
+
# <em>The above returns the User that the page belongs to</em>
|
24
|
+
# [post_date] The date the page was created
|
25
|
+
# [post_date_gmt] The date the page was created in gmt/utc time
|
26
|
+
# [post_content <em>alias: PagePost#content</em>] The content of the page
|
27
|
+
# [post_title <em>alias: PagePost#title</em>] The title of the page
|
28
|
+
# [post_excerpt] The excerpt of the page
|
29
|
+
# [post_status] The status of the page <em>e.g. +Published+</em>
|
30
|
+
# [comment_status] Whether or not comments are allowed e.g. open
|
31
|
+
# [ping_status] Whether or not pings are allowed e.g. open
|
32
|
+
# [post_password] The password (if any) required to view the page
|
33
|
+
# [post_name] The url version of the page e.g. example-page
|
34
|
+
# [to_ping] _Unknown_
|
35
|
+
# [pinged] _Unknown_
|
36
|
+
# [post_modified] The date the page last edited
|
37
|
+
# [post_modified_gmt] The date the page last edited in gmt/utc time
|
38
|
+
# [post_content_filtered] _Unknown_
|
39
|
+
# [post_parent] The pages parent id (if any)
|
40
|
+
# [guid] The full url to the page
|
41
|
+
# [menu_order] The order at which the page sits in the menu
|
42
|
+
# [post_type] The type of the post e.g. page or post (will always be page)
|
43
|
+
# [post_mime_type] The mime type of the post
|
44
|
+
# [comment_count] The amount of comments on the page
|
45
|
+
# [type] Used and created by wpb for activerecord inheritance
|
46
|
+
|
1
47
|
class Page < PagePost
|
2
48
|
belongs_to :user
|
3
49
|
end
|