Skip to content

Instantly share code, notes, and snippets.

@kristjan
Created November 17, 2010 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristjan/703063 to your computer and use it in GitHub Desktop.
Save kristjan/703063 to your computer and use it in GitHub Desktop.
Idea for a copy/asset skinning framework
module Copy
def self.for(wish)
Copy.const_get(@wish.class.name.demodulize).new(@wish)
end
# These methods are used by all Copy packages
class CopyPackage
def initialize(wish)
@wish = wish
end
def [](item)
self.send item
end
end
class Wish < CopyPackage
end
class BirthdayWish < CopyPackage
def creation_title
"Create a Birthday Wish"
end
end
end
module CopyHelper
def copy(item)
(@copy ||= Copy.for(@wish))[item]
end
end
require "spec_helper"
describe Copy do
it "creates a copy package for a wish" do
Copy.for(Wish.new).should be_a(Copy::Wish)
Copy.for(Wish::BirthdayWish.new).should be_a(Copy::BirthdayWish)
end
end
@kristjan
Copy link
Author

First idea for a Copy template framework. Dunno if it will end up being the right way to go about it, but it does some things:

  • Hash-like access: Copy.for(wish)[:title]
  • Wish-data interpolation:
    def favorite_friend
    #{@wish.superstars.first.name} is totally great!"
    end
  • Easy to split into different files/bundles if we like
  • Easy to test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment