haml语法-编写此代码的更好方法? [英] haml syntax - better way of writing this?

查看:142
本文介绍了haml语法-编写此代码的更好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

必须有一种更好的方式来编写此代码-我只是不确定如何(使用 staticmatic )-

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

推荐答案

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

这篇关于haml语法-编写此代码的更好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