Skip to content

Instantly share code, notes, and snippets.

module NotesWidget
class Form < MyWidget
responds_to_event :create, :with => :create_note
preserves_attr :display_mode, :from => '..'
def form # The form to add notes
@note = Notes.new()
render
end
# in a cell view:
%h3 hey, Yahooda
render :state => :yay
#now, render :state internally does nothing more than
elsif opts[:state]
@apotonick
apotonick / gist:760353
Created December 30, 2010 21:49
AV::ViewHelper replacement.rb
# from tag_helper_test.rb
# now:
# TAG TODO: Move this into a real template
def test_content_tag_nested_in_content_tag_in_erb
buffer = content_tag("p") { concat content_tag("b", "Hello") }
assert_equal '<p><b>Hello</b></p>', buffer
end
# better:
@apotonick
apotonick / scribes-ruby-templates.xml
Created December 13, 2011 08:17
My Ruby templates for Scribes
<?xml version="1.0" encoding="UTF-8"?>
<scribes version="0.1">
<snippet><entry><trigger id="ruby">select</trigger><description>select element</description><template>select { |${element}| ${element}.${} }${cursor}</template></entry><entry><trigger id="ruby">when</trigger><description>when</description><template>inject(${object}) do |${injection}, ${element}|
${}
end
${cursor}</template></entry><entry><trigger id="ruby">reject</trigger><description>reject element</description><template>reject { |${element}| ${element}.${} }${cursor}</template></entry><entry><trigger id="ruby">:</trigger><description>hash pair</description><template>:${key} =&gt; ${&quot;value&quot;}${,}${cursor}</template></entry><entry><trigger id="ruby">ife</trigger><description>if...else</description><template>if ${condition}
${statement_1}
else
${statement_2}
end
@apotonick
apotonick / pure_ruby.rb
Created May 7, 2012 06:01
Cells in Sinatra, Webmachine, Love
require 'cell/base'
class FakeRoutes # should be sinatra's url helper instance
def url_for(*)
end
def named_routes # required due to a fucking stupid line in AbstractController::UrlFor#25 (3.2.3)
# super - _routes.named_routes.helper_names
Object.new.instance_eval do
@apotonick
apotonick / speaker.md
Created May 15, 2012 17:57 — forked from matiaskorhonen/speaker.md
Frozen Rails Talk Proposal Template
xml = "<bla>" +
10000.times.collect { "<item />" }.join("") +
"</bla>"
puts( "elapsed time (xpath): " + Benchmark.realtime do
Nokogiri::XML(xml).root.search("./item")
end.to_s)
puts( "elapsed time: " + Benchmark.realtime do
Nokogiri::XML(xml).root.children.find_all do |cld|
@apotonick
apotonick / instance_exec.rb
Last active December 11, 2015 21:29
The problem here is the instance_exec in the anonymous module - the #a method is not mixed into obj.
blk = lambda { def a; end }
mod = Module.new { instance_exec &blk } # this should add #a to mod.
obj = Object.new
obj.extend(mod)
obj.a #=> undefined method `a' for #<Object:0x970543c>
require 'ostruct'
require 'benchmark'
require 'representable/hash'
# --------- extend
module SongRepresenter
include Representable::Hash
@apotonick
apotonick / Problem.rb
Last active August 29, 2015 13:56
Inheritable Module Class Methods
# Here's the original problem:
module Feature
module ClassMethods
def feature
end
end
def self.included(includer)
includer.extend ClassMethods