This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copy this file to ./app/views/component_helper.rb if you want to unlock ViewComponent rendering super powers. | |
module ComponentHelper | |
# Instead of the awkward `render FooComponent.new(title: "foo")` calls in Rails templates, | |
# use a method like `foo_component title: "foo"`. | |
def method_missing(method_name, *args, **kwargs, &block) | |
if method_name.end_with? "_component" | |
component_class = method_name.to_s.classify.constantize | |
component = component_class.new(*args, **kwargs) | |
component.render_in(self, &block) | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Redcarpet | |
module Rails | |
DEFAULT_BASE_RENDERER = Redcarpet::Render::HTML | |
DEFAULT_OPTIONS = Hash.new | |
class << self | |
def stack | |
@stack ||= Stack.new | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem install sitepress --pre | |
sitepress new ./site | |
cd ./site | |
sitepress server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "csv" | |
class CSVDefinition | |
attr_reader :definition | |
def initialize | |
@definition ||= Hash.new | |
end | |
def row(name, &block) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker run ubuntu /bin/echo 'Hello world' | |
Hello world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ./config/initializers/rewrite_ie_header.rb | |
# Don't forget to include the middleware file! If you have a ./lib/middleware folder in rails | |
# a `require './lib/middleware/rewrite_ie_header.rb'` should do the trick | |
# | |
# IE has a really stupid accept header, so here we scope its domain of mime-types that it can negotiate, otherwise we'll | |
# end up with weird bugs where if you hit /mcp/:id, IE will download a .ppt file instead of the .html content. | |
# | |
# Issue documented in more detail at https://github.com/rails/rails/issues/9940. | |
Rails.application.config.middleware.use RewriteIEAcceptHeader do |ie_mime_types| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
export IMAGE_NAME=my_app | |
CONTAINER_ID=$(docker run -d $IMAGE_NAME bundle $@) | |
docker logs -f $CONTAINER_ID | |
docker commit $CONTAINER_ID $IMAGE_NAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module PunditExampleGroup | |
extend ::RSpec::Matchers::DSL | |
matcher :permit do |action| | |
match do |policy| | |
policy.public_send("#{action}?") | |
end | |
failure_message do |policy| | |
"#{policy.class} does not permit #{action} on #{policy.record} for #{policy.user.inspect}." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler' | |
require 'yaml' | |
def format(hash) | |
Hash[hash.keys.map(&:to_s).zip(hash.values)].to_yaml | |
end | |
Bundler.load.specs.each do |spec| | |
puts format({ | |
name: spec.name, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
name: "Todo List", | |
items(href: '/lists/1203/items', next_href: "/lists/1203/items?page=2"): [ | |
item(href: '/items/1'): { | |
description: "Pick up pizza", | |
status: "completed" | |
}, | |
item(href: '/items/12'): { | |
description: "Eat pizza", | |
status: "non_started" |