Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Moar silliness. Generate a set of CSS styles for grid columns. Fixed-width for the moment. ruby col-widther-css.rb, copy and paste.
@colwidth = 100
@margin = 10
@total = 0
@numbers = ["none", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", "twenty_one", "twenty_two", "twenty_three", "twenty_four", "twenty_five", "twenty_six", "twenty_seven", "twenty_eight", "twenty_nine", "thirty", "thirty_one", "thirty_two"]
def spanwidth(cols)
[(cols * @colwidth.to_i), (@margin.to_i * (cols-1))]
end
def calculate
puts ".grid {"
puts " margin-left: #{@margin.to_i}px;"
puts " margin-right: 0px;"
puts " width: #{@colwidth.to_i}px;"
puts "}"
puts ""
puts ".grid:last-child {"
puts " margin-right: 0;"
puts "}"
puts ""
(1..@cols.to_i).each do | multiple |
width = [(multiple * @colwidth.to_i), (@margin.to_i * (multiple-1))]
puts ".grid.#{@numbers[multiple]}_units {"
puts " width: #{width[0] + width[1]}px;"
puts "}"
puts ""
@total += (@colwidth.to_i + @margin.to_i)
end
end
puts "Column width: "
@colwidth = gets
puts "Margin width: "
@margin = gets
puts "Total columns: "
@cols = gets
puts "8<------"
if @cols.to_i > (@numbers.size() - 1)
puts "Dunno how to generate the names of one or more columns"
exit
end
if @colwidth.to_i > 1 && @margin.to_i > 1 && @cols.to_i > 1
calculate
puts "------8<"
puts "Total: #{@total}"
else
puts "Oops."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment