RuGPost 0.1.0.1.beta → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/Gemfile +6 -6
  2. data/Gemfile.lock +34 -5
  3. data/README.rdoc +43 -3
  4. data/Rakefile +13 -39
  5. data/RuGPost.gemspec +54 -12
  6. data/VERSION +1 -1
  7. data/bin/rugpost +9 -0
  8. data/lib/RuGPost.rb +26 -0
  9. data/lib/rugpost/commands.rb +15 -0
  10. data/lib/rugpost/commands/post_commands.rb +20 -0
  11. data/lib/rugpost/commands/project_commands.rb +23 -0
  12. data/lib/rugpost/on_error.rb +6 -0
  13. data/lib/rugpost/post.rb +96 -0
  14. data/lib/rugpost/prepost.rb +10 -0
  15. data/lib/rugpost/project.rb +34 -0
  16. data/lib/rugpost/site.rb +6 -0
  17. data/lib/rugpost/utilis.rb +27 -0
  18. data/rdoc/classes/RuGPost.html +200 -0
  19. data/rdoc/classes/RuGPost/Post.html +462 -0
  20. data/rdoc/classes/RuGPost/Project.html +210 -0
  21. data/rdoc/classes/RuGPost/Site.html +111 -0
  22. data/rdoc/classes/RuGPost/Utilis.html +196 -0
  23. data/rdoc/created.rid +1 -0
  24. data/rdoc/files/README_rdoc.html +204 -0
  25. data/rdoc/files/lib/RuGPost_rb.html +113 -0
  26. data/rdoc/files/lib/rugpost/commands/post_commands_rb.html +101 -0
  27. data/rdoc/files/lib/rugpost/commands/project_commands_rb.html +101 -0
  28. data/rdoc/files/lib/rugpost/commands_rb.html +108 -0
  29. data/rdoc/files/lib/rugpost/on_error_rb.html +101 -0
  30. data/rdoc/files/lib/rugpost/post_rb.html +101 -0
  31. data/rdoc/files/lib/rugpost/prepost_rb.html +101 -0
  32. data/rdoc/files/lib/rugpost/project_rb.html +101 -0
  33. data/rdoc/files/lib/rugpost/site_rb.html +101 -0
  34. data/rdoc/files/lib/rugpost/utilis_rb.html +101 -0
  35. data/rdoc/fr_class_index.html +31 -0
  36. data/rdoc/fr_file_index.html +37 -0
  37. data/rdoc/fr_method_index.html +43 -0
  38. data/rdoc/index.html +26 -0
  39. data/rdoc/rdoc-style.css +208 -0
  40. data/spec/post_spec.rb +76 -0
  41. data/spec/project_spec.rb +40 -0
  42. data/spec/spec_helper.rb +24 -0
  43. metadata +100 -33
data/Gemfile CHANGED
@@ -1,13 +1,13 @@
1
1
  source "http://rubygems.org"
2
2
  # Add dependencies required to use your gem here.
3
3
  # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
4
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
5
+ gem "gli", ">= 1.3.0"
6
+ gem "RedCloth", ">= 4.2.7"
7
+ gem "gmail", ">= 0.4.0"
8
+ gem "extlib", ">= 0.9.15"
9
+
8
10
  group :development do
9
- gem "shoulda", ">= 0"
10
- gem "bundler", "~> 1.0.0"
11
11
  gem "jeweler", "~> 1.6.0"
12
- gem "rcov", ">= 0"
12
+ gem "rspec", "~> 2.5.0"
13
13
  end
data/Gemfile.lock CHANGED
@@ -1,20 +1,49 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ RedCloth (4.2.7)
5
+ diff-lcs (1.1.2)
6
+ extlib (0.9.15)
4
7
  git (1.2.5)
8
+ gli (1.3.0)
9
+ gmail (0.4.0)
10
+ gmail_xoauth (>= 0.3.0)
11
+ mail (>= 2.2.1)
12
+ mime (>= 0.1)
13
+ gmail_xoauth (0.3.0)
14
+ oauth (>= 0.3.6)
15
+ i18n (0.5.0)
5
16
  jeweler (1.6.0)
6
17
  bundler (~> 1.0.0)
7
18
  git (>= 1.2.5)
8
19
  rake
