Skip to content

Instantly share code, notes, and snippets.

View tdreyno's full-sized avatar

Thomas Reynolds tdreyno

  • Portland, OR
  • 04:56 (UTC -08:00)
View GitHub Profile
require 'config/path_helpers'
require 'config/haml_helpers'
Middleman::Base.mime :php, "text/html"
set :index_file, "index.php"
set :images_dir, "assets/images"
set :css_dir, "assets/stylesheets"
set :videos_dir, "assets/videos"
set :js_dir, "assets/javascripts"
def find_and_include_related_sass_file
path = request.path_info.dup
path << self.class.index_file if path.match(%r{/$})
path.gsub!(%r{^/}, '')
path.gsub!(File.extname(path), '')
path.gsub!('/', '-')
sass_file = File.join(File.basename(self.class.views), self.class.css_dir, "#{path}.css.sass")
if File.exists? sass_file
stylesheet_link_tag "#{path}.css"
def partial(name)
haml name.to_sym, :layout => false
end
%pre
:preserve
Text
:table
Col1 | Col2 | Col3
5 | 6 | 7
get "/layoutless_page" do
haml :"layoutless_page.html", :layout => false
end
#header {
height: 108px;
overflow: hidden;
background: #6B4419;
background: #6B4419 -webkit-gradient(linear, 0 bottom, 0 98, from(rgba(0,0,0,0.1)), to(transparent)); }
class Sinatra::Base
# not my code
def self.get(url, *args)
# method body
end
# my code
def self.with_layout(url, layout, &block)
# Basically, I want to call get, but with additional args appended
Generic.class_eval(&block)
# Normal Sinatra version
get "/index.html" do
haml :index
end
# Proposed API
with_layout :custom do
get "/using-custom.html"
get "/admin-area/index.html"
end
In your init.rb
This:
with_layout :admin do
page "/admin/*"
end
Or: