Skip to content

Instantly share code, notes, and snippets.

View augustl's full-sized avatar

August Lilleaas augustl

  • Oslo, Norway
View GitHub Profile
@augustl
augustl / test_helper.rb
Created March 3, 2009 15:18
Test helper for testing engines in 2.3.
dir = File.dirname(__FILE__)
rails_root = File.join(dir, '..', '..', '..', '..')
ENV["RAILS_ENV"] = "test"
ENV["RAILS_ROOT"] = rails_root
require File.join(rails_root, 'config', 'environment')
require 'test/unit'
require 'action_view/test_case'
@augustl
augustl / engine.rb
Created June 24, 2009 20:01
Work in progress lesscss.org parser, based on treetop
module Less
class Engine
attr_reader :css
attr_reader :parser, :build_handler, :root_node
def initialize(less)
@less = less.dup
@parser = LessGrammarParser.new
@build_handler = BuildHandler.new
parse
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
silence_stream(STDOUT) do
ActiveRecord::Schema.define do
create_table(:posts) {|t| t.string :title }
create_table(:comments) {|t| t.integer :post_id; t.string :comment }
end
end
<%= render :partial => "entry_big", :object => @entries.first %>
<%= render :partial => "entry_small", :collection => @entries[1..-1] %>
# Include this module into the controllers you want to easy-mode CRUD
module AdminControllerCrudActions
COLUMN_MAP = {
:string => :text_field,
:text => :text_area,
:integer => :text_field,
:datetime => :datetime_select
}
def index
#!/usr/bin/env ruby
# Just testing. Will create new gist when I worked out the kinks.
class PathResolverController < ApplicationController
def resolve
name = PagePath.find_by_name(params[:path].join('/')).controller_name
case name
when "this"
some_logic
when "than"
other_logic
else
git "git://github.com/rails/arel.git"
git "git://github.com/rails/rack.git"
gem "rails", :git => "git://github.com/rails/rails.git"
anon_class = Class.new
p anon_class.name
# => ""
subanon_class = Class.new(anon_class)
p subanon_class.ancestors
# => [#<Class:0x100a54578>, #<Class:0x100a54618>, Object, Kernel]
NoLongerAnon = anon_class
TheSubclass = subanon_class