Skip to content

Instantly share code, notes, and snippets.

View magnetised's full-sized avatar

Garry Hill magnetised

View GitHub Profile
$ rvm --trace install jruby 2>&1
+__rvm_parse_args:669> [[ -n 4.3.11 ]]
+__rvm_parse_args:704> [[ -z '' && -n '' ]]
+__rvm_parse_args:707> [[ error == || 0 -eq 1 || -n '' ]]
+__rvm_parse_args:16> [[ -n install ]]
+__rvm_parse_args:18> rvm_token=install
+__rvm_parse_args:20> (( 1 > 0 ))
+__rvm_parse_args:22> next_token=jruby
+__rvm_parse_args:23> shift
+__rvm_parse_args:28> case install ([[:alnum:]]*|@*)
@magnetised
magnetised / outputs.rb
Created January 23, 2013 13:53
An example of a content type with multiple outputs
class IntegratedPage < Page
# Define multiple outputs for this page. Each one will be accessible by adding
# the relevant extension to the page's URL. e.g.
# /my-page => HTML
# /my-page.xml => XML
# /my-page.rss => RSS
outputs :html, :rss, :json, :xml
# If the output specified doesn't map to the extension of a a known MIME type
# then you can define the format manually.
@magnetised
magnetised / image_field.rb
Created January 22, 2013 10:57
Example of defining image output sizes
class Photo < Piece
field :image do
# Define a list of outputs that will be generated for each image
size :large do
# Here you have access to a minimagick context which can be used to
# apply any ImageMagick process to your uploaded image.
# https://github.com/minimagick/minimagick
fit 640, 360
end
# Install RVM
$ curl -L https://get.rvm.io | bash -s stable
# Install Ruby 2.1.3
$ rvm install 2.1.3
# Install Spontaneous (which is still in alpha/beta)
$ gem install spontaneous --pre
# Use the `spot` binary to generate a site skeleton
@magnetised
magnetised / blog_post.rb
Last active December 11, 2015 10:38
An example of content type controllers
class BlogPost < Page
controller :comments do
# The comments controller is a Sinatra app
# so you can use its excellent DSL to define
# routes and behaviour for your page application
get "/comments" do
# … load and return a list of comments in JSON format
# each action has access to the current page through
# the `page` variable.
content_type :json
@magnetised
magnetised / indexes.rb
Created January 21, 2013 17:57
How to define multiple search indexes.
# A site-wide search
Site.index :everything
# And a specific index for blog post tags
Site.index :tags do
# Each index has a list of content types to include which defaults to all of them.
# Using #include limits the types to include to the ones specified in this list.
include :BlogPost
# OR we could work with all types except for a few
# exclude :Homepage
@magnetised
magnetised / member.rb
Last active December 11, 2015 10:29
An example of extending a Spontaneous content type
class Member < Piece
# Store people's names in separate first_name & last_name
# fields to enable sorting on the surname
field :first_name
field :last_name
# Call Member::names to get a list of all Members names sorted by their last name
# Member::all returns all the instances of Member from the database.
def self.names
Member.all.sort { |m1, m2| m1.sort_name <=> m2.sort_name }.map(&:name)
@magnetised
magnetised / schema.rb
Last active December 11, 2015 10:28
An simple example Spontaneous schema
# Define a SectionPage that holds fields common across all top-level pages in our site
class SectionPage < Page
# A field to hold some introductory text. All subclasses of this type will inherit this field.
field :welcome_text, :markdown
end
# Create a home page type inheriting methods & fields from our SectionPage
class Homepage < SectionPage
# Add a field for a photo of us
field :photo
This is a ${ name } template.
Cutaneous supports multiple syntaxes, but in this example expressions
are embedded using the syntax `\${ expression }`.
Using the expression tags `\%{ ... }` allows you to embed pure Ruby
code in your templates e.g.
%{ ["Hello", "World"].each do |word| -}
${ word }