views:

196

answers:

1

I have a config file full of this....

   - if current_page.include? "test_string_one"
      - @total_index = 3
      - @next_location = '../random_string/page0.html'
      - @next_name = 'title 2'

    - if current_page.include? "test_string_two"
      - @total_index = 10
      - @next_location = '../another_random_string/page0.html'
      - @next_name = 'title 3'

Is there a cleaner way of writing this? Using Staticmatic.

I see there are filters available in haml. Should all this be in :ruby filter?

+1  A: 

This code would be best in a helper.

it might look like this:

module SomeHelper

  def page_options
    @page_options ||= begin
      options = {}

      if current_page.include? "test_string_one"
         options[:total_index] = 3
         options[:next_location] = '../random_string/page0.html'
         options[:next_name] = 'title 2'
      elsif current_page.include? "test_string_two"
         options[:total_index] = 10
         options[:next_location] = '../another_random_string/page0.html'
         options[:next_name] = 'title 3'
      end

      options
    end

  end

end

Then, in each page you need it, you could access the options like this: page_options[:total_index]

nicholaides
Seem to be coming up with an error - I've saved htis file as page_helper.rb in helpers - staticmatic/mixins/helpers.rb:13:in `load_helper': (eval):1:in `load_helper': uninitialized constant Haml::Helpers::PageHelper (NameError)
Dr. Frankenstein
That's because SomeHelper should be saved as some_helper.rb in helpers
Dr. Frankenstein