Created
November 4, 2008 17:32
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
# Framework | |
require 'foundations/compact' | |
# Gems | |
require 'palettes' | |
require 'cassandra' | |
# App | |
require 'views' | |
module Paletton | |
include Waves::Foundations::Compact | |
module Resources | |
class Map | |
on( :get, []) { mab(@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 |
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
module << Views | |
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.to_s } | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment