diff --git a/sample_source.html b/sample_source.html new file mode 100644 index 0000000..2e29a0c --- /dev/null +++ b/sample_source.html @@ -0,0 +1,29 @@ +

Invisible Alligators

+

by Hayes Roberts

+

2009

+

bluebison.net

+

A young monkey named Sari woke up one morning and knew there was trouble.

+

She hopped out of bed and found that the bridge on her favorite castle had been broken in the night, and it took her forever to fix it.

+

Then she found her stairs covered in toys. She tripped on one and had to pick them all up.

+

THEN she couldn't ride her llama to school because the whole herd was running loose. It took her six tries to get them onto a pointy rock so they would calm down and quit trying to eat her homework.

+

She was so late that she missed almost all of her favorite class, Algebra II. And her homework was covered in bites and hoof prints.

+

She'd had enough.

+

Tonight Sari would put a stop to this.

+

That night she stayed awake long after bedtime. Long enough to hear the rustling of long tails under her bed.

+

She flipped her bed over and found invisible alligators all over her room. "What's going on here?" she demanded.

+

"Sari, we're the invisible alligators and we do this for everyone," one alligator explained. "We're just trying to help; let me show you."

+

So she followed him deep into the alligator catacombs.

+

As they walked he explained, "You see, we cause trouble in all kinds of ways."

+

"In this house I'm hiding the remote control and this sheep will search his house for a week."

+

"And in this house we're stealing the chocolate cake mix and putting out fresh broccoli instead."

+

"And in here we're singing this hippo to sleep in the bath so he gets all pruney."

"I just don't understand why you would do all of these things," Sari said. "Why do we have to have so many things go wrong? Why can't you just make everything right?"

+

"Yes, good point," the alligator sighed, "but let me show you one more thing," and he took her into the invisible alligator main headquarters.

+

"This is your book, Sari. All the things listed in this book are the troubles we've caused you -- and all the things you've learned how to do in your whole life." It was a big book. He looked at her expectantly.

+

"Nope. I don't get it." she said sadly, and left the alligators' lair so she could go back home and get in bed. "Bye."

+

The stairs leading home were covered in rocks. Sari took a moment to pick them all up as she walked so no one would trip and fall.

+

She came to a bridge that was snapped in two,

+

and a herd of wild blue goats which we all know are very dangerous unless someone knows how to herd them on to a pointy mountain top.

+

Sari didn't even have to think. She knew exactly what to do -- fixed the bridge, herded the goats, piled the rocks out of the way in a safe place and was safely in bed in no time at all, fast asleep and dreaming about Algebra II.

+

How did she do it? If you are lucky maybe the invisible alligators will visit you tonight and cause trouble for you.

+

The End.

+ diff --git a/to_dotsies.rb b/to_dotsies.rb new file mode 100644 index 0000000..aa898fc --- /dev/null +++ b/to_dotsies.rb @@ -0,0 +1,159 @@ +class ToDotsies + + # + # > Summary + # Converts html files into a format like this: + # http://dotsies.org/stories/the-runaway-couple.html. + # + # Reads in an html file (presumably a story with paragraphs in + #

tags), and outputs an html file. + # + # > Dependencies + # This file currently has dependencies on Ruby 1.9.2. + # + # > Known problems + # What about existing and tags in input files?... + # - Change them to and some other tags + # - And make style to make be just italic, etc. + # + + def self.gradually_convert txt + + # + # Read in txt, and split into chunks (words, whitespace, and html tags) + # + + # Make first paragraph bigger + txt.sub! "

", "

" + + # Ol << "txt:\n#{txt}" + + l = [] + txt.scan(/<.+?>|[a-z]+|&[#a-z0-9]+;|\s+|.+?|/i) {|m| l << m } # Split into words and tags + + max_underlines = l.length / 700 # Add + # Ol << "max_underlines: #{max_underlines.inspect}" + + future = "eaioztnshqrdlxcujmwfgypbvk" # Dotsiefy chars in this order + underline = {} # Chars that are underlined ( tags), with the count of occurences as the hash value + blocks = "" # Chars that are in Dotsies ( tags) + + total = l.length.to_f + + word_tally = 0 + + # + # Go through each chunks, ignoring tags and space + # + + l.each_with_index do |word, i| + + # + # If we got far enough, underline another letter + # + + last_fraction_used = (27 - (future.length + 1)) / 35.0 + fraction_used = (27 - future.length) / 35.0 + # Ol << "fraction_used: #{fraction_used.inspect}" + fraction_through = i / total + # Ol << "fraction_through: #{fraction_through.inspect}" + + # If we just passed boundary + if last_fraction_used < fraction_through && fraction_through <= fraction_used + # Ol << "passed boundary!" + underline[future.slice!(/^./)] = 0 + end + + next if word !~ /^[a-z]/i # Ignore if tag or space + + word_tally += 1 + + # + # Go through each letter + # + + letters = word.split '' + # Ol << "letters: #{letters.inspect}" + letters.each do |letter| + + # + # Handle future and block letters + # + + # Ol << "letter: #{letter.inspect}" + letter_downcase = letter.downcase + next if future.index(letter_downcase) # Skip, if in future + next letter.replace("#{letter}") if blocks.index(letter_downcase) # Make if in blocks + + # + # It's an underline letter, so increment count, and move to blocks if it exceeded count + # + + # Ol << "underline: #{underline.inspect}" + # Ol << "letter_downcase: #{letter_downcase.inspect}" + # Ol << "underline[letter_downcase]: #{underline[letter_downcase].inspect}" + + next if "etaoinshr".index(letter_downcase) && word_tally % 2 != 0 # Only do every other word, if a common one + + underline[letter_downcase] += 1 + if underline[letter_downcase] >= max_underlines # If exceeded max number of underlines for the letter + underline.delete letter_downcase + blocks << letter_downcase + end + + letter.replace "#{letter}" + # Ol << "underline[letter_downcase]: #{underline[letter_downcase].inspect}" + + end + + word.replace letters.join('') + + end + + # Ol << "unfinished underline: #{underline.inspect}" + # Ol << "unfinished future: #{future.inspect}" + + l.join '' + end + +end + + +inputfilename = ARGV[0] + +content = File.read inputfilename +content = ToDotsies.gradually_convert content +print %` + + + + #{content} + ` \ No newline at end of file