Skip to content

Instantly share code, notes, and snippets.

@ab5tract
Created November 4, 2008 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ab5tract/22171 to your computer and use it in GitHub Desktop.
Save ab5tract/22171 to your computer and use it in GitHub Desktop.
# Framework
require 'foundations/compact'
# Gems
require 'palettes'
require 'cassandra'
# App
require 'views'
module Paletton
include Waves::Foundations::Compact
module Resources
class Map
on( :get, []) { Markaby::Beuilder.new.html Views.index }
on( :post,[]) { to(:palette) }
end
class Palette
on :post, [] do
palettes = Palettes::ColourLovers.search(query[:search_terms])
cssy = Cassandra.new.process({ :palettes => palettes }, Views.cssy)
Markaby::Builder.new.html({ :palettes => palettes, :cssy => cssy }, Views.list)
end
end
end# module Resources
end# module Palleton
module Views; class << self
def index
Markaby::Builder.new.html do
head do
title "Paletton"
end
body do
form :action => "/", :method => "POST" do
self << "Search: "
input :type => "text", :name => "search_terms"
input :type => "submit", :value => "Search"
end
end# body
end# Markaby::Builder.new.html
end# index
def list(assigns)
Markaby::Builder.new(assigns).html do
head do
title 'Paletton'
style :type => 'text/css' { self << @cssy }
end
body :bgcolor => "#BCBDAC" do
@palettes.each |palette, p|
div.palette_bg do
table :width => "350", :height => "222", :cellpadding => "0", cellspacing => "0" do
tr do
if palette[:colors][0].respond_to? :last
colors = palette[:colors].map {|c| c.last }
names = palette[:colors].map {|n| n.first }
else
palette[:colors]
end
colors.each_with_index do |color, i|
td :id => "#{p[:id]}_color_#{i+1}", :width => (350/palette[:colors].length).to_i do
names.exists? ? self << names[i] : self << color
end
end
end#div.palette_bg
end#body
end#html
end#list(assigns)
def cssy
table.palette_canvas {
position 'absolute'
left '4.8%'
border_collapse 'collapse'
}
td {
%w[ margin border padding ].each {|attr| attr '0px'}
color 'white'
vertical_align 'top'
text_align 'center'
}
selector('.palette_bg') {
position 'absolute'
top '35px'
left '11px'
background 'white'
padding '2.2%'
}
@palettes.each_with_index |palette, p|
colors = palette[0].respond_to? :last ? palette[:colors].map{|m| m.last} : palette[:colors]
colors.each_with_index do |color, i|
selector("td.#{p[:id]}_color_#{i+1}") {
background( color )
}
end
end
end#cssy
end;end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment