Created
October 2, 2009 20:58
-
-
Save tal/200118 to your computer and use it in GitHub Desktop.
This file contains 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
# 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