Dr. Frankenstein
Dr. Frankenstein

Reputation: 4684

haml syntax - better way of writing this?

There must be a better way of writing this- I'm just not sure how (using staticmatic)-

- if current_page.include? "0.html"
  - @current_index = 1
- if current_page.include? "1.html"
  - @current_index = 2
- if current_page.include? "2.html"
  - @current_index = 3
- if current_page.include? "3.html"
  - @current_index = 4
- if current_page.include? "4.html"
  - @current_index = 5
- if current_page.include? "5.html"
  - @current_index = 6
- if current_page.include? "6.html"
  - @current_index = 7
- if current_page.include? "7.html"
  - @current_index = 8
- if current_page.include? "8.html"
  - @current_index = 9
- if current_page.include? "9.html"
  - @current_index = 10
- if current_page.include? "10.html"
  - @current_index = 11
- if current_page.include? "11.html"
  - @current_index = 12

Upvotes: 0

Views: 248

Answers (2)

Natalie Weizenbaum
Natalie Weizenbaum

Reputation: 5964

- @current_index = current_page[/(\d+)\.html/, 1].to_i + 1

Upvotes: 2

user155388
user155388

Reputation: 56

- 0.upto(11) do |n|
  - if current_page.include? "#{n}.html"
    - @current_index = n + 1

Upvotes: 4

Related Questions