class MiddlemanTorrent::Extension
Public Class Methods
new(app, options_hash={}, &block)
click to toggle source
Calls superclass method
# File lib/middleman-torrent/extension.rb, line 8 def initialize(app, options_hash={}, &block) super require 'mktorrent' end
Public Instance Methods
after_build(builder)
click to toggle source
Create the torrent after the site is built
# File lib/middleman-torrent/extension.rb, line 22 def after_build(builder) torrent = Torrent.new options.tracker torrent.defaultdir = options.name torrent.set_private if options.private # Move to build_dir so it's not added to the torrent within_build_path do app.sitemap.resources.each do |file| # We decode the path because it can have spaces (%20) and stuff torrent.add_file URI.decode(file.path) builder.say_status 'to torrent', URI.decode(file.path) end torrent.write_torrent options.file end builder.say_status :create, File.join(app.config.build_dir, options.file) end
after_configuration()
click to toggle source
Expose configuration values
# File lib/middleman-torrent/extension.rb, line 14 def after_configuration app.set :torrent_tracker, options.tracker app.set :torrent_file, options.file app.set :torrent_name, options.name app.set :torrent_private, options.private end
within_build_path() { || ... }
click to toggle source
Move to build dir for the block
# File lib/middleman-torrent/extension.rb, line 43 def within_build_path(&block) Dir.chdir app.config.build_dir do yield end end