Skip to content

Instantly share code, notes, and snippets.

View parndt's full-sized avatar

Philip Arndt parndt

View GitHub Profile
@parndt
parndt / Guardfile
Created January 17, 2012 22:17
RSpec support for edge Refinery apps
engines = Dir[File.expand_path('../vendor/engines/*', __FILE__)]
guard 'spork', :wait => 60, :cucumber => false, :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('spec/spec_helper.rb')
watch(%r{^spec/support/.+\.rb$})
@parndt
parndt / gist:1629498
Created January 17, 2012 22:44
A DSL for defining different page types for Refinery CMS. Allows setting default page parts per type and defining which template shall render when the page is requested.
Refinery::Pages.configure do |pages|
pages.types do |types|
types.define :home do |home|
home.parts = %w[intro body]
home.template = 'refinery/pages/home' # this is automatic but shows overriding
end
types.define :show do |show|
show.parts = %w[body side]
# show.template is automatically 'refinery/pages/show' and thus not required.
@parndt
parndt / deep_merge_and_output.rb
Created January 20, 2012 01:26
Psych outputs a different file than it read in
require 'yaml'
my_yaml = YAML::load(File.read('en.yml')).to_yaml
=begin
1.9.3-p0 :002 > YAML::load(File.read('en.yml')).to_yaml
=> "---\nen:\n refinery:\n plugins:\n lovelies:\n title: Lovely Profiles\n people:\n admin:\n lovelies:\n actions:\n create_new: Add New Lovely profile\n reorder: Reorder Lovely profiles\n reorder_done: Done Reordering Lovely profiles\n records:\n title: Lovely\n sorry_no_results: Sorry! There are no results found.\n no_items_yet: There are no Lovely profiles yet. Click \"Add New Lovely\n profile\" to add one.\n lovely:\n view_live_html: View the lovely area live <br/><em>(opens in a new window)</em>\n edit: Edit this lovely profile\n delete: Remove this lovely profile forever\n lovelies:\n show:\n other: Other Lovely profiles\n activerecord:\n attributes:\n refinery/things/lovely:\n
Rails 3.1:
16:04:10: (master $) /code/foo/bar$ time script/rails runner ""
real 0m8.653s
user 0m7.731s
sys 0m0.822s
Rails 3.2:
16:04:33: (master *$) /code/foo/bar$ time script/rails runner ""
def confirmation_message=(value)
value.first.keys.each do |locale|
Refinery::Setting.set("inquiry_confirmation_message_#{locale}".to_sym, {
:value => value.first[locale.to_sym],
:scoping => "inquiries"
})
end
end
@parndt
parndt / gist:1713646
Created January 31, 2012 23:04
Rudimentary page caching.
::PagesController.module_eval do
caches_page :show, :unless => proc {|c| c.user_signed_in? || c.flash.any? }
caches_page :home, :unless => proc {|c| c.user_signed_in? || c.flash.any? }
end
::Page.module_eval do
after_save :clear_static_caching!
after_destroy :clear_static_caching!
def clear_static_caching!
Page.all.map(&:url).map{|u|
@parndt
parndt / application.html.erb
Created February 2, 2012 23:08
Change theme
<%= stylesheet_link_tag(current_theme) %>
@parndt
parndt / gist:1726580
Created February 2, 2012 23:54
change theme in your helper for joshuascott
def current_theme
# first, check if we've tried to access this already and if so @current_theme will be populated with a value.
@current_theme ||= if params[:ChangeTheme] == "true"
# If the user is trying to change the theme, first: construct an array of possible themes.
# then: reject the theme in the current session if it is present.
# Finally, grab a random sample to use a random theme from the array of themes.
%w[power.css creative.css communication.css].reject{|theme| theme == session[:current_theme]}.sample
else
# The user is not trying to change the theme so just return the current theme saved to sesssion OR
# return the default theme which is 'power.css'
Refinery::Core::Engine.routes.draw do
namespace :admin, :path => 'refinery' do
resources :users, :except => :show
end
end
# Can I default namespace :admin to use :path => 'refinery' ?
@parndt
parndt / gist:1761816
Created February 7, 2012 20:43
Seeding in a few locales
page_position = -1
I18n.locale = :en
tuning_page = Page.create(:title => "Tuning", :deletable => true, :position => (page_position += 1))
I18n.locale = :fr
tuning_page.title = 'French Tuning'
tuning_page.save
I18n.locale = :es
tuning_page.title = 'Spanish Tuning'
tuning_page.save