PragTob / wingtips

A nice little presentation written in shoes
MIT License
12 stars 1 forks source link

class for templates #22

Open PragTob opened 10 years ago

PragTob commented 10 years ago

Right now I do not know of a way to make templates happen in the class style, i.e. what I'd like is:

class MyTemplate < Wingtips::Slide #or Template if we need a new class
  def initialize(my_value)
    @value = my_value
  end

  def content
    # use the value to make beautiful things
  end
end

# in config.rb

slides MyTemplate.new 'lalala'

I tried it out shortly, problem is that the initialize of Slide has to get handed an app. I solved a similar problem once through introducing an iniitialize_data hook that gets called, however then people have to overwrite that, not initialize which is slightly odd. However, better than by force trying to make initialize work.

jasonrclark commented 10 years ago

Yeah, since the instance creation for the slide happens in Wingtips::Presentation, that kind of hampers subclasses from doing anything interesting.

I don't typically like type checks, but would this be a case where Wingtips::Presentation should check whether it's been handed a class or not, and only instantiate when it gets a class? Wingtips::Slide could expose an app= that gets called alternatively if you put an instance into the slides list.

I can think of a few other hackier ways to slice it, but that seems the simplest and clearest to me.