20
+ mail (2.3.0)
21
+ i18n (>= 0.4.0)
22
+ mime-types (~> 1.16)
23
+ treetop (~> 1.4.8)
24
+ mime (0.1)
25
+ mime-types (1.16)
26
+ oauth (0.4.4)
27
+ polyglot (0.3.1)
9
28
  rake (0.8.7)
10
- rcov (0.9.9)
11
- shoulda (2.11.3)
29
+ rspec (2.5.0)
30
+ rspec-core (~> 2.5.0)
31
+ rspec-expectations (~> 2.5.0)
32
+ rspec-mocks (~> 2.5.0)
33
+ rspec-core (2.5.2)
34
+ rspec-expectations (2.5.0)
35
+ diff-lcs (~> 1.1.2)
36
+ rspec-mocks (2.5.0)
37
+ treetop (1.4.9)
38
+ polyglot (>= 0.3.1)
12
39
 
13
40
  PLATFORMS
14
41
  ruby
15
42
 
16
43
  DEPENDENCIES
17
- bundler (~> 1.0.0)
44
+ RedCloth (>= 4.2.7)
45
+ extlib (>= 0.9.15)
46
+ gli (>= 1.3.0)
47
+ gmail (>= 0.4.0)
18
48
  jeweler (~> 1.6.0)
19
- rcov
20
- shoulda
49
+ rspec (~> 2.5.0)
data/README.rdoc CHANGED
@@ -1,6 +1,47 @@
1
1
  = RuGPost
2
2
 
3
- Description goes here.
3
+ **RuGPost** (Ruby, Gmail and Posterous) is a command line facility which allows you to create posts on your own [posterous](posterous.com) sites using your GMail account.
4
+
5
+ You simply start creating your site local repo where adding your drafts. Drafts are written using **textile** lightweight markup.
6
+
7
+ When a draft is ready for publishng, you just need to _publish_ it. **RuGPost** will convert the draft to **html** and will create a post on the related site for you, using your GMail account.
8
+
9
+ = Installation
10
+
11
+ gem install RuGPost
12
+
13
+ = Usage
14
+
15
+ Create and initialize a RuGPost project:
16
+
17
+ mkdir MyProject
18
+ cd MyProject
19
+ rugpost init
20
+ rugpost config --gmail=gmailusername
21
+
22
+ Add a repository (must have same name of the posterous site):
23
+
24
+ rugpost repo RuGPost
25
+
26
+ Create your first draft in the just created site repo:
27
+
28
+ rugpost draft helloworld
29
+
30
+ Publish your draft:
31
+
32
+ rugpost publish helloworld gmailpassword
33
+
34
+ That's all. Note that if you follow the above steps as is, you should be able to post in a minute a nice 'helloworld' on rugpost.posterous.com. You are invited to do so.
35
+
36
+ = Help
37
+
38
+ For help about the available commands use:
39
+
40
+ rugpost --help
41
+
42
+ For help about a specific command use:
43
+
44
+ rugpost --help <command>
4
45
 
5
46
  == Contributing to RuGPost
6
47
 
@@ -14,6 +55,5 @@ Description goes here.
14
55
 
15
56
  == Copyright
16
57
 
17
- Copyright (c) 2011 emime. See LICENSE.txt for
58
+ Copyright (c) 2011 empo. See LICENSE.txt for
18
59
  further details.
19
-
data/Rakefile CHANGED
@@ -1,53 +1,27 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
4
  require 'rake'
13
5
 
14
6
  require 'jeweler'
15
7
  Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "RuGPost"
18
- gem.homepage = "http://github.com/3mime/RuGPost"
19
- gem.license = "MIT"
20
- gem.summary = %Q{Ru(by) G(mail) Post(erous) command line facility for creating posts on Posterous}
21
- gem.description = %Q{Ru(by) G(mail) Post(erous) command line facility}
22
- gem.email = "e.141592@gmail.com"
23
- gem.authors = ["emime"]
24
- # dependencies defined in Gemfile
8
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
9
+ gem.name = "RuGPost"
10
+ gem.homepage = "http://github.com/3mime/RuGPost"
11
+ gem.license = "MIT"
12
+ gem.summary = %Q{Ru(by) G(mail) Post(erous) command line facility for creating posts on Posterous}
13
+ gem.description = %Q{Ru(by) G(mail) Post(erous) command line facility}
14
+ gem.email = "e.141592@gmail.com"
15
+ gem.authors = ["emime"]
25
16
  end
26
17
  Jeweler::RubygemsDotOrgTasks.new
27
18
 
28
- require 'rake/testtask'
29
- Rake::TestTask.new(:test) do |test|
30
- test.libs << 'lib' << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
33
- end
34
-
35
- require 'rcov/rcovtask'
36
- Rcov::RcovTask.new do |test|
37
- test.libs << 'test'
38
- test.pattern = 'test/**/test_*.rb'
39
- test.verbose = true
40
- test.rcov_opts << '--exclude "gems/*"'
41
- end
42
-
43
- task :default => :test
44
19
 
45
20
  require 'rake/rdoctask'
46
21
  Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
-
49
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "RuGPost #{version}"
51
- rdoc.rdoc_files.include('README*')
52
- rdoc.rdoc_files.include('lib/**/*.rb')
22
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
23
+ rdoc.rdoc_dir = 'rdoc'
24
+ rdoc.title = "RuGPost #{version}"
25
+ rdoc.rdoc_files.include('README*')
26
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
27
  end
data/RuGPost.gemspec CHANGED
@@ -5,13 +5,14 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{RuGPost}
8
- s.version = "0.1.0.1.beta"
8
+ s.version = "0.1.1"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{emime}]
12
- s.date = %q{2011-05-08}
12
+ s.date = %q{2011-06-01}
13
13
  s.description = %q{Ru(by) G(mail) Post(erous) command line facility}
14
14
  s.email = %q{e.141592@gmail.com}
15
+ s.executables = [%q{rugpost}]
15
16
  s.extra_rdoc_files = [
16
17
  "LICENSE.txt",
17
18
  "README.rdoc"
@@ -25,7 +26,42 @@ Gem::Specification.new do |s|
25
26
  "Rakefile",
26
27
  "RuGPost.gemspec",
27
28
  "VERSION",
29
+ "bin/rugpost",
28
30
  "lib/RuGPost.rb",
31
+ "lib/rugpost/commands.rb",
32
+ "lib/rugpost/commands/post_commands.rb",
33
+ "lib/rugpost/commands/project_commands.rb",
34
+ "lib/rugpost/on_error.rb",
35
+ "lib/rugpost/post.rb",
36
+ "lib/rugpost/prepost.rb",
37
+ "lib/rugpost/project.rb",
38
+ "lib/rugpost/site.rb",
39
+ "lib/rugpost/utilis.rb",
40
+ "rdoc/classes/RuGPost.html",
41
+ "rdoc/classes/RuGPost/Post.html",
42
+ "rdoc/classes/RuGPost/Project.html",
43
+ "rdoc/classes/RuGPost/Site.html",
44
+ "rdoc/classes/RuGPost/Utilis.html",
45
+ "rdoc/created.rid",
46
+ "rdoc/files/README_rdoc.html",
47
+ "rdoc/files/lib/RuGPost_rb.html",
48
+ "rdoc/files/lib/rugpost/commands/post_commands_rb.html",
49
+ "rdoc/files/lib/rugpost/commands/project_commands_rb.html",
50
+ "rdoc/files/lib/rugpost/commands_rb.html",
51
+ "rdoc/files/lib/rugpost/on_error_rb.html",
52
+ "rdoc/files/lib/rugpost/post_rb.html",
53
+ "rdoc/files/lib/rugpost/prepost_rb.html",
54
+ "rdoc/files/lib/rugpost/project_rb.html",
55
+ "rdoc/files/lib/rugpost/site_rb.html",
56
+ "rdoc/files/lib/rugpost/utilis_rb.html",
57
+ "rdoc/fr_class_index.html",
58
+ "rdoc/fr_file_index.html",
59
+ "rdoc/fr_method_index.html",
60
+ "rdoc/index.html",
61
+ "rdoc/rdoc-style.css",
62
+ "spec/post_spec.rb",
63
+ "spec/project_spec.rb",
64
+ "spec/spec_helper.rb",
29
65
  "test/helper.rb",
30
66
  "test/test_RuGPost.rb"
31
67
  ]
@@ -39,21 +75,27 @@ Gem::Specification.new do |s|
39
75
  s.specification_version = 3
40
76
 
41
77
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
- s.add_development_dependency(%q<shoulda>, [">= 0"])
43
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
78
+ s.add_runtime_dependency(%q<gli>, [">= 1.3.0"])
79
+ s.add_runtime_dependency(%q<RedCloth>, [">= 4.2.7"])
80
+ s.add_runtime_dependency(%q<gmail>, [">= 0.4.0"])
81
+ s.add_runtime_dependency(%q<extlib>, [">= 0.9.15"])
44
82
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
45
- s.add_development_dependency(%q<rcov>, [">= 0"])
83
+ s.add_development_dependency(%q<rspec>, ["~> 2.5.0"])
46
84
  else
47
- s.add_dependency(%q<shoulda>, [">= 0"])
48
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
85
+ s.add_dependency(%q<gli>, [">= 1.3.0"])
86
+ s.add_dependency(%q<RedCloth>, [">= 4.2.7"])
87
+ s.add_dependency(%q<gmail>, [">= 0.4.0"])
88
+ s.add_dependency(%q<extlib>, [">= 0.9.15"])
49
89
  s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
50
- s.add_dependency(%q<rcov>, [">= 0"])
90
+ s.add_dependency(%q<rspec>, ["~> 2.5.0"])
51
91
  end
52
92
  else
53
- s.add_dependency(%q<shoulda>, [">= 0"])
54
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
93
+ s.add_dependency(%q<gli>, [">= 1.3.0"])
94
+ s.add_dependency(%q<RedCloth>, [">= 4.2.7"])
95
+ s.add_dependency(%q<gmail>, [">= 0.4.0"])
96
+ s.add_dependency(%q<extlib>, [">= 0.9.15"])
55
97
  s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
56
- s.add_dependency(%q<rcov>, [">= 0"])
98
+ s.add_dependency(%q<rspec>, ["~> 2.5.0"])
57
99
  end
58
100
  end
