Created
September 26, 2014 07:55
-
-
Save lordofthejars/2271f0e5d143c33aec7f 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
############### Block Processor | |
line1 = "( X) Answer"; | |
line11 = "( ) Answer2"; | |
line2 = "[ ] Answer"; | |
line3 = "Question"; | |
line4 = ""; | |
input = [line3, line4, line1, line11, line3, line1] | |
output = []; | |
currentQuestionNumber = 0 | |
currentAnswerNumber = 0 | |
input.each {|x| | |
#detect radiobutton definition with valid answer (X) Answer | |
if ( x =~ /\((\s*X\s*)\) ./ ) | |
currentAnswerNumber += 1 | |
title = x.gsub(/^\((\s*X\s*)\)/, '').strip | |
output<< "<input id='check#{currentAnswerNumber}' name='q#{currentQuestionNumber}' class='question' type='checkbox' data-correct='true'/>" | |
output<< "<label for='check#{currentAnswerNumber}'>#{title}</label>" | |
#detect radiobutton definition with invalid answer () Answer | |
elsif ( x =~ /\(\s*\) ./ ) | |
currentAnswerNumber += 1 | |
title = x.gsub(/^\(\s*\)/, '').strip | |
output<< "<input id='check#{currentAnswerNumber}' name='q#{currentQuestionNumber}' class='question' type='checkbox' data-correct='true'/>" | |
output<< "<label for='check#{currentAnswerNumber}'>#{title}</label>" | |
#detect question title | |
elsif ( x =~ /[\w\d]+/ ) | |
if(currentQuestionNumber > 0) | |
output<<"</div>" | |
output<<"<br/>" | |
end | |
#because names should be the same in a radiobutton group we use this flag to group all in same name | |
currentQuestionNumber += 1 | |
output<<"<div>" | |
output<<"<h1>#{x}</h1>" | |
end | |
output<<"</div>" | |
output<<"<br/>" | |
} | |
puts output | |
################## PostProcessor | |
output2 = "<head></head>" | |
replacement = %( | |
<style> | |
.check { | |
background-color:#599bb3; | |
display:inline-block; | |
cursor:pointer; | |
color:#ffffff; | |
font-family:arial; | |
font-size:17px; | |
padding:8px 15px; | |
text-decoration:none; | |
text-shadow:0px 1px 0px #3d768a; | |
} | |
.check:hover { | |
background-color:#408c99; | |
} | |
input[type=radio], | |
input[type='checkbox'] { | |
display: none; | |
} | |
input[type=radio] + label { | |
display: block; | |
} | |
input[type='checkbox'] + label:before, | |
input[type='radio'] + label:before { | |
display: inline-block; | |
font-family: FontAwesome; | |
font-style: normal; | |
font-weight: normal; | |
line-height: 1; | |
-webkit-font-smoothing: antialiased; | |
-moz-osx-font-smoothing: grayscale; | |
padding-right: 8px; | |
} | |
input[type="checkbox"]:checked + label:before { | |
padding-right: 6px; | |
} | |
input[type=radio] + label:before { | |
content: "\f096"; /* Radio Unchecked */ | |
} | |
input[type=radio]:checked + label:before { | |
content: "\f046"; /* Radio Checked */ | |
} | |
input[type="checkbox"] + label:before { | |
content: "\f096"; /* Checkbox Unchecked */ | |
} | |
input[type="checkbox"]:checked + label:before { | |
content: "\f046"; /* Checkbox Checked */ | |
} | |
</style> | |
</head> | |
) | |
output2 = output2.sub(/<\/head>/m, replacement) | |
puts output2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment