you are on my articles page.

Basic Ruby programming for frontender

  • June 11th, 2011
  • posted at 4:31 pm
  • by ivana

I am writing this post to help myself during coding for SliceCraft’s projects. I actually been wanting to write this post since everytime I run into this “oh-how-I-solved-this” moment, which is pretty often since am super lame.

CASE 1: Body class

// Giving a body class to every page
// page_classes == nameofthefileWITHOUTdotHTML
%body{:class => page_classes}

Let’s get more specific now, what if I ONLY want to have a class name on the index for example – I mean, I just need it there anyway! Sure, here it is:

%body{:class => (request.path_info.include?('index') || request.path_info == '/') ? 'index' : nil}

CASE 2: Show this only on certain page(s)

// Show this ONLY on index page
- if request.path_info.include?('index') || request.path_info == '/'
  %section#signup
  put the code here

CASE 3: Looping
The goal is to make:
- an ordered list
- with several list items(with ordered numbers)
- random positioning on each of the list item

// [10, 2, 4, 10, 7, 4] == #{val}
%ol#chart
  - [10, 2, 4, 10, 7, 4].each_with_index do |val, i|
    %li{:style => "left: #{val}px"}
      %span.num= i+1
      This is the text

Ok – this is it for now. More coming…