FTB-Gamepedia / MediaWiki-Butt-Ruby

A Ruby library for the MediaWiki API
https://rubygems.org/gems/mediawiki-butt
MIT License
9 stars 2 forks source link

Extension support #11

Open xbony2 opened 8 years ago

xbony2 commented 8 years ago

How are we going to deal with the support of extensions? I'd like to be able to stuff like this.

Eli edit:

Here are all the extensions we should support by the first release including this feature. It was a combined list of all the extensions on FTB, Wikipedia, and MediaWiki. I have removed all extensions (and skins) with no API. Many of the CurseGamepedia extensions have no docs, so I'm not sure if they have APIs or not. I'll ask Alexia when we get to them

elifoster commented 8 years ago

I don't know. We should figure that our probably.

elifoster commented 8 years ago

Branch: extension

elifoster commented 8 years ago

@xbony2 We should finish up the two extensions we started supporting, because I'd really like to be able to interact with the new Tilesheets API and the upcoming OreDict API.

xbony2 commented 7 years ago

@elifoster I don't think we really have to finish this for 2.0.0. We're both waiting on 2.0.0 features that aren't this, and doing this will probably take a long time.

elifoster commented 7 years ago

Yeah I've been thinking this too. It won't break any existing things to add this feature so it should be fine as 2.1 or whatever.

elifoster commented 7 years ago

Just thought of a nice way to automatically handle the loading of extension modules

in initialize:

# ...
get_all_extensions.each do |extension_name|
  include MediaWiki::Extensions::Object.const_get(extension_name.delete(' '))
end
# ...

or something along those lines.

elifoster commented 4 years ago

@xbony2 For how to enable modules, what do you think about

# lib/mediawiki/butt.rb
module MediaWiki
  class Butt
    ...
    def enable_extension(ext_module)
      if ext_module.include?(MediaWiki::Extensions::ExtensionModule)
        extend(ext_module)
      else
        raise NotAnExtensionModuleError.new(ext_module)
      end
    end
  end
end

# lib/mediawiki/extensions/extension_module.rb
module MediaWiki
  module Extensions
    class ExtensionModule
    end
  end
end

# lib/mediawiki/extensions/oredict.rb
require_relative 'extension_module'
module MediaWiki
  module Extensions
    module OreDict
      include MediaWiki::Extensions::ExtensionModule
      def get_oredict_whatever_stub; end
    end
  end
end

# script.rb
require 'mediawiki/butt'
require 'mediawiki/extensions/oredict'

@mw = MediaWiki::Butt.new(...)
@mw.enable_extension(MediaWiki::Extensions::OreDict)
@mw.get_oredict_whatever_stub
xbony2 commented 4 years ago

Seems fine to me

elifoster commented 6 months ago

I think it may be better to split extensions up into their own separate gems, but can still be in this repo. So instead of getting every extension imaginable when you download the gem you only download the ones you actually need. It would also mean all the base gem needs is native support for enabling extensions (which it already has in the extension branch). Extension APIs could be created as we need them and the rest, well if someone needs them they can create them. The basic implementation we have would basically stay the same, except you would need to add the extension to your Gemfile and our dir tree would look like

docs/...
lib/
  mediawiki/
    extensions/
      extensions_module.rb
extensions/
  tilesheets/
    lib/
      mediawiki/
        extensions/
          tilesheets.rb
    mediawiki-butt-extensions-tilesheets.gemspec
mediawiki-butt.gemspec
...

How this would interact with our docs I'm not sure.