From 3ef2292c89badbce42f7b3ca4442de2da989ede1 Mon Sep 17 00:00:00 2001 From: Jared Date: Tue, 3 Apr 2012 19:38:15 -0500 Subject: [PATCH 1/7] creating initial standalone script --- to_dotsies.rb | 196 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 to_dotsies.rb diff --git a/to_dotsies.rb b/to_dotsies.rb new file mode 100644 index 0000000..d6957f4 --- /dev/null +++ b/to_dotsies.rb @@ -0,0 +1,196 @@ +require 'pp' + +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 Xiki. At the beginning + # it calles a Xiki function to get the filename. At the end it + # tells Xiki to send the html to the browser so we can see it (in + # addition to the script writing to a file). + # + # > Filenames + # Normally the input file passed will end in "--in.html". If it + # doesn't, the script looks for a file that ends that way. If it + # finds it, it uses it. If it doesn't find it, it assumes the + # file passed was an input file, and so renames it to end that way + # before moving on. + # + # > 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.convert txt + + # + # Read in file, 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 + + + def self.template txt + %` + + + +

hi there!

+

can you read this?

+ +
+ Read this story to gradually learn to read using + dots instead of + letters! + Move your mouse over the green + underlines + when + you need a hint. + If you get to + the + end, + you'll be reading only dots! +
+ + #{txt} + ` + end + +end + + +inputfilename = ARGV[0] +outputfilename = ARGV[1] + +content = File.read inputfilename +content = ToDotsies.convert content +content = ToDotsies.template content + +File.open(outputfilename, "w") { |f| f << txt } From 30024d906584c4b279fd443fd8c97b6d76b3d993 Mon Sep 17 00:00:00 2001 From: Jared Date: Tue, 3 Apr 2012 20:16:05 -0500 Subject: [PATCH 2/7] adding sample --- sample_source.html | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 sample_source.html 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.

+ From 4cf49299172bfb20e50267222793104bffe0139e Mon Sep 17 00:00:00 2001 From: Jared Date: Tue, 3 Apr 2012 20:20:57 -0500 Subject: [PATCH 3/7] cleaning up --- to_dotsies.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/to_dotsies.rb b/to_dotsies.rb index d6957f4..f5747c6 100644 --- a/to_dotsies.rb +++ b/to_dotsies.rb @@ -1,5 +1,3 @@ -require 'pp' - class ToDotsies # @@ -193,4 +191,4 @@ def self.template txt content = ToDotsies.convert content content = ToDotsies.template content -File.open(outputfilename, "w") { |f| f << txt } +File.open(outputfilename, "w") { |f| f << content } From 8e34b02bd1fd581e76a103fcbade01347c7ab991 Mon Sep 17 00:00:00 2001 From: Jared Date: Tue, 3 Apr 2012 20:23:15 -0500 Subject: [PATCH 4/7] removing templating method --- to_dotsies.rb | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/to_dotsies.rb b/to_dotsies.rb index f5747c6..2dc400d 100644 --- a/to_dotsies.rb +++ b/to_dotsies.rb @@ -126,9 +126,15 @@ def self.convert txt l.join '' end +end + + +inputfilename = ARGV[0] +outputfilename = ARGV[1] - def self.template txt - %` +content = File.read inputfilename +content = ToDotsies.convert content +content = %` -

hi there!

-

can you read this?

- -
- Read this story to gradually learn to read using - dots instead of - letters! - Move your mouse over the green - underlines - when - you need a hint. - If you get to - the - end, - you'll be reading only dots! -
- #{content} ` - + File.open(outputfilename, "w") { |f| f << content } From f57d0e1027408119c608adc310f50637cd05e54c Mon Sep 17 00:00:00 2001 From: Jared Date: Tue, 3 Apr 2012 20:38:37 -0500 Subject: [PATCH 6/7] changing output method to print to pipe and updating docs --- to_dotsies.rb | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/to_dotsies.rb b/to_dotsies.rb index 2236795..3d5cb17 100644 --- a/to_dotsies.rb +++ b/to_dotsies.rb @@ -9,17 +9,7 @@ class ToDotsies #

tags), and outputs an html file. # # > Dependencies - # This file currently has dependencies on Xiki. At the beginning - # it calles a Xiki function to get the filename. At the end it - # tells Xiki to send the html to the browser so we can see it (in - # addition to the script writing to a file). - # - # > Filenames - # Normally the input file passed will end in "--in.html". If it - # doesn't, the script looks for a file that ends that way. If it - # finds it, it uses it. If it doesn't find it, it assumes the - # file passed was an input file, and so renames it to end that way - # before moving on. + # This file currently has dependencies on Ruby 1.9.2. # # > Known problems # What about existing and tags in input files?... @@ -130,11 +120,10 @@ def self.gradually_convert txt inputfilename = ARGV[0] -outputfilename = ARGV[1] content = File.read inputfilename content = ToDotsies.gradually_convert content -content = %` +print %` #{content} - ` - -File.open(outputfilename, "w") { |f| f << content } + ` \ No newline at end of file From 6bdfad5d31c83a3ddd9629a7e1f90e8fa7ff80c4 Mon Sep 17 00:00:00 2001 From: Jared Date: Tue, 3 Apr 2012 20:40:39 -0500 Subject: [PATCH 7/7] updating docs --- to_dotsies.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/to_dotsies.rb b/to_dotsies.rb index 3d5cb17..aa898fc 100644 --- a/to_dotsies.rb +++ b/to_dotsies.rb @@ -20,7 +20,7 @@ class ToDotsies def self.gradually_convert txt # - # Read in file, and split into chunks (words, whitespace, and html tags) + # Read in txt, and split into chunks (words, whitespace, and html tags) # # Make first paragraph bigger