Skip to content

Instantly share code, notes, and snippets.

@tal
Created October 2, 2009 20:58
Show Gist options
  • Save tal/200118 to your computer and use it in GitHub Desktop.
Save tal/200118 to your computer and use it in GitHub Desktop.
# can i do something like content.yield
# so i dont have to call content on each line of code?
def follow str
followers = @blog.followers
following = @blog.user.following_users
iterate_on_block str, followers, :Followers do |content,follower|
content.t_replace :FollowBlogName, follower.blog_name
content.t_replace :FollowProfileImage, follower.profile_image
content.t_replace :FollowBlogURL, follower.blog.url
end
iterate_on_block str, following, :Following do |content,follower|
content.t_replace :FollowBlogName, follower.blog_name
content.t_replace :FollowProfileImage, follower.profile_image
content.t_replace :FollowBlogURL, follower.blog.url
end
str
end
def iterate_on_block str, array, matcher, &block
foo = str.block_split matcher
all = Array.new
array.each do |obj|
content = foo[:body].dup
yield(content,obj)
all << content
end
str.replace(foo[:pre]+all.join+foo[:post])
rescue ThemeError
str.swap_block matcher
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment