Created
November 17, 2010 06:26
-
-
Save kristjan/703063 to your computer and use it in GitHub Desktop.
Idea for a copy/asset skinning framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CopyHelper | |
def copy(item) | |
(@copy ||= Copy.for(@wish))[item] | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
Copy.for(wish)[:title]
def favorite_friend
#{@wish.superstars.first.name} is totally great!"
end