This repository has been archived by the owner on Jan 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
framer.rb
150 lines (127 loc) · 3.65 KB
/
framer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
APP_ROOT = File.dirname(File.expand_path(__FILE__)) unless defined?(APP_ROOT)
$LOAD_PATH.unshift('../sinatra/lib') #use latest version of sinatra
require 'rubygems'
require 'RedCloth'
require 'lorem' #required until i can fix faker's paragraphs
require 'faker'
require 'compass'
require 'sinatra'
require 'haml'
require 'staticizer'
use Staticizer, "./static"
# set variables
set :app_file, __FILE__
set :root, File.dirname(__FILE__)
set :views, "views"
configure do
Compass.configuration do |config|
config.project_path = File.dirname(__FILE__)
config.sass_dir = File.join(Sinatra::Application.views, 'stylesheets')
config.output_style = :compact
end
end
helpers do
def browser?(b)
user_agents = {
:firefox => /Firefox/,
:safari=> /Safari/
}
user_agents[b] &&
request.env["HTTP_USER_AGENT"] &&
request.env["HTTP_USER_AGENT"] =~ user_agents[b]
end
def partial(page, options={})
haml "_#{page}".to_sym, options.merge!(:layout => false)
end
def bodyselectors
klass = "blueprint"
klass += " #{@bodyclass}" if @bodyclass
klass += " oldbrowser" unless browser?(:firefox) || browser?(:safari)
if @bodyid && klass
{:id => @bodyid, :class => klass}
elsif @bodyid
{:id => @bodyid}
elsif klass
{:class => klass}
else
{}
end
end
def page_title(title = nil)
if title
"this is a framer wireframe of >> "+ title
else
"framer"
end
end
def lorem(type, amount)
if type == :paragraph
RedCloth.new(Faker::Lorem.paragraph(amount)).to_html
elsif type == :paragraphs
# for some reason, faker doesn't work with paragraphs...
RedCloth.new(Lorem::Base.new('paragraphs', amount).output).to_html
elsif type == :sentence
Faker::Lorem.sentence(amount)
elsif type == :title
Faker::Lorem.sentence(amount).gsub('.','')
elsif type == :sentences
Faker::Lorem.sentences(amount).join(' ')
elsif type == :words
Faker::Lorem.words(amount).join(' ')
else
"You've got no lorems"
end
end
def name(type)
if type == :full
Faker::Name.name
elsif type == :first
Faker::Name.first_name
elsif type == :last
Faker::Name.last_name
elsif type == :user
Faker::Lorem.words(2)
end
end
def link_to(type,action,text)
if type == 'view'
"<a href='"+action+"' alt='go to "+text+"'>"+text+"</a>"
elsif type == 'js'
"<a href='javascript:void(0);' class='"+action+"'>"+text+"</a>"
end
end
def media(type,id,width,height,text)
"<div id='"+id.to_s+"' class='media media-"+type.to_s+"'><img class='media-crosshair' src='/images/image-cross-hair.png' width='"+width.to_s+"' height='"+height.to_s+"' /><p class='media-size'>"+width.to_s+"w x "+height.to_s+"h</p><p class='media-text'>"+text+"</p></div>"
end
end
not_found do
headers["Status"] = "301 Moved Permanently"
redirect("/")
end
# define demo pages
get '/' do
@bodyid = "demo"
haml "= RedCloth.new(File.read('./readme.textile')).to_html", :layout => :"demo/layout"
end
get '/demo' do
haml :"demo/index".to_sym, :layout => :"demo/layout"
end
get '/demo/showtools' do
@showtools = true
haml :"demo/index".to_sym, :layout => :"demo/layout"
end
# define stylesheets
get '/stylesheets/:name.css' do
content_type 'text/css', :charset => 'utf-8'
sass :"stylesheets/#{params[:name]}", :sass => Compass.sass_engine_options
end
# define app pages
get '/:name' do
@bodyid = params[:name].gsub(/[!@\#$%&:?,\.\/-\;]/im, '_')
haml params[:name].to_sym
end
get %r{/(.*?)/showtools} do |n|
@bodyid = n.gsub(/[!@\#$%&:?,\.\/-\;]/im, '_')
@showtools = true
haml n.to_sym
end