Module: Hoe::Publish
- Defined in:
- lib/hoe/publish.rb
Overview
Publish plugin for hoe.
Tasks Provided:
- announce
-
Create news email file and optionally publish docs.
- debug_email
-
Generate email announcement file.
- post_blog
-
Post announcement to blog.
- publish_docs
-
Publish RDoc to ‘rdoc_locations`.
- ridocs
-
Generate ri locally for testing.
Extra Configuration Options:
- publish_on_announce
-
Run
publish_docs
when you runrelease
. - blogs
-
An array of hashes of blog settings.
The blogs entry can either look like:
- path: ~/Work/p4/zss/www/blog.zenspider.com/releases
type: zenweb
cmd: rake sync (optional)
or:
- url: http://example.com/cgi-bin/blog.cgi
blog_id: 1
user: username
password: passwd
extra_headers:
blah: whatever
Instance Attribute Summary collapse
-
#blog_categories ⇒ Object
Optional: An array of the project’s blog categories.
-
#local_rdoc_dir ⇒ Object
Optional: Name of destination directory for RDoc generated files.
-
#need_rdoc ⇒ Object
Optional: Should RDoc and ri generation tasks be defined? [default: true].
-
#rdoc_locations ⇒ Object
Optional: An array of remote (rsync) paths to copy rdoc to.
-
#remote_rdoc_dir ⇒ Object
Optional: Name of RDoc destination directory.
-
#rsync_args ⇒ Object
Optional: Flags for RDoc rsync.
Instance Method Summary collapse
-
#activate_publish_deps ⇒ Object
Declare a dependency on rdoc, IF NEEDED.
-
#announcement ⇒ Object
:nodoc:.
-
#define_publish_tasks ⇒ Object
Define tasks for plugin.
-
#generate_email(full = nil) ⇒ Object
:nodoc:.
-
#initialize_publish ⇒ Object
Initialize variables for plugin.
-
#make_rdoc_cmd(*extra_args) ⇒ Object
:nodoc:.
-
#post_blog_task ⇒ Object
:nodoc:.
-
#post_blog_zenweb(site) ⇒ Object
:nodoc:.
-
#publish_docs_task ⇒ Object
:nodoc:.
-
#publish_on_announce_task ⇒ Object
:nodoc:.
Instance Attribute Details
#blog_categories ⇒ Object
Optional: An array of the project’s blog categories. Defaults to project name.
39 40 41 |
# File 'lib/hoe/publish.rb', line 39 def blog_categories @blog_categories end |
#local_rdoc_dir ⇒ Object
Optional: Name of destination directory for RDoc generated files.
- default: doc
45 46 47 |
# File 'lib/hoe/publish.rb', line 45 def local_rdoc_dir @local_rdoc_dir end |
#need_rdoc ⇒ Object
Optional: Should RDoc and ri generation tasks be defined? [default: true]
Allows you to define custom RDoc tasks then use the publish_rdoc task to upload them all. See also local_rdoc_dir
53 54 55 |
# File 'lib/hoe/publish.rb', line 53 def need_rdoc @need_rdoc end |
#rdoc_locations ⇒ Object
Optional: An array of remote (rsync) paths to copy rdoc to.
eg:
rdoc_locations << "user@server:Sites/rdoc/#{remote_rdoc_dir}"
62 63 64 |
# File 'lib/hoe/publish.rb', line 62 def rdoc_locations @rdoc_locations end |
#remote_rdoc_dir ⇒ Object
Optional: Name of RDoc destination directory. [default: name
]
67 68 69 |
# File 'lib/hoe/publish.rb', line 67 def remote_rdoc_dir @remote_rdoc_dir end |
#rsync_args ⇒ Object
Optional: Flags for RDoc rsync. [default: “-av –delete”]
72 73 74 |
# File 'lib/hoe/publish.rb', line 72 def rsync_args @rsync_args end |
Instance Method Details
#activate_publish_deps ⇒ Object
Declare a dependency on rdoc, IF NEEDED.
102 103 104 |
# File 'lib/hoe/publish.rb', line 102 def activate_publish_deps dependency "rdoc", [">= 4.0", "< 7"], :developer if need_rdoc end |
#announcement ⇒ Object
:nodoc:
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/hoe/publish.rb', line 270 def announcement # :nodoc: changes = self.changes.rdoc_to_markdown subject = "#{name} #{version} Released" title = "#{name} version #{version} has been released!" body = "#{description}\n\nChanges:\n\n#{changes}".rdoc_to_markdown urls = case self.urls when Hash then self.urls.map { |k, v| "* #{k}: <#{v.strip.rdoc_to_markdown}>" } when Array then self.urls.map { |s| "* <#{s.strip.rdoc_to_markdown}>" } else raise "unknown urls format: #{urls.inspect}" end return subject, title, body, urls.join("\n") end |
#define_publish_tasks ⇒ Object
Define tasks for plugin.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 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 |
# File 'lib/hoe/publish.rb', line 109 def define_publish_tasks if need_rdoc then task :isolate # ensure it exists desc "Generate rdoc" task :docs => [:clobber_docs, :isolate] do sh(*make_rdoc_cmd) end desc "Generate rdoc coverage report" task :dcov => :isolate do sh(*make_rdoc_cmd("-C")) end desc "Remove RDoc files" task :clobber_docs do rm_rf local_rdoc_dir end task :clobber => :clobber_docs desc "Generate ri locally for testing." task :ridocs => [:clean, :isolate] do sh(*make_rdoc_cmd("--ri", "-o", "ri")) end end desc "Publish RDoc to wherever you want." task :publish_docs => [:clean, :docs] do publish_docs_task end # no doco for this one task :publish_on_announce do publish_on_announce_task end desc "Generate email announcement file." task :debug_email do puts generate_email ENV["FULL"] end desc 'Post announcement to blog. Uses the "blogs" array in your hoerc.' task :post_blog do post_blog_task end desc "Announce your release." task :announce => [:post_blog, :publish_on_announce ] end |
#generate_email(full = nil) ⇒ Object
:nodoc:
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/hoe/publish.rb', line 247 def generate_email full = nil # :nodoc: require "time" abort "No email 'to' entry. Run `rake config_hoe` to fix." unless !full || email_to from_name, from_email = .first, email.first subject, title, body, urls = announcement [ full && "From: #{from_name} <#{from_email}>", full && "To: #{email_to.join(", ")}", full && "Date: #{Time.now.rfc2822}", "Subject: [ANN] #{subject}", "", title, "", urls, "", body, ].compact.join("\n") end |
#initialize_publish ⇒ Object
Initialize variables for plugin.
90 91 92 93 94 95 96 97 |
# File 'lib/hoe/publish.rb', line 90 def initialize_publish self.blog_categories ||= [self.name] self.local_rdoc_dir ||= "doc" self.need_rdoc ||= true self.rdoc_locations ||= [] self.remote_rdoc_dir ||= self.name self.rsync_args ||= "-av -O --delete" end |
#make_rdoc_cmd(*extra_args) ⇒ Object
:nodoc:
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/hoe/publish.rb', line 204 def make_rdoc_cmd(*extra_args) # :nodoc: title = "#{name}-#{version} Documentation" title = "#{group_name}'s #{title}" if group_name != name ( %W[#{Gem.ruby} -S rdoc --title #{title} -o #{local_rdoc_dir} ] + spec. + extra_args + spec.require_paths + spec.extra_rdoc_files ).reject(&:empty?) end |
#post_blog_task ⇒ Object
:nodoc:
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 |
# File 'lib/hoe/publish.rb', line 173 def post_blog_task # :nodoc: with_config do |config, _path| break unless config["blogs"] config["blogs"].each do |site| if site["path"] then msg = "post_blog_#{site["type"]}" send msg, site system site["cmd"] if site["cmd"] else require "xmlrpc/client" _, title, body, urls = announcement body += "\n\n#{urls}" server = XMLRPC::Client.new2(site["url"]) content = site["extra_headers"].merge(:title => title, :description => body, :categories => blog_categories) server.call("metaWeblog.newPost", site["blog_id"], site["user"], site["password"], content, true) end end end end |
#post_blog_zenweb(site) ⇒ Object
:nodoc:
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/hoe/publish.rb', line 220 def post_blog_zenweb site # :nodoc: dir = site["path"] _, title, body, urls = announcement body += "\n\n#{urls}" Dir.chdir File. dir do time = Time.at Time.now.to_i # nukes fractions path = [time.strftime("%Y-%m-%d-"), title.sub(/\W+$/, "").gsub(/\W+/, "-"), ".html.md"].join header = { "title" => title, "categories" => blog_categories, "date" => time, } File.open path, "w" do |f| f.puts header.to_yaml.gsub(/\s$/, "") f.puts "..." f.puts f.puts body end end end |
#publish_docs_task ⇒ Object
:nodoc:
160 161 162 163 164 165 |
# File 'lib/hoe/publish.rb', line 160 def publish_docs_task # :nodoc: warn "no rdoc_location values" if rdoc_locations.empty? self.rdoc_locations.each do |dest| sh %(rsync #{rsync_args} #{local_rdoc_dir}/ #{dest}) end end |