59
101
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0.1.beta
1
+ 0.1.1
data/bin/rugpost ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $: << File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ require 'RuGPost'
5
+ require 'rugpost/commands'
6
+
7
+ include RuGPost
8
+
9
+ GLI.run(ARGV)
data/lib/RuGPost.rb CHANGED
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'gli'
3
+ require 'redcloth'
4
+ require 'gmail'
5
+ require 'pathname'
6
+ require 'extlib'
7
+
8
+ module RuGPost
9
+
10
+ # directory containing RuGPost library files
11
+ LIB = Pathname(__FILE__).dirname.expand_path/'rugpost'
12
+
13
+ # requires
14
+ require LIB/'utilis'
15
+ require LIB/'site'
16
+ require LIB/'project'
17
+ require LIB/'post'
18
+
19
+ include RuGPost::Utilis
20
+
21
+ # project configuration file
22
+ CONFIG = 'config.yaml'
23
+ TEMPLATE = 'template'
24
+ VERSION = '0.1.1'
25
+
26
+ end
@@ -0,0 +1,15 @@
1
+ include GLI
2
+
3
+ require RuGPost::LIB/'commands/project_commands'
4
+ require RuGPost::LIB/'commands/post_commands'
5
+
6
+ on_error do |exception|
7
+ # Error logic here
8
+ # return false to skip default error handling
9
+
10
+ puts exception.message
11
+ exception.backtrace.each do |b|
12
+ puts b
13
+ end
14
+ false
15
+ end
@@ -0,0 +1,20 @@
1
+ desc 'Create a new draft on the indicated site repository.'
2
+ arg_name '<post-name>'
3
+ command :draft do |c|
4
+ c.desc 'Target site repository where the post draft will be created.'
5
+ c.flag [:site]
6
+ c.action do |glob, ops, args|
7
+ Post.draft(args,ops)
8
+ end
9
+ end
10
+
11
+ desc 'Publish a repository draft on the corresponding posterous site.'
12
+ arg_name '<draft-name>'
13
+ arg_name '<password>'
14
+ command :publish do |c|
15
+ c.desc 'Repository where the draft is stored.'
16
+ c.flag [:site]
17
+ c.action do |glob, ops, args|
18
+ Post.publish(Post.new(args, ops))
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ desc 'Initialize a RuGPost project.'
2
+ command :init do |c|
3
+ c.action do |glob, ops, args|
4
+ Project.init(args,ops)
5
+ end
6
+ end
7
+
8
+ desc 'Create a repo for a posterous site.'
9
+ arg_name '<site-name>'
10
+ command :repo do |c|
11
+ c.action do |glob, ops, args|
12
+ Project.add_repo(args,ops)
13
+ end
14
+ end
15
+
16
+ desc 'Configure project global options'
17
+ command :config do |c|
18
+ c.desc 'Configure gmail account used to post on posterous sites. Needs the gmail (without @gmail).'
19
+ c.flag [:gmail]
20
+ c.action do |glob,ops,args|
21
+ Project.config(args,ops)
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ on_error do |exception|
2
+ # Error logic here
3
+ # return false to skip default error handling
4
+ puts exception.backtrace
5
+ true
6
+ end
@@ -0,0 +1,96 @@
1
+ module RuGPost
2
+
3
+ META = /--- \n.*\n---\n/m
4
+
5
+ DRAFTS = 'drafts'
6
+ PUBLISHED = 'published'
7
+ SOURCE = PUBLISHED/'source'
8
+ OUTPUT = PUBLISHED/'output'
9
+
10
+ class Post
11
+
12
+ attr_accessor :src_body, :draft, :subject, :html_o, :metaops, :pwd
13
+
14
+ def initialize(args,ops)
15
+ ops[:site]=Post.get_site(ops)
16
+ @draftid = args[0]
17
+ @pwd = args[1]
18
+ @draft = Dir.glob(ops[:site]/DRAFTS/@draftid+".*")
19
+ raise "Draft not found! Searched for '#{args[0]}' in '#{ops[:site]}/drafts'" unless @draft
20
+ @draft = @draft[0]
21
+ set_body
22
+ set_html
23
+ set_meta ops
24
+ set_subj
25
+ end
26
+
27
+ def set_meta ops
28
+ projectops = YAML.load_file(CONFIG)
29
+ @metaops = YAML.load_file(@draft)
30
+ @metaops.merge! projectops
31
+ @metaops.merge! ops
32
+ end
33
+
34
+ def set_subj
35
+ @subject = "#{@metaops[:title]} ((tags:#{@metaops[:tags].join(',')}))"
36
+ @subject += "((delay:#{@metaops[:delay]}))" if @metaops[:delay]
37
+ end
38
+
39
+ def set_body
40
+ cnt = ""
41
+ File.open( @draft, 'r' ) { |str| cnt << str.read() }
42
+ @src_body = cnt.sub META, ""
43
+ end
44
+
45
+ def set_html
46
+ @html_o = RedCloth.new(@src_body).to_html
47
+ end
48
+
49
+ def move_source
50
+ FileUtils.mv(@draft,@metaops[:site]/SOURCE)
51
+ end
52
+
53
+ def move_html
54
+ target = @metaops[:site]/OUTPUT/@draftid+'.html'
55
+ File.open( target, 'w' ) {|f| f.write(@html_o)}
56
+ end
57
+
58
+ def remove
59
+ FileUtils.remove_file(@draft)
60
+ end
61
+
62
+ def Post.draft(args,ops)
63
+ ops[:site]=Post.get_site(ops)
64
+ raise "Please provide draft name!" if !args[0]
65
+ target_file = ops[:site]/'drafts'/args[0]+'.textile'
66
+ puts "Adding draft '#{args[0]}' to site repo '#{ops[:site]}'..."
67
+ raise "File already exists!\n\t#{target_file}\n\tPlease indicate a different draft name." if File.exists?(target_file)
68
+ FileUtils.copy_file(TEMPLATE, target_file)
69
+ end
70
+
71
+ def Post.publish(post)
72
+ account = "#{post.metaops[:gmail]}@gmail.com"
73
+ gmail = Gmail.new(account,post.pwd)
74
+ gmail.deliver do
75
+ to "#{post.metaops[:site]}@posterous.com"
76
+ subject post.subject
77
+ text_part do
78
+ body post.html_o
79
+ end
80
+ end
81
+ gmail.logout
82
+ post.move_source
83
+ post.move_html
84
+ end
85
+
86
+ def Post.get_site(ops)
87
+ if ops[:site]==nil then
88
+ ops[:site]=Dir.glob('*').select {|d| File.directory? d}[0]
89
+ puts "No site name option provided, switching to default...'#{ops[:site]}'"
90
+ end
91
+ return ops[:site]
92
+ end
93
+
94
+ end
95
+
96
+ end