Sha256: 3c151de0d9c2aeadf2d88a1b20938e0001d498dafb12ef717d54fa8f0f853107

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

module MiddlemanTorrent
  class Extension < Middleman::Extension
    option :tracker, 'udp://tracker.publicbt.com:80', 'A tracker to announce'
    option :file, 'site.torrent', 'Torrent file name'
    option :name, 'site', 'Torrent name and base directory'
    option :private, false, 'Make torrent private'

    def initialize(app, options_hash={}, &block)
      super
      require 'mktorrent'
    end

    # Create the torrent after the site is built
    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|
          torrent.add_file file.path
          builder.say_status 'to torrent', file.path
        end

        torrent.write_torrent options.file
      end

      builder.say_status :create, File.join(app.config.build_dir, options.file)
    end

    # Move to build dir for the block
    def within_build_path(&block)
      Dir.chdir app.config.build_dir do
        yield
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
middleman-torrent-0.0.3 lib/middleman-torrent/extension.rb
middleman-torrent-0.0.2 lib/middleman-torrent/extension.rb
middleman-torrent-0.0.1 lib/middleman-torrent/extension.rb