Class: MiddlemanTorrent::Extension
- Inherits:
-
Middleman::Extension
- Object
- Middleman::Extension
- MiddlemanTorrent::Extension
- Defined in:
- lib/middleman-torrent/extension.rb
Instance Method Summary collapse
-
#after_build(builder) ⇒ Object
Create the torrent after the site is built.
-
#after_configuration ⇒ Object
Expose configuration values.
-
#initialize(app, options_hash = {}, &block) ⇒ Extension
constructor
A new instance of Extension.
-
#within_build_path(&block) ⇒ Object
Move to build dir for the block.
Constructor Details
#initialize(app, options_hash = {}, &block) ⇒ Extension
Returns a new instance of Extension.
8 9 10 11 |
# File 'lib/middleman-torrent/extension.rb', line 8 def initialize(app, ={}, &block) super require 'mktorrent' end |
Instance Method Details
#after_build(builder) ⇒ Object
Create the torrent after the site is built
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/middleman-torrent/extension.rb', line 22 def after_build(builder) torrent = Torrent.new .tracker torrent.defaultdir = .name torrent.set_private if .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 .file end builder.say_status :create, File.join(app.config.build_dir, .file) end |
#after_configuration ⇒ Object
Expose configuration values
14 15 16 17 18 19 |
# File 'lib/middleman-torrent/extension.rb', line 14 def after_configuration app.set :torrent_tracker, .tracker app.set :torrent_file, .file app.set :torrent_name, .name app.set :torrent_private, .private end |
#within_build_path(&block) ⇒ Object
Move to build dir for the block
43 44 45 46 47 |
# File 'lib/middleman-torrent/extension.rb', line 43 def within_build_path(&block) Dir.chdir app.config.build_dir do yield end end |