Please excuse the mess.

Using Liquid Templates

Posted by rick | 0 comments

Note: This area was yanked from the Shopify Liquid Quick Reference.

There are two types of markup in liquid: Output and Tag.

  • Output is surrounded by {{ two curly brackets }} * Tags are surrounded by {% a curly bracket and a percent %}

Output

Here is a simple example of Output:

Hello {{name}}          
Hello {{user.name}}
Hello {{ 'tobi' }}

Advanced output: Filters

Output markup takes filters. Filters are simple methods. The first parameter is always the output of the left side of the filter. The return value of the filter will be the new left value when the next filter is run. When there are no more filters the template will receive the resulting string.

Hello {{ 'tobi' | upcase }}
Hello tobi has {{ 'tobi' | length }} letters!
Hello {{ '*tobi*' | textilize | upcase }}
Hello {{ now | date: "%Y %h" }}

Tags

Tags are for the logic in your template. New tags are very easy to code and I hope to get many contributions to the standard tag library after releasing this code.

Here is a list of basic Liquid supported tags:

Comments

Comment is the simplest tag. It just swallows content.

Hi tobi {% comment %} you stink {% endcomment %}

If / Else

If else should be well known from any language imaginable. Liquid allows you to write simple expressions in the if.

{% if user %}
  Hi {{ user.name }}
{% endif %}

{% if user.name == 'tobi' %}
  hi tobi
{% endif %}

{% if user.name != 'tobi' %} 
  hi non-tobi
{% endif %}

{% if user.creditcard  null %}
   poor sob
{% endif %}

{% if user.payments  empty %}
   you never payed ! 
{ endif }

{ if user.age > 18 } Login here
{ else } Sorry, you are too young
{ endif }

Case Statement

If you need more than one condition you can use the Case Statement

{% case condition %} 
{% when 1 %} 
hit 1 
{% when 2 %} 

hit 2 
{% else %} 
elseblock 
{% endcase %} 

Example:

{% case template %}

{% when 'label' %}
     // {{ label.title }}
{% when 'product' %}
     // {{ product.vendor | link_to_vendor }} / {{ product.title }}
{% else %}
     // {{page_title}
{% endcase %}

Cycle

Often you have to alternate between different colors or similar tasks. Liquid has build in support for such operations using the cycle tag.

{% cycle 'one', 'two', 'three' %} 
{% cycle 'one', 'two', 'three' %} 
{% cycle 'one', 'two', 'three' %} 
{% cycle 'one', 'two', 'three' %} 

will result in

one
two
three
one

If no name is supplied for the cycle group then its assumed that multiple calls with the same parameters are one group.

If you want to have total control over cycle groups you can optionally specify the name of the group. This can even be a variable.

{% cycle 'group 1': 'one', 'two', 'three' %} 
{% cycle 'group 1': 'one', 'two', 'three' %} 
{% cycle 'group 2': 'one', 'two', 'three' %} 
{% cycle 'group 2': 'one', 'two', 'three' %} 

will result in

one
two 
one
two

For loops

Liquid allows for loops over collections:

  {% for item in array %} 
    {{ item }}
  {% endfor %} 

During every for loop there are following helper variables available for extra styling needs:

 forloop.length      # => length of the entire for loop
 forloop.index       # => index of the current iteration 
 forloop.index0        # => index of the current iteration (zero based) 
 forloop.rindex     # => how many items are still left?
 forloop.rindex0   # => how many items are still left? (zero based)
 forloop.first        # => is this the first iteration?
 forloop.last         # => is this the last iternation? 

There are several attributes you can use to influence which items you receive in your loop

limit lets you restrict how many items you get offset lets you start the collection with the nth item.

  # array = [1,2,3,4,5,6]
  {% for item in array limit:2 offset:2 %} 
    {{ item }}
  {% endfor %} 
  # results in 3,4 

Installing Mephisto

Posted by rick | 0 comments

Downloading Mephisto

There are two main ways to download Mephisto: either download the latest release as a tar.gz file, or grabbing a version from Subversion. The Download page has more info on the various versions available in subversion.

Next, you have to make sure your host is setup to run rails apps. This varies from host to host, so I’ll leave this step up to you. The only gem that Mephisto needs is tzinfo (which is included with the tar.gz download). If you don’t have this, read Installing Mephisto Without Required Gems. Mephisto will use RMagick for asset thumbnails if it is available, but will function just fine without it.

Quick Installation

  1. Create a database named mephisto (or one of your choosing).
  2. Copy config/database.example.yml to config/database.yml
  3. Edit database.yml and set your database credentials.
  4. Upload the entire mephisto directory to your webserver.
  5. Make sure you upload the tzinfo gem (see above) with the directory, or that your host has it preinstalled.
  6. Run rake db:bootstrap from a terminal of some sorts (use rake db:bootstrap RAILS_ENV=production to be sure you’ve bootstrapped the production database.)
  7. Login to your administration at http://domain.com/admin with the username: admin and password: test

The actual web server installation varies from host to host. Mephisto should install like any other Rails app, however. The wiki has some directions for specific hosts.

Upgrading (with a downloaded copy)

When upgrading, it’s usually best to install the new copy of Mephisto in a completely separate directory. This way if something happens to go wrong, you can restore the database and point the web server to the old directory to continue using the older version.

  1. Download Mephisto into a separate directory
  2. Copy config/database.yml, public/assets, and /themes to the new installation. Also be sure to copy any other customized files you may have (such as config/environment.rb possibly).
  3. Backup your database just in case.
  4. Run rake db:migrate RAILS_ENV=production to make any necessary changes to the database. This will affect your current site’s database, so either take it offline, or perform this step on a secondary database.
  5. Reconfigure your web server to point to the new application.

Upgrading (with a subversion working copy)

  1. Update from the latest svn
  2. Backup your database just in case.
  3. Run rake db:migrate RAILS_ENV=production to make any necessary changes to the database. This will affect your current site’s database, so either take it offline, or perform this step on a secondary database.
  4. Restart Mephisto and your web server if needed.

New Mephisto Docs

Posted by rick | 0 comments

Instead of relying on a 3rd party wiki to provide documentation, I’m creating an official set of Mephisto documentation.

What is Mephisto?

Latest Release

0.8 (Drax)

Community

About Mephisto

Mephisto was baked to golden perfection by Rick Olson(Development) and Justin Palmer(UI/Design) with contributions from a bunch of cool people.

railsmachine
Click here to lend your support to: Support Mephisto!!!! and make a donation at www.pledgie.com !