quickpress 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,163 @@
1
+ # quickpress
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/quickpress.png)](http://badge.fury.io/rb/quickpress)
4
+ [![emacs banner](http://badges.alexdantas.net/emacs.png)](http://badges.alexdantas.net/)
5
+ [![free-software banner](http://badges.alexdantas.net/free-software.png)](http://badges.alexdantas.net/)
6
+
7
+ Manage your Wordpress site on the command-line.
8
+
9
+ ## Features
10
+
11
+ Quickpress allows you to quickly post on your Wordpress site.
12
+ It is also:
13
+
14
+ * **Powerful**: With quickpress you can create, delete and list
15
+ your posts and pages. More actions are expected on next releases.
16
+ * **Easy-to-use**: [Two to three commands](#getting-started) should
17
+ be everything you need to know about it.
18
+ * **Versatile**: It supports a wide range of templating languages.
19
+ Markdown, Asciidoc, ERB and [much more](#supported-template-engines)!
20
+ * **Documented**: [The wiki][wiki]
21
+ has all the guides you'll ever need. Also, reference is only
22
+ a `qp help` away.
23
+ * **Unified**: Works on both Wordpress.com and self-hosted Wordpress.org
24
+ websites.
25
+ * **Safe**: Quickpress doesn't store your username/password anywhere.
26
+ * **Free**: It is licensed under the GPLv3. It means that quickpress
27
+ will always be free
28
+ ([both as in "free beer" and as in "freedom"](http://en.wikipedia.org/wiki/Gratis_versus_libre#.22Free_beer.22_vs_.22free_speech.22_distinction)).
29
+
30
+ ## Installation
31
+
32
+ Quickpress is on RubyGems. To install it, do:
33
+
34
+ $ gem install quickpress
35
+
36
+ If you want to install it yourself, [grab the gem][gem]
37
+ and there you go!
38
+
39
+ ## Getting started
40
+
41
+ To use quickpress we call `qp` with some commands, just like `git`.
42
+
43
+ To start using a site withing quickpress, do:
44
+
45
+ $ qp new-site
46
+
47
+ Now you can do a lot with it. For example, let's list all
48
+ existing posts there:
49
+
50
+ $ qp list-posts
51
+
52
+ Want to post? Write it anywhere and point `qp` to it!
53
+
54
+ $ qp new-post my-post.md
55
+
56
+ If you're too lazy, calling `new-post` without no filenames will
57
+ call your default text editor to write it.
58
+ Try it!
59
+
60
+ Oops, you made a mistake and want to delete a post.
61
+ First, list them and then delete by id:
62
+
63
+ $ qp list-posts # shows all posts, with their ID
64
+ $ qp delete-post ID
65
+
66
+ All of the previous commands can be done with pages too.
67
+
68
+ Now say you want to post on another Worpress site.
69
+ By doing `qp new-site` it should become the default.
70
+
71
+ After doing this, you can switch between them by using:
72
+
73
+ $ qp list-sites # shows them all, with their ID
74
+ $ qp use-site ID # sets a default site by it's ID
75
+
76
+ If you want help with any command, just call:
77
+
78
+ $ qp help (command)
79
+
80
+ To see a list of all commands, call:
81
+
82
+ $ qp help
83
+
84
+ Finally, a simple cheatsheet is shown when doing:
85
+
86
+ $ qp
87
+
88
+ For more help and nice guides, check out [the wiki][wiki].
89
+
90
+ ## Supported template engines
91
+
92
+ Thanks to [Tilt][tilt], you can write on `quickpress` with several templating
93
+ engines. Just be sure to have at least one *required gem* of your favorite
94
+ *engine*.
95
+
96
+ | Engine | File extensions | Required gem |
97
+ | ----------------------- | --------------------- | -------------------------- |
98
+ | Asciidoc | .ad, .adoc, .asciidoc | `asciidoctor` (>= 0.1.0)|
99
+ | ERB | .erb, .rhtml | none (included on ruby stdlib)|
100
+ | Interpolated String | .str | none (included on ruby core)|
101
+ | Erubis | .erb, .rhtml, .erubis | `erubis`|
102
+ | Haml | .haml | `haml`|
103
+ | Sass | .sass | `haml` (< 3.1) or `sass` (>= 3.1)|
104
+ | Scss | .scss | `haml` (< 3.1) or `sass` (>= 3.1)|
105
+ | Less CSS | .less | `less`|
106
+ | Builder | .builder | `builder`|
107
+ | Liquid | .liquid | `liquid`|
108
+ | Markdown | .markdown, .mkd, .md | `rdiscount` or `redcarpet` or `bluecloth` or `kramdown` or `maruku`|
109
+ | Textile | .textile | `redcloth`|
110
+ | RDoc | .rdoc | `rdoc`|
111
+ | Radius | .radius | `radius`|
112
+ | Markaby | .mab | `markaby`|
113
+ | Nokogiri | .nokogiri | `nokogiri`|
114
+ | CoffeeScript | .coffee | `coffee-script` (+ javascript)|
115
+ | Creole (Wiki markup) | .wiki, .creole | `creole`|
116
+ | MediaWiki (Wiki markup) | .wiki, .mediawiki, .mw| `wikicloth`|
117
+ | Yajl | .yajl | `yajl-ruby`|
118
+ | CSV | .rcsv | none (Ruby >= 1.9), `fastercsv` (Ruby < 1.9)|
119
+
120
+ As said before, simply point `qp` to the filename or specify the engine in
121
+ lowercase:
122
+
123
+ $ qp post my-markdown.md
124
+ $ qp post my-asciidoc.adoc
125
+ $ qp post -m asciidoc my-text-file.txt
126
+ $ qp post -m textile my-text-file.txt
127
+
128
+ ## Development
129
+
130
+ Quickpress uses [Thor][thor] for it's CLI interface and [rubypress] for
131
+ the Wordpress XMLRPC API.
132
+
133
+ For now the source code is a mess.
134
+ Any comments are well-appreciated.
135
+
136
+ Contributions are *always* welcome, regardless of the size.
137
+ Here's how you can do it:
138
+
139
+ 1. Fork me
140
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
141
+ 3. Do your magic
142
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
143
+ 5. Push to the branch (`git push origin my-new-feature`)
144
+ 6. Create new Pull Request
145
+
146
+ An easy way is to help on documentation. For that, simply head up
147
+ for [the wiki][wiki] and start editing things.
148
+
149
+ ## Contact
150
+
151
+ Hi, I'm Alexandre Dantas! Thanks for having interest in this project.
152
+ Please take the time to visit any of the links below.
153
+
154
+ * `quickpress` homepage: http://quickpress.alexdantas.net/
155
+ * My homepage: http://www.alexdantas.net
156
+ * Mail me: `eu at alexdantas.net`
157
+
158
+ [tilt]:https://github.com/rtomayko/tilt
159
+ [thor]:http://whatisthor.com/
160
+ [rubypress]:https://github.com/zachfeldman/rubypress
161
+ [wiki]:https://github.com/alexdantas/quickpress/wiki
162
+ [gem]:https://rubygems.org/gem/quickpress/
163
+
@@ -0,0 +1,3 @@
1
+ # See default bundler take tasks with `rake -T`
2
+ require "bundler/gem_tasks"
3
+
data/bin/qp ADDED
@@ -0,0 +1,417 @@
1
+ #!/usr/bin/env ruby
2
+ # ___ _ _ __ _ ___ ___ ____ __ __
3
+ # / / \ | | | | | / /` | |_/ | |_) | |_) | |_ ( (` ( (`
4
+ # \_\_\\ \_\_/ |_| \_\_, |_| \ |_| |_| \ |_|__ _)_) _)_)
5
+
6
+ require 'thor'
7
+ require 'quickpress'
8
+
9
+ # Command line interface above the `Quickpress` class.
10
+ #
11
+ class QP < Thor
12
+
13
+ # Global `--debug` flag
14
+ class_option(:debug,
15
+ :desc => "debugging mode",
16
+ :type => :boolean)
17
+
18
+ # _ ____ _ ___ ___ __ _____
19
+ # | |\ | | |_ \ \ / | |_) / / \ ( (` | |
20
+ # |_| \| |_|__ \_\/\/ |_| \_\_/ _)_) |_|
21
+ #
22
+ desc('new-post [FILENAME]',
23
+ 'Creates a post on your Wordpress site')
24
+
25
+ option('markup',
26
+ :banner => "name",
27
+ :desc => "markup language",
28
+ :aliases => "-m")
29
+
30
+ long_desc(<<-END).remove_starting!
31
+ If FILENAME is given, will post it to your Wordpress site.
32
+
33
+ If no FILENAME is set, will launch default text editor and
34
+ \x5wait for you to write a post. After you save it, will post
35
+ \x5that.
36
+
37
+ * Set default text editor with the `EDITOR` environment
38
+ \x5variable.
39
+ \x5* For a list of markup languages, do `qp markup-list`.
40
+ END
41
+
42
+ def new_post(filename=nil)
43
+ $options[:debug] = options[:debug]
44
+ $options[:markup] = options[:markup]
45
+
46
+ Quickpress::new(:post, filename)
47
+ end
48
+
49
+ # _ _ __ _____ ___ ___ __ _____ __
50
+ # | | | | ( (` | | | |_) / / \ ( (` | | ( (`
51
+ # |_|__ |_| _)_) |_| |_| \_\_/ _)_) |_| _)_)
52
+ #
53
+ desc('list-posts [COUNT]',
54
+ 'Shows last posts from Wordpress site')
55
+
56
+ long_desc <<-END.remove_starting!
57
+ If COUNT is given, will show last COUNT posts,
58
+ \x5most recent first.
59
+
60
+ If no COUNT is given, will show all posts.
61
+ END
62
+
63
+ def list_posts(ammount=0)
64
+ $options[:debug] = options[:debug]
65
+ Quickpress::list(:post, ammount.to_i)
66
+ end
67
+
68
+ # ___ ____ _____ ____ _ ____ ___ ___ __ _____
69
+ # | | \ | |_ | | | |_ | | | |_ | |_) / / \ ( (` | |
70
+ # |_|_/ |_|__ |_| |_|__ |_|__ |_|__ |_| \_\_/ _)_) |_|
71
+ #
72
+ desc('delete-post ID',
73
+ 'Deletes post by ID')
74
+
75
+ option('force',
76
+ :type => :boolean,
77
+ :desc => "delete without confirming first",
78
+ :aliases => "-f")
79
+
80
+ long_desc(<<-END).remove_starting!
81
+ Deletes the post with numerical id equal to ID.
82
+
83
+ To see IDs, use `qp list-posts`.
84
+
85
+ You can specify multiple IDs, just make sure to
86
+ \x5keep them apart with commas.
87
+
88
+ For example:
89
+
90
+ > $ qp delete-post "4,8,15,16,23,42"
91
+
92
+ If the post doesn't exist, do nothing.
93
+ END
94
+
95
+ def delete_post(ids)
96
+ $options[:debug] = options[:debug]
97
+ $options[:force] = options[:force]
98
+
99
+ Quickpress::delete(:post, ids)
100
+ end
101
+
102
+ # _ ____ _ ___ __ __ ____
103
+ # | |\ | | |_ \ \ / | |_) / /\ / /`_ | |_
104
+ # |_| \| |_|__ \_\/\/ |_| /_/--\ \_\_/ |_|__
105
+ #
106
+ desc('new-page [FILENAME]',
107
+ 'Creates a page on your Wordpress site')
108
+
109
+ option('markup',
110
+ :banner => "name",
111
+ :desc => "markup language",
112
+ :aliases => "-m")
113
+
114
+ long_desc <<-END.remove_starting!
115
+ If FILENAME is given, will send it as a page to your
116
+ \x5Wordpress site.
117
+
118
+ If no FILENAME is set, will launch default text editor and
119
+ \x5wait for you to write a page. After you save it, will send
120
+ \x5that.
121
+
122
+ * Set default text editor with the `EDITOR` environment
123
+ \x5 variable.
124
+ \x5* For a list of markup languages, do `qp list-markup`.
125
+ END
126
+
127
+ def new_page(filename=nil)
128
+ $options[:debug] = options[:debug]
129
+ $options[:markup] = options[:markup]
130
+
131
+ Quickpress::new(:page, filename)
132
+ end
133
+
134
+ # _ _ __ _____ ___ __ __ ____ __
135
+ # | | | | ( (` | | | |_) / /\ / /`_ | |_ ( (`
136
+ # |_|__ |_| _)_) |_| |_| /_/--\ \_\_/ |_|__ _)_)
137
+ #
138
+ desc('list-pages [COUNT]',
139
+ 'Shows last pages from Wordpress site')
140
+
141
+ long_desc <<-END.remove_starting!
142
+ If COUNT is given, will show last COUNT pages,
143
+ \x5most recent first.
144
+
145
+ If no COUNT is given, will show all pages.
146
+ END
147
+
148
+ def list_pages(ammount=0)
149
+ $options[:debug] = options[:debug]
150
+ Quickpress::list(:page, ammount.to_i)
151
+ end
152
+
153
+ # ___ ____ _ ____ _____ ____ ___ __ __ ____
154
+ # | | \ | |_ | | | |_ | | | |_ | |_) / /\ / /`_ | |_
155
+ # |_|_/ |_|__ |_|__ |_|__ |_| |_|__ |_| /_/--\ \_\_/ |_|__
156
+ #
157
+ desc('delete-page ID',
158
+ 'Deletes page by ID')
159
+
160
+ option('force',
161
+ :type => :boolean,
162
+ :desc => "delete without confirming first",
163
+ :aliases => "-f")
164
+
165
+ long_desc(<<-END).remove_starting!
166
+ Deletes the page with numerical id equal to ID.
167
+
168
+ To see IDs, use `qp list-pages`.
169
+
170
+ You can specify multiple IDs, just make sure to
171
+ \x5keep them apart with commas.
172
+ \x5For example:
173
+
174
+ > $ qp delete-page "42,666,1337"
175
+
176
+ If the page doesn't exist, do nothing.
177
+ END
178
+
179
+ def delete_page(ids)
180
+ $options[:debug] = options[:debug]
181
+ $options[:force] = options[:force]
182
+
183
+ Quickpress::delete(:page, ids)
184
+ end
185
+
186
+ # _ ____ _ __ _ _____ ____
187
+ # | |\ | | |_ \ \ / ( (` | | | | | |_
188
+ # |_| \| |_|__ \_\/\/ _)_) |_| |_| |_|__
189
+ #
190
+ desc('new-site [ADDRESS]',
191
+ 'Starts managing a Wordpress site.')
192
+
193
+ long_desc <<-END.remove_starting!
194
+ If ADDRESS is provided, add it to quickpress.
195
+
196
+ If not, will prompt you for an address, username and password.
197
+ \x5If everything's correct, will add that site to quickpress.
198
+
199
+ By adding we mean you'll be able to do all commands on it.
200
+
201
+ To see all sites added to quickpress, see `qp list-sites`.
202
+ END
203
+
204
+ def new_site(address=nil)
205
+ $options[:debug] = options[:debug]
206
+ Quickpress::new_site address
207
+ end
208
+
209
+ # _ _ __ _____ __ _ _____ ____ __
210
+ # | | | | ( (` | | ( (` | | | | | |_ ( (`
211
+ # |_|__ |_| _)_) |_| _)_) |_| |_| |_|__ _)_)
212
+ #
213
+ desc('list-sites',
214
+ 'Shows all sites currently added to quickpress')
215
+
216
+ long_desc <<-END.remove_starting!
217
+ Will list all sites you've added with `qp new-site`.
218
+ \x5If no COUNT is given, will show all pages.
219
+ END
220
+
221
+ def list_sites
222
+ $options[:debug] = options[:debug]
223
+ Quickpress::list_sites
224
+ end
225
+
226
+ # ____ ___ ___ __ ____ _____ __ _ _____ ____
227
+ # | |_ / / \ | |_) / /`_ | |_ | | ( (` | | | | | |_
228
+ # |_| \_\_/ |_| \ \_\_/ |_|__ |_| _)_) |_| |_| |_|__
229
+ #
230
+ desc('forget-site ID',
231
+ 'Forgets site with ID')
232
+
233
+ option('force',
234
+ :type => :boolean,
235
+ :desc => "forget without confirming first",
236
+ :aliases => "-f")
237
+
238
+ long_desc(<<-END).remove_starting!
239
+ Makes quickpress stop managing the site with numerical
240
+ \x5id equal to ID.
241
+
242
+ To see IDs, use `qp list-sites`.
243
+
244
+ You can specify multiple IDs, just make sure to
245
+ \x5keep them apart with commas.
246
+ \x5For example:
247
+
248
+ > $ qp forget-site "11,24,69"
249
+ END
250
+
251
+ def forget_site(ids)
252
+ $options[:debug] = options[:debug]
253
+ $options[:force] = options[:force]
254
+
255
+ Quickpress::forget_site(ids)
256
+ end
257
+
258
+ # _ __ ____ __ _ _____ ____
259
+ # | | | ( (` | |_ ( (` | | | | | |_
260
+ # \_\_/ _)_) |_|__ _)_) |_| |_| |_|__
261
+ #
262
+ desc('use-site ID',
263
+ 'Sets site with ID as default')
264
+
265
+ long_desc(<<-END).remove_starting!
266
+ From now on will do actions on the site with numerical
267
+ \x5id equal to ID.
268
+
269
+ To see IDs, use `qp list-sites`.
270
+ END
271
+
272
+ def use_site id
273
+ $options[:debug] = options[:debug]
274
+ Quickpress::use_site(id.to_i)
275
+ end
276
+
277
+ # _ _ __ _____ _ __ ___ _ _ ___
278
+ # | | | | ( (` | | | |\/| / /\ | |_) | |_/ | | | | |_)
279
+ # |_|__ |_| _)_) |_| |_| | /_/--\ |_| \ |_| \ \_\_/ |_|
280
+ #
281
+ desc('list-markup',
282
+ 'Show all supported templating languages')
283
+
284
+ long_desc(<<-END).remove_starting!
285
+ Lists all templating languages supported by quickpress.
286
+
287
+ You can use them with the `--markup` option when creating
288
+ \x5new posts or pages.
289
+
290
+ > $ qp new-post --markup asciidoc
291
+
292
+ If you create a post/page with a file, they're implied
293
+ \x5based on it's filename extension.
294
+
295
+ > $ qp new-post filename.asciidoc
296
+ END
297
+
298
+ def list_markup
299
+ Quickpress::list_markup
300
+ end
301
+ end
302
+
303
+ # ___ ____ __ _ _
304
+ # | |_) | |_ / /`_ | | | |\ |
305
+ # |_|_) |_|__ \_\_/ |_| |_| \|
306
+ #
307
+ begin
308
+ if ARGV.empty?
309
+ puts <<-END.remove_starting!
310
+ quickpress v#{Quickpress::VERSION}
311
+ Cheatsheet:
312
+
313
+ $ qp {new,delete}-{post,page}
314
+ $ qp list-(post|page|site)s
315
+ $ qp {new,forget}-site
316
+ $ qp use-site
317
+ $ qp list-markup
318
+
319
+ All commands: `qp help`
320
+ Command info: `qp help (command)`
321
+
322
+ Config directory: `~/.config/quickpress/`
323
+
324
+ homepage: http://quickpress.alexdantas.net
325
+ mailto: eu@alexdantas.net
326
+
327
+ This software is licensed under the
328
+ GNU General Public License version 3 or later.
329
+ END
330
+ exit
331
+ end
332
+
333
+ Quickpress::config_init
334
+ QP.start ARGV
335
+
336
+ # Real mess of error-handling.
337
+ # I wonder if there's a better way to do it.
338
+ #
339
+ # Well, at least I'm not polluting the whole code
340
+ # with this `rescue` stuff.
341
+
342
+ rescue Net::ReadTimeout
343
+ $stderr.puts <<-END.remove_starting!
344
+
345
+ * Connection took too long.
346
+ Check your internet settings and try again.
347
+ END
348
+ exit 666
349
+
350
+ rescue XMLRPC::FaultException => e
351
+ if e.message =~ /Incorrect username or password/
352
+
353
+ $stderr.puts <<-END.remove_starting!
354
+
355
+ * Incorrect username or password.
356
+ END
357
+
358
+ else
359
+ $stderr.puts
360
+ $stderr.puts e.message
361
+ end
362
+ exit 666
363
+
364
+ rescue ArgumentError => arg
365
+ if arg.message =~ /Wrong protocol specified/
366
+ $stderr.puts <<-END.remove_starting!
367
+ * Wrong protocol at Wordpress site.
368
+ Please use `http` or `https`.
369
+ END
370
+ exit 666
371
+ end
372
+
373
+ rescue Interrupt => i
374
+ $stderr.puts
375
+ $stderr.puts "* You've interrupted me, mate"
376
+
377
+ $stderr.puts i.backtrace if $options[:debug]
378
+ exit 666
379
+
380
+ rescue LoadError => l
381
+ $stderr.puts <<-END.remove_starting!
382
+
383
+ * Couldn't load '#{l.path}'.
384
+ Make sure it's gem is installed and try again.
385
+ END
386
+ exit 666
387
+
388
+ rescue StandardError => e
389
+
390
+ if e.message =~ /Wrong content-type/
391
+ $stderr.puts <<-END.remove_starting!
392
+ * This doesn't seem to be a Wordpress site.
393
+ Check the address again.
394
+ END
395
+ exit 666
396
+
397
+ elsif e.message =~ /Name or service not known/
398
+ $stderr.puts <<-END.remove_starting!
399
+
400
+ * Connection error!
401
+ Either site doesn't exist or there's
402
+ something wrong with your internet connection.
403
+ END
404
+
405
+ if Quickpress::CLI::ask("Wanna retry?")
406
+ puts
407
+ retry
408
+ end
409
+ exit 666
410
+ end
411
+
412
+ $stderr.puts e
413
+ $stderr.puts e.message
414
+ $stderr.puts e.backtrace if $options[:debug]
415
+ exit 666
416
+ end
417
+