Skip to content

Instantly share code, notes, and snippets.

View lukesutton's full-sized avatar

Luke Matthew Sutton lukesutton

View GitHub Profile
match("/path/to/match").defer_to do |request, params|
if something? params[:thing]
request.env["REQUEST_PATH"] = "/a/different/path"
new_params = Merb::Router.match(request)[1]
new_params.merge(:custom_parameter => "Weeee!")
else
param
end
end
name: AppName
port: 4020
environment: production
size: 3
it "should destroy the record" do
page_type = PageType.generate
controller = dispatch_to(PageTypes, :destroy, :id => page_type.id)
@response.should redirect_to("/content/page_types")
PageTypes.get(page_type.id).should be_nil
end
# Ajax request
@response = request(url(:help), "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest")
# HTTP Method — "POST", "GET", "DELETE", "PUT"
@response = request(url(:help), :method => "POST")
Gluttonberg::PageDescriptions.describe do
# The key is how this description will be refered to internally. The value
# is the label, which will be used within the UI.
page :home => "Homepage" do
# A description, which will be displayed in the user interface if the
# user requests it.
desc "The home page of the site"
# Limit the number of pages that can be be associatied with this
# description. It can be an Integer between 1—n or it can be a range
# Example usage within Gluttonberg
# Page.localized_tree("australia_english", :depth => (0..1))
def self.localized_tree(locale_name, page_opts = {})
# Find all matching pages
pages = Page.all({:order => [:position.asc]}.merge!(page_opts))
if pages.empty?
pages
else
# Find the localizations that belong to the pages passed in. This is done
# Check types
def type_check(checks)
checks.each do |var, types|
types = types.is_a? Array ? types : [types]
match = false
types.each { |type| match = true if var.is_a? type }
raise ArgumentError unless match
end
end
Gluttonberg::PageDescription.add do
page :home do
home true
label "Home Page"
view "home"
layout "default"
section :main do
label "Main"
type :rich_text
Gluttonberg::Config.locales do
locale :australia_english do
location :au, "Australia"
dialect :en, "English"
default true
end
locale :spain_spanish do
location :es, "Spain", "Espana"
dialect :es, "Spanish", "Espanol"
PUBLIC_DEFER_TO_PROC = lambda do |request, params|
locale = Config::Locale.find(params)
# Find the page with the closest matching path. If the matching path is
# shorter than the one specified, it will still match, since it may actually
# be a redirect.
page = Page.first_with_localization(
:locale_name => locale[:name]
:conditions => ["? LIKE (path || '%')", params[:full_path]],
:order => [:path.asc]
)