class Divy::DivGenerator
Public Instance Methods
content_as_html(grid_size, content, options)
click to toggle source
# File lib/divy/div_generator.rb, line 26 def content_as_html(grid_size, content, options) case content[:type] when :html divy_box(content[:location][0], content[:location][1], grid_size, content[:value], content[:size], options) when :image divy_box(content[:location][0], content[:location][1], grid_size, image_html(content[:value]), content[:size], options) when :none '' end end
content_divy_box_stylez(x, y, grid_size, content_size = nil)
click to toggle source
# File lib/divy/div_generator.rb, line 72 def content_divy_box_stylez(x, y, grid_size, content_size = nil) bottom = scaled_value(grid_size[1], (y - 0.5)) left = scaled_value(grid_size[0], (x - 0.5)) width = scaled_value(grid_size[0], content_size[0]) height = scaled_value(grid_size[1], content_size[1]) "bottom: #{bottom}%; left: #{left}%; width: #{width}%; height: #{height}%; #{default_stylez(nil)}" end
default_stylez(options = {})
click to toggle source
# File lib/divy/div_generator.rb, line 88 def default_stylez(options = {}) if options && options[:show_grid] color = options[:grid_color] || '#000000' "position: absolute; border-style:solid; border-color:#{color};" else 'position: absolute;' end end
divy_box(x = 0, y = 0, grid_size = [10, 10], content = nil, content_size = nil, options = {})
click to toggle source
# File lib/divy/div_generator.rb, line 51 def divy_box(x = 0, y = 0, grid_size = [10, 10], content = nil, content_size = nil, options = {}) style = divy_box_stylez(x, y, grid_size, content_size, options) "<div class=\"divybox\" style=\"#{style}\">#{content}</div>\n" end
divy_box_stylez(x, y, grid_size, content_size = nil, options = {})
click to toggle source
# File lib/divy/div_generator.rb, line 56 def divy_box_stylez(x, y, grid_size, content_size = nil, options = {}) if content_size content_divy_box_stylez(x, y, grid_size, content_size) else general_divy_box_stylez(x, y, grid_size, options) end end
divy_container(container_size, container_content)
click to toggle source
# File lib/divy/div_generator.rb, line 3 def divy_container(container_size, container_content) style = "style=\"position:relative; width: #{size_and_unit(container_size[0])}; height: #{size_and_unit(container_size[1])};\"" begin_tag = "<div class=\"divycontainer\" #{style}>\n" end_tag = "</div>\n" begin_tag + container_content + end_tag end
divy_content(grid_size, content_arr, options = {})
click to toggle source
# File lib/divy/div_generator.rb, line 18 def divy_content(grid_size, content_arr, options = {}) html_content = '' content_arr.each do |content_hsh| html_content += content_as_html(grid_size, content_hsh, options) end html_content end
general_divy_box_stylez(x, y, grid_size, options = {})
click to toggle source
# File lib/divy/div_generator.rb, line 64 def general_divy_box_stylez(x, y, grid_size, options = {}) bottom = scaled_value(grid_size[1], y) left = scaled_value(grid_size[0], x) width = scaled_percentage(grid_size[0]) height = scaled_percentage(grid_size[1]) "bottom: #{bottom}%; left: #{left}%; width: #{width}%; height: #{height}%; #{default_stylez(options)}" end
grid_html(grid_dimensions, options = {})
click to toggle source
# File lib/divy/div_generator.rb, line 41 def grid_html(grid_dimensions, options = {}) div_grid_html = '' (0..(grid_dimensions[0] - 1)).each do |x| (0..(grid_dimensions[1] - 1)).each do |y| div_grid_html += divy_box(x, y, grid_dimensions, nil, nil, options) end end div_grid_html end
image_html(path)
click to toggle source
# File lib/divy/div_generator.rb, line 37 def image_html(path) "<img src=\"#{path}\" height=\"100%\" width=\"100%\"></img>" end
scaled_percentage(total_units)
click to toggle source
# File lib/divy/div_generator.rb, line 84 def scaled_percentage(total_units) (100 / total_units.to_f) end
scaled_value(total_units, val)
click to toggle source
# File lib/divy/div_generator.rb, line 80 def scaled_value(total_units, val) scaled_percentage(total_units) * val.to_f end
size_and_unit(container_size)
click to toggle source
# File lib/divy/div_generator.rb, line 10 def size_and_unit(container_size) if container_size.to_s.match(/%/) container_size else "#{container_size}px" end end