Skip to content

Instantly share code, notes, and snippets.

@brettburwell
brettburwell / img.html
Last active June 26, 2018 09:05
Craft macro to centralize the markup and config for responsive images
{# ================================================================== #}
{# Responsive Image Macro
{# ================================================================== #}
{#
Macro to centralize the markup and config for responsive images.
Based on an article by Marion Newlevant (@marionnewlevant) and
adapted for the Lazysizes plugin. Read more:
https://straightupcraft.com/articles/responsive-images-with-twig-macros
@lukeholder
lukeholder / import.php
Last active January 10, 2018 09:58
Basic example to import Products and their variants into Craft Commerce
<?php
namespace Craft;
// This file could be placed into your public_html folder and visited to import a cheese product.
$craft = require '../craft/app/bootstrap.php';
$craft->plugins->loadPlugins();
$newProduct = new Commerce_ProductModel();
@boboldehampsink
boboldehampsink / SlugifyPlugin.php
Last active May 16, 2016 12:56
Slugify Twig Extension - Use like this: {{ user.fullName | slugify }}. Uses Craft's core slug technology.
<?php
namespace Craft;
class SlugifyPlugin extends BasePlugin
{
public function getName()
{
return Craft::t('Slugify Twig Extension');
}
@sskylar
sskylar / import-siteleaf.json
Last active December 18, 2015 18:10
Siteleaf import script. Imports a JSON dump of blog posts into a Siteleaf page. Requires the Siteleaf Gem (https://github.com/siteleaf/siteleaf-gem). Run in the command line using "ruby import-siteleaf.rb".
[{
"title":"Post 1",
"body":"Body goes here.",
"tags":["Tag 1", "Tag 2"],
"slug":"post-1",
"published_at":"2013-06-05T18:24:59-04:00"
}, {
"title":"Post 2",
"body":"Body goes here.",
"tags":["Tag 1", "Tag 2"],
@jspillers
jspillers / HerokuResqueAutoScale config shortcut
Created April 8, 2011 20:35
Allows each resque worker class to be given auto scaling via config/initializers/resque.rb
# my app had quite a few different worker classes so
# i decided to extend them all from one place:
# config/initializers/resque.rb
if Rails.env == "production" || Rails.env == "staging"
resque_klasses = [
SomeJob,
AnotherJob,
VeryHardWork,
PrettyEasyJobHere
@djktno
djktno / example_worker.rb
Created April 4, 2011 22:42
Integrating MongoDB/Mongoid with SimpleWorker
require 'simple_worker'
require 'mongoid'
class ExampleWorker < SimpleWorker::Base
#Not sure if this is necessary (according to the docs), but
#it stopped complaining when I did it.
merge File.join(File.dirname("__FILE__"), "..", "models", "user.rb")
attr_accessor :user_id, :mongodb_settings
@gmoeck
gmoeck / env.rb
Created June 21, 2010 19:24
Rails 3 Mongoid Cucumber Setup
ENV["RAILS_ENV"] ||= "test"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
require 'cucumber/rails/rspec'
require 'cucumber/rails/world'
require 'cucumber/web/tableish'
require 'capybara/rails'
require 'capybara/cucumber'
@patrickberkeley
patrickberkeley / pages_controller.rb
Created December 7, 2008 02:10
using Paperclip for multiple attachments and displaying them using the method described in Advanced Rails Recipe #13
class PagesController < ApplicationController
before_filter :login_required, :except => [ :show ]
# GET /pages
# GET /pages.xml
def index
@pages = Page.find(:all)
respond_to do |format|
format.html # index.html.erb