quickpress 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,111 @@
1
+ require 'io/console' # ruby 1.9.3 above
2
+ require 'abbrev'
3
+
4
+ module Quickpress
5
+
6
+ # Basic input/output functions for the console.
7
+ #
8
+ # They're *not* how we handle the quickpress commands - for that
9
+ # check `bin/qp`.
10
+ #
11
+ # These are ways to interact with the user - get password
12
+ # input, ask yes-or-no questions and such.
13
+ #
14
+ module CLI
15
+ module_function
16
+
17
+ # Shows `prompt` and gets a string from the user.
18
+ #
19
+ # This ensures that the string is not empty
20
+ # and pre/post spaces are removed.
21
+ def get prompt
22
+ print "#{prompt} "
23
+
24
+ ret = ""
25
+ ret = $stdin.gets.lstrip.strip while ret.empty?
26
+ ret
27
+ end
28
+
29
+ # Shows `prompt` and gets a secret string from the user.
30
+ #
31
+ # Hides things the user is typing.
32
+ def get_secret prompt
33
+ ret = ""
34
+
35
+ $stdin.noecho { ret = get(prompt) }
36
+
37
+ puts
38
+ ret
39
+ end
40
+
41
+ # Asks `prompt` and returns a true/false answer.
42
+ def ask prompt
43
+ print "#{prompt} (Y/n) "
44
+
45
+ ans = $stdin.gets.lstrip.strip
46
+
47
+ return true if ans.empty?
48
+ ['y', 'Y'].include? ans
49
+ end
50
+
51
+ # Erases from the cursor to the beginning of line.
52
+ def clear_line
53
+ print "\r\e[0K"
54
+ end
55
+
56
+ # Runs a block of code withing a quick status `prompt`.
57
+ def with_status(prompt)
58
+ print prompt
59
+ yield
60
+ clear_line
61
+ end
62
+
63
+ # Shows `prompt` and reads a line from commandline,
64
+ # doing tab-completion according to `completions` Array.
65
+ #
66
+ # `separator` is the character to use when separating
67
+ # words.
68
+
69
+ def tab_complete(prompt, completions, separator=" ")
70
+
71
+ abbrevs = Abbrev::abbrev completions
72
+ word = ""
73
+ line = ""
74
+
75
+ $stdin.raw do
76
+ while (char = $stdin.getch) != "\r"
77
+
78
+ if char == "\t"
79
+ if abbrevs.include?(word)
80
+ word = abbrevs[word]
81
+ end
82
+
83
+ elsif (char == "\b" || char.ord == 127) # strange...
84
+ if word.empty?
85
+ line.chop!
86
+ else
87
+ word.chop!
88
+ end
89
+
90
+ else
91
+ word += char
92
+
93
+ if char == separator
94
+ line += word
95
+ word.clear
96
+ end
97
+ end
98
+
99
+ clear_line
100
+ print (line + word)
101
+ end
102
+ line += word
103
+ end
104
+ puts
105
+
106
+ line
107
+ end
108
+
109
+ end
110
+ end
111
+
@@ -0,0 +1,21 @@
1
+
2
+ module Quickpress
3
+ class Options
4
+ def initialize
5
+ @options = {}
6
+ @options[:force] = false
7
+ @options[:markup] = 'markdown'
8
+ end
9
+
10
+ def [] label
11
+ @options[label]
12
+ end
13
+
14
+ def []=(label, val)
15
+ @options[label] = val
16
+ end
17
+ end
18
+
19
+ $options = Options.new
20
+ end
21
+
@@ -0,0 +1,6 @@
1
+ module Quickpress
2
+ VERSION = '0.0.1'
3
+ VERSION_MAJOR = VERSION.split('.')[0]
4
+ VERSION_MINOR = VERSION.split('.')[1]
5
+ VERSION_PATCH = VERSION.split('.')[2]
6
+ end
@@ -0,0 +1,114 @@
1
+ require 'rubypress'
2
+
3
+ module Quickpress
4
+
5
+ # Handles calls to the Wordpress API
6
+ #
7
+ class Wordpress
8
+ # Blog title.
9
+ attr_reader :title
10
+
11
+ # Blog subtitle.
12
+ attr_reader :tagline
13
+
14
+ # Blog address
15
+ attr_reader :url
16
+
17
+ # All categories on blog
18
+ attr_reader :categories
19
+
20
+ # Yes it is
21
+ VERY_LARGE_NUMBER = 2**31 - 1
22
+
23
+ # Creates a new connection to `url` with `user`/`pass`.
24
+ def initialize(url, user, pass)
25
+
26
+ # Sanitizing url:
27
+ #
28
+ # If provided with something like "mysite.com/blog"
29
+ # * host will be "mysite.com"
30
+ # * path will be "/blog/xmlrpc.php"
31
+
32
+ host = url
33
+ path = "/xmlrpc.php"
34
+ paths = url.split '/'
35
+
36
+ if paths.size > 1
37
+ host = paths[0]
38
+
39
+ path = '/' + paths[1..-1].join('/') + "/xmlrpc.php"
40
+ end
41
+
42
+ @client = Rubypress::Client.new(:host => host,
43
+ :path => path,
44
+ :username => user,
45
+ :password => pass)
46
+
47
+ # Actually connecting
48
+ options = @client.getOptions
49
+
50
+ @title = options["blog_title"]["value"]
51
+ @tagline = options["blog_tagline"]["value"]
52
+ @url = options["blog_url"]["value"]
53
+
54
+ @categories = []
55
+ terms = @client.getTerms(:taxonomy => 'category')
56
+ terms.each do |term|
57
+ @categories << term["name"]
58
+ end
59
+ end
60
+
61
+ # Sends a post/page to the Wordpress site.
62
+ def post options
63
+ id = @client.newPost(:content => options)
64
+ link = @client.getPost(:post_id => id, :fields => [:link])["link"]
65
+
66
+ return id, link
67
+ end
68
+
69
+ def get_post id
70
+ @client.getPost(:post_id => id)
71
+ end
72
+
73
+ def get_page id
74
+ @client.getPost(:post_id => id,
75
+ :filter => {
76
+ :post_type => 'page'
77
+ })
78
+ end
79
+
80
+ # Returns `ammount` posts.
81
+ # If `ammount` is zero, will return all posts.
82
+ # FIXME when getting by `ammount` it is ordered by the opposite
83
+ def get_posts(ammount=0)
84
+ ammount = VERY_LARGE_NUMBER if ammount.zero?
85
+
86
+ @client.getPosts(:filter => { :number => ammount })
87
+ end
88
+
89
+ # Returns `ammount` pages.
90
+ # If `ammount` is zero, will return all posts.
91
+ # FIXME when getting by `ammount` it is ordered by the opposite
92
+ def get_pages(ammount=0)
93
+ ammount = VERY_LARGE_NUMBER if ammount.zero?
94
+
95
+ @client.getPosts(:filter => {
96
+ :number => ammount,
97
+ :post_type => 'page'
98
+ })
99
+ end
100
+
101
+ def delete_post id
102
+ @client.deletePost(:post_id => id)
103
+ end
104
+
105
+ def delete_page id
106
+ @client.deletePost(:post_id => id,
107
+ :filter => {
108
+ :post_type => 'page'
109
+ })
110
+ end
111
+
112
+ end
113
+ end
114
+
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'quickpress/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'quickpress'
8
+ spec.version = Quickpress::VERSION
9
+ spec.authors = ["Alexandre Dantas"]
10
+ spec.email = ["eu@alexdantas.net"]
11
+ spec.summary = "Manage your Wordpress site on the command line"
12
+ spec.description = <<END
13
+ Quickpress allows you to create, delete and list your
14
+ posts and pages on the command line.
15
+
16
+ It supports a great deal of template languages allowing you to
17
+ write the way you like.
18
+ END
19
+
20
+ spec.homepage = "http://quickpress.alexdantas.net/"
21
+ spec.license = "GPL-3.0"
22
+
23
+ spec.files = `git ls-files`.split($/)
24
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
25
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_dependency 'rubypress'
29
+ spec.add_dependency 'tilt'
30
+ spec.add_dependency 'thor'
31
+
32
+ spec.add_development_dependency 'rdoc'
33
+ spec.add_development_dependency 'bundler', '~> 1.3'
34
+ spec.add_development_dependency 'rake'
35
+ end
36
+
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quickpress
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexandre Dantas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubypress
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tilt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: |
98
+ Quickpress allows you to create, delete and list your
99
+ posts and pages on the command line.
100
+
101
+ It supports a great deal of template languages allowing you to
102
+ write the way you like.
103
+ email:
104
+ - eu@alexdantas.net
105
+ executables:
106
+ - qp
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - ".gitignore"
111
+ - Gemfile
112
+ - LICENSE
113
+ - README.md
114
+ - Rakefile
115
+ - bin/qp
116
+ - lib/quickpress.rb
117
+ - lib/quickpress/cli.rb
118
+ - lib/quickpress/options.rb
119
+ - lib/quickpress/version.rb
120
+ - lib/quickpress/wordpress.rb
121
+ - quickpress.gemspec
122
+ homepage: http://quickpress.alexdantas.net/
123
+ licenses:
124
+ - GPL-3.0
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.1.7
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Manage your Wordpress site on the command line
146
+ test_files: []
147
+ has_rdoc: