Skip to content

Commit

Permalink
Bug fix: correctly handle paragraphs that start or end with formatted…
Browse files Browse the repository at this point in the history
… text.
  • Loading branch information
danbernier committed Sep 28, 2011
1 parent a4362f5 commit ccfb6d2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
28 changes: 23 additions & 5 deletions app/ui/lessons.rb
Expand Up @@ -449,15 +449,33 @@ def store(shoes_bit)
def paragraph(text)
#puts text

text = text.split('[-]')
para_bits = text.zip(@args).flatten.compact

para_bits = interpolate(text, @args)
#puts "para_bits: #{para_bits.inspect}"
@container.instance_eval { para *para_bits }

@container.instance_eval { para *para_bits }
@args.clear

''
end

# The markdown string "I'd _love_ a cupcake!" comes to us looking like this:
# "Hello, I'd [-] a cupcake!"
# ...and @args looks like this:
# [Shoes::Em]
# #interpolate turns them into this:
# ["Hello, I'd ", Shoes::Em, " a cupcake!"]
# These are the args that'll be passed to Shoes#para.
# It also turns "_I_ like _chocolate!_" into
# [Shoes::Em, " like ", Shoes::Em]
def interpolate(text, args)
results = []
while text.include?('[-]')
head, text = *text.split('[-]', 2)
results << head << args.shift
end
results << text
results << args unless args.empty?

return results.compact
end

end
3 changes: 1 addition & 2 deletions lessons/beginner/ruby.md
Expand Up @@ -52,8 +52,7 @@ Matz has this to say about Ruby:

_I hope to see Ruby help every programmer in the world to be productive, and to
enjoy programming, and to be happy. That is the primary purpose of Ruby
language.
_
language._

One more thing about Ruby: Rubyists (that's what people who like Ruby call
themselves) have a saying: __MINSWAN__. This stands for __M__atz __I__s __N__ice
Expand Down

0 comments on commit ccfb6d2

Please sign in to comment.